kformula

formulastring.cpp
1/* This file is part of the KDE project
2 Copyright (C) 2002 Ulrich Kuettler <ulrich.kuettler@mailbox.tu-dresden.de>
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License as published by the Free Software Foundation; either
7 version 2 of the License, or (at your option) any later version.
8
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18*/
19
20#include <tqlabel.h>
21#include <tqlayout.h>
22#include <tqstringlist.h>
23#include <tqtextedit.h>
24#include <tqtooltip.h>
25#include <tqvariant.h>
26#include <tqwhatsthis.h>
27
28#include <tdeapplication.h>
29#include <tdemessagebox.h>
30#include <tdelocale.h>
31#include <kstdguiitem.h>
32#include <kpushbutton.h>
33
34#include "formulastring.h"
35#include "kformula_view.h"
36
37
38FormulaString::FormulaString( KFormulaPartView* parent, const char* name, bool modal, WFlags fl )
39 : TQDialog( parent, name, modal, fl ), view( parent )
40{
41 if ( !name )
42 setName( "FormulaString" );
43 resize( 511, 282 );
44 setCaption( i18n( "Formula String" ) );
45 setSizeGripEnabled( true );
46 TQVBoxLayout* FormulaStringLayout = new TQVBoxLayout( this, 11, 6, "FormulaStringLayout");
47
48 textWidget = new TQTextEdit( this, "textWidget" );
49 FormulaStringLayout->addWidget( textWidget );
50
51 TQHBoxLayout* Layout2 = new TQHBoxLayout( 0, 0, 6, "Layout2");
52 TQSpacerItem* spacer = new TQSpacerItem( 20, 20, TQSizePolicy::Expanding, TQSizePolicy::Minimum );
53 Layout2->addItem( spacer );
54
55 position = new TQLabel( this, "position" );
56 position->setText( trUtf8( "1:1" ) );
57 Layout2->addWidget( position );
58 FormulaStringLayout->addLayout( Layout2 );
59
60 TQHBoxLayout* Layout1 = new TQHBoxLayout( 0, 0, 6, "Layout1");
61
62 buttonHelp = new KPushButton( KStdGuiItem::help(), this, "buttonHelp" );
63 buttonHelp->setAccel( 4144 );
64 buttonHelp->setAutoDefault( true );
65 Layout1->addWidget( buttonHelp );
66 spacer = new TQSpacerItem( 20, 20, TQSizePolicy::Expanding, TQSizePolicy::Minimum );
67 Layout1->addItem( spacer );
68
69 buttonOk = new KPushButton( KStdGuiItem::ok(), this, "buttonOk" );
70 buttonOk->setAccel( 0 );
71 buttonOk->setAutoDefault( true );
72 buttonOk->setDefault( true );
73 Layout1->addWidget( buttonOk );
74
75 buttonCancel = new KPushButton( KStdGuiItem::cancel(), this, "buttonCancel" );
76 buttonCancel->setAccel( 0 );
77 buttonCancel->setAutoDefault( true );
78 Layout1->addWidget( buttonCancel );
79 FormulaStringLayout->addLayout( Layout1 );
80
81 // signals and slots connections
82 connect( buttonOk, TQ_SIGNAL( clicked() ), this, TQ_SLOT( accept() ) );
83 connect( buttonCancel, TQ_SIGNAL( clicked() ), this, TQ_SLOT( reject() ) );
84 connect( buttonHelp, TQ_SIGNAL(clicked() ), this, TQ_SLOT( helpButtonClicked() ) );
85 connect( textWidget, TQ_SIGNAL( cursorPositionChanged( int, int ) ),
86 this, TQ_SLOT( cursorPositionChanged( int, int ) ) );
87}
88
89/*
90 * Destroys the object and frees any allocated resources
91 */
92FormulaString::~FormulaString()
93{
94 // no need to delete child widgets, TQt does it all for us
95}
96
97void FormulaString::accept()
98{
99 TQStringList errorList = view->readFormulaString( textWidget->text() );
100 if ( errorList.count() == 0 ) {
101 TQDialog::accept();
102 }
103 else {
104 KMessageBox::sorry( this, errorList.join( "\n" ), i18n( "Parser Error" ) );
105 }
106}
107
108void FormulaString::helpButtonClicked()
109{
110 kapp->invokeHelp( "formula-strings", "kformula" );
111}
112
113void FormulaString::cursorPositionChanged( int para, int pos )
114{
115 position->setText( TQString( "%1:%2" ).arg( para+1 ).arg( pos+1 ) );
116}
117
118#include "formulastring.moc"
The parts view.