Subversion Repositories Code-Repo

Rev

Rev 354 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 354 Rev 362
Line 12... Line 12...
12
    btnClear = new QPushButton("&Clear");
12
    btnClear = new QPushButton("&Clear");
13
    currKeyBindInfo = QPair<QPushButton*,int>(NULL, 0);
13
    currKeyBindInfo = QPair<QPushButton*,int>(NULL, 0);
14
 
14
 
15
    mainLayout = new QGridLayout();
15
    mainLayout = new QGridLayout();
16
 
16
 
17
    macroCount = 0;
17
    count = 0;
18
    connected = false;
18
    connected = false;
19
    lastKnownFilePath = ".";
19
    lastKnownFilePath = ".";
20
 
20
 
21
    ioLayout = new QHBoxLayout();
21
    ioLayout = new QHBoxLayout();
22
    ioLayout->addWidget(btnAddMacro);
22
    ioLayout->addWidget(btnAddMacro);
Line 26... Line 26...
26
    ioLayout->addWidget(btnImport);
26
    ioLayout->addWidget(btnImport);
27
    ioLayout->addStretch();
27
    ioLayout->addStretch();
28
    mainLayout->addLayout(ioLayout, 0, 0, 1, 2);
28
    mainLayout->addLayout(ioLayout, 0, 0, 1, 2);
29
 
29
 
30
    for (int i = 0; i < MACRO_DEFAULT_COUNT; i++) {
30
    for (int i = 0; i < MACRO_DEFAULT_COUNT; i++) {
31
        Macro_AddEntry();
31
        AddEntry();
32
    }
32
    }
33
 
33
 
34
    setLayout(mainLayout);
34
    setLayout(mainLayout);
35
 
35
 
36
    connect(btnAddMacro, SIGNAL(clicked()), this, SLOT(Macro_AddEntry()));
36
    connect(btnAddMacro, SIGNAL(clicked()), this, SLOT(AddEntry()));
37
    connect(btnRemoveMacro, SIGNAL(clicked()), this, SLOT(Macro_RemoveEntry()));
37
    connect(btnRemoveMacro, SIGNAL(clicked()), this, SLOT(RemoveEntry()));
38
    connect(btnClear, SIGNAL(clicked()), this, SLOT(Macro_Clear()));
38
    connect(btnClear, SIGNAL(clicked()), this, SLOT(Clear()));
39
    connect(btnExport, SIGNAL(clicked()), this, SLOT(Macro_WriteToFile()));
39
    connect(btnExport, SIGNAL(clicked()), this, SLOT(WriteToFile()));
40
    connect(btnImport, SIGNAL(clicked()), this, SLOT(Macro_ReadFromFile()));
40
    connect(btnImport, SIGNAL(clicked()), this, SLOT(ReadFromFile()));
41
    connect(sigmapTransmit, SIGNAL(mapped(QWidget*)), this, SLOT(Macro_InitTransmit(QWidget*)));
41
    connect(sigmapTransmit, SIGNAL(mapped(QWidget*)), this, SLOT(InitTransmit(QWidget*)));
42
    connect(sigmapKeybind, SIGNAL(mapped(int)), this, SLOT(Macro_KeybindPrompt(int)));
42
    connect(sigmapKeybind, SIGNAL(mapped(int)), this, SLOT(KeybindPrompt(int)));
43
 
43
 
44
    // Register global event process for keyboard shortcut handling
44
    // Register global event process for keyboard shortcut handling
45
    qApp->installEventFilter(this);
45
    qApp->installEventFilter(this);
46
}
46
}
47
 
47
 
Line 53... Line 53...
53
QSize MacroWidget::sizeHint() const
53
QSize MacroWidget::sizeHint() const
54
{
54
{
55
    return this->minimumSizeHint();
55
    return this->minimumSizeHint();
56
}
56
}
57
 
57
 
58
void MacroWidget::Macro_EnableTransmit()
58
void MacroWidget::EnableTransmit()
59
{
59
{
60
    connected = true;
60
    connected = true;
61
    for (int i = 0; i < macroBtnSendList.size(); i++) {
61
    for (int i = 0; i < btnSendList.size(); i++) {
62
        macroBtnSendList[i]->setEnabled(true);
62
        btnSendList[i]->setEnabled(true);
63
    }
63
    }
64
}
64
}
65
 
65
 
66
void MacroWidget::Macro_DisableTransmit()
66
void MacroWidget::DisableTransmit()
67
{
67
{
68
    connected = false;
68
    connected = false;
69
    for (int i = 0; i < macroBtnSendList.size(); i++) {
69
    for (int i = 0; i < btnSendList.size(); i++) {
70
        macroBtnSendList[i]->setEnabled(false);
70
        btnSendList[i]->setEnabled(false);
71
    }
71
    }
72
}
72
}
73
 
73
 
74
void MacroWidget::Macro_InitTransmit(QWidget *t)
74
void MacroWidget::InitTransmit(QWidget *t)
75
{
75
{
76
    if (connected) {
76
    if (connected) {
77
        QTextEdit *text = qobject_cast<QTextEdit*>(t);
77
        QTextEdit *text = qobject_cast<QTextEdit*>(t);
78
        emit Macro_TransmitText(text->toPlainText().toUtf8());
78
        emit TransmitText(text->toPlainText().toUtf8());
79
    }
79
    }
80
}
80
}
81
 
81
 
82
void MacroWidget::Macro_KeybindPrompt(int id)
82
void MacroWidget::KeybindPrompt(int id)
83
{
83
{
84
    QPushButton *btn = qobject_cast<QPushButton*>(sigmapKeybind->mapping(id));
84
    QPushButton *btn = qobject_cast<QPushButton*>(sigmapKeybind->mapping(id));
85
 
85
 
86
    // Check to make sure we arn't processing another key first
86
    // Check to make sure we arn't processing another key first
87
    if (currKeyBindInfo.first != NULL) {
87
    if (currKeyBindInfo.first != NULL) {
Line 104... Line 104...
104
 
104
 
105
    // Inspect all following keyboard events
105
    // Inspect all following keyboard events
106
    btn->installEventFilter(this);
106
    btn->installEventFilter(this);
107
}
107
}
108
 
108
 
109
void MacroWidget::Macro_AddEntry()
109
void MacroWidget::AddEntry()
110
{
110
{
111
    macroCount++;
111
    count++;
112
 
112
 
113
    // Create new layout/widgets
113
    // Create new layout/widgets
114
    QLineEdit *lineEdit = new QLineEdit(QString("Macro %1").arg(macroCount));
114
    QLineEdit *lineEdit = new QLineEdit(QString("Macro %1").arg(count));
115
    lineEdit->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Fixed);
115
    lineEdit->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Fixed);
116
    lineEdit->setMinimumWidth(100);
116
    lineEdit->setMinimumWidth(100);
117
    lineEdit->setAlignment(Qt::AlignCenter);
117
    lineEdit->setAlignment(Qt::AlignCenter);
118
    macroNameList.append(lineEdit);
118
    nameList.append(lineEdit);
119
 
119
 
120
    QTextEdit *textEdit = new QTextEdit();
120
    QTextEdit *textEdit = new QTextEdit();
121
    textEdit->setMinimumHeight(50);
121
    textEdit->setMinimumHeight(50);
122
    textEdit->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
122
    textEdit->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
123
    textEdit->setWordWrapMode(QTextOption::NoWrap);
123
    textEdit->setWordWrapMode(QTextOption::NoWrap);
124
    textEdit->setFont(QFont("Consolas", 8));
124
    textEdit->setFont(QFont("Consolas", 8));
125
    textEdit->setAcceptRichText(false);
125
    textEdit->setAcceptRichText(false);
126
    textEdit->setTabChangesFocus(true);
126
    textEdit->setTabChangesFocus(true);
127
    macroValueList.append(textEdit);
127
    valueList.append(textEdit);
128
 
128
 
129
    QPushButton *keyButton = new QPushButton("Hotkey: None");
129
    QPushButton *keyButton = new QPushButton("Hotkey: None");
130
    keyButton->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
130
    keyButton->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
131
    macroBtnKeyList.append(keyButton);
131
    btnKeyList.append(keyButton);
132
 
132
 
133
    QPushButton *pushButton = new QPushButton("Send Macro");
133
    QPushButton *pushButton = new QPushButton("Send Macro");
134
    pushButton->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
134
    pushButton->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
135
    pushButton->setEnabled(connected);
135
    pushButton->setEnabled(connected);
136
    macroBtnSendList.append(pushButton);
136
    btnSendList.append(pushButton);
137
 
137
 
138
    QVBoxLayout *tmpLayout = new QVBoxLayout();
138
    QVBoxLayout *tmpLayout = new QVBoxLayout();
139
    tmpLayout->addWidget(lineEdit);
139
    tmpLayout->addWidget(lineEdit);
140
    tmpLayout->addWidget(keyButton);
140
    tmpLayout->addWidget(keyButton);
141
    tmpLayout->addWidget(pushButton);
141
    tmpLayout->addWidget(pushButton);
142
 
142
 
143
    // Add layout/widgets to main layout
143
    // Add layout/widgets to main layout
144
    mainLayout->addLayout(tmpLayout, macroCount, 0);
144
    mainLayout->addLayout(tmpLayout, count, 0);
145
    mainLayout->addWidget(textEdit, macroCount, 1);
145
    mainLayout->addWidget(textEdit, count, 1);
146
    mainLayout->setColumnStretch(1, 1);
146
    mainLayout->setColumnStretch(1, 1);
147
 
147
 
148
    // Associate KeyButton with its corresponding ID
148
    // Associate KeyButton with its corresponding ID
149
    sigmapKeybind->setMapping(keyButton, macroCount-1);
149
    sigmapKeybind->setMapping(keyButton, count-1);
150
    connect(keyButton, SIGNAL(clicked()), sigmapKeybind, SLOT(map()));
150
    connect(keyButton, SIGNAL(clicked()), sigmapKeybind, SLOT(map()));
151
 
151
 
152
    // Associate PushButton with its corresponding TextEdit
152
    // Associate PushButton with its corresponding TextEdit
153
    sigmapTransmit->setMapping(pushButton, textEdit);
153
    sigmapTransmit->setMapping(pushButton, textEdit);
154
    connect(pushButton, SIGNAL(clicked()), sigmapTransmit, SLOT(map()));
154
    connect(pushButton, SIGNAL(clicked()), sigmapTransmit, SLOT(map()));
Line 161... Line 161...
161
        parent->resize(parent->width(), parent->height() + height);
161
        parent->resize(parent->width(), parent->height() + height);
162
 
162
 
163
    btnRemoveMacro->setEnabled(true);
163
    btnRemoveMacro->setEnabled(true);
164
}
164
}
165
 
165
 
166
void MacroWidget::Macro_RemoveEntry()
166
void MacroWidget::RemoveEntry()
167
{
167
{
168
 
168
 
169
    // Remove and delete layout/widgets at last macro slot
169
    // Remove and delete layout/widgets at last macro slot
170
    QLayoutItem *item = mainLayout->itemAtPosition(macroCount, 0);
170
    QLayoutItem *item = mainLayout->itemAtPosition(count, 0);
171
    while(!item->isEmpty())
171
    while(!item->isEmpty())
172
        delete item->layout()->takeAt(0)->widget();
172
        delete item->layout()->takeAt(0)->widget();
173
    delete item;
173
    delete item;
174
 
174
 
175
    item = mainLayout->itemAtPosition(macroCount, 1);
175
    item = mainLayout->itemAtPosition(count, 1);
176
    delete item->widget();
176
    delete item->widget();
177
 
177
 
178
    item = mainLayout->itemAtPosition(1, 1);
178
    item = mainLayout->itemAtPosition(1, 1);
179
    int height = item->widget()->height() + mainLayout->verticalSpacing();
179
    int height = item->widget()->height() + mainLayout->verticalSpacing();
180
 
180
 
181
    // Unmap and remove widgets from lists
181
    // Unmap and remove widgets from lists
182
    QPushButton *pushButton = macroBtnSendList.back();
182
    QPushButton *pushButton = btnSendList.back();
183
    sigmapTransmit->removeMappings(pushButton);
183
    sigmapTransmit->removeMappings(pushButton);
184
 
184
 
185
    QPushButton *keyButton = macroBtnKeyList.back();
185
    QPushButton *keyButton = btnKeyList.back();
186
    sigmapKeybind->removeMappings(keyButton);
186
    sigmapKeybind->removeMappings(keyButton);
187
 
187
 
188
    macroNameList.pop_back();
188
    nameList.pop_back();
189
    macroValueList.pop_back();
189
    valueList.pop_back();
190
    macroBtnSendList.pop_back();
190
    btnSendList.pop_back();
191
    macroBtnKeyList.pop_back();
191
    btnKeyList.pop_back();
192
 
192
 
193
    int index = registeredKeyMacroIDs.indexOf(macroCount-1);
193
    int index = registeredKeyMacroIDs.indexOf(count-1);
194
    if (index >= 0) {
194
    if (index >= 0) {
195
        registeredKeySequences.removeAt(index);
195
        registeredKeySequences.removeAt(index);
196
        registeredKeyMacroIDs.removeAt(index);
196
        registeredKeyMacroIDs.removeAt(index);
197
    }
197
    }
198
 
198
 
199
    macroCount--;
199
    count--;
200
 
200
 
201
    QDockWidget *parent = qobject_cast<QDockWidget*>(this->parent());
201
    QDockWidget *parent = qobject_cast<QDockWidget*>(this->parent());
202
    if (parent->isFloating())
202
    if (parent->isFloating())
203
        parent->resize(parent->width(), parent->height() - height);
203
        parent->resize(parent->width(), parent->height() - height);
204
 
204
 
205
    if (macroCount == 1)
205
    if (count == 1)
206
        btnRemoveMacro->setEnabled(false);
206
        btnRemoveMacro->setEnabled(false);
207
}
207
}
208
 
208
 
209
void MacroWidget::Macro_Clear()
209
void MacroWidget::Clear()
210
{
210
{
211
    for (int i = 0; i < macroCount; i++) {
211
    for (int i = 0; i < count; i++) {
212
        macroNameList[i]->setText(QString("Macro %1").arg(i+1));
212
        nameList[i]->setText(QString("Macro %1").arg(i+1));
213
        macroValueList[i]->clear();
213
        valueList[i]->clear();
214
        macroBtnKeyList[i]->setText("Hotkey: None");
214
        btnKeyList[i]->setText("Hotkey: None");
215
    }
215
    }
216
    registeredKeyMacroIDs.clear();
216
    registeredKeyMacroIDs.clear();
217
    registeredKeySequences.clear();
217
    registeredKeySequences.clear();
218
}
218
}
219
 
219
 
220
void MacroWidget::Macro_WriteToFile()
220
void MacroWidget::WriteToFile()
221
{
221
{
222
    QString file = QFileDialog::getSaveFileName(this, "Settings XML File", lastKnownFilePath, "XML File (*.xml)");
222
    QString file = QFileDialog::getSaveFileName(this, "Settings XML File", lastKnownFilePath, "XML File (*.xml)");
223
    QCoreApplication::processEvents(); // Wait for dialog to close
223
    QCoreApplication::processEvents(); // Wait for dialog to close
224
 
224
 
225
    if (file.size() == 0) return;
225
    if (file.size() == 0) return;
Line 239... Line 239...
239
 
239
 
240
    stream.writeStartDocument();
240
    stream.writeStartDocument();
241
    stream.writeStartElement("Settings");
241
    stream.writeStartElement("Settings");
242
    stream.writeStartElement("Macro");
242
    stream.writeStartElement("Macro");
243
 
243
 
244
    for (int i = 0; i < macroCount; i++) {
244
    for (int i = 0; i < count; i++) {
245
        stream.writeStartElement("Macro_Entry");
245
        stream.writeStartElement("Macro_Entry");
246
 
246
 
247
        stream.writeAttribute("Name", macroNameList[i]->text());
247
        stream.writeAttribute("Name", nameList[i]->text());
248
        stream.writeTextElement("Value", macroValueList[i]->toPlainText());
248
        stream.writeTextElement("Value", valueList[i]->toPlainText());
249
 
249
 
250
        int index = registeredKeyMacroIDs.indexOf(i);
250
        int index = registeredKeyMacroIDs.indexOf(i);
251
        if (index >= 0) {
251
        if (index >= 0) {
252
            stream.writeTextElement("Keybinding", registeredKeySequences[index].toString());
252
            stream.writeTextElement("Keybinding", registeredKeySequences[index].toString());
253
        } else {
253
        } else {
Line 262... Line 262...
262
    stream.writeEndDocument();
262
    stream.writeEndDocument();
263
 
263
 
264
    inputFile.close();
264
    inputFile.close();
265
}
265
}
266
 
266
 
267
void MacroWidget::Macro_ReadFromFile()
267
void MacroWidget::ReadFromFile()
268
{
268
{
269
    int counter = 0;
269
    int counter = 0;
270
 
270
 
271
    QString file = QFileDialog::getOpenFileName(this, "Settings XML File", lastKnownFilePath, "XML File (*.xml)");
271
    QString file = QFileDialog::getOpenFileName(this, "Settings XML File", lastKnownFilePath, "XML File (*.xml)");
272
    QCoreApplication::processEvents(); // Wait for dialog to close
272
    QCoreApplication::processEvents(); // Wait for dialog to close
273
 
273
 
274
    if (file.size() == 0) return;
274
    if (file.size() == 0) return;
275
 
275
 
276
    Macro_Clear();
276
    Clear();
277
 
277
 
278
    // If file was selected, save directory for next time
278
    // If file was selected, save directory for next time
279
    QFileInfo fileInfo = QFileInfo(file);
279
    QFileInfo fileInfo = QFileInfo(file);
280
    lastKnownFilePath = fileInfo.absolutePath();
280
    lastKnownFilePath = fileInfo.absolutePath();
281
 
281
 
Line 325... Line 325...
325
                    }
325
                    }
326
                    stream.readNext();
326
                    stream.readNext();
327
                }
327
                }
328
 
328
 
329
                // Write values to GUI
329
                // Write values to GUI
330
                if (counter == macroCount)
330
                if (counter == count)
331
                    Macro_AddEntry();
331
                    AddEntry();
332
 
332
 
333
                macroNameList[counter]->setText(name);
333
                nameList[counter]->setText(name);
334
                macroValueList[counter]->setText(value);
334
                valueList[counter]->setText(value);
335
                if (keybinding != "") {
335
                if (keybinding != "") {
336
                    registeredKeySequences.append(QKeySequence(keybinding));
336
                    registeredKeySequences.append(QKeySequence(keybinding));
337
                    registeredKeyMacroIDs.append(counter);
337
                    registeredKeyMacroIDs.append(counter);
338
                    macroBtnKeyList[counter]->setText("Hotkey: " + keybinding);
338
                    btnKeyList[counter]->setText("Hotkey: " + keybinding);
339
                }
339
                }
340
                counter++;
340
                counter++;
341
            }
341
            }
342
        }
342
        }
343
    }
343
    }
Line 358... Line 358...
358
        if (connected) {
358
        if (connected) {
359
            // First check if key sequence matches any saved ones
359
            // First check if key sequence matches any saved ones
360
            if (!registeredKeySequences.isEmpty()) {
360
            if (!registeredKeySequences.isEmpty()) {
361
                int index = registeredKeySequences.indexOf(seq);
361
                int index = registeredKeySequences.indexOf(seq);
362
                if (index >= 0) {
362
                if (index >= 0) {
363
                    Macro_InitTransmit(macroValueList[registeredKeyMacroIDs[index]]);
363
                    InitTransmit(valueList[registeredKeyMacroIDs[index]]);
364
                    return true;
364
                    return true;
365
                }
365
                }
366
            }
366
            }
367
        }
367
        }
368
 
368