diff options
Diffstat (limited to 'src/server/connectionframe')
-rw-r--r-- | src/server/connectionframe/connectionframe.cpp | 41 | ||||
-rw-r--r-- | src/server/connectionframe/connectionframe.h | 8 |
2 files changed, 30 insertions, 19 deletions
diff --git a/src/server/connectionframe/connectionframe.cpp b/src/server/connectionframe/connectionframe.cpp index fb2c96a..875e031 100644 --- a/src/server/connectionframe/connectionframe.cpp +++ b/src/server/connectionframe/connectionframe.cpp @@ -17,9 +17,9 @@ #include "connectionframe.h" #include "../mainwindow/mainwindow.h" #include "../net/client.h" -#include <QPixmap> #include <QImage> #include <cassert> +#include <cmath> static QString style_student( "QLabel{ background-color: #FFF; border-radius: 2px; color: black;} \ @@ -173,7 +173,7 @@ void ConnectionFrame::assignClient(Client* client) { assert(_client == NULL); connect( client, SIGNAL(disconnected()), this, SLOT(onClientDisconnected()) ); - connect( client, SIGNAL(thumbUpdated(Client*, const QPixmap&, const QByteArray&)), this, SLOT(onThumbUpdated(Client*, const QPixmap&, const QByteArray&)) ); + connect( client, SIGNAL(thumbUpdated(Client*, const QImage&)), this, SLOT(onThumbUpdated(Client*, const QImage&)) ); connect( client, SIGNAL(vncServerStateChange(Client*)), this, SLOT(updateAppearance())); connect( client, SIGNAL(vncClientStateChange(Client*)), this, SLOT(updateAppearance())); connect( client, SIGNAL(stateChanged()), this, SLOT(updateAppearance())); @@ -192,11 +192,15 @@ void ConnectionFrame::assignClient(Client* client) */ void ConnectionFrame::showDefaultThumb() { - const int width = this->width() - 6; - const int height = this->height() - 8 - _lblHostName->height() - _lblUserName->height(); - _remoteScreen = term->pixmap(width, height, QIcon::Normal, QIcon::On); - this->repaint(); - //_imgScreen->setPixmap(_remoteScreen); + _remoteScreen = term->pixmap(_desiredThumbSize, QIcon::Normal, QIcon::On).toImage(); + this->update(); +} + +void ConnectionFrame::calcDesiredThumbSize(const QSize &frameSize) +{ + const int width = frameSize.width() - 10; + const int height = frameSize.height() - 12 - _lblHostName->height() - (_lblUserName->isHidden() ? 0 : _lblUserName->height()); + _desiredThumbSize = QSize(width, height); } void ConnectionFrame::updateLabels() @@ -210,6 +214,7 @@ void ConnectionFrame::updateLabels() _lblUserName->setText(_client->name()); _lblUserName->show(); } + calcDesiredThumbSize(this->size()); } /** @@ -226,7 +231,6 @@ void ConnectionFrame::mouseReleaseEvent(QMouseEvent* event) if ((this->pos() - _previousPosition).manhattanLength() > _startDragDistance ) { emit frameMoved(this); } else { - qDebug("Clicked"); move(_previousPosition); emit clicked(this); } @@ -308,8 +312,16 @@ void ConnectionFrame::paintEvent(QPaintEvent *event) return; } + if (!_desiredThumbSize.isEmpty()) { + if (abs(100 - ((_remoteScreen.width() * 100) / _desiredThumbSize.width())) > 5 + && abs(100 - ((_remoteScreen.height() * 100) / _desiredThumbSize.height())) > 5) { + qDebug() << "Rescale thumb" << _remoteScreen.size() << "to" << _desiredThumbSize; + _remoteScreen = _remoteScreen.scaled(_desiredThumbSize, Qt::KeepAspectRatio, Qt::SmoothTransformation); + } + } + QPainter painter(this); - painter.drawPixmap((this->width() - _remoteScreen.width()) / 2, 4, _remoteScreen); + painter.drawImage((this->width() - _remoteScreen.width()) / 2, 4, _remoteScreen); event->accept(); } @@ -324,9 +336,7 @@ void ConnectionFrame::timerEvent(QTimerEvent* /* event */ ) ++_timerCounter; if (_client->isActiveVncServer() && _timerCounter % 5 != 0) return; - const int width = this->width() - 8; - const int height = this->height() - 9 - _lblHostName->height() - _lblUserName->height(); - _client->requestThumb(width, height); + _client->requestThumb(_desiredThumbSize); } /** @@ -417,9 +427,9 @@ void ConnectionFrame::onClientDisconnected() _timerId = 0; } _client = NULL; - showDefaultThumb(); updateLabels(); updateAppearance(); + showDefaultThumb(); } /** @@ -427,11 +437,10 @@ void ConnectionFrame::onClientDisconnected() * @param client * @param thumb */ -void ConnectionFrame::onThumbUpdated(Client* client, const QPixmap& thumb, const QByteArray&) +void ConnectionFrame::onThumbUpdated(Client* client, const QImage& thumb) { assert(client == _client); _remoteScreen = thumb; - //_imgScreen->setPixmap(_remoteScreen); - this->repaint(); + this->update(); } diff --git a/src/server/connectionframe/connectionframe.h b/src/server/connectionframe/connectionframe.h index 4558406..898d97a 100644 --- a/src/server/connectionframe/connectionframe.h +++ b/src/server/connectionframe/connectionframe.h @@ -27,11 +27,12 @@ private: QLabel *_icoCam, *_icoEye, *_icoLock; QList<QLabel*> _icons; - QPixmap _remoteScreen; + QImage _remoteScreen; QPoint _clickPoint; QPoint _previousPosition; QPoint _gridPosition; + QSize _desiredThumbSize; Client *_client; @@ -43,6 +44,7 @@ private: static const int _startDragDistance = 40; void showDefaultThumb(); + void calcDesiredThumbSize(const QSize &frameSize); QLabel* addIcon(const QIcon* icon); MainWindow *_mainWindow; @@ -59,7 +61,6 @@ public: void setGridPosition(const QPoint& pos); void updateGeometry(); - const QPixmap& getFramePixmap() const { return _remoteScreen; } void assignClient(Client *client); void setSelection(bool selected); inline bool isSelected() { return _isSelected; } @@ -73,6 +74,7 @@ public: void setTutor(bool b); protected: + void resizeEvent(QResizeEvent* event) { calcDesiredThumbSize(event->size()); } void mouseDoubleClickEvent(QMouseEvent* event); void mouseReleaseEvent(QMouseEvent* e); void enterEvent(QEvent* event); @@ -89,7 +91,7 @@ signals: private slots: void onClientDisconnected(); - void onThumbUpdated(Client* client, const QPixmap& thumb, const QByteArray& rawImage); + void onThumbUpdated(Client* client, const QImage& thumb); void updateAppearance(); void updateLabels(); }; |