2,12 → 2,14 |
|
MacroController::MacroController(QWidget *parent) : QWidget(parent) |
{ |
sigMapper = new QSignalMapper(); |
sigmapTransmit = new QSignalMapper(); |
sigmapKeybind = new QSignalMapper(); |
|
btnExport = new QPushButton("&Export"); |
btnImport = new QPushButton("&Import"); |
btnAddMacro = new QPushButton("&Add"); |
btnRemoveMacro = new QPushButton("&Remove"); |
currKeyBindInfo = QPair<QPushButton*,int>(NULL, 0); |
|
mainLayout = new QGridLayout(); |
|
33,7 → 35,8 |
connect(btnRemoveMacro, SIGNAL(clicked()), this, SLOT(Macro_RemoveEntry())); |
connect(btnExport, SIGNAL(clicked()), this, SLOT(Macro_WriteToFile())); |
connect(btnImport, SIGNAL(clicked()), this, SLOT(Macro_ReadFromFile())); |
connect(sigMapper, SIGNAL(mapped(QWidget*)), this, SLOT(Macro_InitTransmit(QWidget*))); |
connect(sigmapTransmit, SIGNAL(mapped(QWidget*)), this, SLOT(Macro_InitTransmit(QWidget*))); |
connect(sigmapKeybind, SIGNAL(mapped(int)), this, SLOT(Macro_KeybindPrompt(int))); |
} |
|
MacroController::~MacroController() |
49,8 → 52,8 |
void MacroController::Macro_EnableTransmit() |
{ |
connected = true; |
for (int i = 0; i < macroBtnList.size(); i++) { |
macroBtnList[i]->setEnabled(true); |
for (int i = 0; i < macroBtnSendList.size(); i++) { |
macroBtnSendList[i]->setEnabled(true); |
} |
} |
|
57,8 → 60,8 |
void MacroController::Macro_DisableTransmit() |
{ |
connected = false; |
for (int i = 0; i < macroBtnList.size(); i++) { |
macroBtnList[i]->setEnabled(false); |
for (int i = 0; i < macroBtnSendList.size(); i++) { |
macroBtnSendList[i]->setEnabled(false); |
} |
} |
|
68,6 → 71,17 |
emit Macro_TransmitText(text->toPlainText()); |
} |
|
void MacroController::Macro_KeybindPrompt(int id) |
{ |
QPushButton *btn = qobject_cast<QPushButton*>(sigmapKeybind->mapping(id)); |
btn->setDown(true); |
btn->setText("Waiting for Key.."); |
currKeyBindInfo = QPair<QPushButton*,int>(btn, id); |
|
// Steal all following keyboard events |
btn->installEventFilter(this); |
} |
|
void MacroController::Macro_AddEntry() |
{ |
macroCount++; |
87,13 → 101,19 |
textEdit->setTabChangesFocus(true); |
macroValueList.append(textEdit); |
|
QPushButton *keyButton = new QPushButton("Key: None"); |
keyButton->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); |
macroBtnKeyList.append(keyButton); |
macroKeybindList.append(QKeySequence(Qt::Key_unknown)); |
|
QPushButton *pushButton = new QPushButton("Send Macro"); |
pushButton->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); |
pushButton->setEnabled(connected); |
macroBtnList.append(pushButton); |
macroBtnSendList.append(pushButton); |
|
QVBoxLayout *tmpLayout = new QVBoxLayout(); |
tmpLayout->addWidget(lineEdit); |
tmpLayout->addWidget(keyButton); |
tmpLayout->addWidget(pushButton); |
|
// Add layout/widgets to main layout |
101,9 → 121,13 |
mainLayout->addWidget(textEdit, macroCount, 1); |
mainLayout->setColumnStretch(1, 1); |
|
// Associate KeyButton with its corresponding ID |
sigmapKeybind->setMapping(keyButton, macroCount-1); |
connect(keyButton, SIGNAL(clicked()), sigmapKeybind, SLOT(map())); |
|
// Associate PushButton with its corresponding TextEdit |
sigMapper->setMapping(pushButton, textEdit); |
connect(pushButton, SIGNAL(clicked()), sigMapper, SLOT(map())); |
sigmapTransmit->setMapping(pushButton, textEdit); |
connect(pushButton, SIGNAL(clicked()), sigmapTransmit, SLOT(map())); |
|
QLayoutItem *item = mainLayout->itemAtPosition(1, 1); |
int height = item->widget()->height() + mainLayout->verticalSpacing(); |
131,12 → 155,17 |
int height = item->widget()->height() + mainLayout->verticalSpacing(); |
|
// Unmap and remove widgets from lists |
QPushButton *pushButton = macroBtnList.back(); |
sigMapper->removeMappings(pushButton); |
QPushButton *pushButton = macroBtnSendList.back(); |
sigmapTransmit->removeMappings(pushButton); |
|
QPushButton *keyButton = macroBtnKeyList.back(); |
sigmapKeybind->removeMappings(keyButton); |
|
macroNameList.pop_back(); |
macroValueList.pop_back(); |
macroBtnList.pop_back(); |
macroBtnSendList.pop_back(); |
macroBtnKeyList.pop_back(); |
macroKeybindList.pop_back(); |
|
macroCount--; |
|
252,3 → 281,38 |
} |
} |
} |
|
bool MacroController::eventFilter(QObject *obj, QEvent *event) |
{ |
if (event->type() == QEvent::KeyPress) { |
QKeyEvent *keyevent = static_cast<QKeyEvent*>(event); |
|
if (currKeyBindInfo.first != NULL) { |
// Ignore modifier keys |
if (keyevent->key() == Qt::Key_Shift || keyevent->key() == Qt::Key_Control || |
keyevent->key() == Qt::Key_Meta || keyevent->key() == Qt::Key_Alt) |
return true; |
|
// Reset on ESC key |
if (keyevent->key() == Qt::Key_Escape) { |
macroKeybindList[currKeyBindInfo.second] = Qt::Key_unknown; |
currKeyBindInfo.first->setText("Key: None"); |
currKeyBindInfo.first->setDown(false); |
currKeyBindInfo.first->removeEventFilter(this); |
currKeyBindInfo = QPair<QPushButton*, int>(NULL, 0); |
return true; |
} |
|
// Otherwise save key sequence |
QKeySequence seq = keyevent->modifiers() + keyevent->key(); |
macroKeybindList[currKeyBindInfo.second] = seq; |
currKeyBindInfo.first->setText(seq.toString()); |
currKeyBindInfo.first->setDown(false); |
currKeyBindInfo.first->removeEventFilter(this); |
currKeyBindInfo = QPair<QPushButton*, int>(NULL, 0); |
} |
return true; |
} |
|
return QWidget::eventFilter(obj, event); |
} |