diff options
-rw-r--r-- | CMakeLists.txt | 1 | ||||
-rw-r--r-- | lib/addressbar/CMakeLists.txt | 21 | ||||
-rw-r--r-- | lib/addressbar/addressbar.cpp (renamed from src/addressbar/addressbar.cpp) | 27 | ||||
-rw-r--r-- | lib/addressbar/addressbar.h (renamed from src/addressbar/addressbar.h) | 14 | ||||
-rw-r--r-- | lib/addressbar/completer.cpp (renamed from src/addressbar/completer.cpp) | 0 | ||||
-rw-r--r-- | lib/addressbar/completer.h (renamed from src/addressbar/completer.h) | 0 | ||||
-rw-r--r-- | lib/addressbar/urllineedit.cpp (renamed from src/addressbar/urllineedit.cpp) | 1 | ||||
-rw-r--r-- | lib/addressbar/urllineedit.h (renamed from src/addressbar/urllineedit.h) | 0 | ||||
-rw-r--r-- | src/CMakeLists.txt | 9 | ||||
-rw-r--r-- | src/mainwindow/mainwindow.cpp | 43 | ||||
-rw-r--r-- | src/mainwindow/mainwindow.h | 9 | ||||
-rw-r--r-- | src/webengine/webview.h | 5 |
12 files changed, 86 insertions, 44 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 673a9d0..f084316 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -55,6 +55,7 @@ endif() configure_file("${PROJECT_SOURCE_DIR}/src/version.h.in" "${PROJECT_BINARY_DIR}/src/version.h") add_subdirectory(lib/about) +add_subdirectory(lib/addressbar) add_subdirectory(lib/bookmarks) add_subdirectory(lib/downloads) add_subdirectory(lib/configuration) diff --git a/lib/addressbar/CMakeLists.txt b/lib/addressbar/CMakeLists.txt new file mode 100644 index 0000000..1122bc3 --- /dev/null +++ b/lib/addressbar/CMakeLists.txt @@ -0,0 +1,21 @@ +# Find includes in corresponding build directories +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +# Instruct CMake to run moc automatically when needed. +set(CMAKE_AUTOMOC ON) +set(CMAKE_AUTOUIC ON) +set(CMAKE_AUTORCC ON) + +add_library(addressbar + addressbar.cpp + addressbar.h + completer.cpp + completer.h + urllineedit.cpp + urllineedit.h +) + +#target_include_directories(addressbar +# PRIVATE ${Boost_INCLUDE_DIRS}) + +target_link_libraries(addressbar Qt5::Widgets Qt5::WebEngineWidgets) diff --git a/src/addressbar/addressbar.cpp b/lib/addressbar/addressbar.cpp index b86230c..9b3970d 100644 --- a/src/addressbar/addressbar.cpp +++ b/lib/addressbar/addressbar.cpp @@ -8,7 +8,7 @@ #include "addressbar.h" #include "urllineedit.h" -#include "webengine/webview.h" +#include <QWebEngineView> #include <QProgressBar> #include <QShortcut> #include <QVBoxLayout> @@ -53,35 +53,42 @@ AddressBar::~AddressBar() disconnect(progressBarConnection); } -void AddressBar::connectWebView(WebView *view) +void AddressBar::setView(QWebEngineView *view) { disconnect(urlChangedConnection); disconnect(loadUrlConnection); disconnect(progressBarConnection); + progressBar->setValue(100); + if(view == nullptr) { urlBar->clear(); urlBar->pageMenu_action->setMenu(nullptr); urlBar->toolsMenu_action->setMenu(nullptr); - - progressBar->setValue(100); return; } urlBar->setUrl(view->url()); - urlBar->pageMenu_action->setMenu(view->pageMenu()); - urlBar->toolsMenu_action->setMenu(view->toolsMenu()); - urlChangedConnection = connect(view, &WebView::urlChanged, urlBar, &UrlLineEdit::setUrl); + urlChangedConnection = connect(view, &QWebEngineView::urlChanged, urlBar, &UrlLineEdit::setUrl); loadUrlConnection = connect(urlBar, &UrlLineEdit::returnPressed, [=]() { if(urlBar->text().startsWith('#')) { - ; - view->search(urlBar->text().mid(1)); + emit search(urlBar->text().mid(1)); } else { view->load(QUrl::fromUserInput(urlBar->text())); } view->setFocus(); }); - progressBar->setValue(view->loadProgress()); + //progressBar->setValue(view->loadProgress()); progressBarConnection = connect(view, &QWebEngineView::loadProgress, progressBar, &QProgressBar::setValue); } + +void AddressBar::setPageMenu(QMenu *menu) +{ + urlBar->pageMenu_action->setMenu(menu); +} + +void AddressBar::setToolsMenu(QMenu *menu) +{ + urlBar->toolsMenu_action->setMenu(menu); +} diff --git a/src/addressbar/addressbar.h b/lib/addressbar/addressbar.h index 9b8b360..861f985 100644 --- a/src/addressbar/addressbar.h +++ b/lib/addressbar/addressbar.h @@ -6,15 +6,16 @@ * SPDX-License-Identifier: GPL-3.0 */ -#ifndef ADDRESSBAR_H -#define ADDRESSBAR_H +#ifndef SMOLBOTE_ADDRESSBAR_H +#define SMOLBOTE_ADDRESSBAR_H #include <QWidget> #include <functional> -class WebView; +class QWebEngineView; class UrlLineEdit; class QProgressBar; +class QMenu; class AddressBar : public QWidget { Q_OBJECT @@ -25,9 +26,12 @@ public: signals: void complete(const QString &term, std::function<void(QStringList &)> callback); + void search(const QString &term); public slots: - void connectWebView(WebView *view); + void setView(QWebEngineView *view); + void setPageMenu(QMenu *menu); + void setToolsMenu(QMenu *menu); private: UrlLineEdit *urlBar; @@ -37,4 +41,4 @@ private: QMetaObject::Connection progressBarConnection; }; -#endif // ADDRESSBAR_H +#endif // SMOLBOTE_ADDRESSBAR_H diff --git a/src/addressbar/completer.cpp b/lib/addressbar/completer.cpp index 9b95ac0..9b95ac0 100644 --- a/src/addressbar/completer.cpp +++ b/lib/addressbar/completer.cpp diff --git a/src/addressbar/completer.h b/lib/addressbar/completer.h index 03ff317..03ff317 100644 --- a/src/addressbar/completer.h +++ b/lib/addressbar/completer.h diff --git a/src/addressbar/urllineedit.cpp b/lib/addressbar/urllineedit.cpp index fa65e5b..27acf60 100644 --- a/src/addressbar/urllineedit.cpp +++ b/lib/addressbar/urllineedit.cpp @@ -12,7 +12,6 @@ #include <QShortcut> #include <QTimer> #include <QWidgetAction> -#include <bookmarks/bookmarkswidget.h> UrlLineEdit::UrlLineEdit(QWidget *parent) : QLineEdit(parent) diff --git a/src/addressbar/urllineedit.h b/lib/addressbar/urllineedit.h index f27addc..f27addc 100644 --- a/src/addressbar/urllineedit.h +++ b/lib/addressbar/urllineedit.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index dd325ec..5757a6d 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -28,14 +28,6 @@ add_executable(poi mainwindow/widgets/tabwidget.cpp mainwindow/widgets/tabwidget.h - # address bar - addressbar/addressbar.cpp - addressbar/addressbar.h - addressbar/completer.cpp - addressbar/completer.h - addressbar/urllineedit.cpp - addressbar/urllineedit.h - # webengine webengine/urlinterceptor.cpp webengine/urlinterceptor.h @@ -63,6 +55,7 @@ target_link_libraries(poi Qt5::Core Qt5::Widgets Qt5::Concurrent Qt5::WebEngineWidgets ${Boost_LIBRARIES} about + addressbar configuration bookmarks downloads) 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; }; diff --git a/src/webengine/webview.h b/src/webengine/webview.h index 5ab04cd..2a99fdd 100644 --- a/src/webengine/webview.h +++ b/src/webengine/webview.h @@ -41,10 +41,11 @@ public: bool isLoaded() const; int loadProgress() const; - void search(const QString &term); - void triggerViewAction(ViewAction action); +public slots: + void search(const QString &term); + signals: // loadStarted is always emitted, be it page load or in-page request, // but loadFinished is only emitted when it's a page load |