#include "vncview.h"
-#include <QMessageBox>
-#include <QInputDialog>
-#define KMessageBox QMessageBox
-#define error(parent, message, caption) \
-critical(parent, caption, message)
-
-#include <QApplication>
-#include <QBitmap>
-#include <QCheckBox>
-#include <QDialog>
-#include <QImage>
-#include <QHBoxLayout>
-#include <QVBoxLayout>
-#include <QPainter>
-#include <QMouseEvent>
-#include <QPushButton>
-#include <QEvent>
-#include <QSettings>
-#include <QTime>
-#include <QTimer>
+#include <QtGui>
// Definition of key modifier mask constants
//local cursor width/height in px, should be an odd number
const int CURSOR_SIZE = 7;
+//in miliseconds
const int TAP_PRESS_TIME = 180;
const int DOUBLE_TAP_UP_TIME = 500;
m_buttonMask(0),
cursor_x(0),
cursor_y(0),
- m_repaint(false),
m_quitFlag(false),
m_firstPasswordTry(true),
m_dontSendClipboard(false),
m_horizontalFactor(1.0),
m_verticalFactor(1.0),
m_forceLocalCursor(false),
- force_full_repaint(false),
quality(quality),
- listen_port(listen_port)
+ listen_port(listen_port),
+ transformation_mode(Qt::FastTransformation)
{
m_url = url;
m_host = url.host();
startQuitting();
}
-void VncView::forceFullRepaint()
-{
- force_full_repaint = true;
- repaint();
-}
-
bool VncView::eventFilter(QObject *obj, QEvent *event)
{
if (m_viewOnly) {
event->type() == QEvent::MouseButtonPress ||
event->type() == QEvent::MouseButtonRelease ||
event->type() == QEvent::Wheel ||
- event->type() == QEvent::MouseMove)
+ event->type() == QEvent::MouseMove) {
+
+ event->ignore();
return true;
+ }
}
+
return RemoteView::eventFilter(obj, event);
}
kDebug(5011) << "about to quit";
- //const bool connected = status() == RemoteView::Connected;
-
setStatus(Disconnecting);
m_quitFlag = true;
- //if(connected) //remove if things work without it
vncThread.stop();
const bool quitSuccess = vncThread.wait(700);
QSettings settings;
settings.beginGroup("hosts");
- QString password = settings.value(QString("%1/password").arg(m_host), "").toString();
+
//check for saved password
+ QString password = settings.value(QString("%1/password").arg(m_host), "").toString();
if(m_firstPasswordTry and !password.isEmpty()) {
kDebug(5011) << "Trying saved password";
m_firstPasswordTry = false;
QHBoxLayout layout1;
QVBoxLayout layout2;
layout2.addWidget(&passwordbox);
- if(!m_host.isEmpty()) //don't save incomming connections
+ if(!m_host.isEmpty()) //don't save incoming connections
layout2.addWidget(&save_password);
layout1.addLayout(&layout2);
layout1.addWidget(&ok_button);
setMouseTracking(true); // get mouse events even when there is no mousebutton pressed
setFocusPolicy(Qt::WheelFocus);
setStatus(Connected);
-// emit framebufferSizeChanged(m_frame.width(), m_frame.height());
emit connected();
resize(width(), height());
old_frame_size = m_frame.size();
kDebug(5011) << "Updating framebuffer size";
setZoomLevel();
+ useFastTransformations(false);
+
emit framebufferSizeChanged(m_frame.width(), m_frame.height());
}
- m_repaint = true;
repaint(qRound(m_x * m_horizontalFactor), qRound(m_y * m_verticalFactor), qRound(m_w * m_horizontalFactor), qRound(m_h * m_verticalFactor));
- m_repaint = false;
}
void VncView::setViewOnly(bool viewOnly)
void VncView::paintEvent(QPaintEvent *event)
{
- //kDebug(5011) << "paint event: x: " << m_x << ", y: " << m_y << ", w: " << m_w << ", h: " << m_h;
if (m_frame.isNull() || m_frame.format() == QImage::Format_Invalid) {
- kDebug(5011) << "no valid image to paint";
+ //no valid image to paint
RemoteView::paintEvent(event);
return;
}
event->accept();
+ const QRect update_rect = event->rect();
QPainter painter(this);
+ if (update_rect != rect()) {
+ // kDebug(5011) << "Partial repaint";
+ const int sx = qRound(update_rect.x()/m_horizontalFactor);
+ const int sy = qRound(update_rect.y()/m_verticalFactor);
+ const int sw = qRound(update_rect.width()/m_horizontalFactor);
+ const int sh = qRound(update_rect.height()/m_verticalFactor);
+
+ painter.drawImage(update_rect,
+ m_frame.copy(sx, sy, sw, sh)
+ .scaled(update_rect.size(), Qt::IgnoreAspectRatio, transformation_mode));
+ } else {
+ //kDebug(5011) << "Full repaint" << width() << height() << m_frame.width() << m_frame.height();
- Qt::TransformationMode transformation_mode = Qt::SmoothTransformation;
- if( m_horizontalFactor >= 1.0 )
- transformation_mode = Qt::FastTransformation;
-
- //TODO: seems to have no purpose, remove
- if (false and m_repaint and !force_full_repaint) {
-// kDebug(5011) << "normal repaint";
- painter.drawImage(QRect(qRound(m_x*m_horizontalFactor), qRound(m_y*m_verticalFactor),
- qRound(m_w*m_horizontalFactor), qRound(m_h*m_verticalFactor)),
- m_frame.copy(m_x, m_y, m_w, m_h).scaled(qRound(m_w*m_horizontalFactor),
- qRound(m_h*m_verticalFactor),
- Qt::IgnoreAspectRatio, transformation_mode));
- } else {
- //kDebug(5011) << "resize repaint";
- const QRect rect = event->rect();
- if (!force_full_repaint and (rect.width() != width() || rect.height() != height())) {
- // kDebug(5011) << "Partial repaint";
- const int sx = rect.x()/m_horizontalFactor;
- const int sy = rect.y()/m_verticalFactor;
- const int sw = rect.width()/m_horizontalFactor;
- const int sh = rect.height()/m_verticalFactor;
- painter.drawImage(rect,
- m_frame.copy(sx, sy, sw, sh).scaled(rect.width(), rect.height(),
- Qt::IgnoreAspectRatio, transformation_mode));
- } else {
- kDebug(5011) << "Full repaint" << width() << height() << m_frame.width() << m_frame.height();
- painter.drawImage(QRect(0, 0, width(), height()),
- m_frame.scaled(m_frame.width() * m_horizontalFactor, m_frame.height() * m_verticalFactor,
- Qt::IgnoreAspectRatio, transformation_mode));
- force_full_repaint = false;
- }
+ painter.drawImage(rect(),
+ m_frame.scaled(size(), Qt::IgnoreAspectRatio, transformation_mode));
}
//draw local cursor ourselves, normal mouse pointer doesn't deal with scrolling
bool VncView::event(QEvent *event)
{
- switch (event->type()) {
- case QEvent::KeyPress:
- case QEvent::KeyRelease:
-// kDebug(5011) << "keyEvent";
- keyEventHandler(static_cast<QKeyEvent*>(event));
- return true;
- break;
- case QEvent::MouseButtonDblClick:
- case QEvent::MouseButtonPress:
- case QEvent::MouseButtonRelease:
- case QEvent::MouseMove:
-// kDebug(5011) << "mouseEvent";
- mouseEventHandler(static_cast<QMouseEvent*>(event));
- return true;
- break;
- case QEvent::Wheel:
-// kDebug(5011) << "wheelEvent";
- wheelEventHandler(static_cast<QWheelEvent*>(event));
- return true;
- break;
- case QEvent::WindowActivate: //input panel may have been closed, prevent IM from interfering with hardware keyboard
- setAttribute(Qt::WA_InputMethodEnabled, false);
- //fall through
- default:
- return RemoteView::event(event);
- }
+ switch (event->type()) {
+ case QEvent::KeyPress:
+ case QEvent::KeyRelease:
+ keyEventHandler(static_cast<QKeyEvent*>(event));
+ return true;
+
+ case QEvent::MouseButtonDblClick:
+ case QEvent::MouseButtonPress:
+ case QEvent::MouseButtonRelease:
+ case QEvent::MouseMove:
+ mouseEventHandler(static_cast<QMouseEvent*>(event));
+ return true;
+
+ case QEvent::Wheel:
+ wheelEventHandler(static_cast<QWheelEvent*>(event));
+ return true;
+
+ case QEvent::WindowActivate: //input panel may have been closed, prevent IM from interfering with hardware keyboard
+ setAttribute(Qt::WA_InputMethodEnabled, false);
+ //fall through
+ default:
+ return RemoteView::event(event);
+ }
}
//call with e == 0 to flush held events
else if(e->key() == Qt::Key_F7)
current_zoom = right_zoom;
else if (k) {
- // kDebug(5011) << "got '" << e->text() << "'.";
+ // kDebug(5011) << "got '" << e->text() << "'.";
vncThread.keyEvent(k, pressed);
} else {
kDebug(5011) << "nativeVirtualKey() for '" << e->text() << "' failed.";
//kDebug(5011) << event->commitString() << "|" << event->preeditString() << "|" << event->replacementLength() << "|" << event->replacementStart();
QString letters = event->commitString();
for(int i = 0; i < letters.length(); i++) {
- char k = letters.at(i).toLatin1(); //works with all 'normal' keys, not umlauts.
+ char k = letters.at(i).toLatin1();
if(!k) {
kDebug(5011) << "unhandled key";
continue;
}
}
-
-#include "moc_vncview.cpp"
+void VncView::useFastTransformations(bool enabled)
+{
+ if(enabled or zoomFactor() >= 1.0) {
+ transformation_mode = Qt::FastTransformation;
+ } else {
+ transformation_mode = Qt::SmoothTransformation;
+ update();
+ }
+}