Changeset View
Changeset View
Standalone View
Standalone View
vnc/vncview.cpp
Show First 20 Lines • Show All 109 Lines • ▼ Show 20 Line(s) | 103 | if (event->type() == QEvent::KeyPress || | |||
---|---|---|---|---|---|
110 | return true; | 110 | return true; | ||
111 | } | 111 | } | ||
112 | 112 | | |||
113 | return RemoteView::eventFilter(obj, event); | 113 | return RemoteView::eventFilter(obj, event); | ||
114 | } | 114 | } | ||
115 | 115 | | |||
116 | QSize VncView::framebufferSize() | 116 | QSize VncView::framebufferSize() | ||
117 | { | 117 | { | ||
118 | return m_frame.size(); | 118 | return m_frame.size() / devicePixelRatioF(); | ||
119 | } | 119 | } | ||
120 | 120 | | |||
121 | QSize VncView::sizeHint() const | 121 | QSize VncView::sizeHint() const | ||
122 | { | 122 | { | ||
123 | return size(); | 123 | return size(); | ||
124 | } | 124 | } | ||
125 | 125 | | |||
126 | QSize VncView::minimumSizeHint() const | 126 | QSize VncView::minimumSizeHint() const | ||
127 | { | 127 | { | ||
128 | return size(); | 128 | return size(); | ||
129 | } | 129 | } | ||
130 | 130 | | |||
131 | void VncView::scaleResize(int w, int h) | 131 | void VncView::scaleResize(int w, int h) | ||
132 | { | 132 | { | ||
133 | RemoteView::scaleResize(w, h); | 133 | RemoteView::scaleResize(w, h); | ||
134 | 134 | | |||
135 | qCDebug(KRDC) << w << h; | 135 | qCDebug(KRDC) << w << h; | ||
136 | if (m_scale) { | 136 | if (m_scale) { | ||
137 | m_verticalFactor = (qreal) h / m_frame.height(); | 137 | const QSize frameSize = m_frame.size() / m_frame.devicePixelRatio(); | ||
138 | m_horizontalFactor = (qreal) w / m_frame.width(); | 138 | m_verticalFactor = (qreal) h / frameSize.height(); | ||
139 | m_horizontalFactor = (qreal) w / frameSize.width(); | ||||
139 | 140 | | |||
140 | #ifndef QTONLY | 141 | #ifndef QTONLY | ||
141 | if (Settings::keepAspectRatio()) { | 142 | if (Settings::keepAspectRatio()) { | ||
142 | m_verticalFactor = m_horizontalFactor = qMin(m_verticalFactor, m_horizontalFactor); | 143 | m_verticalFactor = m_horizontalFactor = qMin(m_verticalFactor, m_horizontalFactor); | ||
143 | } | 144 | } | ||
144 | #else | 145 | #else | ||
145 | m_verticalFactor = m_horizontalFactor = qMin(m_verticalFactor, m_horizontalFactor); | 146 | m_verticalFactor = m_horizontalFactor = qMin(m_verticalFactor, m_horizontalFactor); | ||
146 | #endif | 147 | #endif | ||
147 | 148 | | |||
148 | const qreal newW = m_frame.width() * m_horizontalFactor; | 149 | const qreal newW = frameSize.width() * m_horizontalFactor; | ||
149 | const qreal newH = m_frame.height() * m_verticalFactor; | 150 | const qreal newH = frameSize.height() * m_verticalFactor; | ||
150 | setMaximumSize(newW, newH); //This is a hack to force Qt to center the view in the scroll area | 151 | setMaximumSize(newW, newH); //This is a hack to force Qt to center the view in the scroll area | ||
151 | resize(newW, newH); | 152 | resize(newW, newH); | ||
152 | } | 153 | } | ||
153 | } | 154 | } | ||
154 | 155 | | |||
155 | void VncView::updateConfiguration() | 156 | void VncView::updateConfiguration() | ||
156 | { | 157 | { | ||
157 | RemoteView::updateConfiguration(); | 158 | RemoteView::updateConfiguration(); | ||
▲ Show 20 Lines • Show All 80 Lines • ▼ Show 20 Line(s) | |||||
238 | #ifdef QTONLY | 239 | #ifdef QTONLY | ||
239 | quality = (RemoteView::Quality)((QCoreApplication::arguments().count() > 2) ? | 240 | quality = (RemoteView::Quality)((QCoreApplication::arguments().count() > 2) ? | ||
240 | QCoreApplication::arguments().at(2).toInt() : 2); | 241 | QCoreApplication::arguments().at(2).toInt() : 2); | ||
241 | #else | 242 | #else | ||
242 | quality = m_hostPreferences->quality(); | 243 | quality = m_hostPreferences->quality(); | ||
243 | #endif | 244 | #endif | ||
244 | 245 | | |||
245 | vncThread.setQuality(quality); | 246 | vncThread.setQuality(quality); | ||
247 | vncThread.setDevicePixelRatio(devicePixelRatioF()); | ||||
246 | 248 | | |||
247 | // set local cursor on by default because low quality mostly means slow internet connection | 249 | // set local cursor on by default because low quality mostly means slow internet connection | ||
248 | if (quality == RemoteView::Low) { | 250 | if (quality == RemoteView::Low) { | ||
249 | showDotCursor(RemoteView::CursorOn); | 251 | showDotCursor(RemoteView::CursorOn); | ||
250 | #ifndef QTONLY | 252 | #ifndef QTONLY | ||
251 | // KRDC does always just have one main window, so at(0) is safe | 253 | // KRDC does always just have one main window, so at(0) is safe | ||
252 | KXMLGUIClient *mainWindow = dynamic_cast<KXMLGUIClient*>(KMainWindow::memberList().at(0)); | 254 | KXMLGUIClient *mainWindow = dynamic_cast<KXMLGUIClient*>(KMainWindow::memberList().at(0)); | ||
253 | if (mainWindow) | 255 | if (mainWindow) | ||
▲ Show 20 Lines • Show All 179 Lines • ▼ Show 20 Line(s) | 425 | if (!m_initDone) { | |||
433 | setMouseTracking(true); // get mouse events even when there is no mousebutton pressed | 435 | setMouseTracking(true); // get mouse events even when there is no mousebutton pressed | ||
434 | setFocusPolicy(Qt::WheelFocus); | 436 | setFocusPolicy(Qt::WheelFocus); | ||
435 | setStatus(Connected); | 437 | setStatus(Connected); | ||
436 | emit connected(); | 438 | emit connected(); | ||
437 | 439 | | |||
438 | if (m_scale) { | 440 | if (m_scale) { | ||
439 | #ifndef QTONLY | 441 | #ifndef QTONLY | ||
440 | qCDebug(KRDC) << "Setting initial size w:" <<m_hostPreferences->width() << " h:" << m_hostPreferences->height(); | 442 | qCDebug(KRDC) << "Setting initial size w:" <<m_hostPreferences->width() << " h:" << m_hostPreferences->height(); | ||
441 | emit framebufferSizeChanged(m_hostPreferences->width(), m_hostPreferences->height()); | 443 | QSize frameSize = QSize(m_hostPreferences->width(), m_hostPreferences->height()) / devicePixelRatioF(); | ||
442 | scaleResize(m_hostPreferences->width(), m_hostPreferences->height()); | 444 | emit framebufferSizeChanged(frameSize.width(), frameSize.height()); | ||
445 | scaleResize(frameSize.width(), frameSize.height()); | ||||
443 | qCDebug(KRDC) << "m_frame.size():" << m_frame.size() << "size()" << size(); | 446 | qCDebug(KRDC) << "m_frame.size():" << m_frame.size() << "size()" << size(); | ||
444 | #else | 447 | #else | ||
445 | //TODO: qtonly alternative | 448 | //TODO: qtonly alternative | ||
446 | #endif | 449 | #endif | ||
447 | } | 450 | } | ||
448 | 451 | | |||
449 | m_initDone = true; | 452 | m_initDone = true; | ||
450 | 453 | | |||
451 | #ifndef QTONLY | 454 | #ifndef QTONLY | ||
452 | if (m_hostPreferences->walletSupport()) { | 455 | if (m_hostPreferences->walletSupport()) { | ||
453 | saveWalletPassword(vncThread.password()); | 456 | saveWalletPassword(vncThread.password()); | ||
454 | #ifdef LIBSSH_FOUND | 457 | #ifdef LIBSSH_FOUND | ||
455 | if (m_hostPreferences->useSshTunnel()) { | 458 | if (m_hostPreferences->useSshTunnel()) { | ||
456 | saveWalletSshPassword(); | 459 | saveWalletSshPassword(); | ||
457 | } | 460 | } | ||
458 | #endif | 461 | #endif | ||
459 | } | 462 | } | ||
460 | #endif | 463 | #endif | ||
461 | } | 464 | } | ||
462 | 465 | | |||
463 | if ((y == 0 && x == 0) && (m_frame.size() != size())) { | 466 | const QSize frameSize = m_frame.size() / m_frame.devicePixelRatio(); | ||
467 | if ((y == 0 && x == 0) && (frameSize != size())) { | ||||
464 | qCDebug(KRDC) << "Updating framebuffer size"; | 468 | qCDebug(KRDC) << "Updating framebuffer size"; | ||
465 | if (m_scale) { | 469 | if (m_scale) { | ||
466 | setMaximumSize(QSize(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX)); | 470 | setMaximumSize(QSize(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX)); | ||
467 | if (parentWidget()) | 471 | if (parentWidget()) | ||
468 | scaleResize(parentWidget()->width(), parentWidget()->height()); | 472 | scaleResize(parentWidget()->width(), parentWidget()->height()); | ||
469 | } else { | 473 | } else { | ||
470 | qCDebug(KRDC) << "Resizing: " << m_frame.width() << m_frame.height(); | 474 | qCDebug(KRDC) << "Resizing: " << m_frame.width() << m_frame.height(); | ||
471 | resize(m_frame.width(), m_frame.height()); | 475 | resize(frameSize); | ||
472 | setMaximumSize(m_frame.width(), m_frame.height()); //This is a hack to force Qt to center the view in the scroll area | 476 | setMaximumSize(frameSize); //This is a hack to force Qt to center the view in the scroll area | ||
473 | setMinimumSize(m_frame.width(), m_frame.height()); | 477 | setMinimumSize(frameSize); | ||
474 | emit framebufferSizeChanged(m_frame.width(), m_frame.height()); | 478 | emit framebufferSizeChanged(frameSize.width(), frameSize.height()); | ||
475 | } | 479 | } | ||
476 | } | 480 | } | ||
477 | 481 | | |||
478 | repaint(QRectF(x * m_horizontalFactor, y * m_verticalFactor, w * m_horizontalFactor, h * m_verticalFactor).toAlignedRect()); | 482 | const auto dpr = m_frame.devicePixelRatio(); | ||
483 | repaint(QRectF(x / dpr * m_horizontalFactor, y / dpr * m_verticalFactor, w / dpr * m_horizontalFactor, h / dpr * m_verticalFactor).toAlignedRect()); | ||||
479 | } | 484 | } | ||
480 | 485 | | |||
481 | void VncView::setViewOnly(bool viewOnly) | 486 | void VncView::setViewOnly(bool viewOnly) | ||
482 | { | 487 | { | ||
483 | RemoteView::setViewOnly(viewOnly); | 488 | RemoteView::setViewOnly(viewOnly); | ||
484 | 489 | | |||
485 | m_dontSendClipboard = viewOnly; | 490 | m_dontSendClipboard = viewOnly; | ||
486 | 491 | | |||
Show All 18 Lines | 509 | if (scale) { | |||
505 | setMaximumSize(QSize(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX)); | 510 | setMaximumSize(QSize(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX)); | ||
506 | setMinimumSize(1, 1); | 511 | setMinimumSize(1, 1); | ||
507 | if (parentWidget()) | 512 | if (parentWidget()) | ||
508 | scaleResize(parentWidget()->width(), parentWidget()->height()); | 513 | scaleResize(parentWidget()->width(), parentWidget()->height()); | ||
509 | } else { | 514 | } else { | ||
510 | m_verticalFactor = 1.0; | 515 | m_verticalFactor = 1.0; | ||
511 | m_horizontalFactor = 1.0; | 516 | m_horizontalFactor = 1.0; | ||
512 | 517 | | |||
513 | setMaximumSize(m_frame.width(), m_frame.height()); //This is a hack to force Qt to center the view in the scroll area | 518 | const QSize frameSize = m_frame.size() / m_frame.devicePixelRatio(); | ||
514 | setMinimumSize(m_frame.width(), m_frame.height()); | 519 | setMaximumSize(frameSize); //This is a hack to force Qt to center the view in the scroll area | ||
515 | resize(m_frame.width(), m_frame.height()); | 520 | setMinimumSize(frameSize); | ||
521 | resize(frameSize); | ||||
516 | } | 522 | } | ||
517 | } | 523 | } | ||
518 | 524 | | |||
519 | void VncView::setCut(const QString &text) | 525 | void VncView::setCut(const QString &text) | ||
520 | { | 526 | { | ||
521 | m_dontSendClipboard = true; | 527 | m_dontSendClipboard = true; | ||
522 | m_clipboard->setText(text, QClipboard::Clipboard); | 528 | m_clipboard->setText(text, QClipboard::Clipboard); | ||
523 | m_dontSendClipboard = false; | 529 | m_dontSendClipboard = false; | ||
524 | } | 530 | } | ||
525 | 531 | | |||
526 | void VncView::paintEvent(QPaintEvent *event) | 532 | void VncView::paintEvent(QPaintEvent *event) | ||
527 | { | 533 | { | ||
528 | // qCDebug(KRDC) << "paint event: x: " << m_x << ", y: " << m_y << ", w: " << m_w << ", h: " << m_h; | 534 | // qCDebug(KRDC) << "paint event: x: " << m_x << ", y: " << m_y << ", w: " << m_w << ", h: " << m_h; | ||
529 | if (m_frame.isNull() || m_frame.format() == QImage::Format_Invalid) { | 535 | if (m_frame.isNull() || m_frame.format() == QImage::Format_Invalid) { | ||
530 | qCDebug(KRDC) << "no valid image to paint"; | 536 | qCDebug(KRDC) << "no valid image to paint"; | ||
531 | RemoteView::paintEvent(event); | 537 | RemoteView::paintEvent(event); | ||
532 | return; | 538 | return; | ||
533 | } | 539 | } | ||
534 | 540 | | |||
535 | event->accept(); | 541 | event->accept(); | ||
536 | 542 | | |||
537 | QPainter painter(this); | 543 | QPainter painter(this); | ||
538 | painter.setRenderHint(QPainter::SmoothPixmapTransform); | 544 | painter.setRenderHint(QPainter::SmoothPixmapTransform); | ||
539 | 545 | | |||
546 | const auto dpr = m_frame.devicePixelRatio(); | ||||
540 | const QRectF dstRect = event->rect(); | 547 | const QRectF dstRect = event->rect(); | ||
541 | const QRectF srcRect(dstRect.x() / m_horizontalFactor, dstRect.y() / m_verticalFactor, | 548 | const QRectF srcRect(dstRect.x() * dpr / m_horizontalFactor, dstRect.y() * dpr / m_verticalFactor, | ||
542 | dstRect.width() / m_horizontalFactor, dstRect.height() / m_verticalFactor); | 549 | dstRect.width() * dpr / m_horizontalFactor, dstRect.height() * dpr / m_verticalFactor); | ||
543 | painter.drawImage(dstRect, m_frame, srcRect); | 550 | painter.drawImage(dstRect, m_frame, srcRect); | ||
544 | 551 | | |||
545 | RemoteView::paintEvent(event); | 552 | RemoteView::paintEvent(event); | ||
546 | } | 553 | } | ||
547 | 554 | | |||
548 | void VncView::resizeEvent(QResizeEvent *event) | 555 | void VncView::resizeEvent(QResizeEvent *event) | ||
549 | { | 556 | { | ||
550 | RemoteView::resizeEvent(event); | 557 | RemoteView::resizeEvent(event); | ||
▲ Show 20 Lines • Show All 43 Lines • ▼ Show 20 Line(s) | 600 | if (e->button() & Qt::LeftButton) | |||
594 | m_buttonMask &= 0xfe; | 601 | m_buttonMask &= 0xfe; | ||
595 | if (e->button() & Qt::MidButton) | 602 | if (e->button() & Qt::MidButton) | ||
596 | m_buttonMask &= 0xfd; | 603 | m_buttonMask &= 0xfd; | ||
597 | if (e->button() & Qt::RightButton) | 604 | if (e->button() & Qt::RightButton) | ||
598 | m_buttonMask &= 0xfb; | 605 | m_buttonMask &= 0xfb; | ||
599 | } | 606 | } | ||
600 | } | 607 | } | ||
601 | 608 | | |||
602 | vncThread.mouseEvent(qRound(e->x() / m_horizontalFactor), qRound(e->y() / m_verticalFactor), m_buttonMask); | 609 | const auto dpr = devicePixelRatioF(); | ||
610 | QPointF screenPos = e->screenPos(); | ||||
611 | // We need to restore mouse position in device coordinates. | ||||
612 | // QMouseEvent::localPos() can be rounded (bug in Qt), but QMouseEvent::screenPos() is not. | ||||
613 | QPointF pos = (e->pos() + (screenPos - screenPos.toPoint())) * dpr; | ||||
614 | vncThread.mouseEvent(qRound(pos.x() / m_horizontalFactor), qRound(pos.y() / m_verticalFactor), m_buttonMask); | ||||
603 | } | 615 | } | ||
604 | 616 | | |||
605 | void VncView::wheelEventHandler(QWheelEvent *event) | 617 | void VncView::wheelEventHandler(QWheelEvent *event) | ||
606 | { | 618 | { | ||
607 | int eb = 0; | 619 | int eb = 0; | ||
608 | if (event->delta() < 0) | 620 | if (event->delta() < 0) | ||
609 | eb |= 0x10; | 621 | eb |= 0x10; | ||
610 | else | 622 | else | ||
▲ Show 20 Lines • Show All 79 Lines • Show Last 20 Lines |