00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include <qlabel.h>
00021 #include <qlayout.h>
00022 #include <qstringlist.h>
00023 #include <qtextedit.h>
00024 #include <qtooltip.h>
00025 #include <qvariant.h>
00026 #include <qwhatsthis.h>
00027
00028 #include <kapplication.h>
00029 #include <kmessagebox.h>
00030 #include <klocale.h>
00031 #include <kstdguiitem.h>
00032 #include <kpushbutton.h>
00033
00034 #include "formulastring.h"
00035 #include "kformula_view.h"
00036
00037
00038 FormulaString::FormulaString( KFormulaPartView* parent, const char* name, bool modal, WFlags fl )
00039 : QDialog( parent, name, modal, fl ), view( parent )
00040 {
00041 if ( !name )
00042 setName( "FormulaString" );
00043 resize( 511, 282 );
00044 setCaption( i18n( "Formula String" ) );
00045 setSizeGripEnabled( TRUE );
00046 QVBoxLayout* FormulaStringLayout = new QVBoxLayout( this, 11, 6, "FormulaStringLayout");
00047
00048 textWidget = new QTextEdit( this, "textWidget" );
00049 FormulaStringLayout->addWidget( textWidget );
00050
00051 QHBoxLayout* Layout2 = new QHBoxLayout( 0, 0, 6, "Layout2");
00052 QSpacerItem* spacer = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
00053 Layout2->addItem( spacer );
00054
00055 position = new QLabel( this, "position" );
00056 position->setText( trUtf8( "1:1" ) );
00057 Layout2->addWidget( position );
00058 FormulaStringLayout->addLayout( Layout2 );
00059
00060 QHBoxLayout* Layout1 = new QHBoxLayout( 0, 0, 6, "Layout1");
00061
00062 buttonHelp = new KPushButton( KStdGuiItem::help(), this, "buttonHelp" );
00063 buttonHelp->setAccel( 4144 );
00064 buttonHelp->setAutoDefault( TRUE );
00065 Layout1->addWidget( buttonHelp );
00066 spacer = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
00067 Layout1->addItem( spacer );
00068
00069 buttonOk = new KPushButton( KStdGuiItem::ok(), this, "buttonOk" );
00070 buttonOk->setAccel( 0 );
00071 buttonOk->setAutoDefault( TRUE );
00072 buttonOk->setDefault( TRUE );
00073 Layout1->addWidget( buttonOk );
00074
00075 buttonCancel = new KPushButton( KStdGuiItem::cancel(), this, "buttonCancel" );
00076 buttonCancel->setAccel( 0 );
00077 buttonCancel->setAutoDefault( TRUE );
00078 Layout1->addWidget( buttonCancel );
00079 FormulaStringLayout->addLayout( Layout1 );
00080
00081
00082 connect( buttonOk, SIGNAL( clicked() ), this, SLOT( accept() ) );
00083 connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( reject() ) );
00084 connect( buttonHelp, SIGNAL(clicked() ), this, SLOT( helpButtonClicked() ) );
00085 connect( textWidget, SIGNAL( cursorPositionChanged( int, int ) ),
00086 this, SLOT( cursorPositionChanged( int, int ) ) );
00087 }
00088
00089
00090
00091
00092 FormulaString::~FormulaString()
00093 {
00094
00095 }
00096
00097 void FormulaString::accept()
00098 {
00099 QStringList errorList = view->readFormulaString( textWidget->text() );
00100 if ( errorList.count() == 0 ) {
00101 QDialog::accept();
00102 }
00103 else {
00104 KMessageBox::sorry( this, errorList.join( "\n" ), i18n( "Parser Error" ) );
00105 }
00106 }
00107
00108 void FormulaString::helpButtonClicked()
00109 {
00110 kapp->invokeHelp( "formula-strings", "kformula" );
00111 }
00112
00113 void FormulaString::cursorPositionChanged( int para, int pos )
00114 {
00115 position->setText( QString( "%1:%2" ).arg( para+1 ).arg( pos+1 ) );
00116 }
00117
00118 #include "formulastring.moc"