Implemented full screen button hiding after a delay
authorSami Rämö <sami.ramo@ixonos.com>
Wed, 11 Aug 2010 09:54:14 +0000 (12:54 +0300)
committerSami Rämö <sami.ramo@ixonos.com>
Wed, 11 Aug 2010 10:07:31 +0000 (13:07 +0300)
 - Revieved by Katri Kaikkonen

 - Some clean-up for Application

src/application.cpp
src/application.h
src/ui/fullscreenbutton.cpp
src/ui/fullscreenbutton.h
src/ui/mainwindow.cpp
src/ui/mainwindow.h

index 7f537a5..f331c39 100644 (file)
@@ -86,22 +86,34 @@ bool Application::x11EventFilter(XEvent *event)
     qDebug() << __PRETTY_FUNCTION__;
 
     static Qt::HANDLE rootWindow = QX11Info::appRootWindow();
-    static Atom activeAppAtom = XInternAtom(QX11Info::display(),
-                                            ACTIVE_APP_ATOM, false);
-
-    if (event->type == PropertyNotify) {
-        XPropertyEvent *pevent = (XPropertyEvent*)event;
-        if (pevent->window == rootWindow) {
-            if (pevent->atom == activeAppAtom) {
-                WId activeWindow = activeDesktopWindow(pevent->display,
-                                                       rootWindow);
-
-                if(m_topmost != m_windows.contains(activeWindow)) {
-                    m_topmost = !m_topmost;
-                    emit topmostChanged(!m_topmost);
+    static Atom activeAppAtom = XInternAtom(QX11Info::display(), ACTIVE_APP_ATOM, false);
+
+    switch (event->type) {
+    case PropertyNotify: {
+            XPropertyEvent *pevent = (XPropertyEvent*)event;
+            if (pevent->window == rootWindow) {
+                if (pevent->atom == activeAppAtom) {
+                    WId activeWindow = activeDesktopWindow(pevent->display, rootWindow);
+
+                    if(m_topmost != m_windows.contains(activeWindow)) {
+                        m_topmost = !m_topmost;
+                        emit topmostChanged(!m_topmost);
+                    }
                 }
             }
         }
+        break;
+    case KeyPress:
+    case KeyRelease:
+    case ButtonPress:
+    case ButtonRelease:
+    case MotionNotify:
+    case EnterNotify: // required when returning from statusbar menu
+    case FocusIn: // required when returning from update location dialog
+        emit showFullScreenButton();
+        break;
     }
+
+    // don't block any events here, so false is returned
     return false;
 }
index 4c6deff..32d5e03 100644 (file)
@@ -32,8 +32,8 @@
 class Application : public QApplication
 {
     Q_OBJECT
-public:
 
+public:
     /**
     * @brief Constructor
     *
@@ -42,6 +42,10 @@ public:
     */
     Application(int &argc, char **argv);
 
+/*******************************************************************************
+ * MEMBER FUNCTIONS AND SLOTS
+ ******************************************************************************/
+public:
     /**
     * @brief Registers window
     *
@@ -57,7 +61,6 @@ public:
     void unregisterWindow(WId wId);
 
 private:
-
     /**
     * @brief Return active window
     *
@@ -76,7 +79,18 @@ private:
     */
     bool x11EventFilter(XEvent *event);
 
+/*******************************************************************************
+ * SIGNALS
+ ******************************************************************************/
 signals:
+    /**
+    * @brief Signal is emitted when full screen button must be invoked and it's hiding timer
+             cleared.
+    *
+    * Signal is emitted when user interacts with keyboard or with mouse/finger, or when the
+    * main window is exposed.
+    */
+    void showFullScreenButton();
 
     /**
     * @brief Signals when window state is changed
@@ -85,11 +99,13 @@ signals:
     */
     void topmostChanged(bool topmost);
 
+/*******************************************************************************
+ * DATA MEMBERS
+ ******************************************************************************/
 private:
+    bool m_topmost;             ///< Flag for topmost
 
-    bool m_topmost; ///< Flag for topmost
-
-    QList<WId> m_windows; ///< List of window ids
+    QList<WId> m_windows;       ///< List of window ids
 };
 
 #endif // APPLICATION_H
index 6ca4806..5d84dde 100644 (file)
@@ -22,6 +22,7 @@
 
 #include <QDebug>
 #include <QPainter>
+#include <QTimer>
 
 #include "math.h"
 
@@ -38,6 +39,8 @@ FullScreenButton::FullScreenButton(QWidget *parent) :
 {
     qDebug() << __PRETTY_FUNCTION__;
 
+    const int HIDING_DELAY_MS = 5000;
+
     setIcon(QIcon::fromTheme(QLatin1String("general_fullsize")));
     setFixedSize(sizeHint());
 
@@ -61,6 +64,16 @@ FullScreenButton::FullScreenButton(QWidget *parent) :
     m_backgroundPath.lineTo(0, this->height());             // Bottom left corner
     m_backgroundPath.lineTo(this->width(), this->height()); // Bottom right corner
     m_backgroundPath.closeSubpath();                        // Back to the beginning
+
+    // Timer for hiding the button automatically after a delay
+    m_hidingTimer = new QTimer(this);
+    if (m_hidingTimer) {
+        m_hidingTimer->setSingleShot(true);
+        m_hidingTimer->setInterval(HIDING_DELAY_MS);
+
+        connect(m_hidingTimer, SIGNAL(timeout()),
+                this, SLOT(hide()));
+    }
 }
 
 FullScreenButton::~FullScreenButton()
@@ -71,6 +84,17 @@ FullScreenButton::~FullScreenButton()
     delete m_selectedGradient;
 }
 
+void FullScreenButton::invoke()
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    if (isHidden())
+        show();
+
+    if (m_hidingTimer)
+        m_hidingTimer->start();
+}
+
 void FullScreenButton::paintEvent(QPaintEvent *event)
 {
     qDebug() << __PRETTY_FUNCTION__;
index 7df499e..c447af1 100644 (file)
@@ -25,6 +25,8 @@
 
 #include <QToolButton>
 
+class QTimer;
+
 /**
  * @brief Fullscreen button class
  *
@@ -63,12 +65,22 @@ protected:
     void paintEvent(QPaintEvent *event);
 
 /*******************************************************************************
+ * MEMBER FUNCTIONS AND SLOTS
+ ******************************************************************************/
+public slots:
+    /**
+    * @brief Invoke the button (if not already visible) and set hiding timer
+    */
+    void invoke();
+
+/*******************************************************************************
  * DATA MEMBERS
  ******************************************************************************/
 private:
     QColor *m_normalColor;                  ///< Normal background color
     QLinearGradient *m_selectedGradient;    ///< Selected background
     QPainterPath m_backgroundPath;          ///< Item shape path
+    QTimer *m_hidingTimer;                  ///< Timer for hiding the button after a delay
 };
 
 #endif // FULLSCREENBUTTON_H
index d93ae1a..5a4c343 100644 (file)
@@ -142,10 +142,17 @@ void MainWindow::automaticUpdateDialogFinished(int result)
 void MainWindow::buildFullScreenButton()
 {
     qDebug() << __PRETTY_FUNCTION__;
+
 #ifdef Q_WS_MAEMO_5
     m_fullScreenButton = new FullScreenButton(this);
-    connect(m_fullScreenButton, SIGNAL(clicked()),
-            this, SLOT(toggleFullScreen()));
+
+    if (m_fullScreenButton) {
+        connect(m_fullScreenButton, SIGNAL(clicked()),
+                this, SLOT(toggleFullScreen()));
+
+        connect(qApp, SIGNAL(showFullScreenButton()),
+                m_fullScreenButton, SLOT(invoke()));
+    }
 #endif // Q_WS_MAEMO_5
 }
 
index 2189709..2875c50 100644 (file)
@@ -53,7 +53,6 @@ class User;
 class UserInfoPanel;
 class ZoomButtonPanel;
 
-
 /**
 * @brief Main Window Class
 */
@@ -151,7 +150,6 @@ public:
     const QString username();
 
 public slots:
-
     /**
      * @brief Build direction indicator button and connect slots
      */