1 #include "pirmacroform.h"
2 #include "ui_pirmacroform.h"
4 #include "mainwindow.h"
5 #include "macros/pirmacro.h"
6 #include "macros/pirmacropack.h"
7 #include "macros/pirmacrocommanditem.h"
11 class QTreeWidgetItem;
14 PIRMacroForm::PIRMacroForm(QWidget *parent) :
16 ui(new Ui::PIRMacroForm)
22 PIRMacroForm::PIRMacroForm(
25 ui(new Ui::PIRMacroForm),
33 PIRMacroPack *userPack = mainWindow->getUserPack();
36 if (userPack->childCount())
38 currentMacro = dynamic_cast<PIRMacro *> (userPack->child(0));
41 ui->macroNameLabel->setText(currentMacro->getName());
42 currentMacro->populateList(ui->macroListWidget);
43 ui->addButton->setEnabled(true);
50 SIGNAL(macroChosen(QTreeWidgetItem *)),
52 SLOT(displayMacro(QTreeWidgetItem *)));
56 SIGNAL(newMacroRequested()),
58 SLOT(createNewMacro()));
62 SIGNAL(editMacroRequested(QTreeWidgetItem *)),
64 SLOT(editMacro(QTreeWidgetItem *)));
68 SIGNAL(deleteMacroRequested(QTreeWidgetItem *)),
70 SLOT(deleteMacro(QTreeWidgetItem *)));
72 // Set up the select macro dialog:
73 smd.addPack(mw->getUserPack());
74 smd.addPack(mw->getMultitapPack());
76 // Connect to edit command dialog signals:
80 SIGNAL(deleteCommand()),
82 SLOT(deleteCurrentCommand()));
86 SIGNAL(copyCommand()),
88 SLOT(copyCurrentCommand()));
94 SIGNAL(moveCommandUp()),
96 SLOT(moveCurrentCommandUp()));
100 SIGNAL(moveCommandDown()),
102 SLOT(moveCurrentCommandDown()));
107 PIRMacroForm::~PIRMacroForm()
113 void PIRMacroForm::on_chooseMacroButton_clicked()
115 request = No_Request;
118 // Loop until the user either selects a macro to display,
119 // or makes no request:
120 while (request != No_Request)
124 case DisplayMacro_Request:
125 currentMacro = userRequestMacro;
126 userRequestMacro = 0;
128 ui->macroNameLabel->setText(currentMacro->getName());
130 // Turn on the "new" button
131 ui->addButton->setEnabled(true);
133 currentMacro->populateList(ui->macroListWidget);
137 case NewMacro_Request:
139 if (emd.exec() == QDialog::Accepted)
141 // Create the new macro:
142 currentMacro = new PIRMacro(
143 mainWindow->getUserPack(),
149 ui->macroNameLabel->setText(emd.getText());
151 // Turn on the "new" button
152 ui->addButton->setEnabled(true);
154 mainWindow->updateUserButtons();
156 ui->macroListWidget->clear();
158 mainWindow->storeMacros();
164 case EditMacro_Request:
165 emd.setup(userRequestMacro);
166 if (emd.exec() == QDialog::Accepted)
168 // Store the changes:
169 userRequestMacro->setName(emd.getText());
170 userRequestMacro->setKey(emd.getKey());
171 userRequestMacro->setButtonID(emd.getButtonID());
173 mainWindow->updateUserButtons();
175 mainWindow->storeMacros();
177 userRequestMacro = 0;
180 case DeleteMacro_Request:
181 dmd.setup(userRequestMacro);
182 if (dmd.exec() == QDialog::Accepted)
184 if (currentMacro == userRequestMacro)
187 ui->macroNameLabel->setText("No Macro Selected");
188 ui->addButton->setEnabled(false);
189 ui->macroListWidget->clear();
193 delete userRequestMacro;
195 // Make sure no dangling buttons exist:
196 mainWindow->updateUserButtons();
198 mainWindow->storeMacros();
202 userRequestMacro = 0;
209 // Return to the selector dialog:
210 request = No_Request;
216 void PIRMacroForm::on_runButton_clicked()
218 if (currentMacro) currentMacro->executeMacro();
222 void PIRMacroForm::displayMacro(
223 QTreeWidgetItem *item)
227 PIRMacro *m = dynamic_cast<PIRMacro *> (item);
231 userRequestMacro = m;
232 request = DisplayMacro_Request;
236 QComboBox *PIRMacroForm::getKeysetComboBox()
238 return ccd.getKeysetComboBox();
242 void PIRMacroForm::createNewMacro()
244 request = NewMacro_Request;
248 void PIRMacroForm::editMacro(
249 QTreeWidgetItem *item)
252 userRequestMacro = dynamic_cast<PIRMacro *> (item);
253 request = EditMacro_Request;
257 void PIRMacroForm::deleteMacro(
258 QTreeWidgetItem *item)
261 userRequestMacro = dynamic_cast<PIRMacro *> (item);
262 request = DeleteMacro_Request;
266 void PIRMacroForm::on_addButton_clicked()
269 if (!currentMacro) return;
271 // Initialize the choose command dialog:
274 // Check whether the user has actually created a command:
275 if (ccd.exec() != QDialog::Accepted) return;
277 int index = ui->macroListWidget->currentRow();
279 switch (ccd.getCommandType())
282 currentMacro->appendCommand(
283 new PIRKeysetCommandItem(
287 currentMacro->populateList(ui->macroListWidget);
288 ui->macroListWidget->setCurrentRow(index);
290 mainWindow->storeMacros();
295 currentMacro->appendCommand(
296 new PIRKeyCommandItem(
300 currentMacro->populateList(ui->macroListWidget);
301 ui->macroListWidget->setCurrentRow(index);
303 mainWindow->storeMacros();
308 currentMacro->appendCommand(
309 new PIRPauseCommandItem(
310 ccd.getTimeToWait()));
312 currentMacro->populateList(ui->macroListWidget);
313 ui->macroListWidget->setCurrentRow(index);
315 mainWindow->storeMacros();
326 //void PIRMacroForm::deleteCurrentCommand()
327 void PIRMacroForm::on_deleteButton_clicked()
329 if (!currentMacro) return;
331 int index = ui->macroListWidget->currentRow();
333 if (currentMacro->deleteCommand(index))
335 currentMacro->populateList(ui->macroListWidget);
337 if (index == ui->macroListWidget->count()) --index;
341 ui->macroListWidget->setCurrentRow(index);
344 mainWindow->storeMacros();
349 //void PIRMacroForm::copyCurrentCommand()
350 void PIRMacroForm::on_copyButton_clicked()
352 if (!currentMacro) return;
354 // copy constructor dealing with inheritance issues?
358 //void PIRMacroForm::moveCurrentCommandUp()
359 void PIRMacroForm::on_commandUpButton_clicked()
361 if (!currentMacro) return;
363 int index = ui->macroListWidget->currentRow();
365 if ((index > 0) && currentMacro->moveUp(index))
367 currentMacro->populateList(ui->macroListWidget);
368 ui->macroListWidget->setCurrentRow(index - 1);
370 mainWindow->storeMacros();
375 //void PIRMacroForm::moveCurrentCommandDown()
376 void PIRMacroForm::on_commandDownIcon_clicked()
378 if (!currentMacro) return;
380 int index = ui->macroListWidget->currentRow();
382 if ((index < (ui->macroListWidget->count() - 1) &&
383 currentMacro->moveDown(index)))
385 currentMacro->populateList(ui->macroListWidget);
386 ui->macroListWidget->setCurrentRow(index + 1);
388 mainWindow->storeMacros();
393 void PIRMacroForm::on_macroListWidget_currentRowChanged(int currentRow)
397 ui->deleteButton->setEnabled(false);
401 ui->deleteButton->setEnabled(true);
406 //void PIRMacroForm::on_macroListWidget_itemClicked(QListWidgetItem *item)
408 void PIRMacroForm::on_macroListWidget_itemClicked()
411 currentMacro->getCommandType(ui->macroListWidget->currentRow()),
412 currentMacro->getCommandName(ui->macroListWidget->currentRow()));
420 void PIRMacroForm::on_newMacroButton_clicked()
424 // If no new macro, just give up:
425 if (emd.exec() != QDialog::Accepted) return;
427 // Create the new macro:
428 currentMacro = new PIRMacro(
429 mainWindow->getUserPack(),
434 ui->macroNameLabel->setText(emd.getText());
436 // Turn on the "new" button
437 ui->addButton->setEnabled(true);
439 if (emd.getButtonID())
441 mainWindow->updateUserButtons();
444 ui->macroListWidget->clear();
446 mainWindow->storeMacros();