Skip to content

Commit

Permalink
Hide top widget and tabbar in fullscreen
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
juuz0 committed Jul 23, 2022
1 parent f1aafc1 commit 34ee7c2
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
37 changes: 35 additions & 2 deletions src/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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<QMouseEvent*>(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) {
Expand Down
3 changes: 3 additions & 0 deletions src/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 34ee7c2

Please sign in to comment.