+/*
+ Presence VNC
+ Copyright (C) 2010 Christian Pulvermacher
-#include <QtGui>
-
-#include <QX11Info>
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
-#include "vncview.h"
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
-#include <X11/Xlib.h>
-#include <X11/Xatom.h>
+ You should have received a copy of the GNU General Public License along
+ with this program; if not, write to the Free Software Foundation, Inc.,
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+*/
+#ifndef MAINWINDOW_H
+#define MAINWINDOW_H
-#include <iostream>
+#include "remoteview.h"
+#include "vncview.h"
-class MainWindow : public QScrollArea {
- Q_OBJECT
-private:
- VncView *vnc_view;
- QWidget *menu;
- QPoint swipe_start;
+#include <QtGui>
+//fix tearing during scrolling
+class ScrollArea : public QScrollArea {
public:
- MainWindow(QString url, int quality) : QScrollArea(0) {
- swipe_start = QPoint(0,0);
- setAttribute(Qt::WA_Maemo5StackedWindow);
-
- vnc_view = new VncView(0, url, RemoteView::Quality(quality));
- setWidget(vnc_view);
-
- //set up menu
- QMenuBar *menu = new QMenuBar(this);
- QAction *scaling = new QAction("Rescale Remote Screen", this);
- scaling->setCheckable(true);
- scaling->setChecked(true);
- menu->addAction(scaling);
- QAction *about_action = new QAction("About", this);
- menu->addAction(about_action);
-
- //menu->setAttribute(Qt::WA_Maemo5StackedWindow);
- //menu->hide();
-
- connect(scaling, SIGNAL(toggled(bool)),
- vnc_view, SLOT(enableScaling(bool)));
- connect(about_action, SIGNAL(triggered()),
- this, SLOT(about()));
-
- grabZoomKeys(true);
- setAttribute(Qt::WA_Maemo5AutoOrientation, true);
- //setAttribute(Qt::WA_Maemo5PortraitOrientation, true);
-
- vnc_view->start();
- }
-
- void grabZoomKeys(bool grab)
+ ScrollArea(QWidget *parent) : QScrollArea(parent) { }
+protected:
+ virtual void scrollContentsBy(int dx, int dy)
{
- unsigned long val = (grab)?1:0;
- Atom atom = XInternAtom(QX11Info::display(), "_HILDON_ZOOM_KEY_ATOM", False);
- if(!atom) {
- qWarning("Couldn't get zoom key atom");
- return;
- }
- XChangeProperty(QX11Info::display(), winId(), atom, XA_INTEGER,
- 32, PropModeReplace, reinterpret_cast<unsigned char *>(&val), 1);
- }
- void closeEvent(QCloseEvent*) {
- hide();
- grabZoomKeys(false);
- vnc_view->startQuitting();
- }
-public slots:
- void about() {
- QMessageBox::about(this, tr("About Presence VNC"),
- tr("<center><h1>Presence VNC 0.1 alpha</h1>\
-A touch screen friendly VNC client\
-<small><p>©2010 Christian Pulvermacher <pulvermacher@gmx.de></p>\
-<p>Based on KRDC, © 2007-2008 Urs Wolfer</small></center>\
-<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>"));
+ QScrollArea::scrollContentsBy(dx, dy);
+ if(widget())
+ widget()->update(); //update whole widget
}
+};
+class MainWindow : public QMainWindow {
+ Q_OBJECT
+public:
+ MainWindow(QString url, int quality);
+public slots:
+ void about();
+ void showConnectDialog();
+ void connectToHost(QString url);
+ void disconnectFromHost();
+ void forceResize();
+ void forceResizeDelayed();
+ void sendTab() { vnc_view->sendKey(Qt::Key_Tab); }
+ void sendEsc() { vnc_view->sendKey(Qt::Key_Escape); }
+ void sendPgUp() { vnc_view->sendKey(Qt::Key_PageUp); }
+ void sendPgDn() { vnc_view->sendKey(Qt::Key_PageDown); }
+ void sendReturn() { vnc_view->sendKey(Qt::Key_Return); }
+ void showInputPanel();
+ void showModifierMenu();
+ void showPreferences();
+ void statusChanged(RemoteView::RemoteStatus status);
+ void toggleFullscreen();
protected:
-/* swipe not used, and doesn't work without scaling anyway :/
- virtual bool event(QEvent *event) {
- if(event->type() == QEvent::MouseMove) {
- QMouseEvent *ev = dynamic_cast<QMouseEvent* >(event);
- if(!swipe_start.isNull()) {
- QPoint diff = swipe_start - ev->pos();
- const int swipe_dist = 60;
- if(diff.x() > swipe_dist and diff.y() < swipe_dist and diff.y() > -swipe_dist) { //
- menu->show();
- swipe_start = QPoint(0,0);
- }
- } else if((width() - ev->x()) < 10) {
- swipe_start = ev->pos();
- }
- std::cout << "mousex: " << width() - ev->x() << "\n";
- //TODO: make scrolling over border result in wheel events? i get weird (out of range) mouse events when that happens
- return true;
- } else if(event->type() == QEvent::MouseButtonRelease) {
- swipe_start = QPoint(0,0);
- return true;
- } else {
-// std::cout << "event " << event->type() << "\n";
- return QScrollArea::event(event);
- }
- }
- */
+ void closeEvent(QCloseEvent*);
+private:
+ void grabZoomKeys(bool grab);
+ void reloadSettings();
+ VncView *vnc_view;
+ ScrollArea *scroll_area;
+ QToolBar *toolbar;
+ QAction *scaling, *show_toolbar, *disconnect_action;
};
+#endif