X-Git-Url: http://git.maemo.org/git/?a=blobdiff_plain;f=src%2Fvncview.cpp;h=ccbae253550b93864ed7ebc3093f6a2eb58fb553;hb=176eaefb1342526e63f64a672cd8d4ce46a9f35d;hp=62601609126c681d1e13d30c09570ad2e1c7475c;hpb=4287da4b82e418e6a327d9a64aa946041d8059f9;p=presencevnc diff --git a/src/vncview.cpp b/src/vncview.cpp index 6260160..ccbae25 100644 --- a/src/vncview.cpp +++ b/src/vncview.cpp @@ -53,9 +53,13 @@ critical(parent, caption, message) #define KMOD_Shift_L 0x10 //local cursor width/height in px, should be an odd number -const int cursor_size = 7; +const int CURSOR_SIZE = 7; -VncView::VncView(QWidget *parent, const KUrl &url, RemoteView::Quality quality) +const int TAP_PRESS_TIME = 180; +const int DOUBLE_TAP_UP_TIME = 500; + + +VncView::VncView(QWidget *parent, const KUrl &url, RemoteView::Quality quality, int listen_port) : RemoteView(parent), m_initDone(false), m_buttonMask(0), @@ -69,12 +73,14 @@ VncView::VncView(QWidget *parent, const KUrl &url, RemoteView::Quality quality) m_verticalFactor(1.0), m_forceLocalCursor(false), force_full_repaint(false), - quality(quality) + quality(quality), + listen_port(listen_port) { m_url = url; m_host = url.host(); m_port = url.port(); + //BlockingQueuedConnection can cause deadlocks when exiting, handled in startQuitting() connect(&vncThread, SIGNAL(imageUpdated(int, int, int, int)), this, SLOT(updateImage(int, int, int, int)), Qt::BlockingQueuedConnection); connect(&vncThread, SIGNAL(gotCut(const QString&)), this, SLOT(setCut(const QString&)), Qt::BlockingQueuedConnection); connect(&vncThread, SIGNAL(passwordRequest()), this, SLOT(requestPassword()), Qt::BlockingQueuedConnection); @@ -133,48 +139,28 @@ QSize VncView::minimumSizeHint() const return size(); } -void VncView::scaleResize(int w, int h) -{ - RemoteView::scaleResize(w, h); - - kDebug(5011) << "scaleResize(): " <width(), parentWidget()->height()); - else - scaleResize(width(), height()); - } + resize(width(), height()); m_initDone = true; @@ -354,16 +321,7 @@ if(x == 0 and y == 0) { if ((y == 0 && x == 0) && (m_frame.size() != old_frame_size)) { old_frame_size = m_frame.size(); kDebug(5011) << "Updating framebuffer size"; - if (m_scale) { - //setMaximumSize(QSize(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX)); - if (parentWidget()) - scaleResize(parentWidget()->width(), parentWidget()->height()); - } else { - kDebug(5011) << "Resizing: " << m_frame.width() << m_frame.height(); - resize(m_frame.width(), m_frame.height()); - //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()); - } + setZoomLevel(); emit framebufferSizeChanged(m_frame.width(), m_frame.height()); } @@ -391,57 +349,36 @@ void VncView::showDotCursor(DotCursorState state) setCursor(state == CursorOn ? localDotCursor() : Qt::BlankCursor); } -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] 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; + if(level == -1) { //handle resize + resize(m_frame.width()*m_horizontalFactor, m_frame.height()*m_verticalFactor); + return; + } - resize(m_frame.width(), m_frame.height()); + double magnification; + if(level == 100) { + magnification = 2.0; + } else if(level >= 90) { + magnification = 1.0; } 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; - } + const double min_horiz_magnification = double(parentWidget()->width())/m_frame.width(); + const double min_vert_magnification = double(parentWidget()->height())/m_frame.height(); + const double fit_screen_magnification = qMin(min_horiz_magnification, min_vert_magnification); - scaleResize(parentWidget()->width()*factor, parentWidget()->height()*factor); + //level=90 => magnification=1.0, level=0 => magnification=fit_screen_magnification + magnification = (level)/90.0*(1.0 - fit_screen_magnification) + fit_screen_magnification; } + + if(magnification < 0 //remote display smaller than local? + or magnification != magnification) //nan + magnification = 1.0; + + m_verticalFactor = m_horizontalFactor = magnification; + resize(m_frame.width()*magnification, m_frame.height()*magnification); } void VncView::setCut(const QString &text) @@ -465,13 +402,17 @@ void VncView::paintEvent(QPaintEvent *event) QPainter painter(this); + Qt::TransformationMode transformation_mode = Qt::SmoothTransformation; + if( m_horizontalFactor >= 1.0 ) + transformation_mode = Qt::FastTransformation; + if (m_repaint and !force_full_repaint) { // kDebug(5011) << "normal repaint"; painter.drawImage(QRect(qRound(m_x*m_horizontalFactor), qRound(m_y*m_verticalFactor), qRound(m_w*m_horizontalFactor), qRound(m_h*m_verticalFactor)), m_frame.copy(m_x, m_y, m_w, m_h).scaled(qRound(m_w*m_horizontalFactor), qRound(m_h*m_verticalFactor), - Qt::IgnoreAspectRatio, Qt::SmoothTransformation)); + Qt::IgnoreAspectRatio, transformation_mode)); } else { //kDebug(5011) << "resize repaint"; QRect rect = event->rect(); @@ -483,13 +424,13 @@ void VncView::paintEvent(QPaintEvent *event) const int sh = rect.height()/m_verticalFactor; painter.drawImage(rect, m_frame.copy(sx, sy, sw, sh).scaled(rect.width(), rect.height(), - Qt::IgnoreAspectRatio, Qt::SmoothTransformation)); + Qt::IgnoreAspectRatio, transformation_mode)); } else { kDebug(5011) << "Full repaint" << width() << height() << m_frame.width() << m_frame.height(); painter.drawImage(QRect(0, 0, width(), height()), m_frame.scaled(m_frame.width() * m_horizontalFactor, m_frame.height() * m_verticalFactor, - Qt::IgnoreAspectRatio, Qt::SmoothTransformation)); - force_full_repaint = false; + Qt::IgnoreAspectRatio, transformation_mode)); + force_full_repaint = false; } } @@ -499,7 +440,7 @@ void VncView::paintEvent(QPaintEvent *event) painter.setCompositionMode(QPainter::RasterOp_SourceXorDestination); #endif //rectangle size includes 1px pen width - painter.drawRect(cursor_x*m_horizontalFactor - cursor_size/2, cursor_y*m_verticalFactor - cursor_size/2, cursor_size-1, cursor_size-1); + painter.drawRect(cursor_x*m_horizontalFactor - CURSOR_SIZE/2, cursor_y*m_verticalFactor - CURSOR_SIZE/2, CURSOR_SIZE-1, CURSOR_SIZE-1); } RemoteView::paintEvent(event); @@ -508,8 +449,7 @@ void VncView::paintEvent(QPaintEvent *event) void VncView::resizeEvent(QResizeEvent *event) { RemoteView::resizeEvent(event); - scaleResize(event->size().width(), event->size().height()); - forceFullRepaint(); + update(); } bool VncView::event(QEvent *event) @@ -551,9 +491,6 @@ void VncView::mouseEventHandler(QMouseEvent *e) static QTime press_time; static QTime up_time; //used for double clicks/tap&drag, for time after first tap - const int TAP_PRESS_TIME = 180; - const int DOUBLE_TAP_UP_TIME = 500; - if(!e) { //flush held taps if(tap_detected) { m_buttonMask |= 0x01; @@ -633,9 +570,9 @@ void VncView::mouseEventHandler(QMouseEvent *e) if(((m_dotCursorState == CursorOn) || m_forceLocalCursor) and (cursor_x != old_cursor_x or cursor_y != old_cursor_y)) { //clear last position - repaint(old_cursor_x*m_horizontalFactor - cursor_size/2, old_cursor_y*m_verticalFactor - cursor_size/2, cursor_size, cursor_size); + repaint(old_cursor_x*m_horizontalFactor - CURSOR_SIZE/2, old_cursor_y*m_verticalFactor - CURSOR_SIZE/2, CURSOR_SIZE, CURSOR_SIZE); //and refresh new one - repaint(cursor_x*m_horizontalFactor - cursor_size/2, cursor_y*m_verticalFactor - cursor_size/2, cursor_size, cursor_size); + repaint(cursor_x*m_horizontalFactor - CURSOR_SIZE/2, cursor_y*m_verticalFactor - CURSOR_SIZE/2, CURSOR_SIZE, CURSOR_SIZE); old_cursor_x = cursor_x; old_cursor_y = cursor_y; } @@ -879,10 +816,12 @@ void VncView::sendKeySequence(QKeySequence keys) //to get at individual key presses, we split 'keys' into its components QList key_list; - for(int i = 0; ; i++) { - QString k = keys.toString().section('+', i, i); + int pos = 0; + while(true) { + QString k = keys.toString().section('+', pos, pos); if(k.isEmpty()) break; + //kDebug(5011) << "found key: " << k; if(k == "Alt") { key_list.append(Qt::Key_Alt); @@ -893,6 +832,8 @@ void VncView::sendKeySequence(QKeySequence keys) } else { key_list.append(QKeySequence(k)[0]); } + + pos++; } for(int i = 0; i < key_list.count(); i++) @@ -913,6 +854,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