just unselect 'listen ...' entry when edited by user
[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 public:
29         ScrollArea(QWidget *parent):
30                 QScrollArea(parent)
31         {
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         {
52                 message.setText(s);
53                 message.show();
54                 timer.start();
55         }
56 protected:
57         virtual void resizeEvent(QResizeEvent* ev)
58         {
59                 QScrollArea::resizeEvent(ev);
60                 message.setFixedWidth(width());
61         }
62         virtual void scrollContentsBy(int dx, int dy)
63         {
64                 QScrollArea::scrollContentsBy(dx, dy);
65                 if(widget())
66                         widget()->update(); //update whole widget
67         }
68 private:
69         QLabel message;
70         QTimer timer;
71 };
72 #endif