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 <QScrollArea>
26 //fixes tearing during scrolling and can display messages
27 class ScrollArea : public QScrollArea
31 explicit ScrollArea(QWidget *parent):
35 message.setVisible(false);
36 message.setAlignment(Qt::AlignCenter);
37 message.setWordWrap(true);
39 QPalette pal = message.palette();
40 QColor backgroundColor = pal.color(backgroundRole());
41 backgroundColor.setAlpha(128);
42 pal.setColor(backgroundRole(), backgroundColor);
43 message.setPalette(pal);
44 message.setAutoFillBackground(true);
46 message_timer.setSingleShot(true);
47 message_timer.setInterval(2500);
48 connect(&message_timer, SIGNAL(timeout()),
49 &message, SLOT(hide()));
52 // disable overshooting because it somehow causes repaint events for the whole widget (slow)
53 QAbstractKineticScroller *scroller = property("kineticScroller").value<QAbstractKineticScroller *>();
55 scroller->setOvershootPolicy(QAbstractKineticScroller::OvershootAlwaysOff);
60 void showMessage(const QString &s) {
63 message_timer.start();
66 //provided for convenience
67 void showMessage(QString /*title*/, QString msg) { showMessage(msg); }
69 virtual void resizeEvent(QResizeEvent* ev) {
70 QScrollArea::resizeEvent(ev);
71 message.setFixedWidth(width());
73 virtual void scrollContentsBy(int dx, int dy) {
74 QScrollArea::scrollContentsBy(dx, dy);
76 message.hide(); //overlay-widget slows down scrolling