From 34ee7c2bddfdd98113ef21fe6a68bb219915dd88 Mon Sep 17 00:00:00 2001 From: Nikhil Tanwar <2002nikhiltanwar@gmail.com> Date: Tue, 12 Jul 2022 16:33:15 +0530 Subject: [PATCH] Hide top widget and tabbar in fullscreen This change hides the topwidget and tabbar when fullscreen shortcut/button is pressed. If the mouse is taken to the top of screen, they are shown till the time it is there. --- src/mainwindow.cpp | 37 +++++++++++++++++++++++++++++++++++-- src/mainwindow.h | 3 +++ 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index f5f6211c6..9d669247f 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -22,6 +22,7 @@ MainWindow::MainWindow(QWidget *parent) : mp_ui->tabBar->setStackedWidget(mp_ui->mainView); auto app = KiwixApp::instance(); + addAction(KiwixApp::instance()->getAction(KiwixApp::ToggleFullscreenAction)); connect(app->getAction(KiwixApp::ExitAction), &QAction::triggered, this, &QMainWindow::close); @@ -75,12 +76,44 @@ MainWindow::~MainWindow() } void MainWindow::toggleFullScreen() { - if (isFullScreen()) + if (isFullScreen()) { + QApplication::instance()->removeEventFilter(this); + showTabAndTop(); showNormal(); - else + } + else { + QApplication::instance()->installEventFilter(this); + hideTabAndTop(); showFullScreen(); + } +} + +void MainWindow::hideTabAndTop() { + getTabBar()->hide(); + getTopWidget()->hide(); +} + +void MainWindow::showTabAndTop() { + getTabBar()->show(); + getTopWidget()->show(); +} + +bool MainWindow::eventFilter(QObject* /*object*/, QEvent* event) +{ + if (event->type() == QEvent::MouseMove && isFullScreen()) + { + const auto mouseEvent = static_cast(event); + if (mouseEvent->y() == 0) { + showTabAndTop(); + } else if(mouseEvent->y() >= 150) { + hideTabAndTop(); + } + return true; + } + return false; } + void MainWindow::when_ReadingList_toggled(bool state) { if (state) { diff --git a/src/mainwindow.h b/src/mainwindow.h index 6c669e172..dba035f3f 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -27,11 +27,14 @@ class MainWindow : public QMainWindow protected: void keyPressEvent(QKeyEvent *event); + bool eventFilter(QObject* object, QEvent* event) override; private slots: void toggleFullScreen(); void when_ReadingList_toggled(bool state); void when_libraryPageDisplayed(bool showed); + void hideTabAndTop(); + void showTabAndTop(); private: Ui::MainWindow *mp_ui;