From baedd87c10dabb9178ec870ea43185f4c34795ea Mon Sep 17 00:00:00 2001 From: Lubos Dolezel Date: Thu, 11 Jun 2015 15:16:39 +0200 Subject: Remember OSD/popup location (resolves #16) --- src/gui/osd.cpp | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) (limited to 'src/gui/osd.cpp') 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 # include #endif +#include +#include +#include + +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("hangup"); @@ -31,6 +38,8 @@ OSD::OSD(QObject* parent) m_mute = m_view->rootObject()->findChild("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(); -- cgit v1.2.3