File indexing completed on 2024-12-08 06:46:43

0001 //
0002 // C++ Implementation: cvartriggereditor
0003 //
0004 // Description: 
0005 //
0006 /*
0007 Copyright 2002-2011 Tomas Mecir <kmuddy@kmuddy.com>
0008 
0009 This program is free software; you can redistribute it and/or
0010 modify it under the terms of the GNU General Public License as
0011 published by the Free Software Foundation; either version 2 of 
0012 the License, or (at your option) any later version.
0013 
0014 This program is distributed in the hope that it will be useful,
0015 but WITHOUT ANY WARRANTY; without even the implied warranty of
0016 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0017 GNU General Public License for more details.
0018 
0019 You should have received a copy of the GNU General Public License
0020 along with this program.  If not, see <http://www.gnu.org/licenses/>.
0021 */
0022 
0023 #include "cvartriggereditor.h"
0024 
0025 #include "cactionmanager.h"
0026 
0027 #include <QGridLayout>
0028 #include <QLabel>
0029 #include <QRegExpValidator>
0030 
0031 #include <klineedit.h>
0032 #include <KLocalizedString>
0033 #include <ktextedit.h>
0034 
0035 struct cVarTriggerEditor::Private {
0036   KLineEdit *var;
0037   KTextEdit *cmds;
0038 };
0039 
0040 cVarTriggerEditor::cVarTriggerEditor (QWidget *parent)
0041   : cListEditor (parent)
0042 {
0043   d = new Private;
0044 }
0045 
0046 cVarTriggerEditor::~cVarTriggerEditor ()
0047 {
0048   // the GUI elements will be destroyed automatically
0049   delete d;
0050 }
0051 
0052 void cVarTriggerEditor::createGUI(QWidget *parent)
0053 {
0054   QGridLayout *layout = new QGridLayout (parent);
0055   
0056   //variable
0057   QLabel *lbl1 = new QLabel (i18n ("&Variable name"), parent);
0058   d->var = new KLineEdit (parent);
0059   d->var->setValidator (new QRegExpValidator (QRegExp("^[0-9A-Za-z_ ]+$"), this));
0060   lbl1->setBuddy (d->var);
0061   d->var->setWhatsThis( i18n ("Variable name that this trigger will be reacting on."));
0062   
0063   QLabel *lbl2 = new QLabel (i18n ("&Commands"), parent);
0064   d->cmds = new KTextEdit (parent);
0065   lbl2->setBuddy (d->cmds);
0066   d->cmds->setWhatsThis( i18n ("Commands that will be executed when this trigger matches."));
0067 
0068   QWidget *commonEditor = createCommonAttribEditor (parent);
0069 
0070   //place'em there!
0071   layout->setSpacing (5);
0072   layout->addWidget (lbl1, 0, 0);
0073   layout->addWidget (d->var, 0, 1);
0074   layout->addWidget (lbl2, 1, 0);
0075   layout->addWidget (d->cmds, 1, 1);
0076   layout->addWidget (commonEditor, 2, 0, 1, 2);
0077 }
0078 
0079 void cVarTriggerEditor::fillGUI (const cListObjectData &data)
0080 {
0081   // Common attributes
0082   fillCommonAttribEditor (data);
0083 
0084   d->var->setText (data.strValue ("variable"));
0085   QStringList command;
0086   for (int i = 1; i <= data.intValue ("command-count"); ++i)
0087     command << data.strValue ("command-" + QString::number (i));
0088   d->cmds->setPlainText (command.join("\n"));
0089 }
0090 
0091 void cVarTriggerEditor::getDataFromGUI (cListObjectData *data)
0092 {
0093   // Comon attributes
0094   getDataFromCommonAttribEditor (data);
0095 
0096   data->strValues["variable"] = d->var->text();
0097   QStringList cmds = d->cmds->toPlainText().split ("\n");
0098   data->intValues["command-count"] = cmds.size();
0099   QStringList::iterator it;
0100   int i;
0101   for (it = cmds.begin(), i = 1; it != cmds.end(); ++i, ++it)
0102     data->strValues["command-" + QString::number (i)] = *it;
0103 }
0104 
0105 #include "moc_cvartriggereditor.cpp"