diff options
-rw-r--r-- | src/CMakeLists.txt | 4 | ||||
-rw-r--r-- | src/browser.cpp | 2 | ||||
-rw-r--r-- | src/mainwindow/mainwindow.cpp | 20 | ||||
-rw-r--r-- | src/mainwindow/mainwindow.h | 6 | ||||
-rw-r--r-- | src/mainwindow/subwindow.cpp (renamed from src/mainwindow/window.cpp) | 55 | ||||
-rw-r--r-- | src/mainwindow/subwindow.h (renamed from src/mainwindow/window.h) | 17 | ||||
-rw-r--r-- | src/webengine/webview.cpp | 6 | ||||
-rw-r--r-- | src/webengine/webview.h | 4 |
8 files changed, 59 insertions, 55 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index c326c4b..d0ac915 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -18,8 +18,8 @@ add_executable(poi # main window mainwindow/mainwindow.cpp mainwindow/mainwindow.h - mainwindow/window.cpp - mainwindow/window.h + mainwindow/subwindow.cpp + mainwindow/subwindow.h mainwindow/widgets/dockwidget.cpp mainwindow/widgets/dockwidget.h mainwindow/widgets/navigationbar.cpp diff --git a/src/browser.cpp b/src/browser.cpp index 525f02c..41c73df 100644 --- a/src/browser.cpp +++ b/src/browser.cpp @@ -9,7 +9,7 @@ #include "browser.h" #include "addressbar/addressbar.h" #include "mainwindow/mainwindow.h" -#include "mainwindow/window.h" +#include "mainwindow/subwindow.h" #include "webengine/urlinterceptor.h" #include "webengine/webprofile.h" #include <QAction> diff --git a/src/mainwindow/mainwindow.cpp b/src/mainwindow/mainwindow.cpp index c078d81..7e49ab8 100644 --- a/src/mainwindow/mainwindow.cpp +++ b/src/mainwindow/mainwindow.cpp @@ -11,7 +11,7 @@ #include "webengine/webview.h" #include "widgets/navigationbar.h" #include "widgets/searchform.h" -#include "window.h" +#include "subwindow.h" #include <QApplication> #include <QCloseEvent> #include "widgets/dockwidget.h" @@ -70,7 +70,7 @@ MainWindow::MainWindow(std::shared_ptr<Configuration> &config, QWidget *parent) disconnect(statusBarConnection); subWindowAction->setMenu(nullptr); - auto *w = qobject_cast<Window *>(window); + auto *w = qobject_cast<SubWindow *>(window); if(w == nullptr) { // no current subwindow, clear everything setView(nullptr); @@ -78,8 +78,8 @@ MainWindow::MainWindow(std::shared_ptr<Configuration> &config, QWidget *parent) } else { setView(w->currentView()); subWindowAction->setMenu(w->systemMenu()); - viewChangedConnection = connect(w, &Window::currentViewChanged, this, &MainWindow::setView); - statusBarConnection = connect(w, &Window::showStatusMessage, statusBar(), &QStatusBar::showMessage); + viewChangedConnection = connect(w, &SubWindow::currentViewChanged, this, &MainWindow::setView); + statusBarConnection = connect(w, &SubWindow::showStatusMessage, statusBar(), &QStatusBar::showMessage); } }); @@ -112,7 +112,7 @@ void MainWindow::createMenuBar() Q_CHECK_PTR(mdiArea); auto *smolboteMenu = menuBar()->addMenu(qApp->applicationDisplayName()); - smolboteMenu->addAction(tr("New tab group"), this, [this]() { + smolboteMenu->addAction(tr("New subwindow"), this, [this]() { createSubWindow(); }, QKeySequence(m_config->value<std::string>("mainwindow.shortcuts.newGroup").value().c_str())); @@ -187,7 +187,7 @@ void MainWindow::removeDockWidget(QWidget *widget) void MainWindow::createTab(const QUrl &url) { - auto *w = qobject_cast<Window *>(mdiArea->currentSubWindow()); + auto *w = qobject_cast<SubWindow *>(mdiArea->currentSubWindow()); if(w == nullptr) { w = createSubWindow(url.toString()); } else { @@ -195,14 +195,14 @@ void MainWindow::createTab(const QUrl &url) } } -Window *MainWindow::currentSubWindow() const +SubWindow *MainWindow::currentSubWindow() const { - return qobject_cast<Window *>(mdiArea->currentSubWindow()); + return qobject_cast<SubWindow *>(mdiArea->currentSubWindow()); } -Window *MainWindow::createSubWindow(const QString &url) +SubWindow *MainWindow::createSubWindow(const QString &url) { - auto *w = new Window(m_config->section("window"), this); + auto *w = new SubWindow(m_config->section("window"), this); mdiArea->addSubWindow(w); w->showMaximized(); w->setFocus(); diff --git a/src/mainwindow/mainwindow.h b/src/mainwindow/mainwindow.h index 8f511a3..af713fc 100644 --- a/src/mainwindow/mainwindow.h +++ b/src/mainwindow/mainwindow.h @@ -16,7 +16,7 @@ class Browser; class QMdiArea; class Configuration; -class Window; +class SubWindow; class AddressBar; class SearchForm; class WebView; @@ -42,11 +42,11 @@ public: void addDockWidget(Qt::DockWidgetArea area, QWidget *widget); void removeDockWidget(QWidget *widget); - Window *currentSubWindow() const; + SubWindow *currentSubWindow() const; public slots: void createTab(const QUrl &url); - Window *createSubWindow(const QString &url = QString()); + SubWindow *createSubWindow(const QString &url = QString()); void setView(WebView *view); diff --git a/src/mainwindow/window.cpp b/src/mainwindow/subwindow.cpp index 273aa0a..497e6d0 100644 --- a/src/mainwindow/window.cpp +++ b/src/mainwindow/subwindow.cpp @@ -6,21 +6,21 @@ * SPDX-License-Identifier: GPL-3.0 */ -#include "window.h" +#include "subwindow.h" +#include "browser.h" #include "webengine/webprofile.h" #include "webengine/webview.h" #include "widgets/tabwidget.h" -#include <QToolButton> -#include <QStyle> #include <QAction> -#include <QShortcut> -#include <QMenu> -#include <QJsonObject> #include <QJsonArray> #include <QJsonDocument> -#include "browser.h" +#include <QJsonObject> +#include <QMenu> +#include <QShortcut> +#include <QStyle> +#include <QToolButton> -Window::Window(const QHash<QString, QString> &config, QWidget *parent, Qt::WindowFlags flags) +SubWindow::SubWindow(const QHash<QString, QString> &config, QWidget *parent, Qt::WindowFlags flags) : QMdiSubWindow(parent, flags) , tabWidget(new TabWidget(this)) { @@ -32,20 +32,22 @@ Window::Window(const QHash<QString, QString> &config, QWidget *parent, Qt::Windo profile = WebProfile::defaultProfile(); + // system menu { auto *menu = systemMenu(); menu->addSeparator(); - auto *profileName_action = menu->addAction(tr("Profile: %1").arg(profile->isOffTheRecord() ? tr("off-the-record") : profile->storageName())); + auto *profileName_action = menu->addAction(tr("Profile: %1").arg(profile->name())); profileName_action->setEnabled(false); auto *loadProfile_menu = menu->addMenu(tr("Load profile")); - Browser *instance = qobject_cast<Browser*>(qApp); - Q_ASSERT_X(instance != nullptr, "Window::Window", "Could not cast instance"); - for(const QString &name : instance->profiles()) { + Browser *browser = qobject_cast<Browser *>(qApp); + Q_CHECK_PTR(browser); + + for(const QString &name : browser->profiles()) { auto *loadAction = loadProfile_menu->addAction(name); - connect(loadAction, &QAction::triggered, this, [name, instance, profileName_action, this]() { - auto *profile = instance->profile(name); + connect(loadAction, &QAction::triggered, this, [name, browser, profileName_action, this]() { + auto *profile = browser->profile(name); this->setProfile(profile); profileName_action->setText(tr("Profile: %1").arg(name)); }); @@ -119,24 +121,24 @@ Window::Window(const QHash<QString, QString> &config, QWidget *parent, Qt::Windo }); } -Window::~Window() +SubWindow::~SubWindow() { delete tabWidget; } -WebView *Window::currentView() +WebView *SubWindow::currentView() { return qobject_cast<WebView *>(tabWidget->currentWidget()); } -WebView *Window::view(int index) const +WebView *SubWindow::view(int index) const { return qobject_cast<WebView *>(tabWidget->widget(index)); } -void Window::setProfile(WebProfile *profile) +void SubWindow::setProfile(WebProfile *profile) { - Q_ASSERT_X(profile != nullptr, "Window::setProfile", "Tried to set null profile"); + Q_CHECK_PTR(profile); this->profile = profile; for(int i = 0; i < tabWidget->count(); ++i) { auto *view = qobject_cast<WebView *>(tabWidget->widget(i)); @@ -144,7 +146,7 @@ void Window::setProfile(WebProfile *profile) } } -int Window::addTab(const QUrl &url) +int SubWindow::addTab(const QUrl &url) { auto *view = new WebView(profile, this); if(!url.isEmpty()) @@ -152,12 +154,12 @@ int Window::addTab(const QUrl &url) return tabWidget->addTab(view); } -void Window::swapToTab(int index) +void SubWindow::setCurrentTab(int index) { tabWidget->setCurrentIndex(index); } -QJsonObject Window::session() const +QJsonObject SubWindow::session() const { QJsonObject obj; obj.insert("profile", QJsonValue("")); @@ -174,10 +176,14 @@ QJsonObject Window::session() const return obj; } -void Window::restoreSession(const QJsonObject &sessionData) +void SubWindow::restoreSession(const QJsonObject &sessionData) { + auto *browser = qobject_cast<Browser *>(qApp); + Q_CHECK_PTR(browser); + Q_ASSERT_X(sessionData.value("profile") != QJsonValue::Undefined, "Window::restoreSession", "no profile in json"); - auto *profile = WebProfile::defaultProfile(); + if(browser->profiles().contains(sessionData.value("profile").toString())) + profile = browser->profile(sessionData.value("profile").toString()); Q_ASSERT_X(sessionData.value("tabs") != QJsonValue::Undefined, "Window::restoreSession", "no tabs in json"); const QJsonArray tabs = sessionData.value("tabs").toArray(); @@ -195,5 +201,4 @@ void Window::restoreSession(const QJsonObject &sessionData) view->load(QUrl::fromUserInput(tab.toString())); tabWidget->addTab(view); } - } diff --git a/src/mainwindow/window.h b/src/mainwindow/subwindow.h index 6431466..ac1610a 100644 --- a/src/mainwindow/window.h +++ b/src/mainwindow/subwindow.h @@ -6,23 +6,23 @@ * SPDX-License-Identifier: GPL-3.0 */ -#ifndef SMOLBOTE_WINDOW_H -#define SMOLBOTE_WINDOW_H +#ifndef SMOLBOTE_SUBWINDOW_H +#define SMOLBOTE_SUBWINDOW_H #include <QMdiSubWindow> -#include <memory> #include <QUrl> +#include <memory> class TabWidget; class WebView; class WebProfile; -class Window : public QMdiSubWindow +class SubWindow : public QMdiSubWindow { Q_OBJECT public: - explicit Window(const QHash<QString, QString> &config, QWidget *parent = nullptr, Qt::WindowFlags flags = Qt::WindowFlags()); - ~Window() override; + explicit SubWindow(const QHash<QString, QString> &config, QWidget *parent = nullptr, Qt::WindowFlags flags = Qt::WindowFlags()); + ~SubWindow() override; WebView *currentView(); WebView *view(int index) const; @@ -38,8 +38,7 @@ signals: public slots: int addTab(const QUrl &url = QUrl()); - - void swapToTab(int index); + void setCurrentTab(int index); private: WebProfile *profile; @@ -49,4 +48,4 @@ private: QMetaObject::Connection linkHoveredConnection; }; -#endif // SMOLBOTE_WINDOW_H +#endif // SMOLBOTE_SUBWINDOW_H diff --git a/src/webengine/webview.cpp b/src/webengine/webview.cpp index d5f88d0..c6fd4a4 100644 --- a/src/webengine/webview.cpp +++ b/src/webengine/webview.cpp @@ -7,7 +7,7 @@ */ #include "webview.h" -#include "mainwindow/window.h" +#include "mainwindow/subwindow.h" #include "webpage.h" #include "webprofile.h" #include "widgets/pagemenu.h" @@ -23,7 +23,7 @@ WebView::WebView(WebProfile *profile, QWidget *parent) m_profile = profile; setPage(new WebPage(profile, this)); - m_parentWindow = qobject_cast<Window *>(parent); + m_parentWindow = qobject_cast<SubWindow *>(parent); // load status and progress connect(this, &QWebEngineView::loadStarted, this, [this]() { @@ -86,7 +86,7 @@ WebView *WebView::createWindow(QWebEnginePage::WebWindowType type) case QWebEnginePage::WebBrowserTab: // a web browser tab - m_parentWindow->swapToTab(index); + m_parentWindow->setCurrentTab(index); break; case QWebEnginePage::WebDialog: diff --git a/src/webengine/webview.h b/src/webengine/webview.h index 378296e..4d648d7 100644 --- a/src/webengine/webview.h +++ b/src/webengine/webview.h @@ -14,7 +14,7 @@ class QMenu; class WebProfile; -class Window; +class SubWindow; class WebView : public QWebEngineView { Q_OBJECT @@ -57,7 +57,7 @@ protected: WebView *createWindow(QWebEnginePage::WebWindowType type) override; private: - Window *m_parentWindow = nullptr; + SubWindow *m_parentWindow = nullptr; WebProfile *m_profile = nullptr; QMenu *m_pageMenu = nullptr; |