3 Copyright (C) 2010 Christian Pulvermacher
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 #include "fullscreenexitbutton.h"
24 #include <QScrollArea>
28 //fixes tearing during scrolling and can display messages
29 class ScrollArea : public QScrollArea
33 explicit ScrollArea(QWidget *parent):
36 fullscreen_exit_button(parent) //owned by parent!
38 message.setVisible(false);
39 message.setAlignment(Qt::AlignCenter);
40 message.setWordWrap(true);
42 QPalette pal = message.palette();
43 QColor backgroundColor = pal.color(backgroundRole());
44 backgroundColor.setAlpha(128);
45 pal.setColor(backgroundRole(), backgroundColor);
46 message.setPalette(pal);
47 message.setAutoFillBackground(true);
49 message_timer.setSingleShot(true);
50 message_timer.setInterval(4000);
51 connect(&message_timer, SIGNAL(timeout()),
52 &message, SLOT(hide()));
54 connect(&fullscreen_exit_button, SIGNAL(clicked()),
55 this, SIGNAL(fullscreenButtonClicked()));
57 button_reenable_timer.setSingleShot(true);
58 button_reenable_timer.setInterval(500);
59 connect(&button_reenable_timer, SIGNAL(timeout()),
60 &fullscreen_exit_button, SLOT(reenable()));
63 // disable overshooting because it somehow causes repaint events for the whole widget (slow)
64 QAbstractKineticScroller *scroller = property("kineticScroller").value<QAbstractKineticScroller *>();
66 scroller->setOvershootPolicy(QAbstractKineticScroller::OvershootAlwaysOff);
71 void showMessage(const QString &s) {
74 message_timer.start();
77 //provided for convenience
78 void showMessage(QString /*title*/, QString msg) { showMessage(msg); }
81 void fullscreenButtonClicked();
83 virtual void resizeEvent(QResizeEvent* ev) {
84 QScrollArea::resizeEvent(ev);
85 message.setFixedWidth(width());
87 virtual void scrollContentsBy(int dx, int dy) {
88 QScrollArea::scrollContentsBy(dx, dy);
90 //overlay-widgets slow down scrolling
92 fullscreen_exit_button.hide();
93 fullscreen_exit_button.setEnabled(false);
94 button_reenable_timer.start();
100 FullScreenExitButton fullscreen_exit_button;
101 QTimer button_reenable_timer;