From 9d73e385153656ef998cc8f6378bb01ff36b2090 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Wed, 2 Nov 2016 19:24:07 +0100 Subject: [server] Rewrite positioning logic of connection frames This fixes sevceral bugs: * Frames moved into virtually expanded area (for keeping aspect ratio) could be out of bounds after a window resize before * Finding a free slot to place a frame was slightly sped up * Finding a free slot is not used when loading a room layout, as it was (still is) pretty sluggish for the user * Snap to grid worked incorrectly, did not pick closest grid position --- src/server/connectionframe/connectionframe.cpp | 45 +++++++++++++++++--------- 1 file changed, 29 insertions(+), 16 deletions(-) (limited to 'src/server/connectionframe/connectionframe.cpp') diff --git a/src/server/connectionframe/connectionframe.cpp b/src/server/connectionframe/connectionframe.cpp index 90d72da..205433b 100644 --- a/src/server/connectionframe/connectionframe.cpp +++ b/src/server/connectionframe/connectionframe.cpp @@ -15,6 +15,7 @@ #include "connectionframe.h" +#include "../mainwindow/mainwindow.h" #include "../net/client.h" #include #include @@ -59,14 +60,17 @@ static QString style_disconnected( static QIcon *term = NULL, *cam = NULL, *eye = NULL, *lock = NULL; +bool ConnectionFrame::paintDisabled = false; + /** * Initialize frame for connected client. * @param parent * @param width * @param height */ -ConnectionFrame::ConnectionFrame(QWidget *parent, int width, int height) : - QGroupBox(parent), _client(NULL), _timerId(0), _timerCounter(0), _isSelected(false), _isTutor(false) +ConnectionFrame::ConnectionFrame(MainWindow* main, QWidget *parent) : + QGroupBox(parent), _client(NULL), _timerId(0), _timerCounter(0), _isSelected(false), _isTutor(false), + _mainWindow(main) { //defines the ui-stuff @@ -116,7 +120,6 @@ ConnectionFrame::ConnectionFrame(QWidget *parent, int width, int height) : _mainLayout->addWidget(_lblUserName); _mainLayout->addWidget(_lblHostName); this->setLayout(_mainLayout); - this->setSize(width, height); this->updateAppearance(); this->updateLabels(); } @@ -129,6 +132,25 @@ ConnectionFrame::~ConnectionFrame() _iconLayout->deleteLater(); } +void ConnectionFrame::setGridPosition(const QPoint& pos) +{ + _gridPosition = pos; + updateGeometry(); +} + +void ConnectionFrame::setGridPosition(int x, int y) +{ + setGridPosition(QPoint(x, y)); +} + +void ConnectionFrame::updateGeometry() +{ + const QRect rect = _mainWindow->calcFrameGeometry(this); + setGeometry(rect); + if (this->_client == NULL) + showDefaultThumb(); +} + /** * Add icon to connection frame. * @param icon @@ -144,18 +166,6 @@ QLabel* ConnectionFrame::addIcon(const QIcon* icon) return label; } -/** - * Set size of connectionFrame. - * @param width - * @param height - */ -void ConnectionFrame::setSize(int width, int height) -{ - this->resize(width, height); - if (this->_client == NULL) - showDefaultThumb(); -} - /** * Assign client to connectionFrame. * Set hostName, userName and tutor status to display. @@ -216,7 +226,7 @@ void ConnectionFrame::mouseReleaseEvent(QMouseEvent* event) QApplication::setOverrideCursor(QCursor(Qt::OpenHandCursor)); // Only recognize a move if the distance is larger than _startDragDistance if ((this->pos() - _previousPosition).manhattanLength() > _startDragDistance ) { - emit frameMoved(true, this); + emit frameMoved(this); } else { qDebug("Clicked"); move(_previousPosition); @@ -292,6 +302,9 @@ void ConnectionFrame::mouseDoubleClickEvent(QMouseEvent* event) */ void ConnectionFrame::paintEvent(QPaintEvent *event) { + if (ConnectionFrame::paintDisabled) { + return; + } QGroupBox::paintEvent(event); if (_remoteScreen.isNull()) { return; -- cgit v1.2.3-55-g7522