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 +++++++++++++++++--------- src/server/connectionframe/connectionframe.h | 26 ++++++++------- 2 files changed, 43 insertions(+), 28 deletions(-) (limited to 'src/server/connectionframe') 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; diff --git a/src/server/connectionframe/connectionframe.h b/src/server/connectionframe/connectionframe.h index 9d86c70..2549ae8 100644 --- a/src/server/connectionframe/connectionframe.h +++ b/src/server/connectionframe/connectionframe.h @@ -3,6 +3,8 @@ #include #include "../net/client.h" +class MainWindow; + /** * Class for representing the clients of current session, with a specific frame * displaying username and hostname for each one. @@ -29,11 +31,8 @@ private: QPoint _clickPoint; QPoint _previousPosition; - QPoint _currentPosition; - QPoint _gridPosition; - Client *_client; int _timerId, _timerCounter; @@ -45,22 +44,25 @@ private: void showDefaultThumb(); QLabel* addIcon(const QIcon* icon); + MainWindow *_mainWindow; + public: - ConnectionFrame(QWidget* parent, int width, int height); + + static bool paintDisabled; + + ConnectionFrame(MainWindow* main, QWidget* parent); virtual ~ConnectionFrame(); + const inline QPoint getGridPosition() const { return _gridPosition; } + void setGridPosition(int x, int y); + void setGridPosition(const QPoint& pos); + void updateGeometry(); + const QPixmap& getFramePixmap() const { return _remoteScreen; } - void setSize(int width, int height); - const inline QPoint& getPreviousPosition() const { return _previousPosition; } void assignClient(Client *client); void setSelection(bool selected); const inline bool isSelected() const { return _isSelected; } - inline void setGridPosition(QPoint pos) { _gridPosition = pos; } - inline QPoint getGridPosition() const { return _gridPosition; }; - const inline void setCurrentPosition(QPoint position) { _currentPosition = position; } - const inline QPoint& getCurrentPosition() const { return _currentPosition; } - const QString& computerId() const { return _computerId; } void setComputerId(QString computerId) { if (_client != NULL) return; _computerId = computerId; updateLabels(); } Client* client() const { return _client; } @@ -79,7 +81,7 @@ protected: void timerEvent(QTimerEvent* event); signals: - void frameMoved(bool activateTrash, ConnectionFrame* frame); + void frameMoved(ConnectionFrame* frame); void doubleClicked(ConnectionFrame* frame); void clicked(ConnectionFrame* frame); -- cgit v1.2.3-55-g7522