From 972162123678dbf4fb7fcebf1b561b52488d1cb6 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Thu, 2 Aug 2018 18:44:39 +0200 Subject: [server] Show drop position when moving frame around --- src/server/connectionframe/connectionframe.cpp | 50 ++++++++++++++------------ src/server/connectionframe/connectionframe.h | 3 +- 2 files changed, 28 insertions(+), 25 deletions(-) (limited to 'src/server/connectionframe') diff --git a/src/server/connectionframe/connectionframe.cpp b/src/server/connectionframe/connectionframe.cpp index e8d8349..c2bba70 100644 --- a/src/server/connectionframe/connectionframe.cpp +++ b/src/server/connectionframe/connectionframe.cpp @@ -60,6 +60,8 @@ static QString style_disconnected( static QIcon *term = nullptr, *cam = nullptr, *eye = nullptr, *lock = nullptr; +static const int START_DRAG_DISTANCE = 40; + bool ConnectionFrame::paintDisabled = false; /** @@ -217,26 +219,6 @@ void ConnectionFrame::updateLabels() calcDesiredThumbSize(this->size()); } -/** - * Handle mouse release event on frame. - * Check if frame was clicked or moved, if not moved enough, the event is handled as click. - * @param event - */ -void ConnectionFrame::mouseReleaseEvent(QMouseEvent* event) -{ - event->accept(); - if (event->button() == Qt::LeftButton) { - QApplication::setOverrideCursor(QCursor(Qt::OpenHandCursor)); - // Only recognize a move if the distance is larger than _startDragDistance - if ((this->pos() - _previousPosition).manhattanLength() > _startDragDistance ) { - emit frameMoved(this); - } else { - move(_previousPosition); - emit clicked(this); - } - } -} - /** * Handle if mouse reaches frame. * @param event @@ -263,18 +245,17 @@ void ConnectionFrame::leaveEvent(QEvent* event) */ void ConnectionFrame::mousePressEvent(QMouseEvent *event) { + event->accept(); if (event->button() == Qt::RightButton) { // Menu... - } else { + } else if (event->button() == Qt::LeftButton) { _clickPoint = event->pos(); _previousPosition = this->pos(); QApplication::setOverrideCursor(QCursor(Qt::ClosedHandCursor)); } // On click, the window has to be on the top-level. - activateWindow(); raise(); update(); - event->accept(); } /** @@ -283,9 +264,32 @@ void ConnectionFrame::mousePressEvent(QMouseEvent *event) */ void ConnectionFrame::mouseMoveEvent(QMouseEvent *event) { + event->accept(); QApplication::setOverrideCursor(QCursor(Qt::ClosedHandCursor)); move(mapToParent(event->pos() - _clickPoint)); + if ((this->pos() - _previousPosition).manhattanLength() > START_DRAG_DISTANCE) { + emit frameMoving(this); + } +} + +/** + * Handle mouse release event on frame. + * Check if frame was clicked or moved, if not moved enough, the event is handled as click. + * @param event + */ +void ConnectionFrame::mouseReleaseEvent(QMouseEvent* event) +{ event->accept(); + QApplication::setOverrideCursor(QCursor(Qt::OpenHandCursor)); + if (event->button() == Qt::LeftButton) { + // Only recognize a move if the distance is larger than _startDragDistance + if ((this->pos() - _previousPosition).manhattanLength() > START_DRAG_DISTANCE) { + emit frameMoved(this); + } else { + move(_previousPosition); + emit clicked(this); + } + } } /** diff --git a/src/server/connectionframe/connectionframe.h b/src/server/connectionframe/connectionframe.h index ba5f235..1d004e6 100644 --- a/src/server/connectionframe/connectionframe.h +++ b/src/server/connectionframe/connectionframe.h @@ -41,8 +41,6 @@ private: bool _isTutor; bool _isFromRoomplan; - static const int _startDragDistance = 40; - void showDefaultThumb(); void calcDesiredThumbSize(const QSize &frameSize); QLabel* addIcon(const QIcon* icon); @@ -85,6 +83,7 @@ protected: void timerEvent(QTimerEvent* event); signals: + void frameMoving(ConnectionFrame* frame); void frameMoved(ConnectionFrame* frame); void doubleClicked(ConnectionFrame* frame); void clicked(ConnectionFrame* frame); -- cgit v1.2.3-55-g7522