remove 'fit to screen' menu option, save zoom level
authorChristian Pulvermacher <christian@hazel.(none)>
Mon, 4 Oct 2010 12:55:11 +0000 (14:55 +0200)
committerChristian Pulvermacher <christian@hazel.(none)>
Mon, 4 Oct 2010 12:55:11 +0000 (14:55 +0200)
src/mainwindow.cpp
src/mainwindow.h
src/preferences.cpp
src/vncview.cpp

index 1225ae4..47bfc4e 100644 (file)
@@ -23,8 +23,6 @@
 #include "preferences.h"
 #include "vncview.h"
 
-#include <QSlider>
-
 #ifdef Q_WS_MAEMO_5
 #include <QtMaemo5>
 #include <QX11Info>
@@ -62,7 +60,7 @@ MainWindow::MainWindow(QString url, int quality):
        toolbar->addAction(QIcon("/usr/share/icons/hicolor/48x48/hildon/control_keyboard.png"), "", this, SLOT(showInputPanel()));
 #endif
 
-       //move fullscreen button to the right
+       //move remaining buttons to the right
        QWidget *spacer = new QWidget();
        spacer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
        toolbar->addWidget(spacer);
@@ -73,19 +71,17 @@ MainWindow::MainWindow(QString url, int quality):
 
        //set up zoombar
        zoombar = new QToolBar(0);
-       QSlider *zoom_slider = new QSlider(Qt::Horizontal, 0);
+       zoom_slider = new QSlider(Qt::Horizontal, 0);
        zoom_slider->setRange(0, 100);
        connect(zoom_slider, SIGNAL(valueChanged(int)),
                this, SLOT(setZoomLevel(int)));
+       zoom_slider->setValue(settings.value("zoomlevel", 95).toInt());
        zoombar->addWidget(zoom_slider);
        addToolBar(zoombar);
 
        //set up menu
        QAction *connect_action = new QAction(tr("Connect"), this);
        disconnect_action = new QAction(tr("Disconnect"), this);
-       scaling = new QAction(tr("Fit to Screen"), this);
-       scaling->setCheckable(true);
-       scaling->setChecked(settings.value("rescale", true).toBool());
        show_toolbar = new QAction(tr("Show Toolbar"), this);
        show_toolbar->setCheckable(true);
        show_toolbar->setChecked(settings.value("show_toolbar", true).toBool());
@@ -95,7 +91,6 @@ MainWindow::MainWindow(QString url, int quality):
 #ifdef Q_WS_MAEMO_5
        menuBar()->addAction(connect_action);
        menuBar()->addAction(disconnect_action);
-       menuBar()->addAction(scaling);
        menuBar()->addAction(show_toolbar);
        menuBar()->addAction(pref_action);
        menuBar()->addAction(about_action);
@@ -109,7 +104,6 @@ MainWindow::MainWindow(QString url, int quality):
        session_menu->addAction(tr("&Quit"), this, SLOT(close()));
 
        QMenu* view_menu = menuBar()->addMenu(tr("&View"));
-       view_menu->addAction(scaling);
        view_menu->addAction(show_toolbar);
 
        QMenu* help_menu = menuBar()->addMenu(tr("&Help"));
@@ -141,13 +135,10 @@ MainWindow::MainWindow(QString url, int quality):
                showConnectDialog();
        } else {
                vnc_view = new VncView(this, url, RemoteView::Quality(quality));
-               connect(scaling, SIGNAL(toggled(bool)),
-                       vnc_view, SLOT(enableScaling(bool)));
                connect(vnc_view, SIGNAL(statusChanged(RemoteView::RemoteStatus)),
                        this, SLOT(statusChanged(RemoteView::RemoteStatus)));
                scroll_area->setWidget(vnc_view);
                vnc_view->start();
-               vnc_view->enableScaling(scaling->isChecked());
                key_menu = new KeyMenu(this);
        }
 }
@@ -171,7 +162,7 @@ void MainWindow::closeEvent(QCloseEvent*) {
 
        QSettings settings;
        settings.setValue("show_toolbar", show_toolbar->isChecked());
-       settings.setValue("rescale", scaling->isChecked());
+       settings.setValue("zoomlevel", zoom_slider->value());
        settings.sync();
 
        hide();
@@ -204,13 +195,10 @@ void MainWindow::connectToHost(QString url, int quality)
 
        vnc_view = new VncView(this, url, RemoteView::Quality(quality));
 
-       connect(scaling, SIGNAL(toggled(bool)),
-               vnc_view, SLOT(enableScaling(bool)));
        connect(vnc_view, SIGNAL(statusChanged(RemoteView::RemoteStatus)),
                this, SLOT(statusChanged(RemoteView::RemoteStatus)));
        scroll_area->setWidget(vnc_view);
        vnc_view->start();
-       vnc_view->enableScaling(scaling->isChecked());
        disconnect_action->setEnabled(true);
        toolbar->setEnabled(true);
 
@@ -247,11 +235,13 @@ void MainWindow::statusChanged(RemoteView::RemoteStatus status)
 #ifdef Q_WS_MAEMO_5
                setAttribute(Qt::WA_Maemo5ShowProgressIndicator, false);
 #endif
+               /* TODO: still needed?
                if(!scaling->isChecked()) {
                        //ugly hack to force a refresh (forceFullRepaint() doesn't repaint?? -> vnc_view hidden???)
                        vnc_view->resize(scroll_area->size());
                        vnc_view->enableScaling(false);
                }
+               */
                break;
        case RemoteView::Disconnecting:
                if(old_status != RemoteView::Disconnected) { //Disconnecting also occurs while connecting, so check last state
@@ -283,11 +273,11 @@ void MainWindow::statusChanged(RemoteView::RemoteStatus status)
        old_status = status;
 }
 
-//when rescaling is enabled, this resizes the widget to use available screen space
+//resizes the widget to use available screen space
 //necessary when rotating, showing fullscreen, etc.
 void MainWindow::forceResize()
 {
-       if(vnc_view and scaling->isChecked()) {
+       if(vnc_view) {
                vnc_view->resize(scroll_area->size());
        }
 } 
index 9a6a270..d133ef6 100644 (file)
@@ -71,6 +71,7 @@ private:
        VncView *vnc_view;
        ScrollArea *scroll_area;
        QToolBar *toolbar, *zoombar;
+       QSlider *zoom_slider;
        QAction *scaling, *show_toolbar, *disconnect_action;
        KeyMenu *key_menu;
 };
index 212be34..ea1fe2e 100644 (file)
@@ -31,7 +31,7 @@ void migrateConfiguration()
 {
        QSettings settings;
        int config_ver = settings.value("config_version", 0).toInt();
-       const int current_ver = 2;
+       const int current_ver = 3;
        if(config_ver == current_ver) //config file up-to-date
                return;
        if(config_ver > current_ver) {
@@ -70,6 +70,20 @@ void migrateConfiguration()
                
                config_ver = 2;
        }
+       if(config_ver == 2) {
+               bool rescale = settings.value("rescale", false).toBool();
+               settings.remove("rescale");
+
+               int zoomlevel;
+               if(rescale)
+                       zoomlevel = 0;
+               else
+                       zoomlevel = 95;
+
+               settings.setValue("zoomlevel", zoomlevel);
+               
+               config_ver = 3;
+       }
        Q_ASSERT(config_ver == current_ver);
        settings.setValue("config_version", config_ver);
        settings.sync();
index ff5f5f6..8152bec 100644 (file)
@@ -316,6 +316,7 @@ if(x == 0 and y == 0) {
 
        //with scaled view, artefacts occur because of rounding errors
        //we'll try to only update chunks of screen space that correspond to integer pixel sizes in m_frame
+       //put this into paintEvent
        /*
        int frame_x = x/m_horizontalFactor;
        int frame_w = w/m_horizontalFactor;
@@ -412,22 +413,6 @@ void VncView::showDotCursor(DotCursorState state)
 void VncView::enableScaling(bool scale)
 {
     RemoteView::enableScaling(scale);
-
-    if (scale) {
-        //setMaximumSize(QSize(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX));
-        //setMinimumSize(1, 1);
-        if (parentWidget())
-            scaleResize(parentWidget()->width(), parentWidget()->height());
-           else
-                       scaleResize(width(), height());
-    } else {
-        m_verticalFactor = 1.0;
-        m_horizontalFactor = 1.0;
-
-        //setMaximumSize(m_frame.width(), m_frame.height()); //This is a hack to force Qt to center the view in the scroll area
-        //setMinimumSize(m_frame.width(), m_frame.height());
-        resize(m_frame.width(), m_frame.height());
-    }
 }
 
 //level should be in [0, 100]
@@ -935,6 +920,8 @@ void VncView::reloadSettings()
        bool always_show_local_cursor = settings.value("always_show_local_cursor", false).toBool();
        if(always_show_local_cursor)
                showDotCursor(CursorOn);
+
+       enableScaling(true);
 }
 
 //convert commitString into keyevents