From 58db3b3c242f622eb29d126dce5e162b08d08407 Mon Sep 17 00:00:00 2001 From: Serge Ziryukin Date: Tue, 13 Apr 2010 10:27:27 +0300 Subject: [PATCH] fullscreen button from qt maemo example --- colorflood/src/fullscreenexitbutton.hpp | 85 +++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 colorflood/src/fullscreenexitbutton.hpp diff --git a/colorflood/src/fullscreenexitbutton.hpp b/colorflood/src/fullscreenexitbutton.hpp new file mode 100644 index 0000000..a11f20f --- /dev/null +++ b/colorflood/src/fullscreenexitbutton.hpp @@ -0,0 +1,85 @@ +/* + Copyright 2010 Serge Ziryukin + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; version 2 of the License. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. +*/ + +#ifndef _FULLSCREENEXITBUTTON_HPP +#define _FULLSCREENEXITBUTTON_HPP + +#include +#include + +class FullScreenExitButton : public QToolButton +{ + Q_OBJECT; + +public: + inline explicit FullScreenExitButton(QWidget *parent); + +protected: + inline bool eventFilter(QObject *obj, QEvent *ev); +}; + +FullScreenExitButton::FullScreenExitButton(QWidget *parent) + : QToolButton(parent) +{ + Q_ASSERT(parent); + + // set the fullsize icon from Maemo's theme + setIcon(QIcon::fromTheme(QLatin1String("general_fullsize"))); + + // ensure that our size is fixed to our ideal size + setFixedSize(sizeHint()); + + // set the background to 0.5 alpha + QPalette pal = palette(); + QColor backgroundColor = pal.color(backgroundRole()); + backgroundColor.setAlpha(128); + pal.setColor(backgroundRole(), backgroundColor); + setPalette(pal); + + // ensure that we're painting our background + setAutoFillBackground(true); + + // when we're clicked, tell the parent to exit fullscreen + connect(this, SIGNAL(clicked()), parent, SLOT(showNormal())); + + // install an event filter to listen for the parent's events + parent->installEventFilter(this); +} + +bool FullScreenExitButton::eventFilter(QObject *obj, QEvent *ev) +{ + if (obj != parent()) + return QToolButton::eventFilter(obj, ev); + + QWidget *parent = parentWidget(); + bool isFullScreen = parent->windowState() & Qt::WindowFullScreen; + + switch (ev->type()) { + case QEvent::WindowStateChange: + setVisible(isFullScreen); + if (isFullScreen) + raise(); + // fall through + case QEvent::Resize: + if (isVisible()) + move(parent->width() - width(), + parent->height() - height()); + break; + default: + break; + } + + return QToolButton::eventFilter(obj, ev); +} + +#endif // !_FULLSCREENEXITBUTTON_HPP -- 1.7.9.5