X-Git-Url: http://git.maemo.org/git/?a=blobdiff_plain;f=src%2Fvncview.cpp;h=62601609126c681d1e13d30c09570ad2e1c7475c;hb=60b6d9c9322c44c7f76d45f339e73dd9ebcd00c6;hp=13834b2e1bf4ea226873b708f5f630dab76a9fde;hpb=6e5d8fe77e387c9c989466da77a914cf26620a54;p=presencevnc diff --git a/src/vncview.cpp b/src/vncview.cpp index 13834b2..6260160 100644 --- a/src/vncview.cpp +++ b/src/vncview.cpp @@ -30,6 +30,7 @@ critical(parent, caption, message) #include +#include #include #include #include @@ -51,6 +52,9 @@ critical(parent, caption, message) #define KMOD_Control_L 0x08 #define KMOD_Shift_L 0x10 +//local cursor width/height in px, should be an odd number +const int cursor_size = 7; + VncView::VncView(QWidget *parent, const KUrl &url, RemoteView::Quality quality) : RemoteView(parent), m_initDone(false), @@ -289,6 +293,8 @@ void VncView::updateImage(int x, int y, int w, int h) return; } //kDebug(5011) << "got update" << width() << height(); + + /* static unsigned int frames = 0; static unsigned int updates = 0; static QTime time = QTime::currentTime(); @@ -300,6 +306,7 @@ if(x == 0 and y == 0) { if(frames % 100 == 0) kDebug(5011) << "f/s: " << frames/double(time.elapsed()) * 1000.0; } +*/ m_x = x; m_y = y; @@ -394,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; @@ -405,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; @@ -454,6 +493,15 @@ void VncView::paintEvent(QPaintEvent *event) } } + //draw local cursor ourselves, normal mouse pointer doesn't deal with scrolling + if((m_dotCursorState == CursorOn) || m_forceLocalCursor) { +#if QT_VERSION >= 0x040500 + 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); + } + RemoteView::paintEvent(event); } @@ -532,60 +580,65 @@ void VncView::mouseEventHandler(QMouseEvent *e) cursor_y = qRound(e->y()/m_verticalFactor); vncThread.mouseEvent(cursor_x, cursor_y, m_buttonMask); // plain move event - if(disable_tapping) { //only move cursor - e->ignore(); - return; - } - - if(e->type() == QEvent::MouseButtonPress or e->type() == QEvent::MouseButtonDblClick) { - press_time.start(); - if(tap_detected and up_time.elapsed() < DOUBLE_TAP_UP_TIME) { - tap_detected = false; - double_tap_detected = true; + if(!disable_tapping and e->button() == Qt::LeftButton) { //implement touchpad-like input for left button + if(e->type() == QEvent::MouseButtonPress or e->type() == QEvent::MouseButtonDblClick) { + press_time.start(); + if(tap_detected and up_time.elapsed() < DOUBLE_TAP_UP_TIME) { + tap_detected = false; + double_tap_detected = true; + + QTimer::singleShot(TAP_PRESS_TIME, this, SLOT(mouseEventHandler())); + } + } else if(e->type() == QEvent::MouseButtonRelease) { + if(tap_drag_detected) { + m_buttonMask &= 0xfe; + vncThread.mouseEvent(cursor_x, cursor_y, m_buttonMask); + tap_drag_detected = false; + } else if(double_tap_detected) { //double click + double_tap_detected = false; + + m_buttonMask |= 0x01; + vncThread.mouseEvent(cursor_x, cursor_y, m_buttonMask); + m_buttonMask &= 0xfe; + vncThread.mouseEvent(cursor_x, cursor_y, m_buttonMask); + m_buttonMask |= 0x01; + vncThread.mouseEvent(cursor_x, cursor_y, m_buttonMask); + m_buttonMask &= 0xfe; + vncThread.mouseEvent(cursor_x, cursor_y, m_buttonMask); + } else if(press_time.elapsed() < TAP_PRESS_TIME) { //tap + up_time.start(); + tap_detected = true; + QTimer::singleShot(DOUBLE_TAP_UP_TIME, this, SLOT(mouseEventHandler())); + } - QTimer::singleShot(TAP_PRESS_TIME, this, SLOT(mouseEventHandler())); } - } else if(e->type() == QEvent::MouseButtonRelease) { - if(tap_drag_detected) { - m_buttonMask &= 0xfe; - vncThread.mouseEvent(cursor_x, cursor_y, m_buttonMask); - tap_drag_detected = false; - } else if(double_tap_detected) { //double click - double_tap_detected = false; - - m_buttonMask |= 0x01; - vncThread.mouseEvent(cursor_x, cursor_y, m_buttonMask); - m_buttonMask &= 0xfe; - vncThread.mouseEvent(cursor_x, cursor_y, m_buttonMask); - m_buttonMask |= 0x01; - vncThread.mouseEvent(cursor_x, cursor_y, m_buttonMask); - m_buttonMask &= 0xfe; - vncThread.mouseEvent(cursor_x, cursor_y, m_buttonMask); - } else if(press_time.elapsed() < TAP_PRESS_TIME) { //tap - up_time.start(); - tap_detected = true; - QTimer::singleShot(DOUBLE_TAP_UP_TIME, this, SLOT(mouseEventHandler())); + } else { //middle or right button, send directly + if ((e->type() == QEvent::MouseButtonPress)) { + if (e->button() & Qt::MidButton) + m_buttonMask |= 0x02; + if (e->button() & Qt::RightButton) + m_buttonMask |= 0x04; + } else if (e->type() == QEvent::MouseButtonRelease) { + if (e->button() & Qt::MidButton) + m_buttonMask &= 0xfd; + if (e->button() & Qt::RightButton) + m_buttonMask &= 0xfb; } - + vncThread.mouseEvent(cursor_x, cursor_y, m_buttonMask); } -/* for reference: - if (e->type() != QEvent::MouseMove) { - if ((e->type() == QEvent::MouseButtonPress)) { - if (e->button() & Qt::LeftButton) - m_buttonMask |= 0x01; - if (e->button() & Qt::MidButton) - m_buttonMask |= 0x02; - if (e->button() & Qt::RightButton) - m_buttonMask |= 0x04; - } else if (e->type() == QEvent::MouseButtonRelease) { - if (e->button() & Qt::LeftButton) - m_buttonMask &= 0xfe; - if (e->button() & Qt::MidButton) - m_buttonMask &= 0xfd; - if (e->button() & Qt::RightButton) - m_buttonMask &= 0xfb; - */ + //prevent local cursor artifacts + static int old_cursor_x = cursor_x; + static int old_cursor_y = cursor_y; + 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); + //and refresh new one + 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; + } } void VncView::wheelEventHandler(QWheelEvent *event) @@ -599,7 +652,6 @@ void VncView::wheelEventHandler(QWheelEvent *event) const int x = qRound(event->x() / m_horizontalFactor); const int y = qRound(event->y() / m_verticalFactor); - kDebug(5011) << "Wheelevent"; vncThread.mouseEvent(x, y, eb | m_buttonMask); vncThread.mouseEvent(x, y, m_buttonMask); } @@ -622,6 +674,16 @@ void VncView::keyEventHandler(QKeyEvent *e) const bool pressed = (e->type() == QEvent::KeyPress); +#ifdef Q_WS_MAEMO_5 + //don't send ISO_Level3_Shift (would break things like Win+0-9) + //also enable IM so symbol key works + if(k == 0xfe03) { + setAttribute(Qt::WA_InputMethodEnabled, pressed); + e->ignore(); + return; + } +#endif + // handle modifiers if (k == XK_Shift_L || k == XK_Control_L || k == XK_Meta_L || k == XK_Alt_L) { if (pressed) { @@ -697,8 +759,6 @@ void VncView::unpressModifiers() void VncView::clipboardSelectionChanged() { - kDebug(5011); - if (m_status != Connected) return; @@ -712,8 +772,6 @@ void VncView::clipboardSelectionChanged() void VncView::clipboardDataChanged() { - kDebug(5011); - if (m_status != Connected) return; @@ -775,6 +833,15 @@ void VncView::sendKey(Qt::Key key) case Qt::Key_F12: k = 0xffbe + int(key - Qt::Key_F1); break; + case Qt::Key_Pause: + k = 0xff13; + break; + case Qt::Key_Print: + k = 0xff61; + break; + case Qt::Key_Menu: + k = 0xff67; + break; case Qt::Key_Meta: case Qt::MetaModifier: k = XK_Super_L; @@ -816,7 +883,7 @@ void VncView::sendKeySequence(QKeySequence keys) QString k = keys.toString().section('+', i, i); if(k.isEmpty()) break; - kDebug(5011) << "found key: " << k; + //kDebug(5011) << "found key: " << k; if(k == "Alt") { key_list.append(Qt::Key_Alt); } else if(k == "Ctrl") { @@ -842,6 +909,10 @@ void VncView::reloadSettings() left_zoom = settings.value("left_zoom", 0).toInt(); right_zoom = settings.value("right_zoom", 1).toInt(); disable_tapping = settings.value("disable_tapping", false).toBool(); + + bool always_show_local_cursor = settings.value("always_show_local_cursor", false).toBool(); + if(always_show_local_cursor) + showDotCursor(CursorOn); } //convert commitString into keyevents