File indexing completed on 2024-03-24 04:05:24
0001 // C++ Implementation: cstatusvareditor 0002 // 0003 // Description: 0004 // 0005 /* 0006 Copyright 2002-2011 Tomas Mecir <kmuddy@kmuddy.com> 0007 0008 This program is free software; you can redistribute it and/or 0009 modify it under the terms of the GNU General Public License as 0010 published by the Free Software Foundation; either version 2 of 0011 the License, or (at your option) any later version. 0012 0013 This program is distributed in the hope that it will be useful, 0014 but WITHOUT ANY WARRANTY; without even the implied warranty of 0015 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0016 GNU General Public License for more details. 0017 0018 You should have received a copy of the GNU General Public License 0019 along with this program. If not, see <http://www.gnu.org/licenses/>. 0020 */ 0021 0022 #include "cstatusvareditor.h" 0023 0024 #include "cactionmanager.h" 0025 0026 #include <QCheckBox> 0027 #include <QGridLayout> 0028 #include <QLabel> 0029 #include <QLineEdit> 0030 #include <QRegExpValidator> 0031 0032 #include <KLocalizedString> 0033 0034 struct cStatusVarEditor::Private { 0035 QLineEdit *var, *maxvar, *caption; 0036 QCheckBox *chkpercent; 0037 }; 0038 0039 cStatusVarEditor::cStatusVarEditor (QWidget *parent) 0040 : cListEditor (parent) 0041 { 0042 d = new Private; 0043 } 0044 0045 cStatusVarEditor::~cStatusVarEditor () 0046 { 0047 // the GUI elements will be destroyed automatically 0048 delete d; 0049 } 0050 0051 void cStatusVarEditor::createGUI(QWidget *parent) 0052 { 0053 QGridLayout *layout = new QGridLayout (parent); 0054 0055 //variable 0056 QLabel *lbl1 = new QLabel (i18n ("&Variable name"), parent); 0057 d->var = new QLineEdit (parent); 0058 d->var->setValidator (new QRegExpValidator (QRegExp("^[0-9A-Za-z_ ]+$"), this)); 0059 lbl1->setBuddy (d->var); 0060 d->var->setWhatsThis( i18n ("Variable displayed by this status variable.")); 0061 0062 //max variable 0063 QLabel *lbl2 = new QLabel (i18n ("&Max. variable (optional)"), parent); 0064 d->maxvar = new QLineEdit (parent); 0065 d->maxvar->setValidator (new QRegExpValidator (QRegExp("^[0-9A-Za-z_ ]+$"), this)); 0066 lbl2->setBuddy (d->maxvar); 0067 d->maxvar->setWhatsThis( i18n ("Variable holding the maximum value (default=100)")); 0068 0069 //caption 0070 QLabel *lbl3 = new QLabel (i18n ("&Caption"), parent); 0071 d->caption = new QLineEdit (parent); 0072 lbl3->setBuddy (d->caption); 0073 d->caption->setWhatsThis( i18n ("Caption shown next to variable value.")); 0074 0075 //percent 0076 d->chkpercent = new QCheckBox (i18n ("&Show as percentage"), parent); 0077 d->chkpercent->setWhatsThis( i18n ("When enabled, this variable will be shown as percentage. " 0078 "(of max.value, or of 100 if no max.value given)")); 0079 0080 QWidget *commonEditor = createCommonAttribEditor (parent); 0081 0082 //place'em there! 0083 layout->setSpacing (5); 0084 layout->addWidget (lbl1, 0, 0); 0085 layout->addWidget (d->var, 0, 1); 0086 layout->addWidget (lbl2, 1, 0); 0087 layout->addWidget (d->maxvar, 1, 1); 0088 layout->addWidget (lbl3, 2, 0); 0089 layout->addWidget (d->caption, 2, 1); 0090 layout->addWidget (d->chkpercent, 3, 0, 1, 2); 0091 layout->addWidget (commonEditor, 4, 0, 1, 2); 0092 } 0093 0094 void cStatusVarEditor::fillGUI (const cListObjectData &data) 0095 { 0096 // Common attributes 0097 fillCommonAttribEditor (data); 0098 0099 d->var->setText (data.strValue ("variable")); 0100 d->maxvar->setText (data.strValue ("max-variable")); 0101 d->caption->setText (data.strValue ("caption")); 0102 d->chkpercent->setChecked (data.boolValue ("percentage")); 0103 } 0104 0105 void cStatusVarEditor::getDataFromGUI (cListObjectData *data) 0106 { 0107 // Comon attributes 0108 getDataFromCommonAttribEditor (data); 0109 0110 data->strValues["variable"] = d->var->text(); 0111 data->strValues["max-variable"] = d->maxvar->text(); 0112 data->strValues["caption"] = d->caption->text(); 0113 data->boolValues["percentage"] = d->chkpercent->isChecked(); 0114 } 0115 0116 #include "moc_cstatusvareditor.cpp"