From fcda48e14aee987394e1dbfcd68687ef80f6d2ca Mon Sep 17 00:00:00 2001 From: Aqua-sama Date: Mon, 18 Jun 2018 12:07:34 +0200 Subject: AddressBar: code cleanup AddressBar: match input for protocol or '.' in addition to url validity --- src/mainwindow/mainwindow.cpp | 43 +++++++++++++++++++++++++++++++++++++++---- src/mainwindow/mainwindow.h | 5 ++++- 2 files changed, 43 insertions(+), 5 deletions(-) (limited to 'src/mainwindow') diff --git a/src/mainwindow/mainwindow.cpp b/src/mainwindow/mainwindow.cpp index b2c79cc..48c9e9e 100644 --- a/src/mainwindow/mainwindow.cpp +++ b/src/mainwindow/mainwindow.cpp @@ -93,6 +93,28 @@ MainWindow::MainWindow(std::shared_ptr &config, QWidget *parent) } }); + // address bar + connect(addressBar, &AddressBar::search, this, [this](const QString &term) { + if(this->currentView) { + currentView->search(term); + currentView->setFocus(); + } + }); + connect(addressBar, &AddressBar::load, this, [this](const QUrl &url) { + if(this->currentView) { + currentView->load(url); + currentView->setFocus(); + } + }); + + connect(addressBar, &AddressBar::giveFocus, this, [this]() { + if(this->currentView) { + currentView->setFocus(); + } + }); + + + // search box auto *searchShortcut = new QShortcut(QKeySequence(config->value("mainwindow.shortcuts.search").value().c_str()), this); connect(searchShortcut, &QShortcut::activated, this, [=]() { /* QTBUG-18665 @@ -112,9 +134,10 @@ MainWindow::MainWindow(std::shared_ptr &config, QWidget *parent) MainWindow::~MainWindow() { disconnect(viewChangedConnection); - disconnect(searchConnection); disconnect(searchBoxConnection); disconnect(statusBarConnection); + + disconnect(addressBar); } void MainWindow::createMenuBar() @@ -231,16 +254,28 @@ SubWindow *MainWindow::createSubWindow(const QString &url) void MainWindow::setView(WebView *view) { - disconnect(searchConnection); + if(currentView) { + // disconnect old view + disconnect(currentView, 0, addressBar, 0); + } + currentView = view; - addressBar->setView(view); if(view) { addressBar->setPageMenu(view->pageMenu()); addressBar->setToolsMenu(view->toolsMenu()); - searchConnection = connect(addressBar, &AddressBar::search, view, &WebView::search); + + connect(view, &WebView::urlChanged, addressBar, &AddressBar::setUrl); + addressBar->setUrl(view->url()); + + connect(view, &WebView::loadProgress, addressBar, &AddressBar::setProgress); + addressBar->setProgress(100); + } else { addressBar->setPageMenu(nullptr); addressBar->setToolsMenu(nullptr); + + addressBar->setUrl(QUrl()); + addressBar->setProgress(100); } navigationToolBar->connectWebView(view); diff --git a/src/mainwindow/mainwindow.h b/src/mainwindow/mainwindow.h index af713fc..30d2178 100644 --- a/src/mainwindow/mainwindow.h +++ b/src/mainwindow/mainwindow.h @@ -56,15 +56,18 @@ protected: private: QAction *subWindowAction = nullptr; QMenu *toolsMenu = nullptr; + NavigationBar *navigationToolBar = nullptr; AddressBar *addressBar = nullptr; SearchForm *searchBox = nullptr; + QMdiArea *mdiArea; + WebView *currentView = nullptr; std::shared_ptr m_config; QMetaObject::Connection viewChangedConnection; - QMetaObject::Connection searchConnection, searchBoxConnection; + QMetaObject::Connection searchBoxConnection; QMetaObject::Connection statusBarConnection; }; -- cgit v1.2.1