kformula

formulastring.cc

00001 /* This file is part of the KDE project
00002    Copyright (C) 2002 Ulrich Kuettler <ulrich.kuettler@mailbox.tu-dresden.de>
00003 
00004    This library is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU Library General Public
00006    License as published by the Free Software Foundation; either
00007    version 2 of the License, or (at your option) any later version.
00008 
00009    This library is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012    Library General Public License for more details.
00013 
00014    You should have received a copy of the GNU Library General Public License
00015    along with this library; see the file COPYING.LIB.  If not, write to
00016    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00017  * Boston, MA 02110-1301, USA.
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     // signals and slots connections
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  *  Destroys the object and frees any allocated resources
00091  */
00092 FormulaString::~FormulaString()
00093 {
00094     // no need to delete child widgets, Qt does it all for us
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"
KDE Home | KDE Accessibility Home | Description of Access Keys