2 Copyright 2010 Serge Ziryukin <ftrvxmtrx@gmail.com>
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; version 2 of the License.
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
14 #ifndef _FULLSCREENEXITBUTTON_HPP
15 #define _FULLSCREENEXITBUTTON_HPP
17 #include <QToolButton>
20 class FullScreenExitButton : public QToolButton
25 inline explicit FullScreenExitButton(QWidget *parent);
28 inline bool eventFilter(QObject *obj, QEvent *ev);
31 FullScreenExitButton::FullScreenExitButton(QWidget *parent)
36 // set the fullsize icon from Maemo's theme
37 setIcon(QIcon::fromTheme(QLatin1String("general_fullsize")));
39 // ensure that our size is fixed to our ideal size
40 setFixedSize(sizeHint());
42 // set the background to 0.5 alpha
43 QPalette pal = palette();
44 QColor backgroundColor = pal.color(backgroundRole());
45 backgroundColor.setAlpha(128);
46 pal.setColor(backgroundRole(), backgroundColor);
49 // ensure that we're painting our background
50 setAutoFillBackground(true);
52 // when we're clicked, tell the parent to exit fullscreen
53 connect(this, SIGNAL(clicked()), parent, SLOT(showNormal()));
55 // install an event filter to listen for the parent's events
56 parent->installEventFilter(this);
59 bool FullScreenExitButton::eventFilter(QObject *obj, QEvent *ev)
62 return QToolButton::eventFilter(obj, ev);
64 QWidget *parent = parentWidget();
65 bool isFullScreen = parent->windowState() & Qt::WindowFullScreen;
68 case QEvent::WindowStateChange:
69 setVisible(isFullScreen);
75 move(parent->width() - width(),
76 parent->height() - height());
82 return QToolButton::eventFilter(obj, ev);
85 #endif // !_FULLSCREENEXITBUTTON_HPP