summaryrefslogtreecommitdiffstats
path: root/src/gui/osd.cpp
diff options
context:
space:
mode:
authorLubos Dolezel <lubos@dolezel.info>2015-06-11 15:16:39 +0200
committerLubos Dolezel <lubos@dolezel.info>2015-06-11 15:16:39 +0200
commitbaedd87c10dabb9178ec870ea43185f4c34795ea (patch)
treefd0e5d9b795796f4c6dcdd72b17960f7f13a45af /src/gui/osd.cpp
parentc0fb261ea49f638b49ed68c5eb5385c11ab8d407 (diff)
downloadtwinkle-baedd87c10dabb9178ec870ea43185f4c34795ea.tar
twinkle-baedd87c10dabb9178ec870ea43185f4c34795ea.tar.gz
twinkle-baedd87c10dabb9178ec870ea43185f4c34795ea.tar.lz
twinkle-baedd87c10dabb9178ec870ea43185f4c34795ea.tar.xz
twinkle-baedd87c10dabb9178ec870ea43185f4c34795ea.zip
Remember OSD/popup location (resolves #16)
Diffstat (limited to 'src/gui/osd.cpp')
-rw-r--r--src/gui/osd.cpp37
1 files changed, 37 insertions, 0 deletions
diff --git a/src/gui/osd.cpp b/src/gui/osd.cpp
index 1c0ee34..7dcd5a1 100644
--- a/src/gui/osd.cpp
+++ b/src/gui/osd.cpp
@@ -10,6 +10,11 @@
# include <QDeclarativeContext>
# include <QDeclarativeItem>
#endif
+#include <QDesktopWidget>
+#include <QSettings>
+#include <QApplication>
+
+extern QSettings* g_gui_state;
OSD::OSD(QObject* parent)
: QObject(parent)
@@ -21,6 +26,8 @@ OSD::OSD(QObject* parent)
m_view->rootContext()->setContextProperty("viewerWidget", m_view);
m_view->setSource(QUrl("qrc:/qml/osd.qml"));
+ positionWindow();
+
QObject* buttonHangup;
buttonHangup = m_view->rootObject()->findChild<QObject*>("hangup");
@@ -31,6 +38,8 @@ OSD::OSD(QObject* parent)
m_mute = m_view->rootObject()->findChild<QML_ITEMTYPE*>("mute");
connect(m_mute, SIGNAL(clicked()), this, SLOT(onMuteClicked()));
+
+ connect(m_view->rootObject(), SIGNAL(moved()), this, SLOT(saveState()));
}
OSD::~OSD()
@@ -38,6 +47,34 @@ OSD::~OSD()
delete m_view;
}
+void OSD::positionWindow()
+{
+ QDesktopWidget* desktop = QApplication::desktop();
+ int x, y;
+ int defaultX, defaultY;
+
+ defaultX = desktop->width() - this->width() - 10;
+ defaultY = 10;
+
+ x = g_gui_state->value("osd/x", defaultX).toInt();
+ y = g_gui_state->value("osd/y", defaultY).toInt();
+
+ // Reset position if off screen
+ if (x > desktop->width() || x < 0)
+ x = defaultX;
+ if (y > desktop->height() || y < 0)
+ y = defaultY;
+
+ m_view->move(x, y);
+}
+
+void OSD::saveState()
+{
+ QPoint pos = m_view->pos();
+ g_gui_state->setValue("osd/x", pos.x());
+ g_gui_state->setValue("osd/y", pos.y());
+}
+
void OSD::onHangupClicked()
{
emit hangupClicked();