| 345 |
Kevin |
1 |
#include "MacroController.h"
|
|
|
2 |
|
|
|
3 |
MacroController::MacroController(QWidget *parent) : QWidget(parent)
|
|
|
4 |
{
|
|
|
5 |
sigMapper = new QSignalMapper();
|
|
|
6 |
|
|
|
7 |
btnExport = new QPushButton("&Export");
|
|
|
8 |
btnImport = new QPushButton("&Import");
|
|
|
9 |
btnIncreaseMacro = new QPushButton("&Add");
|
|
|
10 |
btnDecreaseMacro = new QPushButton("&Remove");
|
|
|
11 |
|
|
|
12 |
mainLayout = new QGridLayout();
|
|
|
13 |
|
|
|
14 |
macroCount = 0;
|
|
|
15 |
connected = false;
|
|
|
16 |
|
|
|
17 |
ioLayout = new QHBoxLayout();
|
|
|
18 |
ioLayout->addStretch();
|
|
|
19 |
ioLayout->addWidget(btnIncreaseMacro);
|
|
|
20 |
ioLayout->addWidget(btnDecreaseMacro);
|
|
|
21 |
ioLayout->addWidget(btnExport);
|
|
|
22 |
ioLayout->addWidget(btnImport);
|
|
|
23 |
mainLayout->addLayout(ioLayout, 0, 0, 1, 2);
|
|
|
24 |
|
|
|
25 |
for (int i = 0; i < MACRO_DEFAULT_COUNT; i++) {
|
|
|
26 |
Macro_AddEntry();
|
|
|
27 |
}
|
|
|
28 |
|
|
|
29 |
setLayout(mainLayout);
|
|
|
30 |
this->resize(this->minimumSizeHint());
|
|
|
31 |
|
|
|
32 |
connect(btnIncreaseMacro, SIGNAL(clicked()), this, SLOT(Macro_AddEntry()));
|
|
|
33 |
connect(btnDecreaseMacro, SIGNAL(clicked()), this, SLOT(Macro_RemoveEntry()));
|
|
|
34 |
connect(btnExport, SIGNAL(clicked()), this, SLOT(Macro_WriteToFile()));
|
|
|
35 |
connect(btnImport, SIGNAL(clicked()), this, SLOT(Macro_ReadFromFile()));
|
|
|
36 |
connect(sigMapper, SIGNAL(mapped(QWidget*)), this, SLOT(Macro_InitTransmit(QWidget*)));
|
|
|
37 |
|
|
|
38 |
setWindowTitle("Macro Settings");
|
|
|
39 |
}
|
|
|
40 |
|
|
|
41 |
MacroController::~MacroController()
|
|
|
42 |
{
|
|
|
43 |
|
|
|
44 |
}
|
|
|
45 |
|
|
|
46 |
void MacroController::Macro_EnableTransmit()
|
|
|
47 |
{
|
|
|
48 |
connected = true;
|
|
|
49 |
for (int i = 0; i < macroBtnList.size(); i++) {
|
|
|
50 |
macroBtnList[i]->setEnabled(true);
|
|
|
51 |
}
|
|
|
52 |
}
|
|
|
53 |
|
|
|
54 |
void MacroController::Macro_DisableTransmit()
|
|
|
55 |
{
|
|
|
56 |
connected = false;
|
|
|
57 |
for (int i = 0; i < macroBtnList.size(); i++) {
|
|
|
58 |
macroBtnList[i]->setEnabled(false);
|
|
|
59 |
}
|
|
|
60 |
}
|
|
|
61 |
|
|
|
62 |
void MacroController::Macro_InitTransmit(QWidget *t)
|
|
|
63 |
{
|
|
|
64 |
QTextEdit *text = qobject_cast<QTextEdit*>(t);
|
|
|
65 |
emit Macro_TransmitText(text->toPlainText());
|
|
|
66 |
}
|
|
|
67 |
|
|
|
68 |
void MacroController::Macro_AddEntry()
|
|
|
69 |
{
|
|
|
70 |
macroCount++;
|
|
|
71 |
|
|
|
72 |
// Create new layout/widgets
|
|
|
73 |
QLineEdit *lineEdit = new QLineEdit(QString("Macro %1").arg(macroCount));
|
|
|
74 |
lineEdit->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
|
|
|
75 |
lineEdit->setAlignment(Qt::AlignCenter | Qt::AlignTop);
|
|
|
76 |
macroNameList.append(lineEdit);
|
|
|
77 |
|
|
|
78 |
QTextEdit *textEdit = new QTextEdit();
|
|
|
79 |
textEdit->setMinimumHeight(50);
|
|
|
80 |
textEdit->setWordWrapMode(QTextOption::NoWrap);
|
|
|
81 |
textEdit->setFont(QFont("Consolas", 8));
|
|
|
82 |
textEdit->setAcceptRichText(false);
|
|
|
83 |
macroValueList.append(textEdit);
|
|
|
84 |
|
|
|
85 |
QPushButton *pushButton = new QPushButton("Send Macro");
|
|
|
86 |
pushButton->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
|
|
|
87 |
pushButton->setEnabled(connected);
|
|
|
88 |
macroBtnList.append(pushButton);
|
|
|
89 |
|
|
|
90 |
QVBoxLayout *tmpLayout = new QVBoxLayout();
|
|
|
91 |
tmpLayout->addWidget(lineEdit);
|
|
|
92 |
tmpLayout->addWidget(pushButton);
|
|
|
93 |
|
|
|
94 |
// Add layout/widgets to main layout
|
|
|
95 |
mainLayout->addLayout(tmpLayout, macroCount, 0);
|
|
|
96 |
mainLayout->addWidget(textEdit, macroCount, 1);
|
|
|
97 |
mainLayout->setColumnStretch(1, 1);
|
|
|
98 |
|
|
|
99 |
// Associate PushButton with its corresponding TextEdit
|
|
|
100 |
sigMapper->setMapping(pushButton, textEdit);
|
|
|
101 |
connect(pushButton, SIGNAL(clicked()), sigMapper, SLOT(map()));
|
|
|
102 |
|
|
|
103 |
QLayoutItem *item = mainLayout->itemAtPosition(1, 1);
|
|
|
104 |
int height = item->widget()->height();
|
|
|
105 |
this->resize(this->width(), this->height() + height + 8);
|
|
|
106 |
|
|
|
107 |
btnDecreaseMacro->setEnabled(true);
|
|
|
108 |
}
|
|
|
109 |
|
|
|
110 |
void MacroController::Macro_RemoveEntry()
|
|
|
111 |
{
|
|
|
112 |
|
|
|
113 |
// Remove and delete layout/widgets at last macro slot
|
|
|
114 |
QLayoutItem *item = mainLayout->itemAtPosition(macroCount, 0);
|
|
|
115 |
while(!item->isEmpty())
|
|
|
116 |
delete item->layout()->takeAt(0)->widget();
|
|
|
117 |
delete item;
|
|
|
118 |
|
|
|
119 |
item = mainLayout->itemAtPosition(macroCount, 1);
|
|
|
120 |
int height = item->widget()->height();
|
|
|
121 |
delete item->widget();
|
|
|
122 |
|
|
|
123 |
// Unmap and remove widgets from lists
|
|
|
124 |
QPushButton *pushButton = macroBtnList.back();
|
|
|
125 |
sigMapper->removeMappings(pushButton);
|
|
|
126 |
|
|
|
127 |
macroNameList.pop_back();
|
|
|
128 |
macroValueList.pop_back();
|
|
|
129 |
macroBtnList.pop_back();
|
|
|
130 |
|
|
|
131 |
macroCount--;
|
|
|
132 |
|
|
|
133 |
this->resize(this->width(), this->height() - height - 8);
|
|
|
134 |
|
|
|
135 |
if (macroCount == 1)
|
|
|
136 |
btnDecreaseMacro->setEnabled(false);
|
|
|
137 |
}
|
|
|
138 |
|
|
|
139 |
void MacroController::Macro_WriteToFile()
|
|
|
140 |
{
|
|
|
141 |
|
|
|
142 |
}
|
|
|
143 |
|
|
|
144 |
void MacroController::Macro_ReadFromFile()
|
|
|
145 |
{
|
|
|
146 |
|
|
|
147 |
}
|