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 +++++++++++------ 5 files changed, 68 insertions(+), 12 deletions(-) create mode 100644 qt/RGBController/.controllerwindow.cpp.swo create mode 100644 qt/RGBController/.controllerwindow.h.swo (limited to 'qt/RGBController') 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 + + + -- cgit v1.2.3