summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xqt/RGBController/RGBController.pro.user2
-rwxr-xr-xqt/RGBController/controllerwindow.cpp113
-rwxr-xr-xqt/RGBController/controllerwindow.h3
-rwxr-xr-xqt/RGBController/controllerwindow.ui25
-rwxr-xr-xqt/build/degub/RGBControllerbin1302536 -> 1306008 bytes
-rw-r--r--qt/build/degub/controllerwindow.obin1007824 -> 1018376 bytes
-rw-r--r--qt/build/degub/main.obin872920 -> 872920 bytes
-rwxr-xr-xqt/build/degub/moc_controllerwindow.cpp51
-rw-r--r--qt/build/degub/moc_controllerwindow.obin971016 -> 971632 bytes
-rwxr-xr-xqt/build/degub/ui_controllerwindow.h31
10 files changed, 149 insertions, 76 deletions
diff --git a/qt/RGBController/RGBController.pro.user b/qt/RGBController/RGBController.pro.user
index cd38fba..fea7287 100755
--- a/qt/RGBController/RGBController.pro.user
+++ b/qt/RGBController/RGBController.pro.user
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE QtCreatorProject>
-<!-- Written by QtCreator 4.0.0, 2016-06-15T13:55:50. -->
+<!-- Written by QtCreator 4.0.0, 2016-06-27T00:50:07. -->
<qtcreator>
<data>
<variable>EnvironmentId</variable>
diff --git a/qt/RGBController/controllerwindow.cpp b/qt/RGBController/controllerwindow.cpp
index ef0ab30..b258ff2 100755
--- a/qt/RGBController/controllerwindow.cpp
+++ b/qt/RGBController/controllerwindow.cpp
@@ -16,8 +16,9 @@ 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->preset_save_button->setEnabled(false);
+ ui->preset_delete_button->setEnabled(false);
+ ui->preset_name_textbox->setEnabled(false);
ui->presets_dropdown->setEnabled(false);
ui->r_slider->setEnabled(false);
ui->g_slider->setEnabled(false);
@@ -83,10 +84,8 @@ void controllerWindow::load_presets()
* -> add [0] to dropdown (name), add [1] to an array that stores all the values
*/
- /* PLEASE READ ME
- * This is a hard coded directory for i3wm's sake, you have to fix this yourself.
- */
- QFile inputFile("/home/daniel_j/documents/school/2016\ research\ project/RGBController/qt/build/degub/presets.txt");
+
+ QFile inputFile("presets.txt");
if (inputFile.open(QIODevice::ReadOnly))
{
QTextStream in(&inputFile);
@@ -105,28 +104,72 @@ void controllerWindow::load_presets()
{
show_msgbox("Unable to find the presets file.\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");
+ /* 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::delete_preset(QString name)
+{
+ /*
+ * here we will delete a preset from the presets file
+ * process:
+ * retrieve preset name
+ * go through preset file line by line and write it to a seperate tmp file
+ * if the [0] of split('=') equals the preset name, don't write it to the tmp file
+ * delete the old preset file
+ * rename the tmp file to presets.txt
+ */
+ info_log("deleting preset: " + name);
+ QFile file("tmp.file");
if(!file.open(QIODevice::Append)) {
- show_msgbox("Fatal error opening presets for appending text.");
+ show_msgbox("Fatal error opening temp file for writing");
} else
{
QTextStream stream(&file);
- stream << name << "=" << ui->r_slider->value() << "," << ui->g_slider->value() << "," << ui->b_slider->value() << endl;
+ //stream << "test tmp file" << endl;
+ for (int x = 0; x < ui->presets_dropdown->count(); x++)
+ {
+ if(name != ui->presets_dropdown->itemText(x))
+ {
+ info_log("adding: " + ui->presets_dropdown->itemText(x) + "=" + presets.at(x));
+ stream << ui->presets_dropdown->itemText(x) << "=" << presets.at(x) << endl;
+ } else
+ {
+ info_log("not adding: " + ui->presets_dropdown->itemText(x) + "=" + presets.at(x));
+ }
+ }
file.close();
- info_log("Saved preset: " + name);
- /* things to fix the presets list */
+ /* remove the current presets file then rename the temp file to presets.txt */
+ QFile::remove("presets.txt");
+ QFile::rename("tmp.file", "presets.txt");
+ /* reload presets into memory and clear the drop down box */
ui->presets_dropdown->clear();
presets.clear();
preset_index = 0;
load_presets();
}
+
}
void controllerWindow::serial_rgb_change(int r, int g, int b)
@@ -136,6 +179,7 @@ void controllerWindow::serial_rgb_change(int r, int g, int b)
void controllerWindow::show_msgbox(QString message)
{
+ /* show message box to the user */
QMessageBox msgbox;
msgbox.setText(message);
msgbox.exec();
@@ -168,8 +212,9 @@ 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->preset_save_button->setEnabled(true);
+ ui->preset_delete_button->setEnabled(true);
+ ui->preset_name_textbox->setEnabled(true);
ui->presets_dropdown->setEnabled(true);
ui->r_slider->setEnabled(true);
ui->g_slider->setEnabled(true);
@@ -200,8 +245,9 @@ 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->preset_save_button->setEnabled(false);
+ ui->preset_delete_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);
@@ -288,8 +334,8 @@ 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!");
+ } else
+ show_msgbox("There are no loaded presets!");
}
void controllerWindow::on_presets_dropdown_currentIndexChanged(int index)
@@ -299,16 +345,21 @@ void controllerWindow::on_presets_dropdown_currentIndexChanged(int 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);
- }
- ui->preset_name_textbox->clear();
+ 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);
+ }
+ ui->preset_name_textbox->clear();
+}
+
+void controllerWindow::on_preset_delete_button_clicked()
+{
+ delete_preset(ui->presets_dropdown->currentText());
}
diff --git a/qt/RGBController/controllerwindow.h b/qt/RGBController/controllerwindow.h
index 690b52d..9f73749 100755
--- a/qt/RGBController/controllerwindow.h
+++ b/qt/RGBController/controllerwindow.h
@@ -29,6 +29,7 @@ class controllerWindow : public QMainWindow
void populate_serial_list();
void load_presets();
void save_preset(QString name);
+ void delete_preset(QString name);
void serial_rgb_change(int r, int g, int b);
void show_msgbox(QString message);
/*public variables */
@@ -71,6 +72,8 @@ class controllerWindow : public QMainWindow
void on_preset_save_button_clicked();
+ void on_preset_delete_button_clicked();
+
private:
Ui::controllerWindow *ui;
/* serial communication object */
diff --git a/qt/RGBController/controllerwindow.ui b/qt/RGBController/controllerwindow.ui
index 8ee839e..d582851 100755
--- a/qt/RGBController/controllerwindow.ui
+++ b/qt/RGBController/controllerwindow.ui
@@ -10,7 +10,7 @@
<x>0</x>
<y>0</y>
<width>235</width>
- <height>402</height>
+ <height>428</height>
</rect>
</property>
<property name="windowTitle">
@@ -177,7 +177,7 @@
</property>
</widget>
</item>
- <item row="12" column="0">
+ <item row="14" column="0">
<widget class="QLabel" name="info_log_label">
<property name="text">
<string>Information log</string>
@@ -201,23 +201,30 @@
</property>
</widget>
</item>
- <item row="13" column="0" colspan="2">
+ <item row="15" column="0" colspan="2">
<widget class="QTextEdit" name="info_log_textarea"/>
</item>
- <item row="11" column="0">
+ <item row="12" column="0">
<widget class="QLineEdit" name="preset_name_textbox"/>
</item>
<item row="12" column="1">
- <widget class="QPushButton" name="reload_preset_button">
+ <widget class="QPushButton" name="preset_save_button">
<property name="text">
- <string>Reload</string>
+ <string>Save</string>
</property>
</widget>
</item>
- <item row="11" column="1">
- <widget class="QPushButton" name="preset_save_button">
+ <item row="13" column="1">
+ <widget class="QPushButton" name="preset_delete_button">
<property name="text">
- <string>Save</string>
+ <string>Delete</string>
+ </property>
+ </widget>
+ </item>
+ <item row="11" column="0">
+ <widget class="QPushButton" name="reload_preset_button">
+ <property name="text">
+ <string>Reload</string>
</property>
</widget>
</item>
diff --git a/qt/build/degub/RGBController b/qt/build/degub/RGBController
index 21a2bfd..3dbeac9 100755
--- a/qt/build/degub/RGBController
+++ b/qt/build/degub/RGBController
Binary files differ
diff --git a/qt/build/degub/controllerwindow.o b/qt/build/degub/controllerwindow.o
index 07494b6..7fce5fa 100644
--- a/qt/build/degub/controllerwindow.o
+++ b/qt/build/degub/controllerwindow.o
Binary files differ
diff --git a/qt/build/degub/main.o b/qt/build/degub/main.o
index 8f14278..bb17f39 100644
--- a/qt/build/degub/main.o
+++ b/qt/build/degub/main.o
Binary files differ
diff --git a/qt/build/degub/moc_controllerwindow.cpp b/qt/build/degub/moc_controllerwindow.cpp
index 8d6a754..07e69be 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[18];
- char stringdata0[413];
+ QByteArrayData data[19];
+ char stringdata0[445];
};
#define QT_MOC_LITERAL(idx, ofs, len) \
Q_STATIC_BYTE_ARRAY_DATA_HEADER_INITIALIZER_WITH_OFFSET(len, \
@@ -46,7 +46,8 @@ 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(17, 383, 29) // "on_preset_save_button_clicked"
+QT_MOC_LITERAL(17, 383, 29), // "on_preset_save_button_clicked"
+QT_MOC_LITERAL(18, 413, 31) // "on_preset_delete_button_clicked"
},
"controllerWindow\0on_connect_button_clicked\0"
@@ -60,7 +61,8 @@ QT_MOC_LITERAL(17, 383, 29) // "on_preset_save_button_clicked"
"on_off_button_clicked\0"
"on_set_preset_button_clicked\0"
"on_presets_dropdown_currentIndexChanged\0"
- "index\0on_preset_save_button_clicked"
+ "index\0on_preset_save_button_clicked\0"
+ "on_preset_delete_button_clicked"
};
#undef QT_MOC_LITERAL
@@ -70,7 +72,7 @@ static const uint qt_meta_data_controllerWindow[] = {
7, // revision
0, // classname
0, 0, // classinfo
- 14, 14, // methods
+ 15, 14, // methods
0, 0, // properties
0, 0, // enums/sets
0, 0, // constructors
@@ -78,20 +80,21 @@ static const uint qt_meta_data_controllerWindow[] = {
0, // signalCount
// slots: name, argc, parameters, tag, flags
- 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 */,
+ 1, 0, 89, 2, 0x08 /* Private */,
+ 3, 0, 90, 2, 0x08 /* Private */,
+ 4, 0, 91, 2, 0x08 /* Private */,
+ 5, 0, 92, 2, 0x08 /* Private */,
+ 6, 1, 93, 2, 0x08 /* Private */,
+ 8, 1, 96, 2, 0x08 /* Private */,
+ 9, 1, 99, 2, 0x08 /* Private */,
+ 10, 0, 102, 2, 0x08 /* Private */,
+ 11, 0, 103, 2, 0x08 /* Private */,
+ 12, 0, 104, 2, 0x08 /* Private */,
+ 13, 0, 105, 2, 0x08 /* Private */,
+ 14, 0, 106, 2, 0x08 /* Private */,
+ 15, 1, 107, 2, 0x08 /* Private */,
+ 17, 0, 110, 2, 0x08 /* Private */,
+ 18, 0, 111, 2, 0x08 /* Private */,
// slots: parameters
QMetaType::Void,
@@ -108,6 +111,7 @@ static const uint qt_meta_data_controllerWindow[] = {
QMetaType::Void,
QMetaType::Void, QMetaType::Int, 16,
QMetaType::Void,
+ QMetaType::Void,
0 // eod
};
@@ -132,6 +136,7 @@ void controllerWindow::qt_static_metacall(QObject *_o, QMetaObject::Call _c, int
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;
+ case 14: _t->on_preset_delete_button_clicked(); break;
default: ;
}
}
@@ -162,13 +167,13 @@ int controllerWindow::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
if (_id < 0)
return _id;
if (_c == QMetaObject::InvokeMetaMethod) {
- if (_id < 14)
+ if (_id < 15)
qt_static_metacall(this, _c, _id, _a);
- _id -= 14;
+ _id -= 15;
} else if (_c == QMetaObject::RegisterMethodArgumentMetaType) {
- if (_id < 14)
+ if (_id < 15)
*reinterpret_cast<int*>(_a[0]) = -1;
- _id -= 14;
+ _id -= 15;
}
return _id;
}
diff --git a/qt/build/degub/moc_controllerwindow.o b/qt/build/degub/moc_controllerwindow.o
index 5adbd14..9086496 100644
--- a/qt/build/degub/moc_controllerwindow.o
+++ b/qt/build/degub/moc_controllerwindow.o
Binary files differ
diff --git a/qt/build/degub/ui_controllerwindow.h b/qt/build/degub/ui_controllerwindow.h
index f110c61..03ce981 100755
--- a/qt/build/degub/ui_controllerwindow.h
+++ b/qt/build/degub/ui_controllerwindow.h
@@ -52,15 +52,16 @@ public:
QComboBox *presets_dropdown;
QTextEdit *info_log_textarea;
QLineEdit *preset_name_textbox;
- QPushButton *reload_preset_button;
QPushButton *preset_save_button;
+ QPushButton *preset_delete_button;
+ QPushButton *reload_preset_button;
void setupUi(QMainWindow *controllerWindow)
{
if (controllerWindow->objectName().isEmpty())
controllerWindow->setObjectName(QStringLiteral("controllerWindow"));
controllerWindow->setWindowModality(Qt::WindowModal);
- controllerWindow->resize(235, 402);
+ controllerWindow->resize(235, 428);
centralWidget = new QWidget(controllerWindow);
centralWidget->setObjectName(QStringLiteral("centralWidget"));
formLayout = new QFormLayout(centralWidget);
@@ -163,7 +164,7 @@ public:
info_log_label = new QLabel(centralWidget);
info_log_label->setObjectName(QStringLiteral("info_log_label"));
- formLayout->setWidget(12, QFormLayout::LabelRole, info_log_label);
+ formLayout->setWidget(14, QFormLayout::LabelRole, info_log_label);
set_preset_button = new QPushButton(centralWidget);
set_preset_button->setObjectName(QStringLiteral("set_preset_button"));
@@ -179,22 +180,27 @@ public:
info_log_textarea = new QTextEdit(centralWidget);
info_log_textarea->setObjectName(QStringLiteral("info_log_textarea"));
- formLayout->setWidget(13, QFormLayout::SpanningRole, info_log_textarea);
+ formLayout->setWidget(15, 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);
+ formLayout->setWidget(12, QFormLayout::LabelRole, preset_name_textbox);
preset_save_button = new QPushButton(centralWidget);
preset_save_button->setObjectName(QStringLiteral("preset_save_button"));
- formLayout->setWidget(11, QFormLayout::FieldRole, preset_save_button);
+ formLayout->setWidget(12, QFormLayout::FieldRole, preset_save_button);
+
+ preset_delete_button = new QPushButton(centralWidget);
+ preset_delete_button->setObjectName(QStringLiteral("preset_delete_button"));
+
+ formLayout->setWidget(13, QFormLayout::FieldRole, preset_delete_button);
+
+ reload_preset_button = new QPushButton(centralWidget);
+ reload_preset_button->setObjectName(QStringLiteral("reload_preset_button"));
+
+ formLayout->setWidget(11, QFormLayout::LabelRole, reload_preset_button);
controllerWindow->setCentralWidget(centralWidget);
@@ -220,8 +226,9 @@ public:
off_button->setText(QApplication::translate("controllerWindow", "Off", 0));
info_log_label->setText(QApplication::translate("controllerWindow", "Information log", 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));
+ preset_delete_button->setText(QApplication::translate("controllerWindow", "Delete", 0));
+ reload_preset_button->setText(QApplication::translate("controllerWindow", "Reload", 0));
} // retranslateUi
};