Skip to content

Commit

Permalink
[ADDED] Widgets' info saved more frequently, but not with a high cpu …
Browse files Browse the repository at this point in the history
…usage.
  • Loading branch information
eminfedar committed Jan 15, 2018
1 parent d77c59a commit 205c0d2
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
1 change: 1 addition & 0 deletions widgetci/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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...)
Expand Down
16 changes: 16 additions & 0 deletions widgetci/wwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
10 changes: 10 additions & 0 deletions widgetci/wwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <QQuickView>
#include <QObject>
#include <QMenu>
#include <QSettings>

class WWidget : public QQuickView
{
Expand All @@ -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;
Expand All @@ -44,11 +49,16 @@ class WWidget : public QQuickView
Qt::WindowFlags latestFlags; // For storing the latest change of flags
QVector<QAction*> 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

0 comments on commit 205c0d2

Please sign in to comment.