diff options
Diffstat (limited to 'src/client/toolbar/toolbar.cpp')
-rw-r--r-- | src/client/toolbar/toolbar.cpp | 193 |
1 files changed, 63 insertions, 130 deletions
diff --git a/src/client/toolbar/toolbar.cpp b/src/client/toolbar/toolbar.cpp index 816d5f4..8de9e31 100644 --- a/src/client/toolbar/toolbar.cpp +++ b/src/client/toolbar/toolbar.cpp @@ -13,65 +13,56 @@ #include "toolbar.h" #include "ui_toolbar.h" + +//______________________________________________________________________________ Toolbar::Toolbar(QWidget *parent) : - QWidget(parent), _ui(new Ui::Toolbar), _location(POSITION_TOP_CENTER), - _hideTimer(0), _connection(NULL) + QWidget(parent), _ui(new Ui::Toolbar), _hideTimer(this), _connection(NULL) { - // Initialize the GUI + /* Initialize the GUI */ _ui->setupUi(this); -// QWidget *firstPageWidget = new QWidget; -// QWidget *secondPageWidget = new QWidget; - -// QStackedLayout *stackedLayout = new QStackedLayout; -// stackedLayout->addWidget(firstPageWidget); -// stackedLayout->addWidget(secondPageWidget); - -// QVBoxLayout *mainLayout = new QVBoxLayout; -// mainLayout->addLayout(stackedLayout); -// setLayout(mainLayout); - - - - - + /* Set window properties */ setWindowFlags(Qt::WindowStaysOnTopHint | Qt::X11BypassWindowManagerHint | Qt::FramelessWindowHint); setAttribute(Qt::WA_AlwaysShowToolTips); setAttribute(Qt::WA_QuitOnClose); setVisible(true); - // VNC Window + /* Create the VNC Window */ _vnc = new VncWindow(NULL); - // Connect window + + /* Create the connect window */ _connectWindow = new ConnectWindow(NULL); - connect(_connectWindow, SIGNAL(disconnect()), this, SLOT(onDoDisconnect())); - connect(_connectWindow, SIGNAL(connected(ServerConnection*)), this, SLOT(onConnected(ServerConnection*))); - connect(VncServer::instance(), SIGNAL(started(int, QString&, QString&)), this, SLOT(onVncServerIsRunning(int, QString&, QString&))); - // - setupMenu(); - setLocation(); - hideBar(); -} -void Toolbar::setupMenu() -{ + /* Setup menu */ _menu = new QMenu(this); - // setup actions _acnDisconnect = new QAction(tr("Set &session ID"), this); - //_acnDisconnect->setEnabled(false); _acnQuit = new QAction(tr("&Quit"), this); - - // setup menu _menu->addAction(_acnDisconnect); _menu->addSeparator(); _menu->addAction(_acnQuit); - _ui->cmdMenu->setMenu(_menu); - connect(_acnQuit, SIGNAL(triggered()), this, SLOT(onQuit())); + /* Connect the signals */ + connect(_connectWindow, SIGNAL(disconnect()), this, SLOT(onDoDisconnect())); + connect(_connectWindow, SIGNAL(connected(ServerConnection*)), this, SLOT(onConnected(ServerConnection*))); + connect(VncServer::instance(), SIGNAL(started(int, QString&, QString&)), this, SLOT(onVncServerIsRunning(int, QString&, QString&))); + connect(_acnQuit, SIGNAL(triggered()), qApp, SLOT(quit())); connect(_acnDisconnect, SIGNAL(triggered()), _connectWindow, SLOT(show())); + + /* Set location */ + const QDesktopWidget desktop; + const QRect primaryScreen = desktop.screenGeometry(); + move(primaryScreen.left() + (primaryScreen.width() - this->width())/2 , primaryScreen.top()); + qDebug() << primaryScreen.left() << primaryScreen.top() << primaryScreen.right() << primaryScreen.bottom(); + + /* Setup hide timer */ + _hideTimer.setInterval(600); + _hideTimer.setSingleShot(true); + connect(&_hideTimer, SIGNAL(timeout()), this, SLOT(hideBar())); + _hideTimer.start(); // initially show PVS and hide later } +//______________________________________________________________________________ Toolbar::~Toolbar() { VncServer::instance()->stop(); @@ -80,119 +71,43 @@ Toolbar::~Toolbar() delete _ui; } -//###########\\/\/ - -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() -{ - // Don't hide window if any menu is open or VNC Server is running from this client. - if (_menu->isVisible() || VncServer::instance()->isVncServerRunning()) - return false; - setBarVisible(false); - return true; -} - +//______________________________________________________________________________ /* * Override */ - void Toolbar::leaveEvent(QEvent* e) { - if (_hideTimer == 0) - _hideTimer = startTimer(100); - _hideDelay = 6; + _hideTimer.start(); QWidget::leaveEvent(e); } +//______________________________________________________________________________ void Toolbar::enterEvent(QEvent* e) { - if (_hideTimer != 0) - { - killTimer(_hideTimer); - _hideTimer = 0; - } - setBarVisible(true); + _hideTimer.stop(); + showBar(); QWidget::enterEvent(e); } -void Toolbar::timerEvent(QTimerEvent* event) -{ - if (event->timerId() == _hideTimer) - { - if (--_hideDelay <= 0) - { - if (hideBar()) - { - killTimer(_hideTimer); - _hideTimer = 0; - } - } - } -} - +//______________________________________________________________________________ /* * Slots */ void Toolbar::onVncServerIsRunning(int port, QString&, QString&) { - if (port > 0) - { - setBarVisible(true); - return; - } - hideBar(); - return; + if (port > 0){ + _ui->lblStatus->setStyleSheet("color:red"); + _ui->lblStatus->setText(tr("Recording")); + showBar(); + } else { + _ui->lblStatus->setStyleSheet("color:green"); + _ui->lblStatus->setText(tr("Online")); + hideBar(); + } } +//______________________________________________________________________________ void Toolbar::onDisconnected() { _connectWindow->setConnected(false); @@ -203,6 +118,7 @@ void Toolbar::onDisconnected() _ui->lblStatus->setText(tr("Offline")); } +//______________________________________________________________________________ void Toolbar::onConnected(ServerConnection* connection) { _ui->lblStatus->setStyleSheet("color:green"); @@ -223,13 +139,30 @@ void Toolbar::onConnected(ServerConnection* connection) _connectWindow->setConnected(true); } +//______________________________________________________________________________ void Toolbar::onDoDisconnect() { if (_connection != NULL) _connection->disconnectFromServer(); } -void Toolbar::onQuit() +//______________________________________________________________________________ +void Toolbar::hideBar() { - QApplication::exit(0); + // // Don't hide window if any menu is open or VNC Server is running from this client. + if (_menu->isVisible() || VncServer::instance()->isVncServerRunning()) + return; + const QDesktopWidget desktop; + const QRect primaryScreen = desktop.screenGeometry(); + move(x(), primaryScreen.top() + 2 - height()); + //move(x(), primaryScreen.bottom() - 2); +} + +//______________________________________________________________________________ +void Toolbar::showBar() +{ + const QDesktopWidget desktop; + const QRect primaryScreen = desktop.screenGeometry(); + move(x(), primaryScreen.top()); + //move(x(), primaryScreen.bottom() - height()); } |