#include "keymenu.h"
#include "mainwindow.h"
#include "preferences.h"
+#include "scrollarea.h"
#include "vncview.h"
#ifdef Q_WS_MAEMO_5
#endif
-MainWindow::MainWindow(QString url, int quality):
+MainWindow::MainWindow(QString url, int quality, bool view_only):
QMainWindow(0),
vnc_view(0),
scroll_area(new ScrollArea(0)),
+ input_toolbuttons(new QActionGroup(this)),
key_menu(new KeyMenu(this))
{
setWindowTitle("Presence VNC");
- setContextMenuPolicy(Qt::NoContextMenu);
#ifdef Q_WS_MAEMO_5
+ setContextMenuPolicy(Qt::NoContextMenu);
setAttribute(Qt::WA_Maemo5StackedWindow);
#endif
//set up toolbar
toolbar = new QToolBar(0);
- toolbar->addAction(QChar(0x2026), this, SLOT(showKeyMenu())); //"..." button
- toolbar->addAction(tr("Tab"), this, SLOT(sendTab()));
- toolbar->addAction(tr("Esc"), this, SLOT(sendEsc()));
- toolbar->addAction(tr("PgUp"), this, SLOT(sendPgUp()));
- toolbar->addAction(tr("PgDn"), this, SLOT(sendPgDn()));
+ input_toolbuttons->addAction(toolbar->addAction(QChar(0x2026), this, SLOT(showKeyMenu()))); //"..." button
+ input_toolbuttons->addAction(toolbar->addAction(tr("Tab"), this, SLOT(sendTab())));
+ input_toolbuttons->addAction(toolbar->addAction(tr("Esc"), this, SLOT(sendEsc())));
+ input_toolbuttons->addAction(toolbar->addAction(tr("PgUp"), this, SLOT(sendPgUp())));
+ input_toolbuttons->addAction(toolbar->addAction(tr("PgDn"), this, SLOT(sendPgDn())));
#ifdef Q_WS_MAEMO_5
- toolbar->addAction(QIcon("/usr/share/icons/hicolor/48x48/hildon/chat_enter.png"), "", this, SLOT(sendReturn()));
- toolbar->addAction(QIcon("/usr/share/icons/hicolor/48x48/hildon/control_keyboard.png"), "", this, SLOT(showInputPanel()));
+ input_toolbuttons->addAction(toolbar->addAction(QIcon("/usr/share/icons/hicolor/48x48/hildon/chat_enter.png"), "", this, SLOT(sendReturn())));
+ input_toolbuttons->addAction(toolbar->addAction(QIcon("/usr/share/icons/hicolor/48x48/hildon/control_keyboard.png"), "", this, SLOT(showInputPanel())));
#endif
- /*
- //move remaining buttons to the right
- QWidget *spacer = new QWidget();
- spacer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
- toolbar->addWidget(spacer);
- */
-
QSettings settings;
zoom_slider = new QSlider(Qt::Horizontal, 0);
zoom_slider->setRange(0, 100);
connect(zoom_slider, SIGNAL(valueChanged(int)),
this, SLOT(setZoomLevel(int)));
connect(zoom_slider, SIGNAL(sliderReleased()),
- this, SLOT(forceRepaint()));
+ this, SLOT(zoomSliderReleased()));
zoom_slider->setValue(settings.value("zoomlevel", 95).toInt());
toolbar->addWidget(zoom_slider);
//set up menu
QAction *connect_action = new QAction(tr("Connect"), this);
disconnect_action = new QAction(tr("Disconnect"), this);
- show_toolbar = new QAction(tr("Show Toolbar"), this);
+ show_toolbar = new QAction(tr("Show toolbar"), this);
show_toolbar->setCheckable(true);
show_toolbar->setChecked(settings.value("show_toolbar", true).toBool());
QAction *pref_action = new QAction(tr("Preferences"), this);
this, SLOT(updateScreenSpaceDelayed()));
setCentralWidget(scroll_area);
- new FullScreenExitButton(this);
+
+ FullScreenExitButton* fullscreen_exit_button = new FullScreenExitButton(this);
+ connect(fullscreen_exit_button, SIGNAL(clicked()),
+ this, SLOT(toggleFullscreen()));
grabZoomKeys(true);
reloadSettings();
- if(url.isNull()) {
+ if(url.isEmpty()) {
disconnect_action->setEnabled(false);
showConnectDialog();
} else {
connect(vnc_view, SIGNAL(statusChanged(RemoteView::RemoteStatus)),
this, SLOT(statusChanged(RemoteView::RemoteStatus)));
scroll_area->setWidget(vnc_view);
+ vnc_view->setViewOnly(view_only);
vnc_view->start();
}
}
void MainWindow::about() {
QMessageBox::about(this, tr("About Presence VNC"),
- tr("<center><h1>Presence VNC 0.6</h1>\
+ tr("<center><h1>Presence VNC 0.8</h1>\
<p>A touchscreen friendly VNC client</p>\
<p><a href=\"https://garage.maemo.org/projects/presencevnc/\">https://garage.maemo.org/projects/presencevnc</a></p></center>\
<small><p>©2010 Christian Pulvermacher <pulvermacher@gmx.de><br />\
#endif
toolbar->setEnabled(true);
+ //disable key input buttons in view only mode
+ input_toolbuttons->setEnabled(!vnc_view->viewOnly());
+
vnc_view->setZoomLevel(zoom_slider->value());
- vnc_view->forceFullRepaint();
+ vnc_view->useFastTransformations(false);
+ vnc_view->repaint();
break;
case RemoteView::Disconnecting:
- if(old_status != RemoteView::Disconnected) { //Disconnecting also occurs while connecting, so check last state
-#ifdef Q_WS_MAEMO_5
- if(disconnect_action->isEnabled()) //don't show when manually disconnecting
- QMaemo5InformationBox::information(this, tr("Connection lost"));
-#endif
-
- //clean up
- scroll_area->setWidget(0);
- vnc_view = 0;
- disconnect_action->setEnabled(false);
- toolbar->setEnabled(false);
-
- //exit fullscreen mode
- if(windowState() & Qt::WindowFullScreen)
- setWindowState(windowState() ^ Qt::WindowFullScreen);
- }
+ if(old_status == RemoteView::Disconnected) //Disconnecting also occurs while connecting, so check last state
+ break;
+
+ if(disconnect_action->isEnabled()) //don't show when manually disconnecting
+ scroll_area->showMessage(tr("Connection lost"));
+
+ //clean up
+ scroll_area->setWidget(0);
+ vnc_view = 0;
+ disconnect_action->setEnabled(false);
+ toolbar->setEnabled(false);
+
+ //exit fullscreen mode
+ if(windowState() & Qt::WindowFullScreen)
+ setWindowState(windowState() ^ Qt::WindowFullScreen);
break;
case RemoteView::Disconnected:
#ifdef Q_WS_MAEMO_5
old_status = status;
}
-void MainWindow::forceRepaint()
-{
- if(vnc_view)
- vnc_view->forceFullRepaint();
-}
-
//updates available screen space for current zoom level
//necessary when rotating, showing fullscreen, etc.
void MainWindow::updateScreenSpace()
void MainWindow::reloadSettings()
{
QSettings settings;
+ zoom_to_cursor = settings.value("zoom_to_cursor", true).toBool();
+
#ifdef Q_WS_MAEMO_5
int rotation = settings.value("screen_rotation", 0).toInt();
setAttribute(Qt::WA_Maemo5AutoOrientation, rotation == 0);
if(!vnc_view)
return;
- int old_width = vnc_view->width();
+ const qreal old_factor = vnc_view->zoomFactor();
QPoint center = vnc_view->visibleRegion().boundingRect().center();
vnc_view->setZoomLevel(level);
- int new_width = vnc_view->width();
+ const qreal new_factor = vnc_view->zoomFactor();
//scroll to center, if zoom level actually changed
- if(new_width != old_width) {
- center = center * (double(new_width)/old_width);
+ if(old_factor != new_factor) {
+ if(zoom_to_cursor)
+ center = new_factor * vnc_view->cursorPosition();
+ else //zoom to center of visible region
+ center = center * (double(new_factor)/old_factor);
+
scroll_area->ensureVisible(center.x(), center.y(),
- scroll_area->width()/2, scroll_area->height()/2);
+ vnc_view->visibleRegion().boundingRect().width()/2,
+ vnc_view->visibleRegion().boundingRect().height()/2);
+
+ vnc_view->useFastTransformations(zoom_slider->isSliderDown());
vnc_view->update();
+
+ scroll_area->showMessage(tr("Zoom: %1\%").arg(qRound(100*new_factor)));
}
}
+
+void MainWindow::zoomSliderReleased()
+{
+ static QTime time;
+ if(!time.isNull() and time.elapsed() < 500) //double clicked
+ zoom_slider->setValue(95); //100%
+
+ time.restart();
+
+ //stopped zooming, reenable high quality
+ vnc_view->useFastTransformations(false);
+}
+
+void MainWindow::sendTab() { vnc_view->sendKey(Qt::Key_Tab); }
+void MainWindow::sendEsc() { vnc_view->sendKey(Qt::Key_Escape); }
+void MainWindow::sendPgUp() { vnc_view->sendKey(Qt::Key_PageUp); }
+void MainWindow::sendPgDn() { vnc_view->sendKey(Qt::Key_PageDown); }
+void MainWindow::sendReturn() { vnc_view->sendKey(Qt::Key_Return); }