From 3ebaa902b535773247105f3d0aa4e039ef7b55c6 Mon Sep 17 00:00:00 2001 From: daniel-Jones Date: Tue, 7 Jun 2016 21:38:15 +0930 Subject: Added ability to save presets from the UI, it takes current RGB values and allows you specify a preset name. --- qt/RGBController/.controllerwindow.cpp.swo | Bin 0 -> 16384 bytes qt/RGBController/.controllerwindow.h.swo | Bin 0 -> 12288 bytes qt/RGBController/controllerwindow.cpp | 47 ++++++++++++++++++++++++++-- qt/RGBController/controllerwindow.h | 5 ++- qt/RGBController/controllerwindow.ui | 28 +++++++++++------ qt/build/degub/RGBController | Bin 1294552 -> 1300072 bytes qt/build/degub/controllerwindow.o | Bin 994448 -> 1007624 bytes qt/build/degub/main.o | Bin 872920 -> 872920 bytes qt/build/degub/moc_controllerwindow.cpp | 48 ++++++++++++++++------------- qt/build/degub/moc_controllerwindow.o | Bin 970056 -> 971016 bytes qt/build/degub/old.txt | 12 -------- qt/build/degub/presets.txt | 11 +++++++ qt/build/degub/serial_communication.o | Bin 533368 -> 533368 bytes qt/build/degub/ui_controllerwindow.h | 30 +++++++++++++----- 14 files changed, 127 insertions(+), 54 deletions(-) create mode 100644 qt/RGBController/.controllerwindow.cpp.swo create mode 100644 qt/RGBController/.controllerwindow.h.swo delete mode 100644 qt/build/degub/old.txt create mode 100644 qt/build/degub/presets.txt (limited to 'qt') diff --git a/qt/RGBController/.controllerwindow.cpp.swo b/qt/RGBController/.controllerwindow.cpp.swo new file mode 100644 index 0000000..39ed63a Binary files /dev/null and b/qt/RGBController/.controllerwindow.cpp.swo differ diff --git a/qt/RGBController/.controllerwindow.h.swo b/qt/RGBController/.controllerwindow.h.swo new file mode 100644 index 0000000..b273e95 Binary files /dev/null and b/qt/RGBController/.controllerwindow.h.swo differ diff --git a/qt/RGBController/controllerwindow.cpp b/qt/RGBController/controllerwindow.cpp index c5a8e4d..250be58 100755 --- a/qt/RGBController/controllerwindow.cpp +++ b/qt/RGBController/controllerwindow.cpp @@ -16,6 +16,8 @@ controllerWindow::controllerWindow(QWidget *parent) : ui->off_button->setEnabled(false); ui->reload_preset_button->setEnabled(false); ui->set_preset_button->setEnabled(false); + ui->preset_save_button->setEnabled(false); + ui->preset_name_textbox->setEnabled(false); ui->presets_dropdown->setEnabled(false); ui->r_slider->setEnabled(false); ui->g_slider->setEnabled(false); @@ -99,7 +101,28 @@ void controllerWindow::load_presets() { show_msgbox("Unable to find the presets fle.\nThis file needs to be named 'presets.txt' and be located in the same directory as the binary."); info_log("Presets file not found."); - } + } +} + +void controllerWindow::save_preset(QString name) +{ + /* this function will save our preset to file */ + QFile file("presets.txt"); + if(!file.open(QIODevice::Append)) { + show_msgbox("Fatal error opening presets for appending text."); + + } else + { + QTextStream stream(&file); + stream << name << "=" << ui->r_slider->value() << "," << ui->g_slider->value() << "," << ui->b_slider->value() << endl; + file.close(); + info_log("Saved preset: " + name); + /* things to fix the presets list */ + ui->presets_dropdown->clear(); + presets.clear(); + preset_index = 0; + load_presets(); + } } void controllerWindow::serial_rgb_change(int r, int g, int b) @@ -141,6 +164,8 @@ void controllerWindow::on_connect_button_clicked() ui->off_button->setEnabled(true); ui->reload_preset_button->setEnabled(true); ui->set_preset_button->setEnabled(true); + ui->preset_save_button->setEnabled(true); + ui->preset_name_textbox->setEnabled(true); ui->presets_dropdown->setEnabled(true); ui->r_slider->setEnabled(true); ui->g_slider->setEnabled(true); @@ -171,6 +196,8 @@ void controllerWindow::on_disconnect_button_clicked() ui->blue_button->setEnabled(false); ui->off_button->setEnabled(false); ui->reload_preset_button->setEnabled(false); + ui->preset_save_button->setEnabled(false); + ui->preset_name_textbox->setEnabled(false); ui->set_preset_button->setEnabled(false); ui->presets_dropdown->setEnabled(false); ui->refresh_port_button->setEnabled(true); @@ -257,10 +284,26 @@ void controllerWindow::on_set_preset_button_clicked() ui->r_slider->setValue(temparray[0].toInt()); ui->g_slider->setValue(temparray[1].toInt()); ui->b_slider->setValue(temparray[2].toInt()); - } + } else + show_msgbox("There are no loaded presets!"); } void controllerWindow::on_presets_dropdown_currentIndexChanged(int index) { preset_index = index; } + +void controllerWindow::on_preset_save_button_clicked() +{ + QString tempname = ui->preset_name_textbox->text(); + if (tempname.contains("=")) + { + show_msgbox("Cannot save a preset with a name that contains an '='."); + } else if (tempname.isEmpty()) + { + show_msgbox("Cannot save a preset without a name."); + } else + { + save_preset(tempname); + } +} diff --git a/qt/RGBController/controllerwindow.h b/qt/RGBController/controllerwindow.h index d8c2403..690b52d 100755 --- a/qt/RGBController/controllerwindow.h +++ b/qt/RGBController/controllerwindow.h @@ -28,6 +28,7 @@ class controllerWindow : public QMainWindow void info_log(QString text); void populate_serial_list(); void load_presets(); + void save_preset(QString name); void serial_rgb_change(int r, int g, int b); void show_msgbox(QString message); /*public variables */ @@ -68,7 +69,9 @@ class controllerWindow : public QMainWindow void on_presets_dropdown_currentIndexChanged(int index); - private: + void on_preset_save_button_clicked(); + +private: Ui::controllerWindow *ui; /* serial communication object */ serial_communication portf; diff --git a/qt/RGBController/controllerwindow.ui b/qt/RGBController/controllerwindow.ui index e96fcf0..8ee839e 100755 --- a/qt/RGBController/controllerwindow.ui +++ b/qt/RGBController/controllerwindow.ui @@ -9,8 +9,8 @@ 0 0 - 229 - 394 + 235 + 402 @@ -184,13 +184,6 @@ - - - - Reload - - - @@ -211,6 +204,23 @@ + + + + + + + Reload + + + + + + + Save + + + diff --git a/qt/build/degub/RGBController b/qt/build/degub/RGBController index 5697898..fecc4e7 100755 Binary files a/qt/build/degub/RGBController and b/qt/build/degub/RGBController differ diff --git a/qt/build/degub/controllerwindow.o b/qt/build/degub/controllerwindow.o index 650edf3..c5c9213 100644 Binary files a/qt/build/degub/controllerwindow.o and b/qt/build/degub/controllerwindow.o differ diff --git a/qt/build/degub/main.o b/qt/build/degub/main.o index 1f486a8..8f14278 100644 Binary files a/qt/build/degub/main.o and b/qt/build/degub/main.o differ diff --git a/qt/build/degub/moc_controllerwindow.cpp b/qt/build/degub/moc_controllerwindow.cpp index 6541f0e..8d6a754 100755 --- a/qt/build/degub/moc_controllerwindow.cpp +++ b/qt/build/degub/moc_controllerwindow.cpp @@ -19,8 +19,8 @@ QT_BEGIN_MOC_NAMESPACE struct qt_meta_stringdata_controllerWindow_t { - QByteArrayData data[17]; - char stringdata0[383]; + QByteArrayData data[18]; + char stringdata0[413]; }; #define QT_MOC_LITERAL(idx, ofs, len) \ Q_STATIC_BYTE_ARRAY_DATA_HEADER_INITIALIZER_WITH_OFFSET(len, \ @@ -45,7 +45,8 @@ QT_MOC_LITERAL(12, 263, 22), // "on_blue_button_clicked" QT_MOC_LITERAL(13, 286, 21), // "on_off_button_clicked" QT_MOC_LITERAL(14, 308, 28), // "on_set_preset_button_clicked" QT_MOC_LITERAL(15, 337, 39), // "on_presets_dropdown_currentIn..." -QT_MOC_LITERAL(16, 377, 5) // "index" +QT_MOC_LITERAL(16, 377, 5), // "index" +QT_MOC_LITERAL(17, 383, 29) // "on_preset_save_button_clicked" }, "controllerWindow\0on_connect_button_clicked\0" @@ -59,7 +60,7 @@ QT_MOC_LITERAL(16, 377, 5) // "index" "on_off_button_clicked\0" "on_set_preset_button_clicked\0" "on_presets_dropdown_currentIndexChanged\0" - "index" + "index\0on_preset_save_button_clicked" }; #undef QT_MOC_LITERAL @@ -69,7 +70,7 @@ static const uint qt_meta_data_controllerWindow[] = { 7, // revision 0, // classname 0, 0, // classinfo - 13, 14, // methods + 14, 14, // methods 0, 0, // properties 0, 0, // enums/sets 0, 0, // constructors @@ -77,19 +78,20 @@ static const uint qt_meta_data_controllerWindow[] = { 0, // signalCount // slots: name, argc, parameters, tag, flags - 1, 0, 79, 2, 0x08 /* Private */, - 3, 0, 80, 2, 0x08 /* Private */, - 4, 0, 81, 2, 0x08 /* Private */, - 5, 0, 82, 2, 0x08 /* Private */, - 6, 1, 83, 2, 0x08 /* Private */, - 8, 1, 86, 2, 0x08 /* Private */, - 9, 1, 89, 2, 0x08 /* Private */, - 10, 0, 92, 2, 0x08 /* Private */, - 11, 0, 93, 2, 0x08 /* Private */, - 12, 0, 94, 2, 0x08 /* Private */, - 13, 0, 95, 2, 0x08 /* Private */, - 14, 0, 96, 2, 0x08 /* Private */, - 15, 1, 97, 2, 0x08 /* Private */, + 1, 0, 84, 2, 0x08 /* Private */, + 3, 0, 85, 2, 0x08 /* Private */, + 4, 0, 86, 2, 0x08 /* Private */, + 5, 0, 87, 2, 0x08 /* Private */, + 6, 1, 88, 2, 0x08 /* Private */, + 8, 1, 91, 2, 0x08 /* Private */, + 9, 1, 94, 2, 0x08 /* Private */, + 10, 0, 97, 2, 0x08 /* Private */, + 11, 0, 98, 2, 0x08 /* Private */, + 12, 0, 99, 2, 0x08 /* Private */, + 13, 0, 100, 2, 0x08 /* Private */, + 14, 0, 101, 2, 0x08 /* Private */, + 15, 1, 102, 2, 0x08 /* Private */, + 17, 0, 105, 2, 0x08 /* Private */, // slots: parameters QMetaType::Void, @@ -105,6 +107,7 @@ static const uint qt_meta_data_controllerWindow[] = { QMetaType::Void, QMetaType::Void, QMetaType::Void, QMetaType::Int, 16, + QMetaType::Void, 0 // eod }; @@ -128,6 +131,7 @@ void controllerWindow::qt_static_metacall(QObject *_o, QMetaObject::Call _c, int case 10: _t->on_off_button_clicked(); break; case 11: _t->on_set_preset_button_clicked(); break; case 12: _t->on_presets_dropdown_currentIndexChanged((*reinterpret_cast< int(*)>(_a[1]))); break; + case 13: _t->on_preset_save_button_clicked(); break; default: ; } } @@ -158,13 +162,13 @@ int controllerWindow::qt_metacall(QMetaObject::Call _c, int _id, void **_a) if (_id < 0) return _id; if (_c == QMetaObject::InvokeMetaMethod) { - if (_id < 13) + if (_id < 14) qt_static_metacall(this, _c, _id, _a); - _id -= 13; + _id -= 14; } else if (_c == QMetaObject::RegisterMethodArgumentMetaType) { - if (_id < 13) + if (_id < 14) *reinterpret_cast(_a[0]) = -1; - _id -= 13; + _id -= 14; } return _id; } diff --git a/qt/build/degub/moc_controllerwindow.o b/qt/build/degub/moc_controllerwindow.o index dd21680..5adbd14 100644 Binary files a/qt/build/degub/moc_controllerwindow.o and b/qt/build/degub/moc_controllerwindow.o differ diff --git a/qt/build/degub/old.txt b/qt/build/degub/old.txt deleted file mode 100644 index 776a532..0000000 --- a/qt/build/degub/old.txt +++ /dev/null @@ -1,12 +0,0 @@ -Only add things to this file if you know what you are doing. -Don't be dumb. - -The program only cares for lines here if they contain the equals symbol. -Everything else is ignored - if you add an equals symbol to this file, you will most likely crash it. - -white=255,255,255 -purple=255,0,255 -light purple=255,55,255 -yellow=255,83,0 -light blue=0,255,255 - diff --git a/qt/build/degub/presets.txt b/qt/build/degub/presets.txt new file mode 100644 index 0000000..7bc9af4 --- /dev/null +++ b/qt/build/degub/presets.txt @@ -0,0 +1,11 @@ +Only add things to this file if you know what you are doing. +Don't be dumb. + +The program only cares for lines here if they contain the equals symbol. +Everything else is ignored - if you add an equals symbol to this file, you will most likely crash it. + +white=255,255,255 +purple=255,0,255 +light purple=255,55,255 +yellow=255,83,0 +light blue=0,255,255 diff --git a/qt/build/degub/serial_communication.o b/qt/build/degub/serial_communication.o index f00df38..dd01faa 100644 Binary files a/qt/build/degub/serial_communication.o and b/qt/build/degub/serial_communication.o differ diff --git a/qt/build/degub/ui_controllerwindow.h b/qt/build/degub/ui_controllerwindow.h index 1bebf40..f110c61 100755 --- a/qt/build/degub/ui_controllerwindow.h +++ b/qt/build/degub/ui_controllerwindow.h @@ -17,6 +17,7 @@ #include #include #include +#include #include #include #include @@ -47,17 +48,19 @@ public: QLabel *presets_label; QPushButton *off_button; QLabel *info_log_label; - QPushButton *reload_preset_button; QPushButton *set_preset_button; QComboBox *presets_dropdown; QTextEdit *info_log_textarea; + QLineEdit *preset_name_textbox; + QPushButton *reload_preset_button; + QPushButton *preset_save_button; void setupUi(QMainWindow *controllerWindow) { if (controllerWindow->objectName().isEmpty()) controllerWindow->setObjectName(QStringLiteral("controllerWindow")); controllerWindow->setWindowModality(Qt::WindowModal); - controllerWindow->resize(229, 394); + controllerWindow->resize(235, 402); centralWidget = new QWidget(controllerWindow); centralWidget->setObjectName(QStringLiteral("centralWidget")); formLayout = new QFormLayout(centralWidget); @@ -162,11 +165,6 @@ public: formLayout->setWidget(12, QFormLayout::LabelRole, info_log_label); - reload_preset_button = new QPushButton(centralWidget); - reload_preset_button->setObjectName(QStringLiteral("reload_preset_button")); - - formLayout->setWidget(11, QFormLayout::FieldRole, reload_preset_button); - set_preset_button = new QPushButton(centralWidget); set_preset_button->setObjectName(QStringLiteral("set_preset_button")); @@ -183,6 +181,21 @@ public: formLayout->setWidget(13, QFormLayout::SpanningRole, info_log_textarea); + preset_name_textbox = new QLineEdit(centralWidget); + preset_name_textbox->setObjectName(QStringLiteral("preset_name_textbox")); + + formLayout->setWidget(11, QFormLayout::LabelRole, preset_name_textbox); + + reload_preset_button = new QPushButton(centralWidget); + reload_preset_button->setObjectName(QStringLiteral("reload_preset_button")); + + formLayout->setWidget(12, QFormLayout::FieldRole, reload_preset_button); + + preset_save_button = new QPushButton(centralWidget); + preset_save_button->setObjectName(QStringLiteral("preset_save_button")); + + formLayout->setWidget(11, QFormLayout::FieldRole, preset_save_button); + controllerWindow->setCentralWidget(centralWidget); retranslateUi(controllerWindow); @@ -206,8 +219,9 @@ public: presets_label->setText(QApplication::translate("controllerWindow", "Presets", 0)); off_button->setText(QApplication::translate("controllerWindow", "Off", 0)); info_log_label->setText(QApplication::translate("controllerWindow", "Information log", 0)); - reload_preset_button->setText(QApplication::translate("controllerWindow", "Reload", 0)); set_preset_button->setText(QApplication::translate("controllerWindow", "Set", 0)); + reload_preset_button->setText(QApplication::translate("controllerWindow", "Reload", 0)); + preset_save_button->setText(QApplication::translate("controllerWindow", "Save", 0)); } // retranslateUi }; -- cgit v1.2.3