Hide 'Exit fullscreen' button during scrolling (improves performance)
[presencevnc] / src / mainwindow.cpp
index 4618ad9..07bcf51 100644 (file)
@@ -17,7 +17,6 @@
    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
    */
 #include "connectdialog.h"
-#include "fullscreenexitbutton.h"
 #include "keymenu.h"
 #include "mainwindow.h"
 #include "preferences.h"
@@ -40,7 +39,7 @@
 MainWindow::MainWindow(QString url, int quality, int listen_port, bool view_only):
     QMainWindow(0),
     vnc_view(0),
-    scroll_area(new ScrollArea(0)),
+    scroll_area(new ScrollArea(this)),
     input_toolbuttons(new QActionGroup(this)),
     key_menu(0)
 {
@@ -54,7 +53,8 @@ MainWindow::MainWindow(QString url, int quality, int listen_port, bool view_only
 
     //set up toolbar
     toolbar = new QToolBar(0);
-    input_toolbuttons->addAction(toolbar->addAction(QChar(0x2026), this, SLOT(showKeyMenu()))); //"..." button
+    key_menu_button = input_toolbuttons->addAction(toolbar->addAction(QChar(0x2026), this, SLOT(showKeyMenu()))); //"..." button
+    key_menu_button->setCheckable(true); //used to indicate wether a modifier key is still pressed
     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())));
@@ -74,7 +74,11 @@ MainWindow::MainWindow(QString url, int quality, int listen_port, bool view_only
     zoom_slider->setValue(settings.value("zoomlevel", 95).toInt());
     toolbar->addWidget(zoom_slider);
 
+#ifdef Q_WS_MAEMO_5
     toolbar->addAction(QIcon("/usr/share/icons/hicolor/48x48/hildon/general_fullsize.png"), "", this, SLOT(toggleFullscreen()));
+#else
+    toolbar->addAction(tr("Toggle Fullscreen"), this, SLOT(toggleFullscreen()));
+#endif
     addToolBar(toolbar);
     toolbar->setVisible(settings.value("show_toolbar", true).toBool());
     toolbar->setEnabled(false);
@@ -124,13 +128,12 @@ MainWindow::MainWindow(QString url, int quality, int listen_port, bool view_only
             this, SLOT(updateScreenSpaceDelayed()));
 #ifdef Q_WS_MAEMO_5
     QDBusConnection::systemBus().connect("", MCE_SIGNAL_PATH, MCE_SIGNAL_IF, MCE_DISPLAY_SIG,
-            this, SLOT(displayStateChanged(QString)));
+                                         this, SLOT(displayStateChanged(QString)));
 #endif
 
     setCentralWidget(scroll_area);
 
-    FullScreenExitButton* fullscreen_exit_button = new FullScreenExitButton(this);
-    connect(fullscreen_exit_button, SIGNAL(clicked()),
+    connect(scroll_area, SIGNAL(fullscreenButtonClicked()),
             this, SLOT(toggleFullscreen()));
 
     grabZoomKeys(true);
@@ -154,11 +157,12 @@ void MainWindow::grabZoomKeys(bool grab)
         return;
     }
     XChangeProperty(QX11Info::display(), winId(), atom, XA_INTEGER,
-            32, PropModeReplace, reinterpret_cast<unsigned char *>(&val), 1);
+                    32, PropModeReplace, reinterpret_cast<unsigned char *>(&val), 1);
 #endif
 }
 
-void MainWindow::closeEvent(QCloseEvent*) {
+void MainWindow::closeEvent(QCloseEvent*)
+{
     grabZoomKeys(false);
 
     QSettings settings;
@@ -171,9 +175,10 @@ void MainWindow::closeEvent(QCloseEvent*) {
     disconnectFromHost();
 }
 
-void MainWindow::about() {
+void MainWindow::about()
+{
     QMessageBox::about(this, tr("About Presence VNC"),
-            tr("<center><h1>Presence VNC 0.8</h1>\
+                       tr("<center><h1>Presence VNC 0.8</h1>\
                 <p>A touchscreen friendly VNC client</p>\
                 <p><a href=\"http://presencevnc.garage.maemo.org/\">http://presencevnc.garage.maemo.org/</a></p></center>\
                 <small><p>&copy;2010 Christian Pulvermacher &lt;pulvermacher@gmx.de&gt;<br />\
@@ -200,8 +205,11 @@ void MainWindow::connectToHost(QString url, int quality, int listen_port, bool v
 
     connect(vnc_view, SIGNAL(statusChanged(RemoteView::RemoteStatus)),
             this, SLOT(statusChanged(RemoteView::RemoteStatus)));
+    connect(vnc_view, SIGNAL(errorMessage(QString, QString)),
+        scroll_area, SLOT(showMessage(QString, QString)));
     scroll_area->setWidget(vnc_view);
     vnc_view->start();
+    setWindowTitle(QString("Presence VNC - %1").arg(vnc_view->host()) + (view_only?tr(" [View Only]"):""));
 
     disconnect_action->setEnabled(true);
 
@@ -215,6 +223,7 @@ void MainWindow::disconnectFromHost()
     if(!vnc_view)
         return;
 
+    setWindowTitle("Presence VNC");
     disconnect_action->setEnabled(false);
     toolbar->setEnabled(false);
     scroll_area->setWidget(0);
@@ -228,51 +237,52 @@ void MainWindow::statusChanged(RemoteView::RemoteStatus status)
     static RemoteView::RemoteStatus old_status = RemoteView::Disconnected;
 
     switch(status) {
-        case RemoteView::Connecting:
+    case RemoteView::Connecting:
 #ifdef Q_WS_MAEMO_5
-            setAttribute(Qt::WA_Maemo5ShowProgressIndicator, true);
+        setAttribute(Qt::WA_Maemo5ShowProgressIndicator, true);
 #endif
-            break;
-        case RemoteView::Connected:
+        break;
+    case RemoteView::Connected:
 #ifdef Q_WS_MAEMO_5
-            setAttribute(Qt::WA_Maemo5ShowProgressIndicator, false);
+        setAttribute(Qt::WA_Maemo5ShowProgressIndicator, false);
 #endif
-            toolbar->setEnabled(true);
+        toolbar->setEnabled(true);
 
-            //disable key input buttons in view only mode
-            input_toolbuttons->setEnabled(!vnc_view->viewOnly());
+        //disable key input buttons in view only mode
+        input_toolbuttons->setEnabled(!vnc_view->viewOnly());
 
-            vnc_view->setZoomLevel(zoom_slider->value());
-            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
-                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);
+        vnc_view->setZoomLevel(zoom_slider->value());
+        vnc_view->useFastTransformations(false);
+        vnc_view->update();
+        break;
+    case RemoteView::Disconnecting:
+        if(old_status == RemoteView::Disconnected) //Disconnecting also occurs while connecting, so check last state
             break;
-        case RemoteView::Disconnected:
+
+        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;
+        setWindowTitle("Presence VNC");
+        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
-            setAttribute(Qt::WA_Maemo5ShowProgressIndicator, false);
+        setAttribute(Qt::WA_Maemo5ShowProgressIndicator, false);
 #endif
-            if(old_status == RemoteView::Disconnecting) {
-                scroll_area->setWidget(0); //remove widget
-            }
-            break;
-        default: //avoid compiler warnings
-            break;
+        if(old_status == RemoteView::Disconnecting) {
+            scroll_area->setWidget(0); //remove widget
+        }
+        break;
+    default: //avoid compiler warnings
+        break;
     }
 
     old_status = status;
@@ -285,7 +295,7 @@ void MainWindow::updateScreenSpace()
     if(vnc_view) {
         vnc_view->setZoomLevel();
     }
-} 
+}
 
 void MainWindow::updateScreenSpaceDelayed()
 {
@@ -304,7 +314,7 @@ void MainWindow::toggleFullscreen()
     menuBar()->setVisible(in_fullscreen);
 #endif
 
-    setWindowState(windowState() ^ Qt::WindowFullScreen); 
+    setWindowState(windowState() ^ Qt::WindowFullScreen);
     updateScreenSpaceDelayed();
 }
 
@@ -312,6 +322,7 @@ void MainWindow::showKeyMenu()
 {
     key_menu->exec();
     vnc_view->sendKeySequence(key_menu->getKeySequence());
+    key_menu_button->setChecked(key_menu->isAltChecked() or key_menu->isWinChecked());
 }
 
 void MainWindow::showPreferences()
@@ -385,8 +396,8 @@ void MainWindow::setZoomLevel(int level)
             center = center * (double(new_factor)/old_factor);
 
         scroll_area->ensureVisible(center.x(), center.y(),
-                vnc_view->visibleRegion().boundingRect().width()/2,
-                vnc_view->visibleRegion().boundingRect().height()/2);
+                                   vnc_view->visibleRegion().boundingRect().width()/2,
+                                   vnc_view->visibleRegion().boundingRect().height()/2);
 
         vnc_view->useFastTransformations(zoom_slider->isSliderDown());
         vnc_view->update();