1 /****************************************************************************
3 ** Copyright (C) 2007-2008 Urs Wolfer <uwolfer @ kde.org>
5 ** This file is part of KDE.
7 ** This program is free software; you can redistribute it and/or modify
8 ** it under the terms of the GNU General Public License as published by
9 ** the Free Software Foundation; either version 2 of the License, or
10 ** (at your option) any later version.
12 ** This program is distributed in the hope that it will be useful,
13 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
14 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 ** GNU General Public License for more details.
17 ** You should have received a copy of the GNU General Public License
18 ** along with this program; see the file COPYING. If not, write to
19 ** the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 ** Boston, MA 02110-1301, USA.
22 ****************************************************************************/
26 #include <QMessageBox>
27 #include <QInputDialog>
28 #define KMessageBox QMessageBox
29 #define error(parent, message, caption) \
30 critical(parent, caption, message)
32 #include <QApplication>
37 #include <QHBoxLayout>
38 #include <QVBoxLayout>
40 #include <QMouseEvent>
41 #include <QPushButton>
48 // Definition of key modifier mask constants
49 #define KMOD_Alt_R 0x01
50 #define KMOD_Alt_L 0x02
51 #define KMOD_Meta_L 0x04
52 #define KMOD_Control_L 0x08
53 #define KMOD_Shift_L 0x10
55 //local cursor width/height in px, should be an odd number
56 const int cursor_size = 7;
58 VncView::VncView(QWidget *parent, const KUrl &url, RemoteView::Quality quality)
66 m_firstPasswordTry(true),
67 m_dontSendClipboard(false),
68 m_horizontalFactor(1.0),
69 m_verticalFactor(1.0),
70 m_forceLocalCursor(false),
71 force_full_repaint(false),
78 connect(&vncThread, SIGNAL(imageUpdated(int, int, int, int)), this, SLOT(updateImage(int, int, int, int)), Qt::BlockingQueuedConnection);
79 connect(&vncThread, SIGNAL(gotCut(const QString&)), this, SLOT(setCut(const QString&)), Qt::BlockingQueuedConnection);
80 connect(&vncThread, SIGNAL(passwordRequest()), this, SLOT(requestPassword()), Qt::BlockingQueuedConnection);
81 connect(&vncThread, SIGNAL(outputErrorMessage(QString)), this, SLOT(outputErrorMessage(QString)));
83 m_clipboard = QApplication::clipboard();
84 connect(m_clipboard, SIGNAL(selectionChanged()), this, SLOT(clipboardSelectionChanged()));
85 connect(m_clipboard, SIGNAL(dataChanged()), this, SLOT(clipboardDataChanged()));
94 // Disconnect all signals so that we don't get any more callbacks from the client thread
95 vncThread.disconnect();
100 void VncView::forceFullRepaint()
102 force_full_repaint = true;
106 bool VncView::eventFilter(QObject *obj, QEvent *event)
109 if (event->type() == QEvent::KeyPress ||
110 event->type() == QEvent::KeyRelease ||
111 event->type() == QEvent::MouseButtonDblClick ||
112 event->type() == QEvent::MouseButtonPress ||
113 event->type() == QEvent::MouseButtonRelease ||
114 event->type() == QEvent::Wheel ||
115 event->type() == QEvent::MouseMove)
118 return RemoteView::eventFilter(obj, event);
121 QSize VncView::framebufferSize()
123 return m_frame.size();
126 QSize VncView::sizeHint() const
131 QSize VncView::minimumSizeHint() const
136 void VncView::scaleResize(int w, int h)
138 RemoteView::scaleResize(w, h);
140 kDebug(5011) << "scaleResize(): " <<w << h;
142 m_verticalFactor = (qreal) h / m_frame.height();
143 m_horizontalFactor = (qreal) w / m_frame.width();
145 m_verticalFactor = m_horizontalFactor = qMin(m_verticalFactor, m_horizontalFactor);
147 const qreal newW = m_frame.width() * m_horizontalFactor;
148 const qreal newH = m_frame.height() * m_verticalFactor;
150 setMaximumSize(newW, newH); //This is a hack to force Qt to center the view in the scroll area
151 //also causes the widget's size to flicker
158 void VncView::startQuitting()
160 kDebug(5011) << "about to quit";
162 const bool connected = status() == RemoteView::Connected;
164 setStatus(Disconnecting);
174 const bool quitSuccess = vncThread.wait(500);
176 kDebug(5011) << "startQuitting(): Quit VNC thread success:" << quitSuccess;
178 setStatus(Disconnected);
181 bool VncView::isQuitting()
186 bool VncView::start()
188 vncThread.setHost(m_host);
189 vncThread.setPort(m_port);
191 vncThread.setQuality(quality);
193 // set local cursor on by default because low quality mostly means slow internet connection
194 if (quality == RemoteView::Low) {
195 showDotCursor(RemoteView::CursorOn);
198 setStatus(Connecting);
204 bool VncView::supportsScaling() const
209 bool VncView::supportsLocalCursor() const
214 void VncView::requestPassword()
216 kDebug(5011) << "request password";
218 setStatus(Authenticating);
220 if (!m_url.password().isNull()) {
221 vncThread.setPassword(m_url.password());
226 settings.beginGroup("hosts");
227 QString password = settings.value(QString("%1/password").arg(m_host), "").toString();
228 //check for saved password
229 if(m_firstPasswordTry and !password.isEmpty()) {
230 kDebug(5011) << "Trying saved password";
231 m_firstPasswordTry = false;
232 vncThread.setPassword(password);
235 m_firstPasswordTry = false;
238 QDialog dialog(this);
239 dialog.setWindowTitle(tr("Password required"));
241 QLineEdit passwordbox;
242 passwordbox.setEchoMode(QLineEdit::Password);
243 passwordbox.setText(password);
244 QCheckBox save_password(tr("Save Password"));
245 save_password.setChecked(!password.isEmpty()); //offer to overwrite saved password
246 QPushButton ok_button(tr("Done"));
247 ok_button.setMaximumWidth(100);
248 connect(&ok_button, SIGNAL(clicked()),
249 &dialog, SLOT(accept()));
253 layout2.addWidget(&passwordbox);
254 layout2.addWidget(&save_password);
255 layout1.addLayout(&layout2);
256 layout1.addWidget(&ok_button);
257 dialog.setLayout(&layout1);
259 if(dialog.exec()) { //dialog accepted
260 password = passwordbox.text();
262 if(save_password.isChecked()) {
263 kDebug(5011) << "Saving password for host '" << m_host << "'";
265 settings.setValue(QString("%1/password").arg(m_host), password);
269 vncThread.setPassword(password);
275 void VncView::outputErrorMessage(const QString &message)
277 kDebug(5011) << message;
279 if (message == "INTERNAL:APPLE_VNC_COMPATIBILTY") {
280 setCursor(localDotCursor());
281 m_forceLocalCursor = true;
287 emit errorMessage(i18n("VNC failure"), message);
290 void VncView::updateImage(int x, int y, int w, int h)
292 if(!QApplication::focusWidget()) { //no focus, we're probably minimized
295 //kDebug(5011) << "got update" << width() << height();
298 static unsigned int frames = 0;
299 static unsigned int updates = 0;
300 static QTime time = QTime::currentTime();
302 if(updates % 100 == 0)
303 kDebug(5011) << "u/s: " << updates/double(time.elapsed()) * 1000.0;
304 if(x == 0 and y == 0) {
306 if(frames % 100 == 0)
307 kDebug(5011) << "f/s: " << frames/double(time.elapsed()) * 1000.0;
317 //with scaled view, artefacts occur because of rounding errors
318 //we'll try to only update chunks of screen space that correspond to integer pixel sizes in m_frame
319 //put this into paintEvent
321 int frame_x = x/m_horizontalFactor;
322 int frame_w = w/m_horizontalFactor;
323 int frame_y = y/m_verticalFactor;
324 int frame_h = h/m_verticalFactor;
326 m_x = frame_x*m_horizontalFactor;
327 m_y = frame_y*m_verticalFactor;
329 m_w = (frame_w+2)*m_horizontalFactor;
330 m_h = (frame_h+2)*m_verticalFactor;
331 kDebug(5011)<< "update);
335 if (m_horizontalFactor != 1.0 || m_verticalFactor != 1.0) {
336 // If the view is scaled, grow the update rectangle to avoid artifacts
337 int x_extrapixels = 1.0/m_horizontalFactor + 1;
338 int y_extrapixels = 1.0/m_verticalFactor + 1;
342 m_w+=2*x_extrapixels;
343 m_h+=2*y_extrapixels;
346 m_frame = vncThread.image();
349 setAttribute(Qt::WA_StaticContents);
350 setAttribute(Qt::WA_OpaquePaintEvent);
351 installEventFilter(this);
353 setCursor(((m_dotCursorState == CursorOn) || m_forceLocalCursor) ? localDotCursor() : Qt::BlankCursor);
355 setMouseTracking(true); // get mouse events even when there is no mousebutton pressed
356 setFocusPolicy(Qt::WheelFocus);
357 setStatus(Connected);
358 // emit framebufferSizeChanged(m_frame.width(), m_frame.height());
363 scaleResize(parentWidget()->width(), parentWidget()->height());
365 scaleResize(width(), height());
372 static QSize old_frame_size = QSize();
373 if ((y == 0 && x == 0) && (m_frame.size() != old_frame_size)) {
374 old_frame_size = m_frame.size();
375 kDebug(5011) << "Updating framebuffer size";
377 //setMaximumSize(QSize(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX));
379 scaleResize(parentWidget()->width(), parentWidget()->height());
381 kDebug(5011) << "Resizing: " << m_frame.width() << m_frame.height();
382 resize(m_frame.width(), m_frame.height());
383 //setMaximumSize(m_frame.width(), m_frame.height()); //This is a hack to force Qt to center the view in the scroll area
384 //setMinimumSize(m_frame.width(), m_frame.height());
386 emit framebufferSizeChanged(m_frame.width(), m_frame.height());
390 repaint(qRound(m_x * m_horizontalFactor), qRound(m_y * m_verticalFactor), qRound(m_w * m_horizontalFactor), qRound(m_h * m_verticalFactor));
394 void VncView::setViewOnly(bool viewOnly)
396 RemoteView::setViewOnly(viewOnly);
398 m_dontSendClipboard = viewOnly;
401 setCursor(Qt::ArrowCursor);
403 setCursor(m_dotCursorState == CursorOn ? localDotCursor() : Qt::BlankCursor);
406 void VncView::showDotCursor(DotCursorState state)
408 RemoteView::showDotCursor(state);
410 setCursor(state == CursorOn ? localDotCursor() : Qt::BlankCursor);
413 void VncView::enableScaling(bool scale)
415 RemoteView::enableScaling(scale);
418 //level should be in [0, 100]
419 void VncView::setZoomLevel(int level)
421 Q_ASSERT(parentWidget() != 0);
424 double factor; //actual magnification
427 } else if(level > 90) {
430 const double min_horiz_factor = double(parentWidget()->width())/m_frame.width();
431 const double min_vert_factor = double(parentWidget()->height())/m_frame.height();
432 const double fit_screen_factor = qMin(min_horiz_factor, min_vert_factor);
434 //level=900 => factor=1.0, level=0 => factor=fit_screen_factor
435 factor = (level)/90.0*(1.0 - fit_screen_factor) + fit_screen_factor;
439 //remote display smaller than local?
440 kDebug(5011) << "remote display smaller than local?";
444 m_verticalFactor = m_horizontalFactor = factor;
445 resize(m_frame.width()*factor, m_frame.height()*factor);
448 void VncView::setCut(const QString &text)
450 m_dontSendClipboard = true;
451 m_clipboard->setText(text, QClipboard::Clipboard);
452 m_clipboard->setText(text, QClipboard::Selection);
453 m_dontSendClipboard = false;
456 void VncView::paintEvent(QPaintEvent *event)
458 //kDebug(5011) << "paint event: x: " << m_x << ", y: " << m_y << ", w: " << m_w << ", h: " << m_h;
459 if (m_frame.isNull() || m_frame.format() == QImage::Format_Invalid) {
460 kDebug(5011) << "no valid image to paint";
461 RemoteView::paintEvent(event);
467 QPainter painter(this);
469 Qt::TransformationMode transformation_mode = Qt::SmoothTransformation;
470 if( m_horizontalFactor >= 1.0 )
471 transformation_mode = Qt::FastTransformation;
473 if (m_repaint and !force_full_repaint) {
474 // kDebug(5011) << "normal repaint";
475 painter.drawImage(QRect(qRound(m_x*m_horizontalFactor), qRound(m_y*m_verticalFactor),
476 qRound(m_w*m_horizontalFactor), qRound(m_h*m_verticalFactor)),
477 m_frame.copy(m_x, m_y, m_w, m_h).scaled(qRound(m_w*m_horizontalFactor),
478 qRound(m_h*m_verticalFactor),
479 Qt::IgnoreAspectRatio, transformation_mode));
481 //kDebug(5011) << "resize repaint";
482 QRect rect = event->rect();
483 if (!force_full_repaint and (rect.width() != width() || rect.height() != height())) {
484 // kDebug(5011) << "Partial repaint";
485 const int sx = rect.x()/m_horizontalFactor;
486 const int sy = rect.y()/m_verticalFactor;
487 const int sw = rect.width()/m_horizontalFactor;
488 const int sh = rect.height()/m_verticalFactor;
489 painter.drawImage(rect,
490 m_frame.copy(sx, sy, sw, sh).scaled(rect.width(), rect.height(),
491 Qt::IgnoreAspectRatio, transformation_mode));
493 kDebug(5011) << "Full repaint" << width() << height() << m_frame.width() << m_frame.height();
494 painter.drawImage(QRect(0, 0, width(), height()),
495 m_frame.scaled(m_frame.width() * m_horizontalFactor, m_frame.height() * m_verticalFactor,
496 Qt::IgnoreAspectRatio, transformation_mode));
497 force_full_repaint = false;
501 //draw local cursor ourselves, normal mouse pointer doesn't deal with scrolling
502 if((m_dotCursorState == CursorOn) || m_forceLocalCursor) {
503 #if QT_VERSION >= 0x040500
504 painter.setCompositionMode(QPainter::RasterOp_SourceXorDestination);
506 //rectangle size includes 1px pen width
507 painter.drawRect(cursor_x*m_horizontalFactor - cursor_size/2, cursor_y*m_verticalFactor - cursor_size/2, cursor_size-1, cursor_size-1);
510 RemoteView::paintEvent(event);
513 void VncView::resizeEvent(QResizeEvent *event)
515 RemoteView::resizeEvent(event);
517 scaleResize(event->size().width(), event->size().height());
522 bool VncView::event(QEvent *event)
524 switch (event->type()) {
525 case QEvent::KeyPress:
526 case QEvent::KeyRelease:
527 // kDebug(5011) << "keyEvent";
528 keyEventHandler(static_cast<QKeyEvent*>(event));
531 case QEvent::MouseButtonDblClick:
532 case QEvent::MouseButtonPress:
533 case QEvent::MouseButtonRelease:
534 case QEvent::MouseMove:
535 // kDebug(5011) << "mouseEvent";
536 mouseEventHandler(static_cast<QMouseEvent*>(event));
540 // kDebug(5011) << "wheelEvent";
541 wheelEventHandler(static_cast<QWheelEvent*>(event));
544 case QEvent::WindowActivate: //input panel may have been closed, prevent IM from interfering with hardware keyboard
545 setAttribute(Qt::WA_InputMethodEnabled, false);
548 return RemoteView::event(event);
552 //call with e == 0 to flush held events
553 void VncView::mouseEventHandler(QMouseEvent *e)
555 static bool tap_detected = false;
556 static bool double_tap_detected = false;
557 static bool tap_drag_detected = false;
558 static QTime press_time;
559 static QTime up_time; //used for double clicks/tap&drag, for time after first tap
561 const int TAP_PRESS_TIME = 180;
562 const int DOUBLE_TAP_UP_TIME = 500;
564 if(!e) { //flush held taps
566 m_buttonMask |= 0x01;
567 vncThread.mouseEvent(cursor_x, cursor_y, m_buttonMask);
568 m_buttonMask &= 0xfe;
569 vncThread.mouseEvent(cursor_x, cursor_y, m_buttonMask);
570 tap_detected = false;
571 } else if(double_tap_detected and press_time.elapsed() > TAP_PRESS_TIME) { //got tap + another press -> tap & drag
572 m_buttonMask |= 0x01;
573 vncThread.mouseEvent(cursor_x, cursor_y, m_buttonMask);
574 double_tap_detected = false;
575 tap_drag_detected = true;
581 if(e->x() < 0 or e->y() < 0) { //QScrollArea tends to send invalid events sometimes...
586 cursor_x = qRound(e->x()/m_horizontalFactor);
587 cursor_y = qRound(e->y()/m_verticalFactor);
588 vncThread.mouseEvent(cursor_x, cursor_y, m_buttonMask); // plain move event
590 if(!disable_tapping and e->button() == Qt::LeftButton) { //implement touchpad-like input for left button
591 if(e->type() == QEvent::MouseButtonPress or e->type() == QEvent::MouseButtonDblClick) {
593 if(tap_detected and up_time.elapsed() < DOUBLE_TAP_UP_TIME) {
594 tap_detected = false;
595 double_tap_detected = true;
597 QTimer::singleShot(TAP_PRESS_TIME, this, SLOT(mouseEventHandler()));
599 } else if(e->type() == QEvent::MouseButtonRelease) {
600 if(tap_drag_detected) {
601 m_buttonMask &= 0xfe;
602 vncThread.mouseEvent(cursor_x, cursor_y, m_buttonMask);
603 tap_drag_detected = false;
604 } else if(double_tap_detected) { //double click
605 double_tap_detected = false;
607 m_buttonMask |= 0x01;
608 vncThread.mouseEvent(cursor_x, cursor_y, m_buttonMask);
609 m_buttonMask &= 0xfe;
610 vncThread.mouseEvent(cursor_x, cursor_y, m_buttonMask);
611 m_buttonMask |= 0x01;
612 vncThread.mouseEvent(cursor_x, cursor_y, m_buttonMask);
613 m_buttonMask &= 0xfe;
614 vncThread.mouseEvent(cursor_x, cursor_y, m_buttonMask);
615 } else if(press_time.elapsed() < TAP_PRESS_TIME) { //tap
618 QTimer::singleShot(DOUBLE_TAP_UP_TIME, this, SLOT(mouseEventHandler()));
622 } else { //middle or right button, send directly
623 if ((e->type() == QEvent::MouseButtonPress)) {
624 if (e->button() & Qt::MidButton)
625 m_buttonMask |= 0x02;
626 if (e->button() & Qt::RightButton)
627 m_buttonMask |= 0x04;
628 } else if (e->type() == QEvent::MouseButtonRelease) {
629 if (e->button() & Qt::MidButton)
630 m_buttonMask &= 0xfd;
631 if (e->button() & Qt::RightButton)
632 m_buttonMask &= 0xfb;
634 vncThread.mouseEvent(cursor_x, cursor_y, m_buttonMask);
637 //prevent local cursor artifacts
638 static int old_cursor_x = cursor_x;
639 static int old_cursor_y = cursor_y;
640 if(((m_dotCursorState == CursorOn) || m_forceLocalCursor)
641 and (cursor_x != old_cursor_x or cursor_y != old_cursor_y)) {
642 //clear last position
643 repaint(old_cursor_x*m_horizontalFactor - cursor_size/2, old_cursor_y*m_verticalFactor - cursor_size/2, cursor_size, cursor_size);
644 //and refresh new one
645 repaint(cursor_x*m_horizontalFactor - cursor_size/2, cursor_y*m_verticalFactor - cursor_size/2, cursor_size, cursor_size);
647 old_cursor_x = cursor_x; old_cursor_y = cursor_y;
651 void VncView::wheelEventHandler(QWheelEvent *event)
654 if (event->delta() < 0)
659 const int x = qRound(event->x() / m_horizontalFactor);
660 const int y = qRound(event->y() / m_verticalFactor);
662 vncThread.mouseEvent(x, y, eb | m_buttonMask);
663 vncThread.mouseEvent(x, y, m_buttonMask);
666 void VncView::keyEventHandler(QKeyEvent *e)
668 // strip away autorepeating KeyRelease; see bug #206598
669 if (e->isAutoRepeat() && (e->type() == QEvent::KeyRelease)) {
673 // parts of this code are based on http://italc.sourcearchive.com/documentation/1.0.9.1/vncview_8cpp-source.html
674 rfbKeySym k = e->nativeVirtualKey();
676 // we do not handle Key_Backtab separately as the Shift-modifier
677 // is already enabled
678 if (e->key() == Qt::Key_Backtab) {
682 const bool pressed = (e->type() == QEvent::KeyPress);
685 //don't send ISO_Level3_Shift (would break things like Win+0-9)
686 //also enable IM so symbol key works
688 setAttribute(Qt::WA_InputMethodEnabled, pressed);
695 if (k == XK_Shift_L || k == XK_Control_L || k == XK_Meta_L || k == XK_Alt_L) {
698 } else if (m_mods.contains(k)) {
706 int current_zoom = -1;
707 if(e->key() == Qt::Key_F8)
708 current_zoom = left_zoom;
709 else if(e->key() == Qt::Key_F7)
710 current_zoom = right_zoom;
712 // kDebug(5011) << "got '" << e->text() << "'.";
713 vncThread.keyEvent(k, pressed);
715 kDebug(5011) << "nativeVirtualKey() for '" << e->text() << "' failed.";
719 if(current_zoom == -1)
722 //handle zoom buttons
723 if(current_zoom == 0) { //left click
725 m_buttonMask |= 0x01;
727 m_buttonMask &= 0xfe;
728 vncThread.mouseEvent(cursor_x, cursor_y, m_buttonMask);
729 } else if(current_zoom == 1) { //right click
731 m_buttonMask |= 0x04;
733 m_buttonMask &= 0xfb;
734 vncThread.mouseEvent(cursor_x, cursor_y, m_buttonMask);
735 } else if(current_zoom == 2) { //middle click
737 m_buttonMask |= 0x02;
739 m_buttonMask &= 0xfd;
740 vncThread.mouseEvent(cursor_x, cursor_y, m_buttonMask);
741 } else if(current_zoom == 3 and pressed) { //wheel up
743 vncThread.mouseEvent(cursor_x, cursor_y, eb | m_buttonMask);
744 vncThread.mouseEvent(cursor_x, cursor_y, m_buttonMask);
745 } else if(current_zoom == 4 and pressed) { //wheel down
747 vncThread.mouseEvent(cursor_x, cursor_y, eb | m_buttonMask);
748 vncThread.mouseEvent(cursor_x, cursor_y, m_buttonMask);
749 } else if(current_zoom == 5) { //page up
750 vncThread.keyEvent(0xff55, pressed);
751 } else if(current_zoom == 6) { //page down
752 vncThread.keyEvent(0xff56, pressed);
756 void VncView::unpressModifiers()
758 const QList<unsigned int> keys = m_mods.keys();
759 QList<unsigned int>::const_iterator it = keys.constBegin();
760 while (it != keys.end()) {
761 vncThread.keyEvent(*it, false);
767 void VncView::clipboardSelectionChanged()
769 if (m_status != Connected)
772 if (m_clipboard->ownsSelection() || m_dontSendClipboard)
775 const QString text = m_clipboard->text(QClipboard::Selection);
777 vncThread.clientCut(text);
780 void VncView::clipboardDataChanged()
782 if (m_status != Connected)
785 if (m_clipboard->ownsClipboard() || m_dontSendClipboard)
788 const QString text = m_clipboard->text(QClipboard::Clipboard);
790 vncThread.clientCut(text);
794 void VncView::sendKey(Qt::Key key)
796 //convert Qt::Key into x11 keysym
808 case Qt::Key_PageDown:
826 case Qt::Key_Backspace:
841 k = 0xffbe + int(key - Qt::Key_F1);
853 case Qt::MetaModifier:
857 case Qt::AltModifier:
860 case Qt::Key_Control:
861 case Qt::ControlModifier:
865 kDebug(5011) << "sendKey(): Unhandled Qt::Key value " << key;
869 if (k == XK_Shift_L || k == XK_Control_L || k == XK_Meta_L || k == XK_Alt_L || k == XK_Super_L) {
870 if (m_mods.contains(k)) { //release
872 vncThread.keyEvent(k, false);
875 vncThread.keyEvent(k, true);
877 } else { //normal key
878 vncThread.keyEvent(k, true);
879 vncThread.keyEvent(k, false);
883 void VncView::sendKeySequence(QKeySequence keys)
885 Q_ASSERT(keys.count() <= 1); //we can only handle a single combination
887 //to get at individual key presses, we split 'keys' into its components
889 for(int i = 0; ; i++) {
890 QString k = keys.toString().section('+', i, i);
893 //kDebug(5011) << "found key: " << k;
895 key_list.append(Qt::Key_Alt);
896 } else if(k == "Ctrl") {
897 key_list.append(Qt::Key_Control);
898 } else if(k == "Meta") {
899 key_list.append(Qt::Key_Meta);
901 key_list.append(QKeySequence(k)[0]);
905 for(int i = 0; i < key_list.count(); i++)
906 sendKey(Qt::Key(key_list.at(i)));
908 //release modifiers (everything before final key)
909 for(int i = key_list.count()-2; i >= 0; i--)
910 sendKey(Qt::Key(key_list.at(i)));
913 void VncView::reloadSettings()
916 left_zoom = settings.value("left_zoom", 0).toInt();
917 right_zoom = settings.value("right_zoom", 1).toInt();
918 disable_tapping = settings.value("disable_tapping", false).toBool();
920 bool always_show_local_cursor = settings.value("always_show_local_cursor", false).toBool();
921 if(always_show_local_cursor)
922 showDotCursor(CursorOn);
927 //convert commitString into keyevents
928 void VncView::inputMethodEvent(QInputMethodEvent *event)
930 //TODO handle replacements
931 //NOTE for the return key to work Qt needs to enable multiline input, which only works for Q(Plain)TextEdit
933 //kDebug(5011) << event->commitString() << "|" << event->preeditString() << "|" << event->replacementLength() << "|" << event->replacementStart();
934 QString letters = event->commitString();
935 for(int i = 0; i < letters.length(); i++) {
936 char k = letters.at(i).toLatin1(); //works with all 'normal' keys, not umlauts.
938 kDebug(5011) << "unhandled key";
941 vncThread.keyEvent(k, true);
942 vncThread.keyEvent(k, false);
947 #include "moc_vncview.cpp"