File indexing completed on 2024-04-14 14:32:05

0001 //
0002 // C++ Implementation: cbuttoneditor
0003 //
0004 // Description: 
0005 //
0006 /*
0007 Copyright 2008-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 "cbuttoneditor.h"
0024 #include "cscripteditor.h"
0025 
0026 #include <QGridLayout>
0027 #include <QGroupBox>
0028 #include <QHBoxLayout>
0029 #include <QLabel>
0030 #include <QLineEdit>
0031 #include <QTabWidget>
0032 
0033 #include <KIconButton>
0034 #include <KLocalizedString>
0035 
0036 struct cButtonEditor::Private {
0037   QLineEdit *caption, *command, *command2;
0038   KIconButton *icon;
0039   QGroupBox *pushdown;
0040   cScriptEditor *script, *scriptrel;
0041 };
0042 
0043 cButtonEditor::cButtonEditor (QWidget *parent)
0044   : cListEditor (parent)
0045 {
0046   d = new Private;
0047 }
0048 
0049 cButtonEditor::~cButtonEditor ()
0050 {
0051   // the GUI elements will be destroyed automatically
0052   delete d;
0053 }
0054 
0055 void cButtonEditor::createGUI(QWidget *parent)
0056 {
0057   QVBoxLayout *mainLayout = new QVBoxLayout (parent);
0058   QTabWidget *tabs = new QTabWidget (parent);
0059   mainLayout->addWidget (tabs);
0060 
0061   QFrame *basicPage = new QFrame (tabs);
0062   QGridLayout *basicLayout = new QGridLayout (basicPage);
0063   
0064   // caption
0065   QLabel *lbl1 = new QLabel (i18n ("&Caption"), basicPage);
0066   d->caption = new QLineEdit (basicPage);
0067   lbl1->setBuddy (d->caption);
0068   d->caption->setWhatsThis( i18n ("Caption of this button."));
0069 
0070   //command
0071   QLabel *lblc1 = new QLabel (i18n ("Co&mmand"), basicPage);
0072   d->command = new QLineEdit (basicPage);
0073   lblc1->setBuddy (d->command);
0074   d->command->setWhatsThis( i18n ("Command that will be executed if you click on the button. "
0075       "Note that you can enter multiple commands here (separated by semi-colons, "
0076       "or another character defined in <b>global settings</b>)."));
0077   
0078  //icon
0079   QLabel *il = new QLabel ("&Icon", basicPage);
0080   d->icon = new KIconButton (basicPage);
0081   d->icon->setIconSize (32);
0082   il->setBuddy (d->icon);
0083   d->icon->setWhatsThis (i18n ("Icon displayed on the button toolbar."));
0084 
0085   // pushdown
0086   d->pushdown = new QGroupBox ("&Push-down button", basicPage);
0087   d->pushdown->setCheckable (true);
0088   QHBoxLayout *pushdownlayout = new QHBoxLayout (d->pushdown);
0089 
0090   //command2
0091   QLabel *lblc2 = new QLabel (i18n ("&Un-press command"), d->pushdown);
0092   d->command2 = new QLineEdit (d->pushdown);
0093   lblc2->setBuddy (d->command2);
0094   d->command2->setWhatsThis (i18n ("Command that will be executed if you click on the push-down "
0095         "button while it's pushed down."));
0096   pushdownlayout->addWidget (lblc2);
0097   pushdownlayout->addWidget (d->command2);
0098  
0099   QWidget *commonEditor = createCommonAttribEditor (basicPage);
0100 
0101   //place'em there!
0102   basicLayout->setSpacing (5);
0103   basicLayout->addWidget (lbl1, 0, 0);
0104   basicLayout->addWidget (d->caption, 0, 1);
0105   basicLayout->addWidget (lblc1, 1, 0);
0106   basicLayout->addWidget (d->command, 1, 1);
0107   basicLayout->addWidget (il, 2, 0);
0108   basicLayout->addWidget (d->icon, 2, 1);
0109   basicLayout->addWidget (d->pushdown, 3, 0, 1, 2);
0110   basicLayout->addWidget (commonEditor, 4, 0, 1, 2);
0111 
0112   // the Script tabs
0113   QFrame *scriptPage = new QFrame (tabs);
0114   QVBoxLayout *scriptlayout = new QVBoxLayout (scriptPage);
0115   d->script = new cScriptEditor (scriptPage);
0116   scriptlayout->addWidget (d->script);
0117 
0118   QFrame *scriptPage2 = new QFrame (tabs);
0119   QVBoxLayout *scriptlayout2 = new QVBoxLayout (scriptPage2);
0120   d->scriptrel = new cScriptEditor (scriptPage2);
0121   scriptlayout2->addWidget (d->scriptrel);
0122 
0123   tabs->addTab (basicPage, i18n ("&General"));
0124   tabs->addTab (scriptPage, i18n ("&Script"));
0125   tabs->addTab (scriptPage2, i18n ("Script when &released"));
0126 }
0127 
0128 void cButtonEditor::fillGUI (const cListObjectData &data)
0129 {
0130   // Common attributes
0131   fillCommonAttribEditor (data);
0132 
0133   d->command->setText (data.strValue ("command"));
0134   d->command2->setText (data.strValue ("command-released"));
0135   d->caption->setText (data.strValue ("caption"));
0136   d->icon->setIcon (data.strValue ("icon"));
0137   d->pushdown->setChecked (data.boolValue ("pushdown"));
0138 
0139   // Script
0140   d->script->setText (data.strValue ("script"));
0141   d->scriptrel->setText (data.strValue ("script-release"));
0142 }
0143 
0144 void cButtonEditor::getDataFromGUI (cListObjectData *data)
0145 {
0146   // Comon attributes
0147   getDataFromCommonAttribEditor (data);
0148 
0149   data->strValues["command"] = d->command->text();
0150   data->strValues["command-released"] = d->command2->text();
0151   data->strValues["caption"] = d->caption->text();
0152   data->strValues["icon"] = d->icon->icon();
0153   data->boolValues["pushdown"] = d->pushdown->isChecked();
0154 
0155   // Script
0156   data->strValues["script"] = d->script->text();
0157   data->strValues["script-release"] = d->scriptrel->text();
0158 }
0159 
0160 #include "moc_cbuttoneditor.cpp"