14,7 → 14,7 |
|
mainLayout = new QGridLayout(); |
|
macroCount = 0; |
count = 0; |
connected = false; |
lastKnownFilePath = "."; |
|
28,18 → 28,18 |
mainLayout->addLayout(ioLayout, 0, 0, 1, 2); |
|
for (int i = 0; i < MACRO_DEFAULT_COUNT; i++) { |
Macro_AddEntry(); |
AddEntry(); |
} |
|
setLayout(mainLayout); |
|
connect(btnAddMacro, SIGNAL(clicked()), this, SLOT(Macro_AddEntry())); |
connect(btnRemoveMacro, SIGNAL(clicked()), this, SLOT(Macro_RemoveEntry())); |
connect(btnClear, SIGNAL(clicked()), this, SLOT(Macro_Clear())); |
connect(btnExport, SIGNAL(clicked()), this, SLOT(Macro_WriteToFile())); |
connect(btnImport, SIGNAL(clicked()), this, SLOT(Macro_ReadFromFile())); |
connect(sigmapTransmit, SIGNAL(mapped(QWidget*)), this, SLOT(Macro_InitTransmit(QWidget*))); |
connect(sigmapKeybind, SIGNAL(mapped(int)), this, SLOT(Macro_KeybindPrompt(int))); |
connect(btnAddMacro, SIGNAL(clicked()), this, SLOT(AddEntry())); |
connect(btnRemoveMacro, SIGNAL(clicked()), this, SLOT(RemoveEntry())); |
connect(btnClear, SIGNAL(clicked()), this, SLOT(Clear())); |
connect(btnExport, SIGNAL(clicked()), this, SLOT(WriteToFile())); |
connect(btnImport, SIGNAL(clicked()), this, SLOT(ReadFromFile())); |
connect(sigmapTransmit, SIGNAL(mapped(QWidget*)), this, SLOT(InitTransmit(QWidget*))); |
connect(sigmapKeybind, SIGNAL(mapped(int)), this, SLOT(KeybindPrompt(int))); |
|
// Register global event process for keyboard shortcut handling |
qApp->installEventFilter(this); |
55,31 → 55,31 |
return this->minimumSizeHint(); |
} |
|
void MacroWidget::Macro_EnableTransmit() |
void MacroWidget::EnableTransmit() |
{ |
connected = true; |
for (int i = 0; i < macroBtnSendList.size(); i++) { |
macroBtnSendList[i]->setEnabled(true); |
for (int i = 0; i < btnSendList.size(); i++) { |
btnSendList[i]->setEnabled(true); |
} |
} |
|
void MacroWidget::Macro_DisableTransmit() |
void MacroWidget::DisableTransmit() |
{ |
connected = false; |
for (int i = 0; i < macroBtnSendList.size(); i++) { |
macroBtnSendList[i]->setEnabled(false); |
for (int i = 0; i < btnSendList.size(); i++) { |
btnSendList[i]->setEnabled(false); |
} |
} |
|
void MacroWidget::Macro_InitTransmit(QWidget *t) |
void MacroWidget::InitTransmit(QWidget *t) |
{ |
if (connected) { |
QTextEdit *text = qobject_cast<QTextEdit*>(t); |
emit Macro_TransmitText(text->toPlainText().toUtf8()); |
emit TransmitText(text->toPlainText().toUtf8()); |
} |
} |
|
void MacroWidget::Macro_KeybindPrompt(int id) |
void MacroWidget::KeybindPrompt(int id) |
{ |
QPushButton *btn = qobject_cast<QPushButton*>(sigmapKeybind->mapping(id)); |
|
106,16 → 106,16 |
btn->installEventFilter(this); |
} |
|
void MacroWidget::Macro_AddEntry() |
void MacroWidget::AddEntry() |
{ |
macroCount++; |
count++; |
|
// Create new layout/widgets |
QLineEdit *lineEdit = new QLineEdit(QString("Macro %1").arg(macroCount)); |
QLineEdit *lineEdit = new QLineEdit(QString("Macro %1").arg(count)); |
lineEdit->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Fixed); |
lineEdit->setMinimumWidth(100); |
lineEdit->setAlignment(Qt::AlignCenter); |
macroNameList.append(lineEdit); |
nameList.append(lineEdit); |
|
QTextEdit *textEdit = new QTextEdit(); |
textEdit->setMinimumHeight(50); |
124,16 → 124,16 |
textEdit->setFont(QFont("Consolas", 8)); |
textEdit->setAcceptRichText(false); |
textEdit->setTabChangesFocus(true); |
macroValueList.append(textEdit); |
valueList.append(textEdit); |
|
QPushButton *keyButton = new QPushButton("Hotkey: None"); |
keyButton->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); |
macroBtnKeyList.append(keyButton); |
btnKeyList.append(keyButton); |
|
QPushButton *pushButton = new QPushButton("Send Macro"); |
pushButton->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); |
pushButton->setEnabled(connected); |
macroBtnSendList.append(pushButton); |
btnSendList.append(pushButton); |
|
QVBoxLayout *tmpLayout = new QVBoxLayout(); |
tmpLayout->addWidget(lineEdit); |
141,12 → 141,12 |
tmpLayout->addWidget(pushButton); |
|
// Add layout/widgets to main layout |
mainLayout->addLayout(tmpLayout, macroCount, 0); |
mainLayout->addWidget(textEdit, macroCount, 1); |
mainLayout->addLayout(tmpLayout, count, 0); |
mainLayout->addWidget(textEdit, count, 1); |
mainLayout->setColumnStretch(1, 1); |
|
// Associate KeyButton with its corresponding ID |
sigmapKeybind->setMapping(keyButton, macroCount-1); |
sigmapKeybind->setMapping(keyButton, count-1); |
connect(keyButton, SIGNAL(clicked()), sigmapKeybind, SLOT(map())); |
|
// Associate PushButton with its corresponding TextEdit |
163,16 → 163,16 |
btnRemoveMacro->setEnabled(true); |
} |
|
void MacroWidget::Macro_RemoveEntry() |
void MacroWidget::RemoveEntry() |
{ |
|
// Remove and delete layout/widgets at last macro slot |
QLayoutItem *item = mainLayout->itemAtPosition(macroCount, 0); |
QLayoutItem *item = mainLayout->itemAtPosition(count, 0); |
while(!item->isEmpty()) |
delete item->layout()->takeAt(0)->widget(); |
delete item; |
|
item = mainLayout->itemAtPosition(macroCount, 1); |
item = mainLayout->itemAtPosition(count, 1); |
delete item->widget(); |
|
item = mainLayout->itemAtPosition(1, 1); |
179,45 → 179,45 |
int height = item->widget()->height() + mainLayout->verticalSpacing(); |
|
// Unmap and remove widgets from lists |
QPushButton *pushButton = macroBtnSendList.back(); |
QPushButton *pushButton = btnSendList.back(); |
sigmapTransmit->removeMappings(pushButton); |
|
QPushButton *keyButton = macroBtnKeyList.back(); |
QPushButton *keyButton = btnKeyList.back(); |
sigmapKeybind->removeMappings(keyButton); |
|
macroNameList.pop_back(); |
macroValueList.pop_back(); |
macroBtnSendList.pop_back(); |
macroBtnKeyList.pop_back(); |
nameList.pop_back(); |
valueList.pop_back(); |
btnSendList.pop_back(); |
btnKeyList.pop_back(); |
|
int index = registeredKeyMacroIDs.indexOf(macroCount-1); |
int index = registeredKeyMacroIDs.indexOf(count-1); |
if (index >= 0) { |
registeredKeySequences.removeAt(index); |
registeredKeyMacroIDs.removeAt(index); |
} |
|
macroCount--; |
count--; |
|
QDockWidget *parent = qobject_cast<QDockWidget*>(this->parent()); |
if (parent->isFloating()) |
parent->resize(parent->width(), parent->height() - height); |
|
if (macroCount == 1) |
if (count == 1) |
btnRemoveMacro->setEnabled(false); |
} |
|
void MacroWidget::Macro_Clear() |
void MacroWidget::Clear() |
{ |
for (int i = 0; i < macroCount; i++) { |
macroNameList[i]->setText(QString("Macro %1").arg(i+1)); |
macroValueList[i]->clear(); |
macroBtnKeyList[i]->setText("Hotkey: None"); |
for (int i = 0; i < count; i++) { |
nameList[i]->setText(QString("Macro %1").arg(i+1)); |
valueList[i]->clear(); |
btnKeyList[i]->setText("Hotkey: None"); |
} |
registeredKeyMacroIDs.clear(); |
registeredKeySequences.clear(); |
} |
|
void MacroWidget::Macro_WriteToFile() |
void MacroWidget::WriteToFile() |
{ |
QString file = QFileDialog::getSaveFileName(this, "Settings XML File", lastKnownFilePath, "XML File (*.xml)"); |
QCoreApplication::processEvents(); // Wait for dialog to close |
241,11 → 241,11 |
stream.writeStartElement("Settings"); |
stream.writeStartElement("Macro"); |
|
for (int i = 0; i < macroCount; i++) { |
for (int i = 0; i < count; i++) { |
stream.writeStartElement("Macro_Entry"); |
|
stream.writeAttribute("Name", macroNameList[i]->text()); |
stream.writeTextElement("Value", macroValueList[i]->toPlainText()); |
stream.writeAttribute("Name", nameList[i]->text()); |
stream.writeTextElement("Value", valueList[i]->toPlainText()); |
|
int index = registeredKeyMacroIDs.indexOf(i); |
if (index >= 0) { |
264,7 → 264,7 |
inputFile.close(); |
} |
|
void MacroWidget::Macro_ReadFromFile() |
void MacroWidget::ReadFromFile() |
{ |
int counter = 0; |
|
273,7 → 273,7 |
|
if (file.size() == 0) return; |
|
Macro_Clear(); |
Clear(); |
|
// If file was selected, save directory for next time |
QFileInfo fileInfo = QFileInfo(file); |
327,15 → 327,15 |
} |
|
// Write values to GUI |
if (counter == macroCount) |
Macro_AddEntry(); |
if (counter == count) |
AddEntry(); |
|
macroNameList[counter]->setText(name); |
macroValueList[counter]->setText(value); |
nameList[counter]->setText(name); |
valueList[counter]->setText(value); |
if (keybinding != "") { |
registeredKeySequences.append(QKeySequence(keybinding)); |
registeredKeyMacroIDs.append(counter); |
macroBtnKeyList[counter]->setText("Hotkey: " + keybinding); |
btnKeyList[counter]->setText("Hotkey: " + keybinding); |
} |
counter++; |
} |
360,7 → 360,7 |
if (!registeredKeySequences.isEmpty()) { |
int index = registeredKeySequences.indexOf(seq); |
if (index >= 0) { |
Macro_InitTransmit(macroValueList[registeredKeyMacroIDs[index]]); |
InitTransmit(valueList[registeredKeyMacroIDs[index]]); |
return true; |
} |
} |