From 205c0d2bbc9d4761060b7dbf4a369ea57674e22b Mon Sep 17 00:00:00 2001 From: eminfedar Date: Mon, 15 Jan 2018 17:34:04 +0300 Subject: [PATCH] [ADDED] Widgets' info saved more frequently, but not with a high cpu usage. --- widgetci/mainwindow.cpp | 1 + widgetci/wwidget.cpp | 16 ++++++++++++++++ widgetci/wwidget.h | 10 ++++++++++ 3 files changed, 27 insertions(+) diff --git a/widgetci/mainwindow.cpp b/widgetci/mainwindow.cpp index 9784acd..5dd5f2f 100644 --- a/widgetci/mainwindow.cpp +++ b/widgetci/mainwindow.cpp @@ -74,6 +74,7 @@ void mainWindow::toggleWidget(QTreeWidgetItem *item, int wx = -1000, int wy = -1 WWidget *wid = new WWidget(QUrl::fromLocalFile(widgetsDir + "/" + wid_filename + "/main.qml"), wid_filename, wx, wy); wid->toggleZPos(widConf["z-pos"].toInt()); wid->toggleLock(widConf["lock"].toBool()); + wid->widgetSettings = widgetsDataSettings; // Check for errors. (File not found etc...) diff --git a/widgetci/wwidget.cpp b/widgetci/wwidget.cpp index 7ebe89a..f03f034 100644 --- a/widgetci/wwidget.cpp +++ b/widgetci/wwidget.cpp @@ -76,6 +76,22 @@ void WWidget::mouseReleaseEvent(QMouseEvent *event){ isDragging = false; } +void WWidget::focusOutEvent(QFocusEvent *event){ + Q_UNUSED(event); + saveSettings(); +} + +void WWidget::saveSettings(){ + widgetSettings->beginGroup(filename); + widgetSettings->setValue("x", this->x()); + widgetSettings->setValue("y", this->y()); + widgetSettings->setValue("visible", this->isVisible()); + widgetSettings->setValue("z-pos", this->z_pos); + widgetSettings->setValue("lock", this->lock); + widgetSettings->endGroup(); + widgetSettings->sync(); +} + void WWidget::toggleZPos(int z_index = 0){ this->z_pos = z_index; switch (z_index) { diff --git a/widgetci/wwidget.h b/widgetci/wwidget.h index d6ecdec..38e26ab 100644 --- a/widgetci/wwidget.h +++ b/widgetci/wwidget.h @@ -3,6 +3,7 @@ #include #include #include +#include class WWidget : public QQuickView { @@ -27,6 +28,10 @@ class WWidget : public QQuickView void toggleZPos(int z_index); // Toggle between z positions. void toggleLock(bool t_lock); // Toggle the lock QAction* act_Lock; + QSettings* widgetSettings; + + void saveSettings(); + private: // Window Dragging. bool isDragging = false; @@ -44,11 +49,16 @@ class WWidget : public QQuickView Qt::WindowFlags latestFlags; // For storing the latest change of flags QVector actionsList; + + protected: // Window Dragging & Right Click void mousePressEvent(QMouseEvent* event) override; void mouseMoveEvent(QMouseEvent* event) override; void mouseReleaseEvent(QMouseEvent* event) override; + + void focusOutEvent(QFocusEvent* event) override; + }; #endif // WWIDGET_H