use fast transformations during zoom
authorChristian Pulvermacher <christian@hazel.(none)>
Wed, 27 Oct 2010 16:06:14 +0000 (18:06 +0200)
committerChristian Pulvermacher <christian@hazel.(none)>
Wed, 27 Oct 2010 16:06:14 +0000 (18:06 +0200)
src/mainwindow.cpp
src/vncview.cpp
src/vncview.h

index 29d8d68..46737d4 100644 (file)
@@ -230,6 +230,7 @@ void MainWindow::statusChanged(RemoteView::RemoteStatus status)
                toolbar->setEnabled(true);
 
                vnc_view->setZoomLevel(zoom_slider->value());
+               vnc_view->useFastTransformations(false);
                vnc_view->repaint();
                break;
        case RemoteView::Disconnecting:
@@ -367,6 +368,8 @@ void MainWindow::setZoomLevel(int level)
                scroll_area->ensureVisible(center.x(), center.y(),
                        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)));
@@ -380,4 +383,7 @@ void MainWindow::zoomSliderReleased()
                zoom_slider->setValue(95); //100%
        
        time.restart();
+
+       //stopped zooming, reenable high quality
+       vnc_view->useFastTransformations(false);
 }
index 6d01968..3275140 100644 (file)
@@ -72,7 +72,8 @@ VncView::VncView(QWidget *parent, const KUrl &url, RemoteView::Quality quality,
         m_verticalFactor(1.0),
         m_forceLocalCursor(false),
        quality(quality),
-       listen_port(listen_port)
+       listen_port(listen_port),
+       transformation_mode(Qt::FastTransformation)
 {
     m_url = url;
     m_host = url.host();
@@ -319,6 +320,8 @@ void VncView::updateImage(int x, int y, int w, int h)
            old_frame_size = m_frame.size();
         kDebug(5011) << "Updating framebuffer size";
                setZoomLevel();
+               useFastTransformations(false);
+
         emit framebufferSizeChanged(m_frame.width(), m_frame.height());
     }
 
@@ -395,10 +398,6 @@ void VncView::paintEvent(QPaintEvent *event)
 
     event->accept();
 
-       Qt::TransformationMode transformation_mode = Qt::SmoothTransformation;
-       if( m_horizontalFactor >= 1.0 )
-               transformation_mode = Qt::FastTransformation;
-
        const QRect update_rect = event->rect();
     QPainter painter(this);
        if (update_rect != rect()) {
@@ -409,12 +408,13 @@ void VncView::paintEvent(QPaintEvent *event)
                const int sh = qRound(update_rect.height()/m_verticalFactor);
 
                painter.drawImage(update_rect, 
-                                                 m_frame.copy(sx, sy, sw, sh).scaled(update_rect.size(), Qt::IgnoreAspectRatio, transformation_mode));
+                         m_frame.copy(sx, sy, sw, sh)
+                         .scaled(update_rect.size(), Qt::IgnoreAspectRatio, transformation_mode));
        } else {
                kDebug(5011) << "Full repaint" << width() << height() << m_frame.width() << m_frame.height();
 
                painter.drawImage(rect(),
-                                                 m_frame.scaled(size(), Qt::IgnoreAspectRatio, transformation_mode));
+                       m_frame.scaled(size(), Qt::IgnoreAspectRatio, transformation_mode));
     }
 
        //draw local cursor ourselves, normal mouse pointer doesn't deal with scrolling
@@ -860,5 +860,14 @@ void VncView::inputMethodEvent(QInputMethodEvent *event)
        }
 }
 
+void VncView::useFastTransformations(bool enabled)
+{
+       if(enabled or getZoomFactor() >= 1.0) {
+               transformation_mode = Qt::FastTransformation;
+       } else {
+               transformation_mode = Qt::SmoothTransformation;
+               update();
+       }
+}
 
 #include "moc_vncview.cpp"
index d707f31..1d146c1 100644 (file)
@@ -57,6 +57,7 @@ public:
     void setQuality(int q);
     void setViewOnly(bool viewOnly);
     void showDotCursor(DotCursorState state);
+    void useFastTransformations(bool enabled);
     
 public slots:
     void setZoomLevel(int level = -1); //'level' doesn't correspond to actual magnification, though mapping is done here
@@ -90,6 +91,7 @@ private:
     bool disable_tapping;
     RemoteView::Quality quality;
        int listen_port;
+       Qt::TransformationMode transformation_mode;
 
     void keyEventHandler(QKeyEvent *e);
     void unpressModifiers();