diff --git a/kiwix-desktop.pro b/kiwix-desktop.pro index 6e36d9c..2d6391b 100644 --- a/kiwix-desktop.pro +++ b/kiwix-desktop.pro @@ -49,7 +49,6 @@ SOURCES += \ src/topwidget.cpp \ src/requestinterceptor.cpp \ src/urlschemehandler.cpp \ - src/tabwidget.cpp \ src/webview.cpp \ src/searchbar.cpp \ src/mainmenu.cpp \ @@ -58,6 +57,7 @@ SOURCES += \ src/tocsidebar.cpp \ src/contentmanager.cpp \ src/contentmanagerview.cpp \ + src/tabbar.cpp \ HEADERS += \ src/mainwindow.h \ @@ -68,7 +68,6 @@ HEADERS += \ src/kconstants.h \ src/requestinterceptor.h \ src/urlschemehandler.h \ - src/tabwidget.h \ src/webview.h \ src/searchbar.h \ src/mainmenu.h \ @@ -77,6 +76,7 @@ HEADERS += \ src/tocsidebar.h \ src/contentmanager.h \ src/contentmanagerview.h \ + src/tabbar.h \ FORMS += \ ui/mainwindow.ui \ diff --git a/src/kiwixapp.cpp b/src/kiwixapp.cpp index b4a3e93..cb824c6 100644 --- a/src/kiwixapp.cpp +++ b/src/kiwixapp.cpp @@ -71,7 +71,7 @@ KiwixApp::KiwixApp(int& argc, char *argv[]) createAction(); mp_mainWindow = new MainWindow; - mp_tabWidget = mp_mainWindow->getTabWidget(); + mp_tabWidget = mp_mainWindow->getTabBar(); mp_tabWidget->setContentManagerView(m_manager.getView()); postInit(); @@ -143,6 +143,20 @@ void KiwixApp::openUrl(const QUrl &url, bool newTab) { mp_tabWidget->openUrl(url, newTab); } +void KiwixApp::setSideBar(KiwixApp::SideBarType type) +{ + auto sideDockWidget = mp_mainWindow->getSideDockWidget(); + switch(type) { + case SEARCH_BAR: + sideDockWidget->setCurrentIndex(type); + sideDockWidget->show(); + break; + case NONE: + sideDockWidget->hide(); + break; + } +} + void KiwixApp::openRandomUrl(bool newTab) { auto zimId = mp_tabWidget->currentZimId(); @@ -229,6 +243,8 @@ 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); }); CREATE_ACTION_ICON(ToggleFullscreenAction, "full-screen-enter", tr("Set fullScreen")); SET_SHORTCUT(ToggleFullscreenAction, QKeySequence::FullScreen); @@ -286,10 +302,5 @@ void KiwixApp::createAction() } void KiwixApp::postInit() { - auto realToggleAction = mp_mainWindow->getSideDockWidget()->toggleViewAction(); - auto proxyToggleAction = mpa_actions[FindInPageAction]; - connect(proxyToggleAction, &QAction::triggered, realToggleAction, &QAction::trigger); - connect(realToggleAction, &QAction::toggled, proxyToggleAction, &QAction::setChecked); - realToggleAction->toggle(); emit(m_library.booksChanged()); } diff --git a/src/kiwixapp.h b/src/kiwixapp.h index 6944462..3a88619 100644 --- a/src/kiwixapp.h +++ b/src/kiwixapp.h @@ -5,7 +5,7 @@ #include "contentmanager.h" #include "mainwindow.h" #include "kiwix/downloader.h" -#include "tabwidget.h" +#include "tabbar.h" #include "tocsidebar.h" #include "urlschemehandler.h" #include "requestinterceptor.h" @@ -49,6 +49,10 @@ public: ExitAction, MAX_ACTION }; + enum SideBarType { + SEARCH_BAR, + NONE + }; KiwixApp(int& argc, char *argv[]); virtual ~KiwixApp(); @@ -63,13 +67,14 @@ public: Library* getLibrary() { return &m_library; } MainWindow* getMainWindow() { return mp_mainWindow; } kiwix::Downloader* getDownloader() { return &m_downloader; } - TabWidget* getTabWidget() { return mp_tabWidget; } + TabBar* getTabWidget() { return mp_tabWidget; } QAction* getAction(Actions action); 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 printPage(); protected: @@ -82,7 +87,7 @@ private: kiwix::Downloader m_downloader; ContentManager m_manager; MainWindow* mp_mainWindow; - TabWidget* mp_tabWidget; + TabBar* mp_tabWidget; QErrorMessage* mp_errorDialog; UrlSchemeHandler m_schemeHandler; diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index a299bda..49b1ac1 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -14,7 +14,8 @@ MainWindow::MainWindow(QWidget *parent) : mp_about(new About(this)) { mp_ui->setupUi(this); - mp_ui->tabWidget->tabBar()->setExpanding(false); + mp_ui->tabBar->setExpanding(false); + mp_ui->tabBar->setStackedWidget(mp_ui->mainView); auto app = KiwixApp::instance(); connect(app->getAction(KiwixApp::ExitAction), &QAction::triggered, this, &QMainWindow::close); @@ -39,12 +40,12 @@ void MainWindow::toggleFullScreen() { showFullScreen(); } -TabWidget* MainWindow::getTabWidget() +TabBar* MainWindow::getTabBar() { - return mp_ui->tabWidget; + return mp_ui->tabBar; } -QDockWidget* MainWindow::getSideDockWidget() +QStackedWidget *MainWindow::getSideDockWidget() { - return mp_ui->sideDockWidget; + return mp_ui->sideBar; } diff --git a/src/mainwindow.h b/src/mainwindow.h index 0d91063..11fb00f 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -4,7 +4,7 @@ #include #include #include "webview.h" -#include "tabwidget.h" +#include "tabbar.h" #include "tocsidebar.h" #include "about.h" @@ -20,8 +20,8 @@ public: explicit MainWindow(QWidget *parent = 0); ~MainWindow(); - TabWidget* getTabWidget(); - QDockWidget* getSideDockWidget(); + TabBar* getTabBar(); + QStackedWidget* getSideDockWidget(); protected slots: void toggleFullScreen(); diff --git a/src/tabwidget.cpp b/src/tabbar.cpp similarity index 71% rename from src/tabwidget.cpp rename to src/tabbar.cpp index 295c16c..c7158ea 100644 --- a/src/tabwidget.cpp +++ b/src/tabbar.cpp @@ -1,4 +1,4 @@ -#include "tabwidget.h" +#include "tabbar.h" #include "kiwixapp.h" #include @@ -7,15 +7,15 @@ #define QUITIFNOTCURRENT(VIEW) if((VIEW)!=currentWidget()) {return;} #define CURRENTIFNULL(VIEW) if(nullptr==VIEW) { VIEW = currentWidget();} -TabWidget::TabWidget(QWidget *parent) : - QTabWidget(parent) +TabBar::TabBar(QWidget *parent) : + QTabBar(parent) { setTabsClosable(true); setElideMode(Qt::ElideNone); setDocumentMode(true); setFocusPolicy(Qt::NoFocus); - connect(this, &QTabWidget::tabCloseRequested, this, &TabWidget::closeTab); - connect(this, &QTabWidget::currentChanged, this, &TabWidget::onCurrentChanged); + connect(this, &QTabBar::tabCloseRequested, this, &TabBar::closeTab); + connect(this, &QTabBar::currentChanged, this, &TabBar::onCurrentChanged); auto app = KiwixApp::instance(); connect(app->getAction(KiwixApp::NewTabAction), &QAction::triggered, this, [=]() { @@ -31,6 +31,10 @@ TabWidget::TabWidget(QWidget *parent) : return; } this->closeTab(index); + auto widget = mp_stackedWidget->widget(index); + mp_stackedWidget->removeWidget(widget); + widget->setParent(nullptr); + delete widget; }); connect(app->getAction(KiwixApp::ZoomInAction), &QAction::triggered, this, [=]() { @@ -58,13 +62,22 @@ TabWidget::TabWidget(QWidget *parent) : }); } -void TabWidget::setContentManagerView(ContentManagerView* view) -{ - mp_contentManagerView = view; - addTab(mp_contentManagerView, ""); +void TabBar::setStackedWidget(QStackedWidget *widget) { + mp_stackedWidget = widget; + connect(this, &QTabBar::currentChanged, + widget, &QStackedWidget::setCurrentIndex); } -WebView* TabWidget::createNewTab(bool setCurrent) +void TabBar::setContentManagerView(ContentManagerView* view) +{ + qInfo() << "add widget"; + mp_contentManagerView = view; + mp_stackedWidget->addWidget(mp_contentManagerView); + mp_stackedWidget->show(); + addTab("contentManager"); +} + +WebView* TabBar::createNewTab(bool setCurrent) { WebView* webView = new WebView(); connect(webView, &WebView::titleChanged, this, @@ -78,14 +91,15 @@ WebView* TabWidget::createNewTab(bool setCurrent) } ); // Ownership of webview is passed to the tabWidget - addTab(webView, ""); + mp_stackedWidget->addWidget(webView); + auto index = addTab(""); if (setCurrent) { - setCurrentWidget(webView); + setCurrentIndex(index); } return webView; } -void TabWidget::openUrl(const QUrl& url, bool newTab) +void TabBar::openUrl(const QUrl& url, bool newTab) { WebView* webView = currentWidget(); if (newTab || !webView) { @@ -95,31 +109,31 @@ void TabWidget::openUrl(const QUrl& url, bool newTab) webView->setUrl(url); } -void TabWidget::setTitleOf(const QString& title, WebView* webView) +void TabBar::setTitleOf(const QString& title, WebView* webView) { CURRENTIFNULL(webView); if (title.startsWith("zim://")) { auto url = QUrl(title); - setTabText(indexOf(webView), url.path()); + setTabText(mp_stackedWidget->indexOf(webView), url.path()); } else { - setTabText(indexOf(webView), title); + setTabText(mp_stackedWidget->indexOf(webView), title); } } -void TabWidget::setIconOf(const QIcon &icon, WebView *webView) +void TabBar::setIconOf(const QIcon &icon, WebView *webView) { CURRENTIFNULL(webView); - setTabIcon(indexOf(webView), icon); + setTabIcon(mp_stackedWidget->indexOf(webView), icon); } -QString TabWidget::currentZimId() +QString TabBar::currentZimId() { if (!currentWidget()) return ""; return currentWidget()->zimId(); } -void TabWidget::triggerWebPageAction(QWebEnginePage::WebAction action, WebView *webView) +void TabBar::triggerWebPageAction(QWebEnginePage::WebAction action, WebView *webView) { CURRENTIFNULL(webView); QUITIFNULL(webView); @@ -127,7 +141,7 @@ void TabWidget::triggerWebPageAction(QWebEnginePage::WebAction action, WebView * webView->setFocus(); } -void TabWidget::closeTab(int index) +void TabBar::closeTab(int index) { if (index == 0) return; @@ -137,7 +151,7 @@ void TabWidget::closeTab(int index) delete webview; } -void TabWidget::onCurrentChanged(int index) +void TabBar::onCurrentChanged(int index) { if (index == -1) return; diff --git a/src/tabwidget.h b/src/tabbar.h similarity index 77% rename from src/tabwidget.h rename to src/tabbar.h index b2aa866..599cd79 100644 --- a/src/tabwidget.h +++ b/src/tabbar.h @@ -1,22 +1,24 @@ #ifndef TABWIDGET_H #define TABWIDGET_H -#include +#include +#include #include #include "webview.h" #include "contentmanagerview.h" -class TabWidget : public QTabWidget +class TabBar : public QTabBar { Q_OBJECT Q_PROPERTY(QString currentZimId READ currentZimId NOTIFY currentZimIdChanged) public: - TabWidget(QWidget* parent=nullptr); + TabBar(QWidget* parent=nullptr); + void setStackedWidget(QStackedWidget* widget); void setContentManagerView(ContentManagerView* view); WebView* createNewTab(bool setCurrent); - WebView* widget(int index) { return (index != 0) ? static_cast(QTabWidget::widget(index)) : nullptr; } - WebView* currentWidget() { auto current = QTabWidget::currentWidget(); + WebView* widget(int index) { return (index != 0) ? static_cast(mp_stackedWidget->widget(index)) : nullptr; } + WebView* currentWidget() { auto current = mp_stackedWidget->currentWidget(); if (current == mp_contentManagerView) return nullptr; return static_cast(current); } @@ -38,6 +40,7 @@ public slots: private: ContentManagerView* mp_contentManagerView; + QStackedWidget* mp_stackedWidget; }; diff --git a/src/tocsidebar.cpp b/src/tocsidebar.cpp index 39b13c5..da41c37 100644 --- a/src/tocsidebar.cpp +++ b/src/tocsidebar.cpp @@ -8,6 +8,8 @@ TocSideBar::TocSideBar(QWidget *parent) : { mp_ui->setupUi(this); mp_findLineEdit = mp_ui->findEdit; + connect(mp_ui->hideButton, &QPushButton::released, + this, [=]() { KiwixApp::instance()->setSideBar(KiwixApp::NONE);}); connect(mp_ui->fNextButton, &QPushButton::released, this, &TocSideBar::findNext); connect(mp_ui->fPreviousButton, &QPushButton::released, diff --git a/src/tocsidebar.ui b/src/tocsidebar.ui index b1f0ad0..aae03ac 100644 --- a/src/tocsidebar.ui +++ b/src/tocsidebar.ui @@ -20,75 +20,97 @@ Form - - QLayout::SetMaximumSize - - - 0 - - - 0 - - - 0 - - - 0 - - - - 0 - - - QLayout::SetMaximumSize - + - + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + 0 + 0 + + + + Hide + + + true + + + + - - - + + + 0 - - - :/icons/search_forward.svg:/icons/search_forward.svg + + QLayout::SetMaximumSize - - true - - + + + + + + + + + + + :/icons/search_forward.svg:/icons/search_forward.svg + + + true + + + + + + + + + + + :/icons/search_backward.svg:/icons/search_backward.svg + + + true + + + + - - - + + + Qt::Vertical - - - :/icons/search_backward.svg:/icons/search_backward.svg + + + 20 + 40 + - - true - - + - - - - Qt::Vertical - - - - 20 - 40 - - - - diff --git a/ui/mainwindow.ui b/ui/mainwindow.ui index 2c6de19..d6d787e 100644 --- a/ui/mainwindow.ui +++ b/ui/mainwindow.ui @@ -24,6 +24,9 @@ + + 0 + 0 @@ -37,17 +40,40 @@ 0 - - - QTabWidget::Rounded + + + + + + 0 - - -1 - - - false - - + + + + true + + + + 0 + 0 + + + + QFrame::NoFrame + + + QFrame::Plain + + + 0 + + + + + + + + @@ -60,39 +86,6 @@ - - - true - - - - 0 - 0 - - - - false - - - QDockWidget::DockWidgetClosable - - - Qt::LeftDockWidgetArea - - - Find in page - - - 1 - - - - - - - - - @@ -101,18 +94,18 @@ QToolBar
src/topwidget.h
- - TabWidget - QTabWidget -
src/tabwidget.h
- 1 -
TocSideBar QWidget
src/tocsidebar.h
1
+ + TabBar + QWidget +
src/tabbar.h
+ 1 +