2 * KmPlot - a math. function plotter for the KDE-Desktop
4 * Copyright (C) 2004 Fredrik Edemar
7 * This file is part of the KDE Project.
8 * KmPlot is part of the KDE-EDU Project.
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
27 #include <klineedit.h>
29 #include <kmessagebox.h>
30 #include <qpushbutton.h>
33 #include "keditconstant.h"
35 KEditConstant::KEditConstant(XParser
*p
, char &c
, QString
&v
, QWidget
*parent
, const char *name
)
36 : QEditConstant(parent
, name
,Qt::WDestructiveClose
), constant(c
), value(v
), m_parser(p
)
38 if ( constant
!= '0' )
40 txtConstant
->setEnabled(false);
41 txtConstant
->setText(QChar(constant
));
42 txtValue
->setText(value
);
44 txtValue
->selectAll();
46 connect( cmdCancel
, SIGNAL( clicked() ), this, SLOT( deleteLater() ));
47 connect( cmdOK
, SIGNAL( clicked() ), this, SLOT( cmdOK_clicked() ));
51 KEditConstant::~KEditConstant()
55 void KEditConstant::cmdOK_clicked()
57 constant
= txtConstant
->text().at(0).latin1();
58 value
= txtValue
->text();
59 if ( constant
<'A' || constant
>'Z')
61 KMessageBox::error(this, i18n("Please insert a valid constant name between A and Z."));
62 txtConstant
->setFocus();
63 txtConstant
->selectAll();
67 if ( txtConstant
->isEnabled() ) //creating, not edit a constant
70 QValueVector
<Constant
>::iterator it
;
71 for(it
= m_parser
->constant
.begin(); it
!= m_parser
->constant
.end() && !found
;++it
)
73 if ( it
->constant
== constant
)
78 KMessageBox::error(this, i18n("The constant already exists."));
82 (double) m_parser
->eval(value
);
83 if ( m_parser
->parserError() )
86 txtValue
->selectAll();
94 void KEditConstant::txtVariable_lostFocus()
96 txtConstant
->setText( txtConstant
->text().upper() );
99 #include "keditconstant.moc"