From 1a5709501f94014d41987b956338bb6424b9f90c Mon Sep 17 00:00:00 2001 From: sr Date: Mon, 4 Feb 2013 19:50:31 +0100 Subject: Initial commit --- src/server/connectionframe/connectionframe.cpp | 278 +++++++++++++++++++++++++ src/server/connectionframe/connectionframe.h | 77 +++++++ 2 files changed, 355 insertions(+) create mode 100644 src/server/connectionframe/connectionframe.cpp create mode 100644 src/server/connectionframe/connectionframe.h (limited to 'src/server/connectionframe') diff --git a/src/server/connectionframe/connectionframe.cpp b/src/server/connectionframe/connectionframe.cpp new file mode 100644 index 0000000..1544c76 --- /dev/null +++ b/src/server/connectionframe/connectionframe.cpp @@ -0,0 +1,278 @@ +/* +# Copyright (c) 2009 - OpenSLX Project, Computer Center University of Freiburg +# +# This program is free software distributed under the GPL version 2. +# See http://openslx.org/COPYING +# +# If you have any feedback please consult http://openslx.org/feedback and +# send your suggestions, praise, or complaints to feedback@openslx.org +# +# General information about OpenSLX can be found at http://openslx.org/ +# ----------------------------------------------------------------------------- +# src/gui/connectionFrame.cpp +# ----------------------------------------------------------------------------- +*/ + + +#include "connectionframe.h" +#include "../net/client.h" +#include +#include +#include + +static QIcon *term = NULL, *cam = NULL, *eye = NULL; + +static QString backgroundStyle("background-color: %1; margin: 1px; border: 1px solid black; border-radius: 6px"); + +ConnectionFrame::ConnectionFrame(QWidget *parent, int width, int height) : + QGroupBox(parent), _client(NULL), _timerId(0), _timerCounter(0), _selected(false), _isTutor(false) +{ + + //defines the ui-stuff + // load icons first + if (term == NULL) + { + term = new QIcon(":terminal"); + cam = new QIcon(":cam32"); + eye = new QIcon(":eye"); + } + + //this->setAttribute(Qt::WA_OpaquePaintEvent); + + _mainLayout = new QBoxLayout(QBoxLayout::TopToBottom, this); + _mainLayout->setSpacing(1); + _mainLayout->setMargin(3); + _mainLayout->setAlignment(Qt::AlignHCenter); + + _iconLayout = new QBoxLayout(QBoxLayout::RightToLeft, NULL); + _iconLayout->setSpacing(1); + _iconLayout->setMargin(3); + + _lblUserName = new QLabel("Test", this); + _lblUserName->setStyleSheet(QString::fromUtf8("background-color: white; color: black;")); + _lblUserName->setAlignment(Qt::AlignHCenter); + //_lblUsername->resize(_lblUsername->width(), _lblUsername->font().pixelSize()); + + _lblHostName = new QLabel("PC", this); + _lblHostName->setStyleSheet(QString::fromUtf8("background-color: white; color: black;")); + _lblHostName->setAlignment(Qt::AlignHCenter); + + _icoCam = addIcon(cam); + _icoEye = addIcon(eye); + + _iconLayout->addWidget(_icoCam); + _iconLayout->addWidget(_icoEye); + _iconLayout->addStretch(); + + //_layout->addWidget(_imgScreen); + _mainLayout->addLayout(_iconLayout); + _mainLayout->addStretch(); + _mainLayout->addWidget(_lblUserName); + _mainLayout->addWidget(_lblHostName); + this->setLayout(_mainLayout); + this->setSize(width, height); + this->updateColor(); +} + +ConnectionFrame::~ConnectionFrame() +{ + // +} + +QLabel* ConnectionFrame::addIcon(const QIcon* icon) +{ + QLabel *label = new QLabel(this); + label->setPixmap(icon->pixmap(24, 24, QIcon::Normal, QIcon::On)); + label->setAttribute(Qt::WA_TranslucentBackground); + label->hide(); + _icons.append(label); + return label; +} + +void ConnectionFrame::setSize(int width, int height) +{ + this->resize(width, height); +} + +void ConnectionFrame::assignClient(Client* client) +{ + assert(_client == NULL); + connect(client, SIGNAL(destroyed(QObject*)), this, SLOT(onClientDisconnected(QObject*))); + connect(client, SIGNAL(thumbUpdated(Client*, const QPixmap&)), this, SLOT(onThumbUpdated(Client*, const QPixmap&))); + connect(client, SIGNAL(vncServerStateChange(Client*)), this, SLOT(onVncServerStateChange(Client*))); + connect(client, SIGNAL(vncClientStateChange(Client*)), this, SLOT(onVncClientStateChange(Client*))); + _client = client; + _computerId = client->computerId(); + _lblHostName->setText(client->ip()); + _lblHostName->setToolTip(client->host()); + _lblUserName->setText(client->name()); + showDefaultThumb(); + if (_timerId == 0) + _timerId = startTimer(1000 + qrand() % 150); + this->updateColor(); +} + +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); +} + +void ConnectionFrame::mouseReleaseEvent(QMouseEvent* event) +{ + event->accept(); + if (event->button() == Qt::LeftButton) + { + QApplication::setOverrideCursor(QCursor(Qt::OpenHandCursor)); + if (this->pos() != _previousPosition) { + qDebug("Moved"); + emit frameMoved(this); + } + else + { + qDebug("Clicked"); + emit clicked(this); + } + } +} + +void ConnectionFrame::enterEvent(QEvent* event) +{ + QApplication::setOverrideCursor(QCursor(Qt::OpenHandCursor)); + event->accept(); +} + +void ConnectionFrame::leaveEvent(QEvent* event) +{ + QApplication::setOverrideCursor(QCursor(Qt::ArrowCursor)); + event->accept(); +} + +void ConnectionFrame::mousePressEvent(QMouseEvent *event) +{ + if (event->button() == Qt::RightButton) + { + // Menu... + } + else + { + _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(); +} + +void ConnectionFrame::mouseMoveEvent(QMouseEvent *event) +{ + QApplication::setOverrideCursor(QCursor(Qt::ClosedHandCursor)); + move(mapToParent(event->pos()-_clickPoint)); + event->accept(); +} + +void ConnectionFrame::mouseDoubleClickEvent(QMouseEvent* event) +{ + emit doubleClicked(this); + event->accept(); +} + +void ConnectionFrame::paintEvent(QPaintEvent *event) +{ + QGroupBox::paintEvent(event); + if (_remoteScreen.isNull()) + return; + QPainter painter(this); + painter.drawPixmap((this->width() - _remoteScreen.width()) / 2, 4, _remoteScreen); + event->accept(); +} + +void ConnectionFrame::timerEvent(QTimerEvent* event) +{ + if (_client == NULL) + return; + ++_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); +} + +void ConnectionFrame::setSelection(bool selected) +{ + if (_selected == selected) + return; + _selected = selected; + this->updateColor(); +} + +void ConnectionFrame::updateColor() +{ + if (_client == NULL) + { + // Unconnected Frame + if (_selected) + this->setStyleSheet(backgroundStyle.arg("rgb(140, 140, 170)")); + else + this->setStyleSheet(backgroundStyle.arg("rgb(140, 140, 140)")); + for (QList::iterator it(_icons.begin()); it != _icons.end(); ++it) + (**it).hide(); + return; + } + _icoCam->setVisible(_client->isActiveVncServer()); + _icoEye->setVisible(_client->isActiveVncClient()); + + // Normal client, no special stuff active + + if (_selected && _isTutor) + this->setStyleSheet(backgroundStyle.arg("rgb(255, 220, 180)")); + else if (_isTutor) + this->setStyleSheet(backgroundStyle.arg("rgb(255, 180, 180)")); + else if (_selected) + this->setStyleSheet(backgroundStyle.arg("rgb(180, 180, 210)")); + else + this->setStyleSheet(backgroundStyle.arg("rgb(180, 180, 180)")); +} + +/** + * Slots + */ + +void ConnectionFrame::onClientDisconnected(QObject* client) +{ + assert(client == _client); + if (_timerId != 0) + { + killTimer(_timerId); + _timerId = 0; + } + _client = NULL; + _lblUserName->setText(QString()); + showDefaultThumb(); + this->updateColor(); +} + +void ConnectionFrame::onThumbUpdated(Client* client, const QPixmap& thumb) +{ + assert(client == _client); + _remoteScreen = thumb; + //_imgScreen->setPixmap(_remoteScreen); + this->repaint(); +} + +void ConnectionFrame::onVncServerStateChange(Client* client) +{ + this->updateColor(); +} + +void ConnectionFrame::onVncClientStateChange(Client* client) +{ + this->updateColor(); +} diff --git a/src/server/connectionframe/connectionframe.h b/src/server/connectionframe/connectionframe.h new file mode 100644 index 0000000..2b78056 --- /dev/null +++ b/src/server/connectionframe/connectionframe.h @@ -0,0 +1,77 @@ +#ifndef _CONNECTIONFRAME_H_ +#define _CONNECTIONFRAME_H_ +#include + +class Client; + +class ConnectionFrame : public QGroupBox +{ + +Q_OBJECT + +private: + + QString _computerId; + + QBoxLayout *_mainLayout; + QBoxLayout *_iconLayout; + QLabel *_lblUserName; + QLabel *_lblHostName; + + QLabel *_icoCam, *_icoEye; + QList _icons; + + QPixmap _remoteScreen; + + QPoint _clickPoint; + QPoint _previousPosition; + + Client *_client; + + int _timerId, _timerCounter; + bool _selected; + bool _isTutor; + + void showDefaultThumb(); + void updateColor(); + QLabel* addIcon(const QIcon* icon); + +public: + ConnectionFrame(QWidget* parent, int width, int height); + virtual ~ConnectionFrame(); + + const QPixmap& getFramePixmap() const { return _remoteScreen; } + void setSize(int width, int height); + void assignClient(Client *client); + void setSelection(bool selected); + const inline bool selected() const { return _selected; } + + const QString& computerId() const { return _computerId; } + Client* client() const { return _client; } + + inline const bool isTutor() const { return _isTutor; } + inline void setTutor(bool b) { _isTutor = b; } + +protected: + void mouseDoubleClickEvent(QMouseEvent* event); + void mouseReleaseEvent(QMouseEvent* e); + void enterEvent(QEvent* event); + void leaveEvent(QEvent* event); + void mousePressEvent(QMouseEvent* event); + void mouseMoveEvent(QMouseEvent* event); + void paintEvent(QPaintEvent *event); + void timerEvent(QTimerEvent* event); + +signals: + void frameMoved(ConnectionFrame* frame); + void doubleClicked(ConnectionFrame* frame); + void clicked(ConnectionFrame* frame); + +private slots: + void onClientDisconnected(QObject* client); + void onThumbUpdated(Client* client, const QPixmap& thumb); + void onVncServerStateChange(Client* client); + void onVncClientStateChange(Client* client); +}; + +#endif -- cgit v1.2.3-55-g7522