menu: read MRU "Always on Top" value from .skin.properties 89/29389/2
authorGiWoong Kim <giwoong.kim@samsung.com>
Thu, 16 Oct 2014 05:18:15 +0000 (14:18 +0900)
committerGiWoong Kim <giwoong.kim@samsung.com>
Tue, 28 Oct 2014 08:11:21 +0000 (01:11 -0700)
Change-Id: I8cc1f6c0af859f35c91294419aceb73e1e0e3b53
Signed-off-by: GiWoong Kim <giwoong.kim@samsung.com>
tizen/src/display/qt5_supplement.cpp
tizen/src/ui/mainwindow.cpp
tizen/src/ui/mainwindow.h
tizen/src/ui/menu/contextmenu.cpp
tizen/src/ui/menu/contextmenu.h
tizen/src/ui/uistate.cpp
tizen/src/ui/uistate.h

index 5a362bf93f17da2cf132cf392e86442fa9b8ae5a..dd2ef40300d1f9d7f00680974d60741fdbff1c5c 100644 (file)
@@ -61,6 +61,7 @@ static UIInformation *uiInfo;
 #define SKIN_PROPERTY_WINDOW_X "window.x"
 #define SKIN_PROPERTY_WINDOW_Y "window.y"
 #define SKIN_PROPERTY_WINDOW_SCALE "window.scale"
+#define SKIN_PROPERTY_WINDOW_TOPMOST "window.ontop"
 #define SKIN_PROPERTY_CONTROLLER_INDEX "controller.index"
 #define SKIN_PROPERTY_CONTROLLER_DOCK "controller.dock"
 
@@ -182,8 +183,14 @@ void qt5_gui_init(void)
     }
     mainwindow->move(xx, yy);
 
+    bool onTop = mruInfo.value(SKIN_PROPERTY_WINDOW_TOPMOST).toBool();
+    if (onTop == true) {
+        mainwindow->setTopMost(true);
+    }
+
     mainwindow->show();
 
+    /* controller */
     int conIndex = mruInfo.value(SKIN_PROPERTY_CONTROLLER_INDEX).toInt();
     if (conIndex >= 0 && conIndex < uiInfo->conFormList.count()) {
         int conDockPos = mruInfo.value(SKIN_PROPERTY_CONTROLLER_DOCK).toInt();
@@ -207,6 +214,7 @@ void qt5_destroy()
     mruInfo.setValue(SKIN_PROPERTY_WINDOW_X, mainwindow->pos().x());
     mruInfo.setValue(SKIN_PROPERTY_WINDOW_Y, mainwindow->pos().y());
     mruInfo.setValue(SKIN_PROPERTY_WINDOW_SCALE, uiInfo->uiState.mainFormScale);
+    mruInfo.setValue(SKIN_PROPERTY_WINDOW_TOPMOST, uiInfo->uiState.isOnTop());
     mruInfo.setValue(SKIN_PROPERTY_CONTROLLER_INDEX, uiInfo->uiState.conState.conFormIndex);
 
     DockingController *con = uiInfo->uiState.conState.dockingCon;
index 2ca0014349d929aaa7b246620f8f9405d1d90720..ca383764ee53fa334b68069c135690ee10271349 100644 (file)
@@ -71,8 +71,8 @@ void DisplaySwapper::display()
     }
 }
 
-MainWindow::MainWindow(UIInformation *uiInfo, QWidget *parent) :
-    QWidget(parent)
+MainWindow::MainWindow(UIInformation *uiInfo, QWidget *parent)
+    QWidget(parent)
 {
     this->label = NULL;
     /* initialize */
@@ -84,7 +84,6 @@ MainWindow::MainWindow(UIInformation *uiInfo, QWidget *parent) :
 
     /* windowing */
     setWindowTitle("Emulator");
-    /* app icon */
     setWindowIcon(QIcon(QPixmap(":/icons/emulator_icon.ico")));
 
     //setStyleSheet("background:transparent;");
@@ -325,6 +324,11 @@ void MainWindow::scale(int scale)
     adjustSize();
 }
 
+void MainWindow::setTopMost(bool on)
+{
+    popupMenu->slotTopMost(on);
+}
+
 MainWindow::~MainWindow()
 {
     qDebug("destory main window");
index e68c1d33de47927e047ec3596f4f64c725aaffa6..4a636403dc1fc3dce2f91a05baefabe94f63fff1 100644 (file)
@@ -76,6 +76,7 @@ public:
     UIState *getUIState(void);
     void rotate(int angle);
     void scale(int scale);
+    void setTopMost(bool on);
     DockingController *getDockingCon();
     FloatingController *getFloatingCon();
     void openController(int index, int dockPos);
@@ -84,7 +85,7 @@ public:
     void terminateSwapper();
 
     UIInformation *uiInfo;
-    QLabel *getLabel();
+    QLabel *getLabel(); // TODO: delete
 
 public slots:
     void showContextMenu(const QPoint& pos);
index e4facb52eb29ac63194aabea5f63e40b58cf3bb7..9e36c4ad93d64a86223cee8ccacb528388287bd0 100644 (file)
 #include "mainwindow.h"
 
 #ifdef CONFIG_WIN32
-#include "windows.h"
-
+#include <windows.h>
 #else
 #include <X11/Xlib.h>
 #include <X11/Xatom.h>
-
 #endif
 
-
-ContextMenu::ContextMenu(QWidget *parent) :
-    QMenu(parent)
+ContextMenu::ContextMenu(QWidget *parent) : QMenu(parent)
 {
-    infoDialog = NULL;
-    aboutDialog = NULL;
-    vmName = ((MainWindow *)parent)->uiInfo->vmName + " : "
+    this->parent = (MainWindow *)parent;
+    this->infoDialog = NULL;
+    this->aboutDialog = NULL;
+    this->vmName = ((MainWindow *)parent)->uiInfo->vmName + " : "
         + QString::number(get_device_serial_number());
 
+    actionDetailedInfo = NULL;
+    actionTopMost = NULL;
+    actionShell = NULL;
+    actionControlPanel = NULL;
+    actionAbout = NULL;
+    actionForceClose = NULL;
+    actionClose = NULL;
+
+    longPressTimer = new QTimer(this);
+
     createItems();
 
     installEventFilter(this);
 }
 
 void ContextMenu::createItems() {
-    MainWindow *win = (MainWindow *)this->parent();
+    MainWindow *win = parent;
+    QAction *action = NULL;
 
     /* Detailed Info menu */
-    QAction *action = addAction(vmName);
-    action->setIcon(QIcon(QPixmap(":/icons/detailed_info.png")));
-    connect(action, SIGNAL(triggered()), this, SLOT(slotDetailedInfo()));
+    actionDetailedInfo = addAction(vmName);
+    actionDetailedInfo->setIcon(QIcon(QPixmap(":/icons/detailed_info.png")));
+    connect(actionDetailedInfo, SIGNAL(triggered()), this, SLOT(slotDetailedInfo()));
 
     addSeparator();
 
     /* Always On Top menu */
-    action = addAction("&Always on Top");
-    action->setCheckable(true);
-    connect(action, SIGNAL(triggered(bool)), this, SLOT(slotTopMost(bool)));
+    actionTopMost = addAction("&Always on Top");
+    actionTopMost->setCheckable(true);
+    connect(actionTopMost, SIGNAL(triggered(bool)), this, SLOT(slotTopMost(bool)));
 
     /* = Rotate menu = */
     if (win->uiInfo->mainFormList.count() > 1) {
@@ -190,33 +198,32 @@ void ContextMenu::createItems() {
     advancedMenu->addSeparator();
 
     /* Advanced > About menu */
-    action = advancedMenu->addAction("&About");
-    action->setIcon(QIcon(QPixmap(":/icons/about.png")));
-    connect(action, SIGNAL(triggered()), this, SLOT(slotAbout()));
+    actionAbout = advancedMenu->addAction("&About");
+    actionAbout->setIcon(QIcon(QPixmap(":/icons/about.png")));
+    connect(actionAbout, SIGNAL(triggered()), this, SLOT(slotAbout()));
 
     /* Advanced > Force Close menu */
-    action = advancedMenu->addAction("&Force Close");
-    action->setIcon(QIcon(QPixmap(":/icons/force_close.png")));
-    connect(action, SIGNAL(triggered()), this, SLOT(slotForceClose()));
+    actionForceClose = advancedMenu->addAction("&Force Close");
+    actionForceClose->setIcon(QIcon(QPixmap(":/icons/force_close.png")));
+    connect(actionForceClose, SIGNAL(triggered()), this, SLOT(slotForceClose()));
     /* ================= */
 
     /* Shell menu */
-    action = addAction("S&hell");
-    action->setIcon(QIcon(QPixmap(":/icons/shell.png")));
-    connect(action, SIGNAL(triggered()), this, SLOT(slotShell()));
+    actionShell = addAction("S&hell");
+    actionShell->setIcon(QIcon(QPixmap(":/icons/shell.png")));
+    connect(actionShell, SIGNAL(triggered()), this, SLOT(slotShell()));
 
     /* Control Panel menu */
-    action = addAction("Control &Panel");
-    action->setIcon(QIcon(QPixmap(":/icons/control_panel.png")));
-    connect(action, SIGNAL(triggered()), this, SLOT(slotControlPanel()));
+    actionControlPanel = addAction("Control &Panel");
+    actionControlPanel->setIcon(QIcon(QPixmap(":/icons/control_panel.png")));
+    connect(actionControlPanel, SIGNAL(triggered()), this, SLOT(slotControlPanel()));
 
     addSeparator();
 
     /* Close menu */
-    longPressTimer = new QTimer(this);
-    action = addAction("&Close");
-    action->setIcon(QIcon(QPixmap(":/icons/close.png")));
-    connect(action, SIGNAL(triggered()), this, SLOT(slotClose()));
+    actionClose = addAction("&Close");
+    actionClose->setIcon(QIcon(QPixmap(":/icons/close.png")));
+    connect(actionClose, SIGNAL(triggered()), this, SLOT(slotClose()));
 }
 
 bool ContextMenu::eventFilter(QObject *obj, QEvent *event)
@@ -242,7 +249,7 @@ void ContextMenu::slotDetailedInfo()
     qDebug("VM info");
 
     if (infoDialog == NULL) {
-        infoDialog = new DetailedInfoDialog((QWidget *)this->parent());
+        infoDialog = new DetailedInfoDialog((QWidget *)parent);
     }
 
     infoDialog->show();
@@ -252,68 +259,60 @@ void ContextMenu::slotTopMost(bool on)
 {
     qDebug("stays on top : %s", on? "on" : "off");
 
-    QWidget *win = (QWidget *)this->parent();
-
 #ifdef CONFIG_WIN32
-    /*
-    if (on == true) {
-        win->setWindowFlags(win->windowFlags() | Qt::WindowStaysOnTopHint);
-    } else {
-        win->setWindowFlags(win->windowFlags() & ~(Qt::WindowStaysOnTopHint));
-    }
-
-    win->show();
-    */
-    HWND hWnd = (HWND)win->winId();
-    HWND hWndInsertAfter = ( (on == true) ? HWND_TOPMOST : HWND_NOTOPMOST);
-    SetWindowPos(hWnd, hWndInsertAfter, win->pos().x(), win->pos().y(), 0, 0, SWP_NOSIZE);
-    win->show();
-
+    HWND hWnd = (HWND)parent->winId();
+    HWND hWndInsertAfter = ((on == true) ? HWND_TOPMOST : HWND_NOTOPMOST);
+    SetWindowPos(hWnd, hWndInsertAfter, parent->pos().x(), parent->pos().y(), 0, 0, SWP_NOSIZE);
 #else
-    Display* display = XOpenDisplay (NULL);
+    Display* display = XOpenDisplay(NULL);
     if (display == NULL) {
         qDebug("Error: XOpenDisplay() Failed. Always on top failed.");
         return;
     }
+
     XClientMessageEvent event;
-    memset(&event,0,sizeof(event));
+    memset(&event, 0, sizeof(event));
     event.type = ClientMessage;
-    event.window  = win->winId();
-    event.message_type = XInternAtom (display, "_NET_WM_STATE", False);
+    event.window = parent->winId();
+    event.message_type = XInternAtom(display, "_NET_WM_STATE", False);
     event.format = 32;
-    event.data.l[0] = on ? 1 : 0;  // 1:_NET_WM_STATE_ADD  , 0:_NET_WM_STATE_REMOVE
-    event.data.l[1] = XInternAtom (display, "_NET_WM_STATE_ABOVE", False);
-    event.data.l[2] = 0; //unused.
+    event.data.l[0] = on ? 1 : 0; /* 1:_NET_WM_STATE_ADD, 0:_NET_WM_STATE_REMOVE */
+    event.data.l[1] = XInternAtom(display, "_NET_WM_STATE_ABOVE", False);
+    event.data.l[2] = 0; /* unused */
     event.data.l[3] = 0;
     event.data.l[4] = 0;
-    XSendEvent (display, DefaultRootWindow(display), False, SubstructureRedirectMask|SubstructureNotifyMask, (XEvent*)&event);
+
+    XSendEvent(display, DefaultRootWindow(display), False,
+        SubstructureRedirectMask | SubstructureNotifyMask, (XEvent *)&event);
     XFlush(display);
+
     XCloseDisplay(display);
 #endif
 
-
+    actionTopMost->setChecked(on);
+    parent->getUIState()->setOnTop(on);
 }
 
 void ContextMenu::slotRotate(int angle)
 {
     qDebug("rotate : %d", angle);
 
-    ((MainWindow *)this->parent())->rotate(angle);
+    parent->rotate(angle);
 }
 
 void ContextMenu::slotScale(int scale)
 {
     qDebug("scale : %d", scale);
 
-    ((MainWindow *)this->parent())->scale(scale);
+    parent->scale(scale);
 }
 
 void ContextMenu::slotController(int index)
 {
     qDebug("controller : %d", index);
 
-    MainWindow *win = ((MainWindow *)this->parent());
-    win->openController(index, win->getUIState()->conState.recentlyDockPos);
+    parent->openController(index,
+        parent->getUIState()->conState.recentlyDockPos);
 }
 
 void ContextMenu::slotShell()
@@ -325,7 +324,7 @@ void ContextMenu::slotShell()
         qDebug() << msg;
 
         QMessageBox *msgBox = new QMessageBox(QMessageBox::Information,
-            "Emulator", msg, QMessageBox::Ok, (QWidget*)this->parent());
+            "Emulator", msg, QMessageBox::Ok, (QWidget*)parent);
         msgBox->setAttribute(Qt::WA_DeleteOnClose);
         msgBox->setModal(false);
         msgBox->show();
@@ -350,7 +349,7 @@ void ContextMenu::slotShell()
         qWarning() << msg;
 
         QMessageBox *msgBox = new QMessageBox(QMessageBox::Warning,
-            "Emulator", msg, QMessageBox::Ok, (QWidget*)this->parent());
+            "Emulator", msg, QMessageBox::Ok, (QWidget*)parent);
         msgBox->setAttribute(Qt::WA_DeleteOnClose);
         msgBox->setModal(false);
         msgBox->show();
@@ -383,7 +382,7 @@ void ContextMenu::slotShell()
         qDebug() << msg;
 
         QMessageBox *msgBox = new QMessageBox(QMessageBox::Warning,
-            "Emulator", msg, QMessageBox::Ok ,(QWidget*)this->parent());
+            "Emulator", msg, QMessageBox::Ok ,(QWidget*)parent);
         msgBox->setAttribute(Qt::WA_DeleteOnClose);
         msgBox->setModal(false);
         msgBox->show();
@@ -396,7 +395,7 @@ void ContextMenu::slotControlPanel()
 {
     qDebug("Control Panel");
 
-    MainWindow *win = (MainWindow *)this->parent();
+    MainWindow *win = (MainWindow *)parent;
     QString basePortOpt = "base.port=" + QString::number(win->uiInfo->basePort);
     QString vmNameOpt = "vmname=" + win->uiInfo->vmName;
 
@@ -414,7 +413,7 @@ void ContextMenu::slotControlPanel()
         qWarning() << msg;
 
         QMessageBox *msgBox = new QMessageBox(QMessageBox::Warning,
-            "Emulator", msg, QMessageBox::Ok, (QWidget*)this->parent());
+            "Emulator", msg, QMessageBox::Ok, (QWidget*)parent);
         msgBox->setAttribute(Qt::WA_DeleteOnClose);
         msgBox->setModal(false);
         msgBox->show();
@@ -442,7 +441,7 @@ void ContextMenu::slotControlPanel()
         qDebug() << msg;
 
         QMessageBox *msgBox = new QMessageBox(QMessageBox::Warning,
-            "Emulator", msg, QMessageBox::Ok, (QWidget*)this->parent());
+            "Emulator", msg, QMessageBox::Ok, (QWidget*)parent);
         msgBox->setAttribute(Qt::WA_DeleteOnClose);
         msgBox->setModal(false);
         msgBox->show();
@@ -463,7 +462,7 @@ void ContextMenu::slotAbout()
     qDebug("about");
 
     if (aboutDialog == NULL) {
-        aboutDialog = new AboutDialog((QWidget *)this->parent());
+        aboutDialog = new AboutDialog((QWidget *)parent);
     }
 
     aboutDialog->show();
@@ -473,7 +472,7 @@ void ContextMenu::slotForceClose()
 {
     qDebug("force close");
 
-    QMessageBox *msg = new QMessageBox((QWidget*)this->parent());
+    QMessageBox *msg = new QMessageBox((QWidget*)parent);
     msg->setAttribute(Qt::WA_DeleteOnClose);
     msg->setWindowTitle("Emulator");
     msg->setText("If you force stop an emulator, it may cause some problems.\n"
@@ -508,10 +507,10 @@ void ContextMenu::slotClose()
     qDebug("close");
     do_hw_key_event(KEY_PRESSED, HARD_KEY_POWER);
 
-    this->longPressTimer->setInterval(CLOSE_POWER_KEY_INTERVAL);
-    this->longPressTimer->setSingleShot(true);
+    longPressTimer->setInterval(CLOSE_POWER_KEY_INTERVAL);
+    longPressTimer->setSingleShot(true);
     connect(longPressTimer, SIGNAL(timeout()), this, SLOT(slotPwkeyRelease()));
-    this->longPressTimer->start();
+    longPressTimer->start();
 }
 
 QSignalMapper *ContextMenu::getRotateMapper()
@@ -532,4 +531,6 @@ QSignalMapper *ContextMenu::getControllerMapper()
 ContextMenu::~ContextMenu()
 {
     qDebug("destroy menu");
+
+    longPressTimer->stop();
 }
index 6738431012ac82f4fcaa2f8c59a16499fc934435..c5ed7a6f8a15cbef7c66a38577e9f690525583d6 100644 (file)
@@ -36,6 +36,8 @@
 #include "detailedinfodialog.h"
 #include "aboutdialog.h"
 
+class MainWindow;
+
 extern "C" {
 #include "skin/maruskin_operation.h"
 #include "skin/maruskin_server.h"
@@ -78,6 +80,8 @@ protected:
     bool eventFilter(QObject *obj, QEvent *event);
 
 private:
+    MainWindow *parent;
+
     QString vmName;
     DetailedInfoDialog *infoDialog;
     AboutDialog *aboutDialog;
@@ -86,5 +90,13 @@ private:
     QSignalMapper *rotateMapper;
     QSignalMapper *scaleMapper;
     QSignalMapper *controllerMapper;
+
+    QAction *actionDetailedInfo;
+    QAction *actionTopMost;
+    QAction *actionShell;
+    QAction *actionControlPanel;
+    QAction *actionAbout;
+    QAction *actionForceClose;
+    QAction *actionClose;
 };
 #endif // CONTEXTMENU_H
index dff66fdad97a0cf02b13c2108aba4b28e0a65619..938d7c85882b6a2be1797f44a7b09803bb09b830 100644 (file)
@@ -32,6 +32,7 @@
 UIState::UIState() :
     mainFormAngle(0), mainFormScale(100)
 {
+    onTop = false;
     conState.conFormIndex = 0;
     conState.dockingCon = NULL;
     conState.floatingCon = NULL;
@@ -78,3 +79,15 @@ qreal UIState::getScaleFactor()
 {
     return getScaleFactor(this->mainFormScale);
 }
+
+void UIState::setOnTop(bool on)
+{
+    qDebug("set on top : %d", on);
+
+    onTop = on;
+}
+
+bool UIState::isOnTop()
+{
+    return onTop;
+}
index bbd99c56bea541773dcb7ad28b94cdd3569d19e5..392881bf10a1df40d8274bdc05d6af6daa5f4285 100644 (file)
@@ -30,8 +30,6 @@
 #ifndef UISTATE_H
 #define UISTATE_H
 
-#include <QtWidgets>
-
 #include "dockingcontroller.h"
 #include "floatingcontroller.h"
 
@@ -59,10 +57,16 @@ public:
     qreal getScaleFactor(int scale);
     qreal getScaleFactor(); /* current */
 
+    void setOnTop(bool on);
+    bool isOnTop();
+
     int mainFormAngle;
     int mainFormScale; /* percentage */
 
     ControllerState conState;
+
+private:
+    bool onTop;
 };
 
 #endif // UISTATE_H