diff options
author | Aqua-sama <aqua@iserlohn-fortress.net> | 2018-05-01 15:54:49 +0200 |
---|---|---|
committer | Aqua-sama <aqua@iserlohn-fortress.net> | 2018-05-01 15:54:49 +0200 |
commit | 1ee841364215042f1f284e692ae191ebf7a64156 (patch) | |
tree | 48c1f49e29fe6b13cef68cd73dd2cab039fea822 /src/mainwindow | |
parent | Window::session (diff) | |
download | smolbote-1ee841364215042f1f284e692ae191ebf7a64156.tar.xz |
Split off addressbar into lib/
Diffstat (limited to 'src/mainwindow')
-rw-r--r-- | src/mainwindow/mainwindow.cpp | 43 | ||||
-rw-r--r-- | src/mainwindow/mainwindow.h | 9 |
2 files changed, 34 insertions, 18 deletions
diff --git a/src/mainwindow/mainwindow.cpp b/src/mainwindow/mainwindow.cpp index be5e6e4..35cc598 100644 --- a/src/mainwindow/mainwindow.cpp +++ b/src/mainwindow/mainwindow.cpp @@ -46,7 +46,7 @@ MainWindow::MainWindow(std::shared_ptr<Configuration> &config, QWidget *parent) createMenuBar(); - auto *navigationToolBar = new NavigationBar(config->section("navigation"), this); + navigationToolBar = new NavigationBar(config->section("navigation"), this); navigationToolBar->setMovable(config->value<bool>("navigation.movable").value()); addToolBar(Qt::TopToolBarArea, navigationToolBar); navigationToolBar->connectWebView(nullptr); @@ -63,9 +63,8 @@ MainWindow::MainWindow(std::shared_ptr<Configuration> &config, QWidget *parent) searchBox->setVisible(false); // connect signlas - connect(mdiArea, &QMdiArea::subWindowActivated, this, [this, navigationToolBar](QMdiSubWindow *window) { - disconnect(addressBarConnection); - disconnect(navigationBarConnection); + connect(mdiArea, &QMdiArea::subWindowActivated, this, [this](QMdiSubWindow *window) { + disconnect(viewChangedConnection); disconnect(searchBoxConnection); disconnect(statusBarConnection); subWindowAction->setMenu(nullptr); @@ -73,18 +72,12 @@ MainWindow::MainWindow(std::shared_ptr<Configuration> &config, QWidget *parent) auto *w = qobject_cast<Window *>(window); if(w == nullptr) { // no current subwindow, clear everything - setWindowTitle(tr("smolbote")); - addressBar->connectWebView(nullptr); - navigationToolBar->connectWebView(nullptr); - searchBox->setView(nullptr); + setView(nullptr); + subWindowAction->setMenu(nullptr); } else { + setView(w->currentView()); subWindowAction->setMenu(w->systemMenu()); - addressBar->connectWebView(w->currentView()); - addressBarConnection = connect(w, &Window::currentViewChanged, addressBar, &AddressBar::connectWebView); - navigationToolBar->connectWebView(w->currentView()); - navigationBarConnection = connect(w, &Window::currentViewChanged, navigationToolBar, &NavigationBar::connectWebView); - searchBox->setView(w->currentView()); - searchBoxConnection = connect(w, &Window::currentViewChanged, searchBox, &SearchForm::setView); + viewChangedConnection = connect(w, &Window::currentViewChanged, this, &MainWindow::setView); statusBarConnection = connect(w, &Window::showStatusMessage, statusBar(), &QStatusBar::showMessage); } }); @@ -97,8 +90,8 @@ MainWindow::MainWindow(std::shared_ptr<Configuration> &config, QWidget *parent) MainWindow::~MainWindow() { - disconnect(addressBarConnection); - disconnect(navigationBarConnection); + disconnect(viewChangedConnection); + disconnect(searchConnection); disconnect(searchBoxConnection); disconnect(statusBarConnection); } @@ -192,6 +185,24 @@ Window *MainWindow::createSubWindow(const QUrl &url) return w; } +void MainWindow::setView(WebView *view) +{ + disconnect(searchConnection); + + addressBar->setView(view); + if(view) { + addressBar->setPageMenu(view->pageMenu()); + addressBar->setToolsMenu(view->toolsMenu()); + searchConnection = connect(addressBar, &AddressBar::search, view, &WebView::search); + } else { + addressBar->setPageMenu(nullptr); + addressBar->setToolsMenu(nullptr); + } + + navigationToolBar->connectWebView(view); + searchBox->setView(view); +} + void MainWindow::closeEvent(QCloseEvent *event) { if(mdiArea->subWindowList().count() > 1) { diff --git a/src/mainwindow/mainwindow.h b/src/mainwindow/mainwindow.h index 1257a56..489075f 100644 --- a/src/mainwindow/mainwindow.h +++ b/src/mainwindow/mainwindow.h @@ -18,6 +18,8 @@ class Configuration; class Window; class AddressBar; class SearchForm; +class WebView; +class NavigationBar; class MainWindow : public QMainWindow { friend class Browser; @@ -42,20 +44,23 @@ public slots: void createTab(const QUrl &url); Window *createSubWindow(const QUrl &url); + void setView(WebView *view); + protected: void closeEvent(QCloseEvent *event) override; private: QAction *subWindowAction = nullptr; QMenu *toolsMenu = nullptr; + NavigationBar *navigationToolBar = nullptr; AddressBar *addressBar = nullptr; SearchForm *searchBox = nullptr; QMdiArea *mdiArea; std::shared_ptr<Configuration> m_config; - QMetaObject::Connection addressBarConnection, navigationBarConnection; - QMetaObject::Connection searchBoxConnection; + QMetaObject::Connection viewChangedConnection; + QMetaObject::Connection searchConnection, searchBoxConnection; QMetaObject::Connection statusBarConnection; }; |