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 authored and kelson42 committed Jul 20, 2022
1 parent 30ac41c commit cda4a91
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 @@ -67,6 +68,8 @@ MainWindow::MainWindow(QWidget *parent) :

mp_ui->contentmanagerside->setContentManager(app->getContentManager());
mp_ui->sideBar->setCurrentWidget(mp_ui->contentmanagerside);
QApplication::instance()->installEventFilter(this);
setMouseTracking(true);
}

MainWindow::~MainWindow()
Expand All @@ -75,12 +78,42 @@ MainWindow::~MainWindow()
}

void MainWindow::toggleFullScreen() {
if (isFullScreen())
if (isFullScreen()) {
showTabAndTop();
showNormal();
else
}
else {
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 cda4a91

Please sign in to comment.