From 1d3b34144d3fa0dffab2ceb8619a3acaf0794eb3 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Sami=20R=C3=A4m=C3=B6?= Date: Wed, 11 Aug 2010 12:54:14 +0300 Subject: [PATCH] Implemented full screen button hiding after a delay - Revieved by Katri Kaikkonen - Some clean-up for Application --- src/application.cpp | 38 +++++++++++++++++++++++++------------- src/application.h | 26 +++++++++++++++++++++----- src/ui/fullscreenbutton.cpp | 24 ++++++++++++++++++++++++ src/ui/fullscreenbutton.h | 12 ++++++++++++ src/ui/mainwindow.cpp | 11 +++++++++-- src/ui/mainwindow.h | 2 -- 6 files changed, 91 insertions(+), 22 deletions(-) diff --git a/src/application.cpp b/src/application.cpp index 7f537a5..f331c39 100644 --- a/src/application.cpp +++ b/src/application.cpp @@ -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; } diff --git a/src/application.h b/src/application.h index 4c6deff..32d5e03 100644 --- a/src/application.h +++ b/src/application.h @@ -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 m_windows; ///< List of window ids + QList m_windows; ///< List of window ids }; #endif // APPLICATION_H diff --git a/src/ui/fullscreenbutton.cpp b/src/ui/fullscreenbutton.cpp index 6ca4806..5d84dde 100644 --- a/src/ui/fullscreenbutton.cpp +++ b/src/ui/fullscreenbutton.cpp @@ -22,6 +22,7 @@ #include #include +#include #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__; diff --git a/src/ui/fullscreenbutton.h b/src/ui/fullscreenbutton.h index 7df499e..c447af1 100644 --- a/src/ui/fullscreenbutton.h +++ b/src/ui/fullscreenbutton.h @@ -25,6 +25,8 @@ #include +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 diff --git a/src/ui/mainwindow.cpp b/src/ui/mainwindow.cpp index d93ae1a..5a4c343 100644 --- a/src/ui/mainwindow.cpp +++ b/src/ui/mainwindow.cpp @@ -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 } diff --git a/src/ui/mainwindow.h b/src/ui/mainwindow.h index 2189709..2875c50 100644 --- a/src/ui/mainwindow.h +++ b/src/ui/mainwindow.h @@ -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 */ -- 1.7.9.5