run astyle (k&r style, indent with 4 spaces)
[presencevnc] / src / scrollarea.h
1 /*
2     Presence VNC
3     Copyright (C) 2010 Christian Pulvermacher
4
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.
9
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.
14
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.
18 */
19 #ifndef SCROLLAREA_H
20 #define SCROLLAREA_H
21
22 #include <QScrollArea>
23 #include <QLabel>
24 #include <QTimer>
25
26 //fixes tearing during scrolling and can display messages
27 class ScrollArea : public QScrollArea
28 {
29 public:
30     ScrollArea(QWidget *parent):
31         QScrollArea(parent) {
32         message.setParent(this);
33         message.setVisible(false);
34         message.setAlignment(Qt::AlignCenter);
35         message.setWordWrap(true);
36
37         QPalette pal = message.palette();
38         QColor backgroundColor = pal.color(backgroundRole());
39         backgroundColor.setAlpha(128);
40         pal.setColor(backgroundRole(), backgroundColor);
41         message.setPalette(pal);
42         message.setAutoFillBackground(true);
43
44         timer.setSingleShot(true);
45         timer.setInterval(2500);
46         connect(&timer, SIGNAL(timeout()),
47                 &message, SLOT(hide()));
48     }
49
50     void showMessage(const QString &s) {
51         message.setText(s);
52         message.show();
53         timer.start();
54     }
55 protected:
56     virtual void resizeEvent(QResizeEvent* ev) {
57         QScrollArea::resizeEvent(ev);
58         message.setFixedWidth(width());
59     }
60     virtual void scrollContentsBy(int dx, int dy) {
61         QScrollArea::scrollContentsBy(dx, dy);
62         if(widget())
63             widget()->update(); //update whole widget
64     }
65 private:
66     QLabel message;
67     QTimer timer;
68 };
69 #endif