don't use 32bit color depth on N900 (16bit display); on other platforms, use 32bit...
[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 "fullscreenexitbutton.h"
23
24 #include <QtGui>
25
26 //fixes tearing during scrolling and can display messages
27 class ScrollArea : public QScrollArea
28 {
29     Q_OBJECT
30 public:
31     explicit ScrollArea(QWidget *parent):
32         QScrollArea(parent),
33         message(this),
34         fullscreen_exit_button(parent) //owned by parent!
35     {
36         message.setVisible(false);
37         message.setAlignment(Qt::AlignCenter);
38         message.setWordWrap(true);
39
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);
46
47         message_timer.setSingleShot(true);
48         message_timer.setInterval(4000);
49         connect(&message_timer, SIGNAL(timeout()),
50                 &message, SLOT(hide()));
51
52         connect(&fullscreen_exit_button, SIGNAL(clicked()),
53             this, SIGNAL(fullscreenButtonClicked()));
54
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()));
59
60 #ifdef Q_WS_MAEMO_5
61         // disable overshooting because it somehow causes repaint events for the whole widget (slow)
62         QAbstractKineticScroller *scroller = property("kineticScroller").value<QAbstractKineticScroller *>();
63         if (scroller)
64             scroller->setOvershootPolicy(QAbstractKineticScroller::OvershootAlwaysOff);
65 #endif
66     }
67
68 public slots:
69     void showMessage(const QString &s) {
70         message.setText(s);
71         message.show();
72         message_timer.start();
73     }
74
75     //provided for convenience
76     void showMessage(QString /*title*/, QString msg) { showMessage(msg); }
77
78 signals:
79     void fullscreenButtonClicked();
80 protected:
81     virtual void resizeEvent(QResizeEvent* ev) {
82         QScrollArea::resizeEvent(ev);
83         message.setFixedWidth(width());
84     }
85     virtual void scrollContentsBy(int dx, int dy) {
86         QScrollArea::scrollContentsBy(dx, dy);
87         if(widget()) {
88             //overlay-widgets slow down scrolling
89             message.hide();
90             fullscreen_exit_button.hide();
91             fullscreen_exit_button.setEnabled(false);
92             button_reenable_timer.start();
93         }
94     }
95 private:
96     QLabel message;
97     QTimer message_timer;
98     FullScreenExitButton fullscreen_exit_button;
99     QTimer button_reenable_timer;
100 };
101 #endif