From ce71fe027510ec0ad75840e82b1db758c151e68c Mon Sep 17 00:00:00 2001 From: Matthieu Gautier Date: Mon, 10 Dec 2018 16:40:42 +0100 Subject: [PATCH] Correctly handle the sideBar. The side bar has some constraints : - If the contentManager is displayed, we cannot change or hide the side bar. - The readingList button must follow the currentside bar, not its internal status (checked/unchecked). --- src/kiwixapp.cpp | 30 +++++++++++++++++++++--------- src/kiwixapp.h | 6 +++++- 2 files changed, 26 insertions(+), 10 deletions(-) diff --git a/src/kiwixapp.cpp b/src/kiwixapp.cpp index 11378c2..486665c 100644 --- a/src/kiwixapp.cpp +++ b/src/kiwixapp.cpp @@ -181,6 +181,20 @@ void KiwixApp::setSideBar(KiwixApp::SideBarType type) sideDockWidget->hide(); break; } + m_currentSideType = type; + emit(currentSideTypeChanged(type)); +} + +void KiwixApp::toggleSideBar(KiwixApp::SideBarType type) { + if (m_currentSideType == type) { + setSideBar(NONE); + return; + } + + if (m_currentSideType == CONTENTMANAGER_BAR) { + return; + } + setSideBar(type); } void KiwixApp::openRandomUrl(bool newTab) @@ -287,7 +301,7 @@ void KiwixApp::createAction() CREATE_ACTION(FindInPageAction, tr("Find in page")); SET_SHORTCUT(FindInPageAction, QKeySequence::Find); connect(mpa_actions[FindInPageAction], &QAction::triggered, - this, [=]() { setSideBar(SEARCH_BAR); }); + this, [=]() { toggleSideBar(SEARCH_BAR); }); CREATE_ACTION_ICON(ToggleFullscreenAction, "full-screen-enter", tr("Set fullScreen")); SET_SHORTCUT(ToggleFullscreenAction, QKeySequence::FullScreen); @@ -306,15 +320,13 @@ void KiwixApp::createAction() CREATE_ACTION_ICON(ToggleReadingListAction, "reading-list" ,tr("Reading list")); SET_SHORTCUT(ToggleReadingListAction, QKeySequence(Qt::CTRL+Qt::SHIFT+Qt::Key_2)); - connect(mpa_actions[ToggleReadingListAction], &QAction::toggled, - this, [=](bool checked) { - auto action = mpa_actions[ToggleReadingListAction]; - action->setIcon( - QIcon(checked ? ":/icons/reading-list-active.svg" : ":/icons/reading-list.svg")); - setSideBar(checked ? READINGLIST_BAR : NONE); + connect(mpa_actions[ToggleReadingListAction], &QAction::triggered, + this, [=]() { toggleSideBar(READINGLIST_BAR); }); + connect(this, &KiwixApp::currentSideTypeChanged, + this, [=](SideBarType type) { + mpa_actions[ToggleReadingListAction]->setIcon( + QIcon((type == READINGLIST_BAR) ? ":/icons/reading-list-active.svg" : ":/icons/reading-list.svg")); }); - mpa_actions[ToggleReadingListAction]->setCheckable(true); - CREATE_ACTION(ZoomInAction, tr("Zoom in")); SET_SHORTCUT(ZoomInAction, QKeySequence::ZoomIn); diff --git a/src/kiwixapp.h b/src/kiwixapp.h index 8ba2402..7723d32 100644 --- a/src/kiwixapp.h +++ b/src/kiwixapp.h @@ -17,6 +17,8 @@ class KiwixApp : public QApplication { Q_OBJECT + Q_PROPERTY(SideBarType currentSideType MEMBER m_currentSideType NOTIFY currentSideTypeChanged) + public: enum Actions { KiwixServeAction, @@ -74,12 +76,14 @@ public: signals: void currentTitleChanged(const QString& title); + void currentSideTypeChanged(SideBarType type); public slots: void openZimFile(const QString& zimfile=""); void openUrl(const QString& url, bool newTab=true); void openUrl(const QUrl& url, bool newTab=true); void setSideBar(SideBarType type); + void toggleSideBar(KiwixApp::SideBarType type); void printPage(); protected: @@ -94,7 +98,7 @@ private: ContentManager m_manager; MainWindow* mp_mainWindow; TabBar* mp_tabWidget; - QWidget* mp_currentSideBar; + SideBarType m_currentSideType; QErrorMessage* mp_errorDialog; QAction* mpa_actions[MAX_ACTION];