imported project
[presencevnc] / src / mainwindow.h
1
2 #include <QtGui>
3
4 #include <QX11Info>
5
6 #include "vncview.h"
7
8 #include <X11/Xlib.h>
9 #include <X11/Xatom.h>
10
11 #include <iostream>
12
13 class MainWindow : public QScrollArea {
14         Q_OBJECT
15 private:
16         VncView *vnc_view;
17         QWidget *menu;
18         QPoint swipe_start;
19
20 public:
21         MainWindow(QString url, int quality) : QScrollArea(0) {
22                 swipe_start = QPoint(0,0);
23                 setAttribute(Qt::WA_Maemo5StackedWindow);
24
25                 vnc_view = new VncView(0, url, RemoteView::Quality(quality));
26                 setWidget(vnc_view);
27
28                 //set up menu
29                 QMenuBar *menu = new QMenuBar(this);
30                 QAction *scaling = new QAction("Rescale Remote Screen", this);
31                 scaling->setCheckable(true);
32                 scaling->setChecked(true);
33                 menu->addAction(scaling);
34                 QAction *about_action = new QAction("About", this);
35                 menu->addAction(about_action);
36
37                 //menu->setAttribute(Qt::WA_Maemo5StackedWindow);
38                 //menu->hide();
39
40                 connect(scaling, SIGNAL(toggled(bool)),
41                         vnc_view, SLOT(enableScaling(bool)));
42                 connect(about_action, SIGNAL(triggered()),
43                         this, SLOT(about()));
44
45                 grabZoomKeys(true);
46                 setAttribute(Qt::WA_Maemo5AutoOrientation, true);
47                 //setAttribute(Qt::WA_Maemo5PortraitOrientation, true);
48
49                 vnc_view->start();
50         }
51
52         void grabZoomKeys(bool grab)
53         {
54                 unsigned long val = (grab)?1:0;
55                 Atom atom = XInternAtom(QX11Info::display(), "_HILDON_ZOOM_KEY_ATOM", False);
56                 if(!atom) {
57                         qWarning("Couldn't get zoom key atom");
58                         return;
59                 }
60                 XChangeProperty(QX11Info::display(), winId(), atom, XA_INTEGER,
61                         32, PropModeReplace, reinterpret_cast<unsigned char *>(&val), 1);
62         }
63         void closeEvent(QCloseEvent*) {
64                 hide();
65                 grabZoomKeys(false);
66                 vnc_view->startQuitting();
67         }
68 public slots:
69         void about() {
70                 QMessageBox::about(this, tr("About Presence VNC"),
71                         tr("<center><h1>Presence VNC 0.1 alpha</h1>\
72 A touch screen friendly VNC client\
73 <small><p>&copy;2010 Christian Pulvermacher &lt;pulvermacher@gmx.de&gt</p>\
74 <p>Based on KRDC, &copy; 2007-2008 Urs Wolfer</small></center>\
75 <p>This program is free software; License: <a href=\"http://www.gnu.org/licenses/gpl-2.0.html\">GNU GPL 2</a> or later.</p>"));
76         }
77
78 protected:
79 /* swipe not used, and doesn't work without scaling anyway :/
80         virtual bool event(QEvent *event) {
81                 if(event->type() == QEvent::MouseMove) {
82                         QMouseEvent *ev = dynamic_cast<QMouseEvent* >(event);
83                         if(!swipe_start.isNull()) {
84                                 QPoint diff = swipe_start - ev->pos();
85                                 const int swipe_dist = 60;
86                                 if(diff.x() > swipe_dist and diff.y() < swipe_dist and diff.y() > -swipe_dist) { //
87                                         menu->show();
88                                         swipe_start = QPoint(0,0);
89                                 }
90                         } else if((width() - ev->x()) < 10) {
91                                 swipe_start = ev->pos();
92                         }
93                         std::cout << "mousex: " << width() - ev->x() << "\n";
94                         //TODO: make scrolling over border result in wheel events? i get weird (out of range) mouse events when that happens
95                         return true;
96                 } else if(event->type() == QEvent::MouseButtonRelease) {
97                         swipe_start = QPoint(0,0);
98                         return true;
99                 } else {
100 //                      std::cout << "event " << event->type() << "\n";
101                         return QScrollArea::event(event);
102                 }
103         }
104         */
105 };