From 33bcdbf3e8e919aa293057784c30d3bf06b94c26 Mon Sep 17 00:00:00 2001 From: Jonathan Bauer Date: Mon, 18 Jun 2018 14:14:54 +0200 Subject: [client] top/bottom position detection if a top system bar/panel is detected (i.e. reserves a region of the screen geometry), place the toolbar at the bottom of the screen --- src/client/toolbar/toolbar.cpp | 37 +++++++++++++++++++++++++++---------- src/client/toolbar/toolbar.h | 3 +++ 2 files changed, 30 insertions(+), 10 deletions(-) diff --git a/src/client/toolbar/toolbar.cpp b/src/client/toolbar/toolbar.cpp index 7b57c7e..dc8181c 100644 --- a/src/client/toolbar/toolbar.cpp +++ b/src/client/toolbar/toolbar.cpp @@ -130,10 +130,12 @@ void Toolbar::init() /* Connect the signals from vnc server */ connect(VncServer::instance(), SIGNAL(started(int, QString&, QString&)), this, SLOT(onVncServerIsRunning(int))); - /* Set position */ - const QDesktopWidget desktop; - const QRect primaryScreen = desktop.screenGeometry(); - move(primaryScreen.left() + (primaryScreen.width() - this->width()) / 2 , primaryScreen.top()); + /* React to screen geometry change */ + connect(QGuiApplication::primaryScreen(), &QScreen::availableGeometryChanged, this, &Toolbar::setToolbarPosition); + + /* Detect task bars and set position */ + const QRect availableScreen = QGuiApplication::primaryScreen()->availableGeometry(); + setToolbarPosition(availableScreen); /* Setup show & hide timer */ _showTimer.setInterval(500); @@ -428,9 +430,7 @@ void Toolbar::hideBar() if (--_hideCountdown > 0) return; _hideTimer.stop(); - const QDesktopWidget desktop; - const QRect primaryScreen = desktop.screenGeometry(); - move(x(), primaryScreen.top() + 2 - height()); + move(x(), yPosHidden); } void Toolbar::delayedHideBar() @@ -447,9 +447,7 @@ void Toolbar::delayedHideBar() */ void Toolbar::showBar() { - const QDesktopWidget desktop; - const QRect primaryScreen = desktop.screenGeometry(); - move(x(), primaryScreen.top()); + move(x(), yPos); delayedHideBar(); } @@ -531,3 +529,22 @@ void Toolbar::enableLockBtn() _ui->btnManager->setEnabled(true); } +void Toolbar::setToolbarPosition(const QRect &availableGeometry) +{ + const QRect primaryScreen = QGuiApplication::primaryScreen()->geometry(); + // set center position + centerPos = primaryScreen.left() + (primaryScreen.width() - this->width()) / 2; + + // detect system task bars + if (primaryScreen.height() > availableGeometry.height() && primaryScreen.y() < availableGeometry.y()) { + // system task bar already in top position, prefer to show toolbar on bottom + yPos = primaryScreen.height() - this->height(); + yPosHidden = primaryScreen.height() - 2; + } else { + // no task bars at all or a bottom task bar, either way show our toolbar on top + yPos = primaryScreen.top(); + yPosHidden = yPos - this->height() + 2; + } + move(centerPos, yPos); + delayedShowBar(); +} diff --git a/src/client/toolbar/toolbar.h b/src/client/toolbar/toolbar.h index a7cd5ad..a8e929f 100644 --- a/src/client/toolbar/toolbar.h +++ b/src/client/toolbar/toolbar.h @@ -53,6 +53,8 @@ private: bool _isManagerPc; const QPixmap _cam32, _beWatchedEye; + int centerPos, yPos, yPosHidden; + void enterEvent(QEvent* e); QList myRooms(); bool isManagerPc(); @@ -81,6 +83,7 @@ private slots: void showInformationDialog(); void enableLockBtn(); void updateButtonVisibility(); + void setToolbarPosition(const QRect &geometry); }; #endif /* PVSCLIENTGUI_H_ */ -- cgit v1.2.3-55-g7522