diff options
author | Aqua-sama <aqua@iserlohn-fortress.net> | 2018-06-18 12:07:34 +0200 |
---|---|---|
committer | Aqua-sama <aqua@iserlohn-fortress.net> | 2018-06-18 12:07:34 +0200 |
commit | fcda48e14aee987394e1dbfcd68687ef80f6d2ca (patch) | |
tree | 01aee0a74ced05220d2b796d8daf8477c024ad3e /src | |
parent | .desktop: add run with firejail action (diff) | |
download | smolbote-fcda48e14aee987394e1dbfcd68687ef80f6d2ca.tar.xz |
AddressBar: code cleanup
AddressBar: match input for protocol or '.' in addition to url validity
Diffstat (limited to 'src')
-rw-r--r-- | src/mainwindow/mainwindow.cpp | 43 | ||||
-rw-r--r-- | src/mainwindow/mainwindow.h | 5 |
2 files changed, 43 insertions, 5 deletions
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<Configuration> &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<std::string>("mainwindow.shortcuts.search").value().c_str()), this); connect(searchShortcut, &QShortcut::activated, this, [=]() { /* QTBUG-18665 @@ -112,9 +134,10 @@ MainWindow::MainWindow(std::shared_ptr<Configuration> &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<Configuration> m_config; QMetaObject::Connection viewChangedConnection; - QMetaObject::Connection searchConnection, searchBoxConnection; + QMetaObject::Connection searchBoxConnection; QMetaObject::Connection statusBarConnection; }; |