File indexing completed on 2024-03-24 04:05:22

0001 //
0002 // C++ Implementation: cgaugeeditor
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 "cgaugeeditor.h"
0024 
0025 #include "cactionmanager.h"
0026 
0027 #include <QCheckBox>
0028 #include <QGridLayout>
0029 #include <QLabel>
0030 #include <QLineEdit>
0031 #include <QRegExpValidator>
0032 
0033 #include <kcolorbutton.h>
0034 #include <KLocalizedString>
0035 
0036 struct cGaugeEditor::Private {
0037   QLineEdit *var, *maxvar, *caption;
0038   KColorButton *btcolor;
0039 };
0040 
0041 cGaugeEditor::cGaugeEditor (QWidget *parent)
0042   : cListEditor (parent)
0043 {
0044   d = new Private;
0045 }
0046 
0047 cGaugeEditor::~cGaugeEditor ()
0048 {
0049   // the GUI elements will be destroyed automatically
0050   delete d;
0051 }
0052 
0053 void cGaugeEditor::createGUI(QWidget *parent)
0054 {
0055   QGridLayout *layout = new QGridLayout (parent);
0056   
0057   //variable
0058   QLabel *lbl1 = new QLabel (i18n ("&Variable name"), parent);
0059   d->var = new QLineEdit (parent);
0060   d->var->setValidator (new QRegExpValidator (QRegExp("^[0-9A-Za-z_ ]+$"), this));
0061   lbl1->setBuddy (d->var);
0062   d->var->setWhatsThis( i18n ("Variable displayed by this gauge."));
0063   
0064   //max variable
0065   QLabel *lbl2 = new QLabel (i18n ("&Max. variable (optional)"), parent);
0066   d->maxvar = new QLineEdit (parent);
0067   d->maxvar->setValidator (new QRegExpValidator (QRegExp("^[0-9A-Za-z_ ]+$"), this));
0068   lbl2->setBuddy (d->maxvar);
0069   d->maxvar->setWhatsThis( i18n ("Variable holding the maximum value (default=100)"));
0070   
0071   //caption
0072   QLabel *lbl3 = new QLabel (i18n ("&Caption"), parent);
0073   d->caption = new QLineEdit (parent);
0074   lbl3->setBuddy (d->caption);
0075   d->caption->setWhatsThis( i18n ("Caption shown next to variable value."));
0076 
0077   // color
0078   QLabel *lbl4 = new QLabel (i18n ("&Color"), parent);
0079   d->btcolor = new KColorButton (Qt::white, parent);
0080   lbl4->setBuddy (d->btcolor);
0081   d->btcolor->setWhatsThis( i18n ("Color used to paint this gauge."));
0082 
0083   QWidget *commonEditor = createCommonAttribEditor (parent);
0084 
0085   //place'em there!
0086   layout->setSpacing (5);
0087   layout->addWidget (lbl1, 0, 0);
0088   layout->addWidget (d->var, 0, 1);
0089   layout->addWidget (lbl2, 1, 0);
0090   layout->addWidget (d->maxvar, 1, 1);
0091   layout->addWidget (lbl3, 2, 0);
0092   layout->addWidget (d->caption, 2, 1);
0093   layout->addWidget (lbl4, 3, 0);
0094   layout->addWidget (d->btcolor, 3, 1);
0095   layout->addWidget (commonEditor, 4, 0, 1, 2);
0096 }
0097 
0098 void cGaugeEditor::fillGUI (const cListObjectData &data)
0099 {
0100   // Common attributes
0101   fillCommonAttribEditor (data);
0102 
0103   d->var->setText (data.strValue ("variable"));
0104   d->maxvar->setText (data.strValue ("max-variable"));
0105   d->caption->setText (data.strValue ("caption"));
0106   int color = data.intValue ("color");
0107   QColor c;
0108   c.setBlue (color % 256);
0109   color /= 256;
0110   c.setGreen (color % 256);
0111   color /= 256;
0112   c.setRed (color % 256);
0113   d->btcolor->setColor (c);
0114 }
0115 
0116 void cGaugeEditor::getDataFromGUI (cListObjectData *data)
0117 {
0118   // Comon attributes
0119   getDataFromCommonAttribEditor (data);
0120 
0121   data->strValues["variable"] = d->var->text();
0122   data->strValues["max-variable"] = d->maxvar->text();
0123   data->strValues["caption"] = d->caption->text();
0124   QColor c = d->btcolor->color ();
0125   data->intValues["color"] = c.red() * 256 * 256 + c.green() * 256 + c.blue();
0126 }
0127 
0128 #include "moc_cgaugeeditor.cpp"