diff options
Diffstat (limited to 'src/gui/connectionFrame.cpp')
| -rw-r--r-- | src/gui/connectionFrame.cpp | 557 |
1 files changed, 557 insertions, 0 deletions
diff --git a/src/gui/connectionFrame.cpp b/src/gui/connectionFrame.cpp new file mode 100644 index 0000000..e889991 --- /dev/null +++ b/src/gui/connectionFrame.cpp @@ -0,0 +1,557 @@ +/* +# 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 <src/gui/connectionFrame.h> +#include <src/gui/dialog.h> +#include <src/gui/mainWindow.h> +#include <iostream> +extern "C" +{ +#include <rfb/rfbclient.h> +} +#include <src/core/pvsConnectionManager.h> + + +ConnectionFrame::ConnectionFrame(QWidget *parent) : + QGroupBox(parent) +{ + + //defines the ui-stuff + + _gL = new QGridLayout(this); + _gL->setSpacing(6); + _gL->setMargin(1); + + _split = new QSplitter(this); + _split->setOrientation(Qt::Vertical); + + _frame = new Frame("", _split); + _frame->setConFrame(this); + _split->addWidget(_frame); + + _conFrameTaskbar = new QWidget(_split); + _conFrameTaskbar->setMaximumHeight(30); + + _gLayout = new QGridLayout(_conFrameTaskbar); + _gLayout->setMargin(0); + _gLayout->setSpacing(0); + + _hLayoutInCfTaskbar = new QHBoxLayout(); + + _username = new QLabel(_conFrameTaskbar); + _username->setStyleSheet(QString::fromUtf8("background-color: rgb(150, 150, 168);")); + _username->setAlignment(Qt::AlignLeft); + + _hLayoutInCfTaskbar->addWidget(_username); + + _dozentContaimner = new QLabel(_conFrameTaskbar); + _dozentContaimner->setStyleSheet(QString::fromUtf8("background-color: rgb(150, 150, 168);")); + _dozentContaimner->setAlignment(Qt::AlignRight); + _dozentContaimner->setMaximumSize(QSize(20, 20)); + _dozentContaimner->setScaledContents(true); + + _hLayoutInCfTaskbar->addWidget(_dozentContaimner); + + _dozentContaimner->setDisabled(true); + + _status = new QLabel(_conFrameTaskbar); + _status->setStyleSheet(QString::fromUtf8("background-color: rgb(150, 150, 168);")); + _status->setAlignment(Qt::AlignRight); + _status->setMaximumSize(QSize(22, 21)); + + _hLayoutInCfTaskbar->addWidget(_status); + + _gLayout->addLayout(_hLayoutInCfTaskbar, 0, 0, 1, 1); + _split->addWidget(_conFrameTaskbar); + + _gL->addWidget(_split, 0, 0, 1, 1); + + this->setLayout(_gL); + + setInitSize(190,168); + + initFrame(); + + nat_height = 0; + nat_width = 0; + _ratio = 100; + overSized = false; + _fullscreen = false; + _closeup = false; + active = false; + _isOnProjekt = false; + isClientOnline = true; + + //slots and signals + + DelDummy = new QAction(tr("&Remove dummy..."),this); + connect(DelDummy, SIGNAL(triggered()), this, SLOT(delDummy())); + lockClient = new QAction(tr("&Lock Client(s)"),this); + connect(lockClient, SIGNAL(triggered()), this, SLOT(on_lock())); + uLockClient = new QAction(tr("&Unlock Client(s)"),this); + connect(uLockClient, SIGNAL(triggered()), this, SLOT(on_unlock())); + /*invertlockClient = new QAction(tr("&Invertlock Client(s)"),this); + connect(invertlockClient, SIGNAL(triggered()), this, SLOT(on_lock_invert())); + LockAllClient = new QAction(tr("&Lock all Client(s)"),this); + connect(LockAllClient, SIGNAL(triggered()), this, SLOT(on_lock_all())); + uLockAllClient = new QAction(tr("&Unlock all Client(s)"),this); + connect(uLockAllClient, SIGNAL(triggered()), this, SLOT(on_unlock_all()));*/ + msgLockClient = new QAction(tr("&MsgLock Client(s)"),this); + connect(msgLockClient, SIGNAL(triggered()), this, SLOT(on_lock_with_message())); + msgLockAllClient = new QAction(tr("&MsgLock all Client(s)"),this); + connect(msgLockAllClient, SIGNAL(triggered()), this, SLOT(on_lock_all_with_message())); + msgClient = new QAction(tr("&Message Client(s)"),this); + connect(msgClient, SIGNAL(triggered()), this, SLOT(on_message())); + project = new QAction(tr("&Projection"),this); + connect(project, SIGNAL(triggered()), this, SLOT(on_projection())); + uproject = new QAction(tr("&Unprojection"),this); + connect(uproject, SIGNAL(triggered()), this, SLOT(on_unprojection())); + /*rHelp = new QAction(tr("&Remote Help"),this); + connect(rHelp, SIGNAL(triggered()), this, SLOT(on_remoteHelp()));*/ + + //connect(_frame, SIGNAL(clicked()), this, SLOT(on_click())); + + //menu entries + + menu = new QMenu(this); + menu->addAction(DelDummy); + menu->addSeparator(); + menu->addAction(lockClient); + menu->addAction(uLockClient); + /*menu->addAction(invertlockClient); + menu->addAction(LockAllClient); + menu->addAction(uLockAllClient);*/ + menu->addAction(msgLockClient); + menu->addAction(msgLockAllClient); + menu->addAction(msgClient); + menu->addAction(project); + menu->addAction(uproject); + //menu->addAction(rHelp); + + this->show(); +} + +ConnectionFrame::~ConnectionFrame() +{ + +} + +QString ConnectionFrame::getTitle() // get frame title +{ + return title(); +} + +void ConnectionFrame::setTheTitle(QString title) // set frame title +{ + if (title.isNull()) return; + setTitle(title); +} + +QString ConnectionFrame::getTaskbarTitle() // get taskbar title +{ + if (!_username->text().isNull()) + return _username->text(); + else + return _myConnection->getIp(); +} + +void ConnectionFrame::setTaskbarTitle(QString title) // set taskbar title +{ + _username->setText(title); + _frame->ip = title; +} + +void ConnectionFrame::setInitSize(int w, int h) +{ + resize(w, h); + _frame->resize(w, h); + _conFrameTaskbar->resize(w, h); + prev_height = h; + prev_width = w; + init_w = w; + init_h = h; +} + +void ConnectionFrame::Resize(int w, int h) +{ + resize(w, h); + _frame->resize(w, h); +} + +void ConnectionFrame::initFrame() +{ + _clientStatus = QPixmap(":/offline"); + _clientDozent = QPixmap(":/dozent2"); + _dozentContaimner->setPixmap(_clientDozent.scaled(3*_dozentContaimner->size()/4, + Qt::KeepAspectRatio, Qt::SmoothTransformation)); +} + + +void ConnectionFrame::setConnection(PVSClient* newConnection) +{ + if (newConnection) + { + _myConnection = newConnection; + _myConnection->setConnectionFrame(this); + const QString userName = QString( + _myConnection->getUserName().toUtf8().data()); + if (_myConnection->getVNCConnection() && _myConnection->getVNCConnection()->getVNCClientThread()) + { + _myConnection->getVNCConnection()->setFrame(this); + _frame->setVNCThreadConnection(_myConnection->getVNCConnection()->getVNCClientThread()); + setActive(true); + setToolTip(userName); + setTitle(userName); + } + else + { + setToolTip(userName); + setTitle(userName); + } + } + +} + +/* + * We set a new VNCConnection to the pvsmgr with a new quality. + * To do this, that is very easy. At this point we have already a ruuning + * Connection between the server an the client. This connection is controlled in a thread. + * So we disconnect all Qt-Signals on this thread and we terminate the thread. + * After do this we have to set a new thread(VNCClientThread) and connect the signals again. + * + * When you want to read about this, please check the developper's book. + */ +void ConnectionFrame::resetConnectionWithQuality(int quality) +{ + if (getFrame()) + { + _myConnection->getVNCConnection()->reInitClientWithQuality(quality); + getFrame()->stopVNCThreadConnection(); + getFrame()->setVNCThreadConnection(_myConnection->getVNCConnection()->getVNCClientThread()); + getFrame()->update(); + } +} + +void ConnectionFrame::delDummy() +{ + MainWindow::getConnectionWindow()->removeFromList(this); +} + +void ConnectionFrame::on_projection() +{ + MainWindow::getConnectionList()->on_projection(); +} + +void ConnectionFrame::on_unprojection() +{ + MainWindow::getConnectionList()->on_unprojection(); +} + +void ConnectionFrame::on_lock() +{ + if (_myConnection->getVNCConnection()) + MainWindow::getConnectionWindow()->lockStation(_myConnection); +} + +void ConnectionFrame::on_unlock() +{ + if (_myConnection->getVNCConnection()) + MainWindow::getConnectionWindow()->unlockStation(_myConnection); +} + +void ConnectionFrame::on_message() +{ + Dialog msgD; + QString myString = NULL; + int result = msgD.exec(); + + if (result == 1) + { + myString = MainWindow::getWindow()->getMsgDialog(); + if(!myString.isEmpty()) + MainWindow::getConnectionWindow()->messageStations("BROADCAST",myString); + } +} + +void ConnectionFrame::on_lock_with_message() +{ + Dialog msgD; + QString myString = NULL; + int result = msgD.exec(); + + if(result == 1) + { + myString = MainWindow::getWindow()->getMsgDialog(); + if(!myString.isEmpty()) + { + MainWindow::getConnectionWindow()->lockStationsWithMessage(myString); + } + } +} + +void ConnectionFrame::on_lock_all_with_message() +{ + QString myString = NULL; + Dialog msgD; + int result = msgD.exec(); + + if(result == 1) + { + myString = MainWindow::getWindow()->getMsgDialog(); + if(!myString.isEmpty()) + { + MainWindow::getConnectionWindow()->lockAllStationsWithMessage(myString); + } + } +} + +void ConnectionFrame::on_lock_all() +{ + MainWindow::getConnectionWindow()->lockAllStations(); +} + +void ConnectionFrame::on_unlock_all() +{ + MainWindow::getConnectionWindow()->unlockAllStations(); +} + +void ConnectionFrame::on_lock_invert() +{ + //MainWindow::getConnectionWindow()->lockInvertStations(); +} + +void ConnectionFrame::on_remoteHelp() +{ + +} + +void ConnectionFrame::setIgnoreRatio(bool ignore) +{ + ignore_ratio = ignore; +} + +void ConnectionFrame::setFullscreen(bool fs) +{ + _fullscreen = fs; + setIgnoreRatio(!fs); +} + +void ConnectionFrame::setCloseup(bool cu) +{ + _closeup = cu; + setIgnoreRatio(false); +} + +void ConnectionFrame::setInteractive(bool doit) +{ + viewOnly = !doit; +} + +void ConnectionFrame::setActive(bool activate) +{ + active = activate; +} + +void ConnectionFrame::setDummy(bool dummy) +{ + _dummy = dummy; + if (_dummy) + { + _clientStatus = QPixmap(0, 0); //ein leeres Pixmap erstellen + _clientStatus.fill(Qt::white); // benöigt bevor man drin zeichen + _clientStatus = QPixmap(":/offline"); + _status->setMaximumSize(QSize(30, 30)); + _status->setPixmap(_clientStatus.scaled(29,27, + Qt::KeepAspectRatio, Qt::SmoothTransformation)); + //_status->setPixmap(clientStatus.scaled(3*_status->size()/4, + // Qt::KeepAspectRatio, Qt::SmoothTransformation)); + //setConnection(NULL); + } + else + { + _clientStatus = QPixmap(0, 0); //ein leeres Pixmap erstellen + _clientStatus.fill(Qt::white); // benöigt bevor man drin zeichen + _clientStatus = QPixmap(":/online"); + _status->setMaximumSize(QSize(30, 30)); + _status->setPixmap(_clientStatus.scaled(29,27, + Qt::KeepAspectRatio, Qt::SmoothTransformation)); + //_status->setPixmap(clientStatus.scaled(3*_status->size()/4, + // Qt::KeepAspectRatio, Qt::SmoothTransformation)); + } + // } +} + +void ConnectionFrame::setFrameRate(int newRate) +{ + //newRate = 5000; +} + +void ConnectionFrame::mouseReleaseEvent ( QMouseEvent * e ) +{ + if (e->button() == Qt::LeftButton) + { + QPoint relPoint = mapToParent(e->pos()); + QRect r = MainWindow::getConnectionWindow()->frameGeometry(); + /* + * We don't want to move the client in a position where we can't catch it again! + */ + if (relPoint.x() > r.width() || relPoint.y() > r.height() || + relPoint.x() < 0 || relPoint.y() < 0) + move(_previousPoint); + QApplication::setOverrideCursor(QCursor(Qt::OpenHandCursor)); + } +} + +void ConnectionFrame::enterEvent ( QEvent * event ) +{ + update(); + QApplication::setOverrideCursor(QCursor(Qt::OpenHandCursor)); + if (!_dummy) + _frame->setToolButtonListVisible(true); +} + +void ConnectionFrame::leaveEvent ( QEvent * event ) +{ + QApplication::setOverrideCursor(QCursor(Qt::ArrowCursor)); + if (!_dummy) + _frame->setToolButtonListVisible(false); +} + +void ConnectionFrame::mousePressEvent(QMouseEvent *event) +{ + if (event->button() == Qt::RightButton) + { + if (!_dummy) + { + DelDummy->setDisabled(true); + menu->exec(QCursor::pos()); + } + else + { + foreach (QAction* a, menu->actions()) + a->setDisabled(true); + DelDummy->setDisabled(false); + menu->exec(QCursor::pos()); + } + } + else + { + _clickPoint = event->pos(); + _previousPoint = pos(); + QApplication::setOverrideCursor(QCursor(Qt::ClosedHandCursor)); + } + /* + * On click, the window have to be on the top-level. + */ + activateWindow(); + raise(); + update(); +} + +void ConnectionFrame::mouseMoveEvent(QMouseEvent *event) +{ + QApplication::setOverrideCursor(QCursor(Qt::ClosedHandCursor)); + move(mapToParent(event->pos()-_clickPoint)); +} + +void ConnectionFrame::paintCloseUp(int w, int h) +{ + + + if (!_frame->image().isNull()) + { + /*this->setFixedWidth(w); + _conFrameTaskbar->setMaximumWidth(w); + resize(w, h);*/ + resizeComponent(w, h); + setMaximumSize(w,h); + resize(w, h); + } + else + { + std::cout << "pixel is NULL" << std::endl; + } + +} + +void ConnectionFrame::resizeComponent(int w, int h) +{ + int th = (h*_conFrameTaskbar->width())/w; + int uh = (h*_username->width())/w; + _conFrameTaskbar->setMaximumSize(w, th); + _conFrameTaskbar->resize(w, th); + _username->setMaximumSize(w, uh); + _username->resize(w,uh); +} + +void ConnectionFrame::setSource() +{ + _clientStatus = QPixmap(0, 0); //ein leeres Pixmap erstellen + _clientStatus.fill(Qt::white); // benöigt bevor man drin zeichen + _clientStatus = QPixmap(":/source"); + _status->setMaximumSize(QSize(62, 30)); + _status->setPixmap(_clientStatus.scaled(61,29, + Qt::KeepAspectRatio, Qt::SmoothTransformation)); + _isOnProjekt = true; +} + +void ConnectionFrame::setTarget() +{ + _clientStatus = QPixmap(0, 0); //ein leeres Pixmap erstellen + _clientStatus.fill(Qt::white); // benöigt bevor man drin zeichen + _clientStatus = QPixmap(":/target"); + _status->setMaximumSize(QSize(62, 30)); + _status->setPixmap(_clientStatus.scaled(61,29, + Qt::KeepAspectRatio, Qt::SmoothTransformation)); +} + +void ConnectionFrame::setUnproject() +{ + _clientStatus = QPixmap(0, 0); //ein leeres Pixmap erstellen + _clientStatus.fill(Qt::white); // benöigt bevor man drin zeichen + _clientStatus = QPixmap(":/online"); + _status->setMaximumSize(QSize(30, 30)); + _status->setPixmap(_clientStatus.scaled(29,27, + Qt::KeepAspectRatio, Qt::SmoothTransformation)); + _isOnProjekt = false; +} + +void ConnectionFrame::setDozent(bool isDozent) +{ + if (isDozent) + _dozentContaimner->setDisabled(false); + else + _dozentContaimner->setDisabled(true); +} + +void ConnectionFrame::on_click() +{ + //std::cout << "HALLO! WAS?" << std::endl; +} + +const QPixmap* ConnectionFrame::getFramePixmap() +{ + if (_frame == NULL) return NULL; + return _frame->pixmap(); +} + +Frame* ConnectionFrame::getFrame() +{ + if(_myConnection && _myConnection->getVNCConnection()) return _frame; + return NULL; +}; + +//Frame* ConnectionFrame::_frame = NULL; |
