moved kdeaccessibility kdeaddons kdeadmin kdeartwork kdebindings kdeedu kdegames...
[kdeedu.git] / kmplot / kmplot / keditconstant.cpp
blobc5d765c74e8694c502fc67a9975c529c1d70c7d0
1 /*
2 * KmPlot - a math. function plotter for the KDE-Desktop
4 * Copyright (C) 2004 Fredrik Edemar
5 * f_edemar@linux.se
6 *
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.
26 #include <kdebug.h>
27 #include <klineedit.h>
28 #include <klocale.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);
43 txtValue->setFocus();
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();
64 return;
67 if ( txtConstant->isEnabled() ) //creating, not edit a constant
69 bool found= false;
70 QValueVector<Constant>::iterator it;
71 for(it = m_parser->constant.begin(); it!= m_parser->constant.end() && !found;++it)
73 if ( it->constant == constant)
74 found = true;
76 if (found)
78 KMessageBox::error(this, i18n("The constant already exists."));
79 return;
82 (double) m_parser->eval(value);
83 if ( m_parser->parserError() )
85 txtValue->setFocus();
86 txtValue->selectAll();
87 return;
90 emit finished();
91 QDialog::accept();
94 void KEditConstant::txtVariable_lostFocus()
96 txtConstant->setText( txtConstant->text().upper() );
99 #include "keditconstant.moc"