diff options
| author | sr | 2013-02-04 19:50:31 +0100 |
|---|---|---|
| committer | sr | 2013-02-04 19:50:31 +0100 |
| commit | 1a5709501f94014d41987b956338bb6424b9f90c (patch) | |
| tree | d3b93fe8dc406bca56aff147ef5cc4cbf9ed6be0 /src/client/toolbar | |
| parent | Test (diff) | |
| download | pvs2-1a5709501f94014d41987b956338bb6424b9f90c.tar.gz pvs2-1a5709501f94014d41987b956338bb6424b9f90c.tar.xz pvs2-1a5709501f94014d41987b956338bb6424b9f90c.zip | |
Initial commit
Diffstat (limited to 'src/client/toolbar')
| -rw-r--r-- | src/client/toolbar/toolbar.cpp | 200 | ||||
| -rw-r--r-- | src/client/toolbar/toolbar.h | 78 |
2 files changed, 278 insertions, 0 deletions
diff --git a/src/client/toolbar/toolbar.cpp b/src/client/toolbar/toolbar.cpp new file mode 100644 index 0000000..416a68f --- /dev/null +++ b/src/client/toolbar/toolbar.cpp @@ -0,0 +1,200 @@ +/* + * toolbar.cpp + * + * Created on: 21.01.2013 + * Author: sr + */ + +#include "toolbar.h" +#include "../../shared/settings.h" +#include "../net/serverconnection.h" +#include "../vnc/vncwindow.h" +#include "../vnc/vncserver.h" + +Toolbar::Toolbar(QWidget *parent) : + QWidget(parent), _location(POSITION_TOP_CENTER), _hideTimer(0), _connection(NULL) +{ + setupUi(this); + setWindowFlags(Qt::WindowStaysOnTopHint | Qt::X11BypassWindowManagerHint | Qt::FramelessWindowHint); + setAttribute(Qt::WA_AlwaysShowToolTips); + setAttribute(Qt::WA_QuitOnClose); + setVisible(true); + // VNC Window + _vnc = new VncWindow(NULL); + // Connect window + _connectWindow = new ConnectWindow(NULL); + connect(_connectWindow, SIGNAL(disconnect()), this, SLOT(onDoDisconnect())); + connect(_connectWindow, SIGNAL(connected(ServerConnection*)), this, SLOT(onConnected(ServerConnection*))); + // + setupMenu(); + setLocation(); + hideBar(); +} + +void Toolbar::setupMenu() +{ + _menu = new QMenu(this); + // setup actions + _acnDisconnect = new QAction(tr("&Connect"), this); + //_acnDisconnect->setEnabled(false); + _acnQuit = new QAction(tr("&Quit"), this); + + // setup menu + _menu->addAction(_acnDisconnect); + _menu->addSeparator(); + _menu->addAction(_acnQuit); + + cmdMenu->setMenu(_menu); + + connect(_acnQuit, SIGNAL(triggered()), this, SLOT(onQuit())); + connect(_acnDisconnect, SIGNAL(triggered()), _connectWindow, SLOT(show())); +} + +Toolbar::~Toolbar() +{ + VncServer::instance()->stop(); + _vnc->deleteLater(); + _connectWindow->deleteLater(); +} + +//###########\\/\/ + +void Toolbar::setLocation() +{ + const QDesktopWidget desktop; + const QRect primaryScreen = desktop.screenGeometry(); + switch (_location) + { + case POSITION_TOP_LEFT: + move(primaryScreen.left(), primaryScreen.top()); + break; + case POSITION_TOP_CENTER: + move((primaryScreen.width() - this->width()) / 2 + primaryScreen.left(), primaryScreen.top()); + break; + case POSITION_TOP_RIGHT: + move(primaryScreen.right() - width(), primaryScreen.top()); + break; + case POSITION_BOTTOM_LEFT: + move(primaryScreen.left(), primaryScreen.bottom() - height()); + break; + case POSITION_BOTTOM_CENTER: + move((primaryScreen.width() - this->width()) / 2 + primaryScreen.left(), primaryScreen.bottom() - height()); + break; + case POSITION_BOTTOM_RIGHT: + move(primaryScreen.right() - width(), primaryScreen.bottom() - height()); + break; + default: + break; + } +} + +void Toolbar::setBarVisible(bool shown) +{ + const QDesktopWidget desktop; + const QRect primaryScreen = desktop.screenGeometry(); + if (!shown) + { + if (_location <= POSITION_TOP_RIGHT) + move(x(), primaryScreen.top() + 2 - height()); + else + move(x(), primaryScreen.bottom() - 2); + } + else + { + if (_location <= POSITION_TOP_RIGHT) + move(x(), primaryScreen.top()); + else + move(x(), primaryScreen.bottom() - height()); + } +} + +bool Toolbar::hideBar() +{ + if (_menu->isVisible()) // Don't hide window if any menu is open + return false; + setBarVisible(false); + return true; +} + +/** + * Override + */ + +void Toolbar::leaveEvent(QEvent* e) +{ + if (_hideTimer == 0) + _hideTimer = startTimer(100); + _hideDelay = 6; + QWidget::leaveEvent(e); +} + +void Toolbar::enterEvent(QEvent* e) +{ + if (_hideTimer != 0) + { + killTimer(_hideTimer); + _hideTimer = 0; + } + setBarVisible(true); + QWidget::enterEvent(e); +} + +void Toolbar::timerEvent(QTimerEvent* event) +{ + if (event->timerId() == _hideTimer) + { + if (--_hideDelay <= 0) + { + if (hideBar()) + { + killTimer(_hideTimer); + _hideTimer = 0; + } + } + } +} + +/** + * Slots + */ + +void Toolbar::onDisconnected(QObject* connection) +{ + if (connection != _connection) + qDebug("onDisconnect pointer mismatch!"); + _connectWindow->setConnected(false); + _connection = NULL; + lblStatus->setStyleSheet("color:red"); + lblStatus->setText(tr("Offline")); +} + +void Toolbar::onConnected(ServerConnection* connection) +{ + lblStatus->setStyleSheet("color:green"); + lblStatus->setText(tr("Online")); + // + if (_connection != NULL) + { + disconnect(_connection, SIGNAL(destroyed(QObject*)), this, SLOT(onDisconnected(QObject*))); + _connection->blockSignals(true); + _connection->disconnectFromServer(); + } + _connection = connection; + connect(_connection, SIGNAL(destroyed(QObject*)), this, SLOT(onDisconnected(QObject*))); + connect(_connection, SIGNAL(openVnc(const QString&, int, const QString&, bool, bool, const QString&, const int)), + _vnc, SLOT(open(const QString&, int, const QString&, bool, bool, const QString&, const int))); + connect(_connection, SIGNAL(closeVnc()), _vnc, SLOT(close())); + connect(_vnc, SIGNAL(running(const bool, const int)), _connection, SLOT(onVncViewerStartStop(const bool, const int))); + _connectWindow->setConnected(true); +} + +void Toolbar::onDoDisconnect() +{ + if (_connection != NULL) + _connection->disconnectFromServer(); +} + +void Toolbar::onQuit() +{ + QApplication::exit(0); +} diff --git a/src/client/toolbar/toolbar.h b/src/client/toolbar/toolbar.h new file mode 100644 index 0000000..0ce4d2b --- /dev/null +++ b/src/client/toolbar/toolbar.h @@ -0,0 +1,78 @@ +/* + # Copyright (c) 2009, 2010 - 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/ + */ + +#ifndef PVSCLIENTGUI_H_ +#define PVSCLIENTGUI_H_ + +#include <QtGui> +#include "ui_toolbar.h" + +class ServerConnection; +class VncWindow; +class ConnectWindow; +class BlankScreen; + +class Toolbar : public QWidget, private Ui_ToolbarClass +{ +Q_OBJECT + +private: + int _location; + int _hideTimer; + int _hideDelay; + QMenu *_menu; + QAction *_acnDisconnect; + QAction *_acnQuit; + ServerConnection *_connection; + + ConnectWindow *_connectWindow; + VncWindow *_vnc; + + void setLocation(); + bool hideBar(); + void setBarVisible(bool shown); + void setupMenu(); + + void leaveEvent(QEvent* e); + void enterEvent(QEvent* e); + void timerEvent(QTimerEvent* event); + +public: + Toolbar(QWidget *parent = NULL); + virtual ~Toolbar(); + + int const static POSITION_TOP_LEFT = 0; + int const static POSITION_TOP_CENTER = 1; + int const static POSITION_TOP_RIGHT = 2; + int const static POSITION_BOTTOM_LEFT = 3; + int const static POSITION_BOTTOM_CENTER = 4; + int const static POSITION_BOTTOM_RIGHT = 5; + +protected: + /* + void enterEvent(QEvent *e); + void leaveEvent(QEvent *e); + void mousePressEvent(QMouseEvent *event); + void mouseReleaseEvent(QMouseEvent *event); + void mouseMoveEvent(QMouseEvent *event); + */ + +private slots: + void onDisconnected(QObject* connection); + void onConnected(ServerConnection* connection); + void onDoDisconnect(); + void onQuit(); + +}; + +#endif /* PVSCLIENTGUI_H_ */ |
