Changeset View
Changeset View
Standalone View
Standalone View
vnc/vncview.cpp
Show First 20 Lines • Show All 50 Lines • ▼ Show 20 Line(s) | |||||
51 | #define KMOD_Meta_L 0x04 | 51 | #define KMOD_Meta_L 0x04 | ||
52 | #define KMOD_Control_L 0x08 | 52 | #define KMOD_Control_L 0x08 | ||
53 | #define KMOD_Shift_L 0x10 | 53 | #define KMOD_Shift_L 0x10 | ||
54 | 54 | | |||
55 | VncView::VncView(QWidget *parent, const QUrl &url, KConfigGroup configGroup) | 55 | VncView::VncView(QWidget *parent, const QUrl &url, KConfigGroup configGroup) | ||
56 | : RemoteView(parent), | 56 | : RemoteView(parent), | ||
57 | m_initDone(false), | 57 | m_initDone(false), | ||
58 | m_buttonMask(0), | 58 | m_buttonMask(0), | ||
59 | m_repaint(false), | | |||
60 | m_quitFlag(false), | 59 | m_quitFlag(false), | ||
61 | m_firstPasswordTry(true), | 60 | m_firstPasswordTry(true), | ||
62 | m_dontSendClipboard(false), | 61 | m_dontSendClipboard(false), | ||
63 | m_horizontalFactor(1.0), | 62 | m_horizontalFactor(1.0), | ||
64 | m_verticalFactor(1.0), | 63 | m_verticalFactor(1.0), | ||
65 | m_forceLocalCursor(false) | 64 | m_forceLocalCursor(false) | ||
66 | #ifdef LIBSSH_FOUND | 65 | #ifdef LIBSSH_FOUND | ||
67 | , m_sshTunnelThread(nullptr) | 66 | , m_sshTunnelThread(nullptr) | ||
▲ Show 20 Lines • Show All 346 Lines • ▼ Show 20 Line(s) | 412 | { | |||
414 | return m_hostPreferences; | 413 | return m_hostPreferences; | ||
415 | } | 414 | } | ||
416 | #endif | 415 | #endif | ||
417 | 416 | | |||
418 | void VncView::updateImage(int x, int y, int w, int h) | 417 | void VncView::updateImage(int x, int y, int w, int h) | ||
419 | { | 418 | { | ||
420 | // qCDebug(KRDC) << "got update" << width() << height(); | 419 | // qCDebug(KRDC) << "got update" << width() << height(); | ||
421 | 420 | | |||
422 | m_x = x; | | |||
423 | m_y = y; | | |||
424 | m_w = w; | | |||
425 | m_h = h; | | |||
426 | | ||||
427 | if (m_horizontalFactor != 1.0 || m_verticalFactor != 1.0) { | | |||
428 | // If the view is scaled, grow the update rectangle to avoid artifacts | | |||
429 | m_x-=1; | | |||
430 | m_y-=1; | | |||
431 | m_w+=2; | | |||
432 | m_h+=2; | | |||
433 | } | | |||
434 | | ||||
435 | m_frame = vncThread.image(); | 421 | m_frame = vncThread.image(); | ||
436 | 422 | | |||
437 | if (!m_initDone) { | 423 | if (!m_initDone) { | ||
438 | if (!vncThread.username().isEmpty()) { | 424 | if (!vncThread.username().isEmpty()) { | ||
439 | m_url.setUserName(vncThread.username()); | 425 | m_url.setUserName(vncThread.username()); | ||
440 | } | 426 | } | ||
441 | setAttribute(Qt::WA_StaticContents); | 427 | setAttribute(Qt::WA_StaticContents); | ||
442 | setAttribute(Qt::WA_OpaquePaintEvent); | 428 | setAttribute(Qt::WA_OpaquePaintEvent); | ||
▲ Show 20 Lines • Show All 41 Lines • ▼ Show 20 Line(s) | 469 | } else { | |||
484 | qCDebug(KRDC) << "Resizing: " << m_frame.width() << m_frame.height(); | 470 | qCDebug(KRDC) << "Resizing: " << m_frame.width() << m_frame.height(); | ||
485 | resize(m_frame.width(), m_frame.height()); | 471 | resize(m_frame.width(), m_frame.height()); | ||
486 | setMaximumSize(m_frame.width(), m_frame.height()); //This is a hack to force Qt to center the view in the scroll area | 472 | setMaximumSize(m_frame.width(), m_frame.height()); //This is a hack to force Qt to center the view in the scroll area | ||
487 | setMinimumSize(m_frame.width(), m_frame.height()); | 473 | setMinimumSize(m_frame.width(), m_frame.height()); | ||
488 | emit framebufferSizeChanged(m_frame.width(), m_frame.height()); | 474 | emit framebufferSizeChanged(m_frame.width(), m_frame.height()); | ||
489 | } | 475 | } | ||
490 | } | 476 | } | ||
491 | 477 | | |||
492 | m_repaint = true; | 478 | repaint(QRectF(x * m_horizontalFactor, y * m_verticalFactor, w * m_horizontalFactor, h * m_verticalFactor).toAlignedRect()); | ||
493 | repaint(qRound(m_x * m_horizontalFactor), qRound(m_y * m_verticalFactor), qRound(m_w * m_horizontalFactor), qRound(m_h * m_verticalFactor)); | | |||
494 | m_repaint = false; | | |||
495 | } | 479 | } | ||
496 | 480 | | |||
497 | void VncView::setViewOnly(bool viewOnly) | 481 | void VncView::setViewOnly(bool viewOnly) | ||
498 | { | 482 | { | ||
499 | RemoteView::setViewOnly(viewOnly); | 483 | RemoteView::setViewOnly(viewOnly); | ||
500 | 484 | | |||
501 | m_dontSendClipboard = viewOnly; | 485 | m_dontSendClipboard = viewOnly; | ||
502 | 486 | | |||
▲ Show 20 Lines • Show All 43 Lines • ▼ Show 20 Line(s) | 529 | if (m_frame.isNull() || m_frame.format() == QImage::Format_Invalid) { | |||
546 | qCDebug(KRDC) << "no valid image to paint"; | 530 | qCDebug(KRDC) << "no valid image to paint"; | ||
547 | RemoteView::paintEvent(event); | 531 | RemoteView::paintEvent(event); | ||
548 | return; | 532 | return; | ||
549 | } | 533 | } | ||
550 | 534 | | |||
551 | event->accept(); | 535 | event->accept(); | ||
552 | 536 | | |||
553 | QPainter painter(this); | 537 | QPainter painter(this); | ||
538 | painter.setRenderHint(QPainter::SmoothPixmapTransform); | ||||
554 | 539 | | |||
555 | if (m_repaint) { | 540 | QRectF dstRect = event->rect(); | ||
aacid: const | |||||
556 | // qCDebug(KRDC) << "normal repaint"; | 541 | QRectF srcRect(dstRect.x() / m_horizontalFactor, dstRect.y() / m_verticalFactor, | ||
aacid: const | |||||
557 | painter.drawImage(QRect(qRound(m_x*m_horizontalFactor), qRound(m_y*m_verticalFactor), | 542 | dstRect.width() / m_horizontalFactor, dstRect.height() / m_verticalFactor); | ||
558 | qRound(m_w*m_horizontalFactor), qRound(m_h*m_verticalFactor)), | 543 | painter.drawImage(dstRect, m_frame, srcRect); | ||
559 | m_frame.copy(m_x, m_y, m_w, m_h).scaled(qRound(m_w*m_horizontalFactor), | | |||
560 | qRound(m_h*m_verticalFactor), | | |||
561 | Qt::IgnoreAspectRatio, Qt::SmoothTransformation)); | | |||
562 | } else { | | |||
563 | // qCDebug(KRDC) << "resize repaint"; | | |||
564 | QRect rect = event->rect(); | | |||
565 | if (rect.width() != width() || rect.height() != height()) { | | |||
566 | // qCDebug(KRDC) << "Partial repaint"; | | |||
567 | const int sx = rect.x()/m_horizontalFactor; | | |||
568 | const int sy = rect.y()/m_verticalFactor; | | |||
569 | const int sw = rect.width()/m_horizontalFactor; | | |||
570 | const int sh = rect.height()/m_verticalFactor; | | |||
571 | painter.drawImage(rect, | | |||
572 | m_frame.copy(sx, sy, sw, sh).scaled(rect.width(), rect.height(), | | |||
573 | Qt::IgnoreAspectRatio, Qt::SmoothTransformation)); | | |||
574 | } else { | | |||
575 | // qCDebug(KRDC) << "Full repaint" << width() << height() << m_frame.width() << m_frame.height(); | | |||
576 | painter.drawImage(QRect(0, 0, width(), height()), | | |||
577 | m_frame.scaled(m_frame.width() * m_horizontalFactor, m_frame.height() * m_verticalFactor, | | |||
578 | Qt::IgnoreAspectRatio, Qt::SmoothTransformation)); | | |||
579 | } | | |||
580 | } | | |||
581 | 544 | | |||
582 | RemoteView::paintEvent(event); | 545 | RemoteView::paintEvent(event); | ||
583 | } | 546 | } | ||
584 | 547 | | |||
585 | void VncView::resizeEvent(QResizeEvent *event) | 548 | void VncView::resizeEvent(QResizeEvent *event) | ||
586 | { | 549 | { | ||
587 | RemoteView::resizeEvent(event); | 550 | RemoteView::resizeEvent(event); | ||
588 | update(); | 551 | update(); | ||
▲ Show 20 Lines • Show All 138 Lines • Show Last 20 Lines |
const