File indexing completed on 2024-03-24 04:05:25
0001 // 0002 // C++ Implementation: ctimereditor 0003 // 0004 // Description: timer editor 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 "ctimereditor.h" 0024 0025 #include "cactionmanager.h" 0026 #include "cscripteditor.h" 0027 0028 #include <QCheckBox> 0029 #include <QGridLayout> 0030 #include <QGroupBox> 0031 #include <QLabel> 0032 #include <QLineEdit> 0033 #include <QSpinBox> 0034 #include <QTabWidget> 0035 0036 #include <KLocalizedString> 0037 0038 struct cTimerEditor::Private { 0039 QLineEdit *cmd, *advcmd; 0040 QSpinBox *interval, *advinterval; 0041 QCheckBox *chksingleshot, *chkadvance; 0042 cScriptEditor *script; 0043 }; 0044 0045 cTimerEditor::cTimerEditor (QWidget *parent) 0046 : cListEditor (parent) 0047 { 0048 d = new Private; 0049 } 0050 0051 cTimerEditor::~cTimerEditor () 0052 { 0053 // the GUI elements will be destroyed automatically 0054 delete d; 0055 } 0056 0057 void cTimerEditor::createGUI(QWidget *parent) 0058 { 0059 QVBoxLayout *mainLayout = new QVBoxLayout (parent); 0060 QTabWidget *tabs = new QTabWidget (parent); 0061 mainLayout->addWidget (tabs); 0062 0063 QFrame *basicPage = new QFrame (tabs); 0064 QGridLayout *basicLayout = new QGridLayout (basicPage); 0065 0066 //command 0067 QLabel *lbl1 = new QLabel (i18n ("&Command"), basicPage); 0068 d->cmd = new QLineEdit (basicPage); 0069 lbl1->setBuddy (d->cmd); 0070 d->cmd->setWhatsThis( i18n ("Command that will be executed on each tick.\n" 0071 "Command can include aliases, script calls and similar stuff.")); 0072 0073 //interval 0074 QLabel *lbl2 = new QLabel (i18n ("&Interval"), basicPage); 0075 d->interval = new QSpinBox (basicPage); 0076 d->interval->setRange(1, 3600); 0077 d->interval->setSuffix (i18n (" secs")); 0078 lbl2->setBuddy (d->interval); 0079 0080 //single-shot 0081 d->chksingleshot = new QCheckBox (i18n ("&Single-shot"), basicPage); 0082 d->chksingleshot->setWhatsThis( i18n ("When enabled, the timer will only be executed once and then disabled.")); 0083 0084 d->chkadvance = new QCheckBox (i18n ("&Run a command in advance"), basicPage); 0085 d->chkadvance->setWhatsThis( i18n ("Run a command a given number of seconds before each timer tick.")); 0086 0087 QGroupBox *grpadvance = new QGroupBox (i18n ("Advance command"), basicPage); 0088 QGridLayout *advancelayout = new QGridLayout (grpadvance); 0089 0090 QLabel *lbl3 = new QLabel (i18n ("&Seconds before tick"), grpadvance); 0091 d->advinterval = new QSpinBox (grpadvance); 0092 d->advinterval->setRange(1, 180); 0093 d->advinterval->setMaximum (180); 0094 d->advinterval->setSuffix (i18n (" secs")); 0095 lbl3->setBuddy (d->interval); 0096 0097 QLabel *lbl4 = new QLabel (i18n ("C&ommand"), basicPage); 0098 d->advcmd = new QLineEdit (basicPage); 0099 lbl4->setBuddy (d->advcmd); 0100 d->cmd->setWhatsThis( i18n ("Command that will be executed the specified time before each tick.\n" 0101 "Command can include aliases, script calls and similar stuff.")); 0102 0103 advancelayout->addWidget (lbl3, 0, 0); 0104 advancelayout->addWidget (d->advinterval, 0, 1); 0105 advancelayout->addWidget (lbl4, 1, 0); 0106 advancelayout->addWidget (d->advcmd, 1, 1); 0107 0108 QWidget *commonEditor = createCommonAttribEditor (basicPage); 0109 0110 //place'em there! 0111 basicLayout->setSpacing (5); 0112 basicLayout->addWidget (lbl1, 0, 0); 0113 basicLayout->addWidget (d->cmd, 0, 1); 0114 basicLayout->addWidget (lbl2, 1, 0); 0115 basicLayout->addWidget (d->interval, 1, 1); 0116 basicLayout->addWidget (d->chksingleshot, 2, 0, 1, 2); 0117 basicLayout->addWidget (d->chkadvance, 3, 0, 1, 2); 0118 basicLayout->addWidget (grpadvance, 4, 0, 1, 2); 0119 basicLayout->addWidget (commonEditor, 5, 0, 1, 2); 0120 0121 connect (d->chkadvance, &QCheckBox::toggled, grpadvance, &QGroupBox::setEnabled); 0122 // initial state 0123 d->chkadvance->setChecked (false); 0124 grpadvance->setEnabled (false); 0125 0126 // the Script tab 0127 QFrame *scriptPage = new QFrame (tabs); 0128 QVBoxLayout *scriptlayout = new QVBoxLayout (scriptPage); 0129 d->script = new cScriptEditor (scriptPage); 0130 scriptlayout->addWidget (d->script); 0131 0132 tabs->addTab (basicPage, i18n ("&General")); 0133 tabs->addTab (scriptPage, i18n ("&Script")); 0134 } 0135 0136 void cTimerEditor::fillGUI (const cListObjectData &data) 0137 { 0138 // Common attributes 0139 fillCommonAttribEditor (data); 0140 0141 d->cmd->setText (data.strValue ("command")); 0142 d->interval->setValue (data.intValue ("interval")); 0143 d->chksingleshot->setChecked (data.boolValue ("single-shot")); 0144 d->chkadvance->setChecked (data.boolValue ("advance")); 0145 d->advcmd->setText (data.strValue ("command-advance")); 0146 d->advinterval->setValue (data.intValue ("advance-seconds")); 0147 // Script 0148 d->script->setText (data.strValue ("script")); 0149 } 0150 0151 void cTimerEditor::getDataFromGUI (cListObjectData *data) 0152 { 0153 // Comon attributes 0154 getDataFromCommonAttribEditor (data); 0155 0156 data->strValues["command"] = d->cmd->text(); 0157 data->intValues["interval"] = d->interval->value(); 0158 data->boolValues["single-shot"] = d->chksingleshot->isChecked(); 0159 data->boolValues["advance"] = d->chkadvance->isChecked(); 0160 data->strValues["command-advance"] = d->advcmd->text(); 0161 data->intValues["advance-seconds"] = d->advinterval->value(); 0162 // Script 0163 data->strValues["script"] = d->script->text(); 0164 } 0165 0166 #include "moc_ctimereditor.cpp"