diff options
author | Lubos Dolezel <lubos@dolezel.info> | 2015-06-11 15:16:39 +0200 |
---|---|---|
committer | Lubos Dolezel <lubos@dolezel.info> | 2015-06-11 15:16:39 +0200 |
commit | baedd87c10dabb9178ec870ea43185f4c34795ea (patch) | |
tree | fd0e5d9b795796f4c6dcdd72b17960f7f13a45af | |
parent | c0fb261ea49f638b49ed68c5eb5385c11ab8d407 (diff) | |
download | twinkle-baedd87c10dabb9178ec870ea43185f4c34795ea.tar twinkle-baedd87c10dabb9178ec870ea43185f4c34795ea.tar.gz twinkle-baedd87c10dabb9178ec870ea43185f4c34795ea.tar.lz twinkle-baedd87c10dabb9178ec870ea43185f4c34795ea.tar.xz twinkle-baedd87c10dabb9178ec870ea43185f4c34795ea.zip |
Remember OSD/popup location (resolves #16)
-rw-r--r-- | src/gui/incoming_call_popup.cpp | 47 | ||||
-rw-r--r-- | src/gui/incoming_call_popup.h | 4 | ||||
-rw-r--r-- | src/gui/main.cpp | 6 | ||||
-rw-r--r-- | src/gui/mphoneform.cpp | 5 | ||||
-rw-r--r-- | src/gui/osd.cpp | 37 | ||||
-rw-r--r-- | src/gui/osd.h | 3 | ||||
-rw-r--r-- | src/gui/qml/incoming_call.qml | 23 | ||||
-rw-r--r-- | src/gui/qml/osd.qml | 6 |
8 files changed, 118 insertions, 13 deletions
diff --git a/src/gui/incoming_call_popup.cpp b/src/gui/incoming_call_popup.cpp index 4dedea4..8397f45 100644 --- a/src/gui/incoming_call_popup.cpp +++ b/src/gui/incoming_call_popup.cpp @@ -2,6 +2,9 @@ #include <QDesktopWidget> #include <QApplication> #include <QDeclarativeContext> +#include <QSettings> + +extern QSettings* g_gui_state; IncomingCallPopup::IncomingCallPopup(QObject *parent) : QObject(parent) { @@ -12,14 +15,8 @@ IncomingCallPopup::IncomingCallPopup(QObject *parent) : QObject(parent) m_view->setSource(QUrl("qrc:/qml/incoming_call.qml")); - // Place into the middle of the screen - QDesktopWidget* desktop = qApp->desktop(); - QPoint pos; - - pos.setX(desktop->width()/2 - m_view->width()/2); - pos.setY(desktop->height()/2 - m_view->height()/2); - - m_view->move(pos); + // Place into the middle of the screen + positionWindow(); QObject* button; @@ -30,6 +27,7 @@ IncomingCallPopup::IncomingCallPopup(QObject *parent) : QObject(parent) connect(button, SIGNAL(clicked()), this, SLOT(onRejectClicked())); m_callerText = m_view->rootObject()->findChild<QDeclarativeItem*>("callerText"); + connect(m_view->rootObject(), SIGNAL(moved()), this, SLOT(saveState())); } IncomingCallPopup::~IncomingCallPopup() @@ -37,6 +35,39 @@ IncomingCallPopup::~IncomingCallPopup() delete m_view; } +void IncomingCallPopup::positionWindow() +{ + QDesktopWidget* desktop = qApp->desktop(); + int x, y; + int defaultX, defaultY; + + defaultX = desktop->width()/2 - m_view->width()/2; + defaultY = desktop->height()/2 - m_view->height()/2; + + x = g_gui_state->value("incoming_popup/x", defaultX).toInt(); + y = g_gui_state->value("incoming_popup/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 IncomingCallPopup::saveState() +{ + QPoint pos = m_view->pos(); + g_gui_state->setValue("incoming_popup/x", pos.x()); + g_gui_state->setValue("incoming_popup/y", pos.y()); +} + +void IncomingCallPopup::move(int x, int y) +{ + m_view->move(QPoint(x, y)); +} + void IncomingCallPopup::setCallerName(const QString& name) { QString text = tr("%1 calling").arg(name); diff --git a/src/gui/incoming_call_popup.h b/src/gui/incoming_call_popup.h index e61d99a..461e610 100644 --- a/src/gui/incoming_call_popup.h +++ b/src/gui/incoming_call_popup.h @@ -15,13 +15,17 @@ public: void show(); void hide(); void setVisible(bool v) { if (v) show(); else hide(); } + void move(int x, int y); +private: + void positionWindow(); signals: void answerClicked(); void rejectClicked(); public slots: void onAnswerClicked(); void onRejectClicked(); + void saveState(); private: QDeclarativeView* m_view; QDeclarativeItem* m_callerText; diff --git a/src/gui/main.cpp b/src/gui/main.cpp index 6401fea..529052e 100644 --- a/src/gui/main.cpp +++ b/src/gui/main.cpp @@ -27,6 +27,8 @@ #include <qapplication.h> #include <qtranslator.h> #include <qtextcodec.h> +#include <QSettings> +#include <QDir> #include "mphoneform.h" @@ -165,6 +167,7 @@ pthread_t thread_id_main; // Indicates if LinuxThreads or NPTL is active. bool threading_is_LinuxThreads; +QSettings* g_gui_state; /** * Parse arguments passed to application @@ -511,6 +514,9 @@ QApplication *create_user_interface(bool cli_mode, int argc, char **argv, QTrans QTextCodec::setCodecForCStrings(QTextCodec::codecForName("utf8")); QTextCodec::setCodecForTr(QTextCodec::codecForName("utf8")); #endif + + g_gui_state = new QSettings(QDir::home().absoluteFilePath(QString("%1/%2").arg(DIR_USER).arg("gui_state.ini")), + QSettings::IniFormat, qa); // Install Qt translator // Do not report to memman as the translator will be deleted diff --git a/src/gui/mphoneform.cpp b/src/gui/mphoneform.cpp index 13f0d6e..1fc86e2 100644 --- a/src/gui/mphoneform.cpp +++ b/src/gui/mphoneform.cpp @@ -54,11 +54,13 @@ #include <QCursor> #include <QRegExp> #include <QValidator> +#include <QSettings> #include "buddyform.h" #include "diamondcardprofileform.h" #include "osd.h" #include "incoming_call_popup.h" +extern QSettings* g_gui_state; // Time (s) that the conversation timer of a line should stay visible after // a call has ended @@ -170,10 +172,7 @@ void MphoneForm::init() //to2Label->setPaletteBackgroundColor(paletteBackgroundColor()); //subject2Label->setPaletteBackgroundColor(paletteBackgroundColor()); - QDesktopWidget* desktop = QApplication::desktop(); osdWindow = new OSD(this); - - osdWindow->move(desktop->width() - osdWindow->width() - 10, 10); connect(osdWindow, SIGNAL(hangupClicked()), this, SLOT(phoneBye())); connect(osdWindow, SIGNAL(muteClicked()), this, SLOT(osdMuteClicked())); 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(); diff --git a/src/gui/osd.h b/src/gui/osd.h index 3d26468..c5f83af 100644 --- a/src/gui/osd.h +++ b/src/gui/osd.h @@ -34,9 +34,12 @@ public: int height() const; void setVisible(bool v) { if (v) show(); else hide(); } +private: + void positionWindow(); public slots: void onHangupClicked(); void onMuteClicked(); + void saveState(); signals: void hangupClicked(); diff --git a/src/gui/qml/incoming_call.qml b/src/gui/qml/incoming_call.qml index bdcb161..1b8428e 100644 --- a/src/gui/qml/incoming_call.qml +++ b/src/gui/qml/incoming_call.qml @@ -1,11 +1,13 @@ import QtQuick 1.1 Rectangle { - id: rectangle1 + id: rectanglePopup width: 400 height: 70 color: "black" + signal moved + Image { id: image1 anchors.bottom: parent.bottom @@ -58,5 +60,24 @@ Rectangle { anchors.leftMargin: 15 image: "qrc:/icons/images/popup_incoming_reject.png" } + + MouseArea { + anchors.fill: parent + property variant previousPosition + onPressed: { + previousPosition = Qt.point(mouseX, mouseY) + } + onPositionChanged: { + if (pressedButtons == Qt.LeftButton) { + var dx = mouseX - previousPosition.x + var dy = mouseY - previousPosition.y + viewerWidget.pos = Qt.point(viewerWidget.pos.x + dx, + viewerWidget.pos.y + dy) + + previousPosition = Qt.point(mouseX, mouseY) + rectanglePopup.moved() + } + } + } } diff --git a/src/gui/qml/osd.qml b/src/gui/qml/osd.qml index cfbf85e..42f7b1f 100644 --- a/src/gui/qml/osd.qml +++ b/src/gui/qml/osd.qml @@ -1,11 +1,13 @@ import QtQuick 1.1 Rectangle { - id: rectangle1 + id: rectangleOsd width: 310 height: 55 color: "black" + signal moved + Image { id: image1 anchors.bottom: parent.bottom @@ -87,6 +89,8 @@ Rectangle { var dy = mouseY - previousPosition.y viewerWidget.pos = Qt.point(viewerWidget.pos.x + dx, viewerWidget.pos.y + dy) + + rectangleOsd.moved() } } } |