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);
169 kDebug(5011) << "stopping vncThread";
175 const bool quitSuccess = vncThread.wait(700);
177 kDebug(5011) << "startQuitting(): Quit VNC thread success:" << quitSuccess;
179 setStatus(Disconnected);
182 bool VncView::isQuitting()
187 bool VncView::start()
189 vncThread.setHost(m_host);
190 vncThread.setPort(m_port);
192 vncThread.setQuality(quality);
194 // set local cursor on by default because low quality mostly means slow internet connection
195 if (quality == RemoteView::Low) {
196 showDotCursor(RemoteView::CursorOn);
199 setStatus(Connecting);
205 bool VncView::supportsScaling() const
210 bool VncView::supportsLocalCursor() const
215 void VncView::requestPassword()
217 kDebug(5011) << "request password";
219 setStatus(Authenticating);
221 if (!m_url.password().isNull()) {
222 vncThread.setPassword(m_url.password());
227 settings.beginGroup("hosts");
228 QString password = settings.value(QString("%1/password").arg(m_host), "").toString();
229 //check for saved password
230 if(m_firstPasswordTry and !password.isEmpty()) {
231 kDebug(5011) << "Trying saved password";
232 m_firstPasswordTry = false;
233 vncThread.setPassword(password);
236 m_firstPasswordTry = false;
239 QDialog dialog(this);
240 dialog.setWindowTitle(tr("Password required"));
242 QLineEdit passwordbox;
243 passwordbox.setEchoMode(QLineEdit::Password);
244 passwordbox.setText(password);
245 QCheckBox save_password(tr("Save Password"));
246 save_password.setChecked(!password.isEmpty()); //offer to overwrite saved password
247 QPushButton ok_button(tr("Done"));
248 ok_button.setMaximumWidth(100);
249 connect(&ok_button, SIGNAL(clicked()),
250 &dialog, SLOT(accept()));
254 layout2.addWidget(&passwordbox);
255 layout2.addWidget(&save_password);
256 layout1.addLayout(&layout2);
257 layout1.addWidget(&ok_button);
258 dialog.setLayout(&layout1);
260 if(dialog.exec()) { //dialog accepted
261 password = passwordbox.text();
263 if(save_password.isChecked()) {
264 kDebug(5011) << "Saving password for host '" << m_host << "'";
266 settings.setValue(QString("%1/password").arg(m_host), password);
270 vncThread.setPassword(password);
276 void VncView::outputErrorMessage(const QString &message)
278 kDebug(5011) << message;
280 if (message == "INTERNAL:APPLE_VNC_COMPATIBILTY") {
281 setCursor(localDotCursor());
282 m_forceLocalCursor = true;
288 emit errorMessage(i18n("VNC failure"), message);
291 void VncView::updateImage(int x, int y, int w, int h)
293 if(!QApplication::focusWidget()) { //no focus, we're probably minimized
296 //kDebug(5011) << "got update" << width() << height();
299 static unsigned int frames = 0;
300 static unsigned int updates = 0;
301 static QTime time = QTime::currentTime();
303 if(updates % 100 == 0)
304 kDebug(5011) << "u/s: " << updates/double(time.elapsed()) * 1000.0;
305 if(x == 0 and y == 0) {
307 if(frames % 100 == 0)
308 kDebug(5011) << "f/s: " << frames/double(time.elapsed()) * 1000.0;
318 //with scaled view, artefacts occur because of rounding errors
319 //we'll try to only update chunks of screen space that correspond to integer pixel sizes in m_frame
320 //put this into paintEvent
322 int frame_x = x/m_horizontalFactor;
323 int frame_w = w/m_horizontalFactor;
324 int frame_y = y/m_verticalFactor;
325 int frame_h = h/m_verticalFactor;
327 m_x = frame_x*m_horizontalFactor;
328 m_y = frame_y*m_verticalFactor;
330 m_w = (frame_w+2)*m_horizontalFactor;
331 m_h = (frame_h+2)*m_verticalFactor;
332 kDebug(5011)<< "update);
336 if (m_horizontalFactor != 1.0 || m_verticalFactor != 1.0) {
337 // If the view is scaled, grow the update rectangle to avoid artifacts
338 int x_extrapixels = 1.0/m_horizontalFactor + 1;
339 int y_extrapixels = 1.0/m_verticalFactor + 1;
343 m_w+=2*x_extrapixels;
344 m_h+=2*y_extrapixels;
347 m_frame = vncThread.image();
350 setAttribute(Qt::WA_StaticContents);
351 setAttribute(Qt::WA_OpaquePaintEvent);
352 installEventFilter(this);
354 setCursor(((m_dotCursorState == CursorOn) || m_forceLocalCursor) ? localDotCursor() : Qt::BlankCursor);
356 setMouseTracking(true); // get mouse events even when there is no mousebutton pressed
357 setFocusPolicy(Qt::WheelFocus);
358 setStatus(Connected);
359 // emit framebufferSizeChanged(m_frame.width(), m_frame.height());
364 scaleResize(parentWidget()->width(), parentWidget()->height());
366 scaleResize(width(), height());
373 static QSize old_frame_size = QSize();
374 if ((y == 0 && x == 0) && (m_frame.size() != old_frame_size)) {
375 old_frame_size = m_frame.size();
376 kDebug(5011) << "Updating framebuffer size";
378 //setMaximumSize(QSize(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX));
380 scaleResize(parentWidget()->width(), parentWidget()->height());
382 kDebug(5011) << "Resizing: " << m_frame.width() << m_frame.height();
383 resize(m_frame.width(), m_frame.height());
384 //setMaximumSize(m_frame.width(), m_frame.height()); //This is a hack to force Qt to center the view in the scroll area
385 //setMinimumSize(m_frame.width(), m_frame.height());
387 emit framebufferSizeChanged(m_frame.width(), m_frame.height());
391 repaint(qRound(m_x * m_horizontalFactor), qRound(m_y * m_verticalFactor), qRound(m_w * m_horizontalFactor), qRound(m_h * m_verticalFactor));
395 void VncView::setViewOnly(bool viewOnly)
397 RemoteView::setViewOnly(viewOnly);
399 m_dontSendClipboard = viewOnly;
402 setCursor(Qt::ArrowCursor);
404 setCursor(m_dotCursorState == CursorOn ? localDotCursor() : Qt::BlankCursor);
407 void VncView::showDotCursor(DotCursorState state)
409 RemoteView::showDotCursor(state);
411 setCursor(state == CursorOn ? localDotCursor() : Qt::BlankCursor);
414 void VncView::enableScaling(bool scale)
416 RemoteView::enableScaling(scale);
419 //level should be in [0, 100]
420 void VncView::setZoomLevel(int level)
422 Q_ASSERT(parentWidget() != 0);
425 double factor; //actual magnification
428 } else if(level > 90) {
431 const double min_horiz_factor = double(parentWidget()->width())/m_frame.width();
432 const double min_vert_factor = double(parentWidget()->height())/m_frame.height();
433 const double fit_screen_factor = qMin(min_horiz_factor, min_vert_factor);
435 //level=900 => factor=1.0, level=0 => factor=fit_screen_factor
436 factor = (level)/90.0*(1.0 - fit_screen_factor) + fit_screen_factor;
440 //remote display smaller than local?
441 kDebug(5011) << "remote display smaller than local?";
445 m_verticalFactor = m_horizontalFactor = factor;
446 resize(m_frame.width()*factor, m_frame.height()*factor);
449 void VncView::setCut(const QString &text)
451 m_dontSendClipboard = true;
452 m_clipboard->setText(text, QClipboard::Clipboard);
453 m_clipboard->setText(text, QClipboard::Selection);
454 m_dontSendClipboard = false;
457 void VncView::paintEvent(QPaintEvent *event)
459 //kDebug(5011) << "paint event: x: " << m_x << ", y: " << m_y << ", w: " << m_w << ", h: " << m_h;
460 if (m_frame.isNull() || m_frame.format() == QImage::Format_Invalid) {
461 kDebug(5011) << "no valid image to paint";
462 RemoteView::paintEvent(event);
468 QPainter painter(this);
470 Qt::TransformationMode transformation_mode = Qt::SmoothTransformation;
471 if( m_horizontalFactor >= 1.0 )
472 transformation_mode = Qt::FastTransformation;
474 if (m_repaint and !force_full_repaint) {
475 // kDebug(5011) << "normal repaint";
476 painter.drawImage(QRect(qRound(m_x*m_horizontalFactor), qRound(m_y*m_verticalFactor),
477 qRound(m_w*m_horizontalFactor), qRound(m_h*m_verticalFactor)),
478 m_frame.copy(m_x, m_y, m_w, m_h).scaled(qRound(m_w*m_horizontalFactor),
479 qRound(m_h*m_verticalFactor),
480 Qt::IgnoreAspectRatio, transformation_mode));
482 //kDebug(5011) << "resize repaint";
483 QRect rect = event->rect();
484 if (!force_full_repaint and (rect.width() != width() || rect.height() != height())) {
485 // kDebug(5011) << "Partial repaint";
486 const int sx = rect.x()/m_horizontalFactor;
487 const int sy = rect.y()/m_verticalFactor;
488 const int sw = rect.width()/m_horizontalFactor;
489 const int sh = rect.height()/m_verticalFactor;
490 painter.drawImage(rect,
491 m_frame.copy(sx, sy, sw, sh).scaled(rect.width(), rect.height(),
492 Qt::IgnoreAspectRatio, transformation_mode));
494 kDebug(5011) << "Full repaint" << width() << height() << m_frame.width() << m_frame.height();
495 painter.drawImage(QRect(0, 0, width(), height()),
496 m_frame.scaled(m_frame.width() * m_horizontalFactor, m_frame.height() * m_verticalFactor,
497 Qt::IgnoreAspectRatio, transformation_mode));
498 force_full_repaint = false;
502 //draw local cursor ourselves, normal mouse pointer doesn't deal with scrolling
503 if((m_dotCursorState == CursorOn) || m_forceLocalCursor) {
504 #if QT_VERSION >= 0x040500
505 painter.setCompositionMode(QPainter::RasterOp_SourceXorDestination);
507 //rectangle size includes 1px pen width
508 painter.drawRect(cursor_x*m_horizontalFactor - cursor_size/2, cursor_y*m_verticalFactor - cursor_size/2, cursor_size-1, cursor_size-1);
511 RemoteView::paintEvent(event);
514 void VncView::resizeEvent(QResizeEvent *event)
516 RemoteView::resizeEvent(event);
518 scaleResize(event->size().width(), event->size().height());
523 bool VncView::event(QEvent *event)
525 switch (event->type()) {
526 case QEvent::KeyPress:
527 case QEvent::KeyRelease:
528 // kDebug(5011) << "keyEvent";
529 keyEventHandler(static_cast<QKeyEvent*>(event));
532 case QEvent::MouseButtonDblClick:
533 case QEvent::MouseButtonPress:
534 case QEvent::MouseButtonRelease:
535 case QEvent::MouseMove:
536 // kDebug(5011) << "mouseEvent";
537 mouseEventHandler(static_cast<QMouseEvent*>(event));
541 // kDebug(5011) << "wheelEvent";
542 wheelEventHandler(static_cast<QWheelEvent*>(event));
545 case QEvent::WindowActivate: //input panel may have been closed, prevent IM from interfering with hardware keyboard
546 setAttribute(Qt::WA_InputMethodEnabled, false);
549 return RemoteView::event(event);
553 //call with e == 0 to flush held events
554 void VncView::mouseEventHandler(QMouseEvent *e)
556 static bool tap_detected = false;
557 static bool double_tap_detected = false;
558 static bool tap_drag_detected = false;
559 static QTime press_time;
560 static QTime up_time; //used for double clicks/tap&drag, for time after first tap
562 const int TAP_PRESS_TIME = 180;
563 const int DOUBLE_TAP_UP_TIME = 500;
565 if(!e) { //flush held taps
567 m_buttonMask |= 0x01;
568 vncThread.mouseEvent(cursor_x, cursor_y, m_buttonMask);
569 m_buttonMask &= 0xfe;
570 vncThread.mouseEvent(cursor_x, cursor_y, m_buttonMask);
571 tap_detected = false;
572 } else if(double_tap_detected and press_time.elapsed() > TAP_PRESS_TIME) { //got tap + another press -> tap & drag
573 m_buttonMask |= 0x01;
574 vncThread.mouseEvent(cursor_x, cursor_y, m_buttonMask);
575 double_tap_detected = false;
576 tap_drag_detected = true;
582 if(e->x() < 0 or e->y() < 0) { //QScrollArea tends to send invalid events sometimes...
587 cursor_x = qRound(e->x()/m_horizontalFactor);
588 cursor_y = qRound(e->y()/m_verticalFactor);
589 vncThread.mouseEvent(cursor_x, cursor_y, m_buttonMask); // plain move event
591 if(!disable_tapping and e->button() == Qt::LeftButton) { //implement touchpad-like input for left button
592 if(e->type() == QEvent::MouseButtonPress or e->type() == QEvent::MouseButtonDblClick) {
594 if(tap_detected and up_time.elapsed() < DOUBLE_TAP_UP_TIME) {
595 tap_detected = false;
596 double_tap_detected = true;
598 QTimer::singleShot(TAP_PRESS_TIME, this, SLOT(mouseEventHandler()));
600 } else if(e->type() == QEvent::MouseButtonRelease) {
601 if(tap_drag_detected) {
602 m_buttonMask &= 0xfe;
603 vncThread.mouseEvent(cursor_x, cursor_y, m_buttonMask);
604 tap_drag_detected = false;
605 } else if(double_tap_detected) { //double click
606 double_tap_detected = false;
608 m_buttonMask |= 0x01;
609 vncThread.mouseEvent(cursor_x, cursor_y, m_buttonMask);
610 m_buttonMask &= 0xfe;
611 vncThread.mouseEvent(cursor_x, cursor_y, m_buttonMask);
612 m_buttonMask |= 0x01;
613 vncThread.mouseEvent(cursor_x, cursor_y, m_buttonMask);
614 m_buttonMask &= 0xfe;
615 vncThread.mouseEvent(cursor_x, cursor_y, m_buttonMask);
616 } else if(press_time.elapsed() < TAP_PRESS_TIME) { //tap
619 QTimer::singleShot(DOUBLE_TAP_UP_TIME, this, SLOT(mouseEventHandler()));
623 } else { //middle or right button, send directly
624 if ((e->type() == QEvent::MouseButtonPress)) {
625 if (e->button() & Qt::MidButton)
626 m_buttonMask |= 0x02;
627 if (e->button() & Qt::RightButton)
628 m_buttonMask |= 0x04;
629 } else if (e->type() == QEvent::MouseButtonRelease) {
630 if (e->button() & Qt::MidButton)
631 m_buttonMask &= 0xfd;
632 if (e->button() & Qt::RightButton)
633 m_buttonMask &= 0xfb;
635 vncThread.mouseEvent(cursor_x, cursor_y, m_buttonMask);
638 //prevent local cursor artifacts
639 static int old_cursor_x = cursor_x;
640 static int old_cursor_y = cursor_y;
641 if(((m_dotCursorState == CursorOn) || m_forceLocalCursor)
642 and (cursor_x != old_cursor_x or cursor_y != old_cursor_y)) {
643 //clear last position
644 repaint(old_cursor_x*m_horizontalFactor - cursor_size/2, old_cursor_y*m_verticalFactor - cursor_size/2, cursor_size, cursor_size);
645 //and refresh new one
646 repaint(cursor_x*m_horizontalFactor - cursor_size/2, cursor_y*m_verticalFactor - cursor_size/2, cursor_size, cursor_size);
648 old_cursor_x = cursor_x; old_cursor_y = cursor_y;
652 void VncView::wheelEventHandler(QWheelEvent *event)
655 if (event->delta() < 0)
660 const int x = qRound(event->x() / m_horizontalFactor);
661 const int y = qRound(event->y() / m_verticalFactor);
663 vncThread.mouseEvent(x, y, eb | m_buttonMask);
664 vncThread.mouseEvent(x, y, m_buttonMask);
667 void VncView::keyEventHandler(QKeyEvent *e)
669 // strip away autorepeating KeyRelease; see bug #206598
670 if (e->isAutoRepeat() && (e->type() == QEvent::KeyRelease)) {
674 // parts of this code are based on http://italc.sourcearchive.com/documentation/1.0.9.1/vncview_8cpp-source.html
675 rfbKeySym k = e->nativeVirtualKey();
677 // we do not handle Key_Backtab separately as the Shift-modifier
678 // is already enabled
679 if (e->key() == Qt::Key_Backtab) {
683 const bool pressed = (e->type() == QEvent::KeyPress);
686 //don't send ISO_Level3_Shift (would break things like Win+0-9)
687 //also enable IM so symbol key works
689 setAttribute(Qt::WA_InputMethodEnabled, pressed);
696 if (k == XK_Shift_L || k == XK_Control_L || k == XK_Meta_L || k == XK_Alt_L) {
699 } else if (m_mods.contains(k)) {
707 int current_zoom = -1;
708 if(e->key() == Qt::Key_F8)
709 current_zoom = left_zoom;
710 else if(e->key() == Qt::Key_F7)
711 current_zoom = right_zoom;
713 // kDebug(5011) << "got '" << e->text() << "'.";
714 vncThread.keyEvent(k, pressed);
716 kDebug(5011) << "nativeVirtualKey() for '" << e->text() << "' failed.";
720 if(current_zoom == -1)
723 //handle zoom buttons
724 if(current_zoom == 0) { //left click
726 m_buttonMask |= 0x01;
728 m_buttonMask &= 0xfe;
729 vncThread.mouseEvent(cursor_x, cursor_y, m_buttonMask);
730 } else if(current_zoom == 1) { //right click
732 m_buttonMask |= 0x04;
734 m_buttonMask &= 0xfb;
735 vncThread.mouseEvent(cursor_x, cursor_y, m_buttonMask);
736 } else if(current_zoom == 2) { //middle click
738 m_buttonMask |= 0x02;
740 m_buttonMask &= 0xfd;
741 vncThread.mouseEvent(cursor_x, cursor_y, m_buttonMask);
742 } else if(current_zoom == 3 and pressed) { //wheel up
744 vncThread.mouseEvent(cursor_x, cursor_y, eb | m_buttonMask);
745 vncThread.mouseEvent(cursor_x, cursor_y, m_buttonMask);
746 } else if(current_zoom == 4 and pressed) { //wheel down
748 vncThread.mouseEvent(cursor_x, cursor_y, eb | m_buttonMask);
749 vncThread.mouseEvent(cursor_x, cursor_y, m_buttonMask);
750 } else if(current_zoom == 5) { //page up
751 vncThread.keyEvent(0xff55, pressed);
752 } else if(current_zoom == 6) { //page down
753 vncThread.keyEvent(0xff56, pressed);
757 void VncView::unpressModifiers()
759 const QList<unsigned int> keys = m_mods.keys();
760 QList<unsigned int>::const_iterator it = keys.constBegin();
761 while (it != keys.end()) {
762 vncThread.keyEvent(*it, false);
768 void VncView::clipboardSelectionChanged()
770 if (m_status != Connected)
773 if (m_clipboard->ownsSelection() || m_dontSendClipboard)
776 const QString text = m_clipboard->text(QClipboard::Selection);
778 vncThread.clientCut(text);
781 void VncView::clipboardDataChanged()
783 if (m_status != Connected)
786 if (m_clipboard->ownsClipboard() || m_dontSendClipboard)
789 const QString text = m_clipboard->text(QClipboard::Clipboard);
791 vncThread.clientCut(text);
795 void VncView::sendKey(Qt::Key key)
797 //convert Qt::Key into x11 keysym
809 case Qt::Key_PageDown:
827 case Qt::Key_Backspace:
842 k = 0xffbe + int(key - Qt::Key_F1);
854 case Qt::MetaModifier:
858 case Qt::AltModifier:
861 case Qt::Key_Control:
862 case Qt::ControlModifier:
866 kDebug(5011) << "sendKey(): Unhandled Qt::Key value " << key;
870 if (k == XK_Shift_L || k == XK_Control_L || k == XK_Meta_L || k == XK_Alt_L || k == XK_Super_L) {
871 if (m_mods.contains(k)) { //release
873 vncThread.keyEvent(k, false);
876 vncThread.keyEvent(k, true);
878 } else { //normal key
879 vncThread.keyEvent(k, true);
880 vncThread.keyEvent(k, false);
884 void VncView::sendKeySequence(QKeySequence keys)
886 Q_ASSERT(keys.count() <= 1); //we can only handle a single combination
888 //to get at individual key presses, we split 'keys' into its components
890 for(int i = 0; ; i++) {
891 QString k = keys.toString().section('+', i, i);
894 //kDebug(5011) << "found key: " << k;
896 key_list.append(Qt::Key_Alt);
897 } else if(k == "Ctrl") {
898 key_list.append(Qt::Key_Control);
899 } else if(k == "Meta") {
900 key_list.append(Qt::Key_Meta);
902 key_list.append(QKeySequence(k)[0]);
906 for(int i = 0; i < key_list.count(); i++)
907 sendKey(Qt::Key(key_list.at(i)));
909 //release modifiers (everything before final key)
910 for(int i = key_list.count()-2; i >= 0; i--)
911 sendKey(Qt::Key(key_list.at(i)));
914 void VncView::reloadSettings()
917 left_zoom = settings.value("left_zoom", 0).toInt();
918 right_zoom = settings.value("right_zoom", 1).toInt();
919 disable_tapping = settings.value("disable_tapping", false).toBool();
921 bool always_show_local_cursor = settings.value("always_show_local_cursor", false).toBool();
922 if(always_show_local_cursor)
923 showDotCursor(CursorOn);
928 //convert commitString into keyevents
929 void VncView::inputMethodEvent(QInputMethodEvent *event)
931 //TODO handle replacements
932 //NOTE for the return key to work Qt needs to enable multiline input, which only works for Q(Plain)TextEdit
934 //kDebug(5011) << event->commitString() << "|" << event->preeditString() << "|" << event->replacementLength() << "|" << event->replacementStart();
935 QString letters = event->commitString();
936 for(int i = 0; i < letters.length(); i++) {
937 char k = letters.at(i).toLatin1(); //works with all 'normal' keys, not umlauts.
939 kDebug(5011) << "unhandled key";
942 vncThread.keyEvent(k, true);
943 vncThread.keyEvent(k, false);
948 #include "moc_vncview.cpp"