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:
79 SIGNAL(deleteCommand()),
81 SLOT(deleteCurrentCommand()));
85 SIGNAL(moveCommandUp()),
87 SLOT(moveCurrentCommandUp()));
91 SIGNAL(moveCommandDown()),
93 SLOT(moveCurrentCommandDown()));
97 PIRMacroForm::~PIRMacroForm()
103 void PIRMacroForm::on_chooseMacroButton_clicked()
105 request = No_Request;
108 // Loop until the user either selects a macro to display,
109 // or makes no request:
110 while (request != No_Request)
114 case DisplayMacro_Request:
115 currentMacro = userRequestMacro;
116 userRequestMacro = 0;
118 ui->macroNameLabel->setText(currentMacro->getName());
120 // Turn on the "new" button
121 ui->addButton->setEnabled(true);
123 currentMacro->populateList(ui->macroListWidget);
127 case NewMacro_Request:
129 if (emd.exec() == QDialog::Accepted)
131 // Create the new macro:
132 currentMacro = new PIRMacro(
133 mainWindow->getUserPack(),
139 ui->macroNameLabel->setText(emd.getText());
141 // Turn on the "new" button
142 ui->addButton->setEnabled(true);
144 mainWindow->updateUserButtons();
146 ui->macroListWidget->clear();
148 mainWindow->storeMacros();
154 case EditMacro_Request:
155 emd.setup(userRequestMacro);
156 if (emd.exec() == QDialog::Accepted)
158 // Store the changes:
159 userRequestMacro->setName(emd.getText());
160 userRequestMacro->setKey(emd.getKey());
161 userRequestMacro->setButtonID(emd.getButtonID());
163 mainWindow->updateUserButtons();
165 mainWindow->storeMacros();
167 userRequestMacro = 0;
170 case DeleteMacro_Request:
171 dmd.setup(userRequestMacro);
172 if (dmd.exec() == QDialog::Accepted)
174 if (currentMacro == userRequestMacro)
177 ui->macroNameLabel->setText("No Macro Selected");
178 ui->addButton->setEnabled(false);
179 ui->macroListWidget->clear();
183 delete userRequestMacro;
185 // Make sure no dangling buttons exist:
186 mainWindow->updateUserButtons();
188 mainWindow->storeMacros();
192 userRequestMacro = 0;
199 // Return to the selector dialog:
200 request = No_Request;
206 void PIRMacroForm::on_runButton_clicked()
208 if (currentMacro) currentMacro->executeMacro();
212 void PIRMacroForm::displayMacro(
213 QTreeWidgetItem *item)
217 PIRMacro *m = dynamic_cast<PIRMacro *> (item);
221 userRequestMacro = m;
222 request = DisplayMacro_Request;
226 QComboBox *PIRMacroForm::getKeysetComboBox()
228 return ccd.getKeysetComboBox();
232 void PIRMacroForm::createNewMacro()
234 request = NewMacro_Request;
238 void PIRMacroForm::editMacro(
239 QTreeWidgetItem *item)
242 userRequestMacro = dynamic_cast<PIRMacro *> (item);
243 request = EditMacro_Request;
247 void PIRMacroForm::deleteMacro(
248 QTreeWidgetItem *item)
251 userRequestMacro = dynamic_cast<PIRMacro *> (item);
252 request = DeleteMacro_Request;
256 void PIRMacroForm::on_addButton_clicked()
259 if (!currentMacro) return;
261 // Initialize the choose command dialog:
264 // Check whether the user has actually created a command:
265 if (ccd.exec() != QDialog::Accepted) return;
267 int index = ui->macroListWidget->currentRow();
269 switch (ccd.getCommandType())
272 currentMacro->appendCommand(
273 new PIRKeysetCommandItem(
277 currentMacro->populateList(ui->macroListWidget);
278 ui->macroListWidget->setCurrentRow(index);
280 mainWindow->storeMacros();
285 currentMacro->appendCommand(
286 new PIRKeyCommandItem(
290 currentMacro->populateList(ui->macroListWidget);
291 ui->macroListWidget->setCurrentRow(index);
293 mainWindow->storeMacros();
298 currentMacro->appendCommand(
299 new PIRPauseCommandItem(
300 ccd.getTimeToWait()));
302 currentMacro->populateList(ui->macroListWidget);
303 ui->macroListWidget->setCurrentRow(index);
305 mainWindow->storeMacros();
316 void PIRMacroForm::deleteCurrentCommand()
318 int index = ui->macroListWidget->currentRow();
319 if (currentMacro->deleteCommand(index))
321 currentMacro->populateList(ui->macroListWidget);
323 if (index == ui->macroListWidget->count()) --index;
327 ui->macroListWidget->setCurrentRow(index);
330 mainWindow->storeMacros();
335 void PIRMacroForm::moveCurrentCommandUp()
337 int index = ui->macroListWidget->currentRow();
338 if (currentMacro->moveUp(index))
340 currentMacro->populateList(ui->macroListWidget);
341 ui->macroListWidget->setCurrentRow(index - 1);
343 mainWindow->storeMacros();
348 void PIRMacroForm::moveCurrentCommandDown()
350 int index = ui->macroListWidget->currentRow();
352 if (currentMacro->moveDown(index))
354 currentMacro->populateList(ui->macroListWidget);
355 ui->macroListWidget->setCurrentRow(index + 1);
357 mainWindow->storeMacros();
362 //void PIRMacroForm::on_macroListWidget_itemClicked(QListWidgetItem *item)
363 void PIRMacroForm::on_macroListWidget_itemClicked()
366 currentMacro->getCommandType(ui->macroListWidget->currentRow()),
367 currentMacro->getCommandName(ui->macroListWidget->currentRow()));
374 void PIRMacroForm::on_newMacroButton_clicked()
378 // If no new macro, just give up:
379 if (emd.exec() != QDialog::Accepted) return;
381 // Create the new macro:
382 currentMacro = new PIRMacro(
383 mainWindow->getUserPack(),
388 ui->macroNameLabel->setText(emd.getText());
390 // Turn on the "new" button
391 ui->addButton->setEnabled(true);
393 if (emd.getButtonID())
395 mainWindow->updateUserButtons();
398 ui->macroListWidget->clear();
400 mainWindow->storeMacros();