Subversion Repositories Code-Repo

Compare Revisions

No changes between revisions

Ignore whitespace Rev 348 → Rev 349

/Misc Projects/PcMarlinInterface/MacroController.cpp
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);
}
/Misc Projects/PcMarlinInterface/MacroController.h
3,7 → 3,7
 
#include "GlobalDefines.h"
 
#define MACRO_DEFAULT_COUNT 6
#define MACRO_DEFAULT_COUNT 4
 
class MacroController : public QWidget
{
19,6 → 19,7
void Macro_EnableTransmit(void);
void Macro_DisableTransmit(void);
void Macro_InitTransmit(QWidget* t);
void Macro_KeybindPrompt(int id);
void Macro_AddEntry(void);
void Macro_RemoveEntry(void);
void Macro_WriteToFile(void);
27,6 → 28,9
signals:
void Macro_TransmitText(QString string);
 
protected:
bool eventFilter(QObject *, QEvent *);
 
private:
int macroCount;
bool connected;
39,12 → 43,16
 
QList<QLineEdit*> macroNameList;
QList<QTextEdit*> macroValueList;
QList<QPushButton*> macroBtnList;
QList<QPushButton*> macroBtnSendList;
QList<QPushButton*> macroBtnKeyList;
QList<QKeySequence> macroKeybindList;
 
QGridLayout *mainLayout;
QHBoxLayout *ioLayout;
QSignalMapper *sigMapper;
QSignalMapper *sigmapTransmit;
QSignalMapper *sigmapKeybind;
 
QPair<QPushButton*,int> currKeyBindInfo;
};
 
#endif // MACROCONTROLLER
 
/Misc Projects/PcMarlinInterface/MainWindow.cpp
216,6 → 216,10
btnSerialConnect->setText("&Disconnect");
cboxSerialPort->setEnabled(false);
cboxSerialSpeed->setEnabled(false);
cboxSerialDataBits->setEnabled(false);
cboxSerialStopBits->setEnabled(false);
cboxSerialParity->setEnabled(false);
cboxSerialFlowControl->setEnabled(false);
btnSerialRefresh->setEnabled(false);
textSerialTransmit->setEnabled(true);
btnSerialTransmit->setEnabled(true);
226,6 → 230,10
btnSerialConnect->setText("&Connect");
cboxSerialPort->setEnabled(true);
cboxSerialSpeed->setEnabled(true);
cboxSerialDataBits->setEnabled(true);
cboxSerialStopBits->setEnabled(true);
cboxSerialParity->setEnabled(true);
cboxSerialFlowControl->setEnabled(true);
btnSerialRefresh->setEnabled(true);
textSerialTransmit->setEnabled(false);
btnSerialTransmit->setEnabled(false);
/Misc Projects/PcMarlinInterface/Resources/Icon.ico
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream