added zoom bar prototype
authorChristian Pulvermacher <christian@hazel.(none)>
Sun, 3 Oct 2010 08:40:10 +0000 (10:40 +0200)
committerChristian Pulvermacher <christian@hazel.(none)>
Sun, 3 Oct 2010 08:40:10 +0000 (10:40 +0200)
src/connectdialog.cpp
src/mainwindow.cpp
src/mainwindow.h
src/vncview.cpp
src/vncview.h

index 11281e4..ed3ca0f 100644 (file)
@@ -97,12 +97,14 @@ void ConnectDialog::hostnameUpdated(QString newtext)
        newtext.remove(QChar('\\'));
        hosts.lineEdit()->setText(newtext.toLower());
 
+#ifdef Q_WS_MAEMO_5
        //saved quality setting available?
        QSettings settings;
        int quality = settings.value(QString("hosts/%1/quality").arg(hosts.lineEdit()->text()), 2).toInt();
        if(quality < 1 or quality > 3)
                quality = 2;
        quality_selector->setCurrentIndex(quality-1);
+#endif
 }
 
 void ConnectDialog::accept()
@@ -144,8 +146,12 @@ void ConnectDialog::accept()
                //move selected host to front
                settings.setValue(QString("%1/position").arg(hosts.currentText()), 0);
        }
+#ifdef Q_WS_MAEMO_5
        int quality = quality_selector->currentIndex() + 1;
        settings.setValue(QString("%1/quality").arg(hosts.currentText()), quality);
+#else
+       int quality = 2;
+#endif
 
        settings.endGroup();
        settings.sync();
index 0c1c1e3..a905816 100644 (file)
@@ -23,6 +23,8 @@
 #include "preferences.h"
 #include "vncview.h"
 
+#include <QSlider>
+
 #ifdef Q_WS_MAEMO_5
 #include <QtMaemo5>
 #include <QX11Info>
@@ -32,6 +34,7 @@
 #endif
 
 
+
 MainWindow::MainWindow(QString url, int quality):
        QMainWindow(0),
        vnc_view(0),
@@ -68,6 +71,15 @@ MainWindow::MainWindow(QString url, int quality):
        addToolBar(toolbar);
        toolbar->setVisible(settings.value("show_toolbar", true).toBool());
 
+       //set up zoombar
+       zoombar = new QToolBar(0);
+       QSlider *zoom_slider = new QSlider(Qt::Horizontal, 0);
+       zoom_slider->setRange(0, 100);
+       connect(zoom_slider, SIGNAL(valueChanged(int)),
+               this, SLOT(setZoomLevel(int)));
+       zoombar->addWidget(zoom_slider);
+       addToolBar(zoombar);
+
        //set up menu
        QAction *connect_action = new QAction(tr("Connect"), this);
        disconnect_action = new QAction(tr("Disconnect"), this);
@@ -348,3 +360,9 @@ void MainWindow::showInputPanel()
        QApplication::sendEvent(vnc_view, &event);
 #endif
 }
+
+void MainWindow::setZoomLevel(int level)
+{
+       if(vnc_view)
+               vnc_view->setZoomLevel(level);
+}
index a0096da..9a6a270 100644 (file)
@@ -56,6 +56,7 @@ public slots:
        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 setZoomLevel(int level);
        void showInputPanel();
        void showKeyMenu();
        void showPreferences();
@@ -69,7 +70,7 @@ private:
        void reloadSettings();
        VncView *vnc_view;
        ScrollArea *scroll_area;
-       QToolBar *toolbar;      
+       QToolBar *toolbar, *zoombar;
        QAction *scaling, *show_toolbar, *disconnect_action;
        KeyMenu *key_menu;
 };
index 14f5d0a..6260160 100644 (file)
@@ -401,7 +401,7 @@ void VncView::enableScaling(bool scale)
         if (parentWidget())
             scaleResize(parentWidget()->width(), parentWidget()->height());
            else
-               scaleResize(width(), height());
+                       scaleResize(width(), height());
     } else {
         m_verticalFactor = 1.0;
         m_horizontalFactor = 1.0;
@@ -412,6 +412,38 @@ void VncView::enableScaling(bool scale)
     }
 }
 
+void VncView::setZoomLevel(int level)
+{
+       Q_ASSERT(parentWidget() != 0);
+       kDebug(5011) << "zooming to " << level;
+
+       //level should be in [0, 100]
+       if(level == 0) {
+               //double
+        m_verticalFactor = 2.0;
+        m_horizontalFactor = 2.0;
+
+        resize(m_frame.width()*2, m_frame.height()*2);
+       } else if(level < 10) {
+               //1:1
+        m_verticalFactor = 1.0;
+        m_horizontalFactor = 1.0;
+
+        resize(m_frame.width(), m_frame.height());
+       } else {
+               //map level to factor: level=10 => factor=nozoom_factor, level=100 => factor=1.0
+               double nozoom_factor = qMin(double(m_frame.width()/parentWidget()->width()),  double(m_frame.height()/parentWidget()->height()));
+               double factor = double(level-10)/90*(1.0 - nozoom_factor) + nozoom_factor;
+               if(factor < 0) {
+                       //remote display smaller than local?
+                       kDebug(5011) << "remote display smaller than local?";
+                       factor = 1.0;
+               }
+
+               scaleResize(parentWidget()->width()*factor, parentWidget()->height()*factor);
+       }
+}
+
 void VncView::setCut(const QString &text)
 {
     m_dontSendClipboard = true;
index f9e040d..d98a72c 100644 (file)
@@ -59,7 +59,8 @@ public:
     void showDotCursor(DotCursorState state);
     
 public slots:
-    void enableScaling(bool scale);
+    void enableScaling(bool scale); //TODO: i may want to remove this
+    void setZoomLevel(int level); //'level' doesn't correspond to actual magnification, though mapping is done here
     void scaleResize(int w, int h);
     void sendKey(Qt::Key key);
     void sendKeySequence(QKeySequence keys);