**
** If you have questions regarding the use of this file, please contact
** Nokia at qt-info@nokia.com.
-**
-**
-**
-**
-**
-**
-**
-**
+
** $QT_END_LICENSE$
**
****************************************************************************/
#ifndef FULLSCREENEXITBUTTON_H
#define FULLSCREENEXITBUTTON_H
-#include <QtGui/qtoolbutton.h>
-#include <QtGui/qevent.h>
+#include <QToolButton>
+#include <QEvent>
#include <QTimer>
class FullScreenExitButton : public QToolButton
public:
inline explicit FullScreenExitButton(QWidget *parent);
+public slots:
+ inline void reenable();
protected:
inline bool eventFilter(QObject *obj, QEvent *ev);
private:
- QTimer timer;
+ QTimer hide_timer;
};
FullScreenExitButton::FullScreenExitButton(QWidget *parent)
- : QToolButton(parent)
+ : QToolButton(parent)
{
Q_ASSERT(parent);
+#ifdef Q_WS_MAEMO_5
// set the fullsize icon from Maemo's theme
setIcon(QIcon("/usr/share/icons/hicolor/48x48/hildon/general_fullsize.png"));
+#else
+ setText(tr("Toggle Fullscreen"));
+#endif
// ensure that our size is fixed to our ideal size
setFixedSize(sizeHint());
setAutoFillBackground(true);
// hide after 4s of inactivity
- connect(&timer, SIGNAL(timeout()), this, SLOT(hide()));
- timer.setInterval(4000);
- timer.setSingleShot(true);
+ connect(&hide_timer, SIGNAL(timeout()), this, SLOT(hide()));
+ hide_timer.setInterval(4000);
+ hide_timer.setSingleShot(true);
// install an event filter to listen for the parent's events
parent->installEventFilter(this);
setVisible(false); //assuming we don't start in fullscreen
- timer.start();
}
bool FullScreenExitButton::eventFilter(QObject *obj, QEvent *ev)
{
+ if(!isEnabled())
+ return QToolButton::eventFilter(obj, ev);
if (obj != parent())
return QToolButton::eventFilter(obj, ev);
case QEvent::MouseButtonRelease:
case QEvent::MouseMove:
case QEvent::HoverMove:
- //fall through to show button
+ //fall through to show button
case QEvent::WindowStateChange:
setVisible(isFullScreen);
if (isFullScreen)
raise();
// fall through
case QEvent::Resize:
- if (isVisible()) {
- move(parent->width() - width(), parent->height() - height());
- timer.start();
- }
+ move(parent->width() - width(), parent->height() - height());
+ if (isVisible()) {
+ hide_timer.start();
+ }
break;
default:
break;
return QToolButton::eventFilter(obj, ev);
}
+void FullScreenExitButton::reenable()
+{
+ setEnabled(true);
+
+ const QWidget *parent = parentWidget();
+ const bool isFullScreen = parent->windowState() & Qt::WindowFullScreen;
+ setVisible(isFullScreen);
+ if (isFullScreen)
+ raise();
+ hide_timer.start();
+}
+
#endif