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"
26 //fixes tearing during scrolling and can display messages
27 class ScrollArea : public QScrollArea
31 explicit ScrollArea(QWidget *parent):
34 fullscreen_exit_button(parent) //owned by parent!
36 message.setVisible(false);
37 message.setAlignment(Qt::AlignCenter);
38 message.setWordWrap(true);
40 QPalette pal = message.palette();
41 QColor backgroundColor = pal.color(backgroundRole());
42 backgroundColor.setAlpha(128);
43 pal.setColor(backgroundRole(), backgroundColor);
44 message.setPalette(pal);
45 message.setAutoFillBackground(true);
47 message_timer.setSingleShot(true);
48 message_timer.setInterval(4000);
49 connect(&message_timer, SIGNAL(timeout()),
50 &message, SLOT(hide()));
52 connect(&fullscreen_exit_button, SIGNAL(clicked()),
53 this, SIGNAL(fullscreenButtonClicked()));
55 button_reenable_timer.setSingleShot(true);
56 button_reenable_timer.setInterval(500);
57 connect(&button_reenable_timer, SIGNAL(timeout()),
58 &fullscreen_exit_button, SLOT(reenable()));
61 // disable overshooting because it somehow causes repaint events for the whole widget (slow)
62 QAbstractKineticScroller *scroller = property("kineticScroller").value<QAbstractKineticScroller *>();
64 scroller->setOvershootPolicy(QAbstractKineticScroller::OvershootAlwaysOff);
69 void showMessage(const QString &s) {
72 message_timer.start();
75 //provided for convenience
76 void showMessage(QString /*title*/, QString msg) { showMessage(msg); }
79 void fullscreenButtonClicked();
81 virtual void resizeEvent(QResizeEvent* ev) {
82 QScrollArea::resizeEvent(ev);
83 message.setFixedWidth(width());
85 virtual void scrollContentsBy(int dx, int dy) {
86 QScrollArea::scrollContentsBy(dx, dy);
88 //overlay-widgets slow down scrolling
90 fullscreen_exit_button.hide();
91 fullscreen_exit_button.setEnabled(false);
92 button_reenable_timer.start();
98 FullScreenExitButton fullscreen_exit_button;
99 QTimer button_reenable_timer;