diff options
author | Aqua-sama <aqua@iserlohn-fortress.net> | 2020-04-29 18:49:07 +0300 |
---|---|---|
committer | Aqua-sama <aqua@iserlohn-fortress.net> | 2020-05-08 13:40:29 +0300 |
commit | e87693c54ca97ed3a6ed25f9eaae8ab223fc18b1 (patch) | |
tree | 54194ca979ac7e646ff3f10ed6d7f7753273f0be /src/mainwindow | |
parent | Expand pluginloader test coverage (diff) | |
download | smolbote-e87693c54ca97ed3a6ed25f9eaae8ab223fc18b1.tar.xz |
libwebengine
Make src/webengine into a static library
- Add some tests
- Updated manpage
- Remove WebProfileManager::id and WebProfileManager::instance
- Add consumable semantics checks to WebProfileManager
- Add WebProfileManager::walk
Add ApplicationMenu class
Diffstat (limited to 'src/mainwindow')
-rw-r--r-- | src/mainwindow/mainwindow.cpp | 11 | ||||
-rw-r--r-- | src/mainwindow/mainwindow.h | 4 | ||||
-rw-r--r-- | src/mainwindow/menubar.cpp | 102 | ||||
-rw-r--r-- | src/mainwindow/menubar.h | 5 |
4 files changed, 22 insertions, 100 deletions
diff --git a/src/mainwindow/mainwindow.cpp b/src/mainwindow/mainwindow.cpp index e16f34f..4ec79b1 100644 --- a/src/mainwindow/mainwindow.cpp +++ b/src/mainwindow/mainwindow.cpp @@ -24,7 +24,7 @@ #include <QMessageBox> #include <QStatusBar> -MainWindow::MainWindow(const Session::MainWindow &data, QWidget *parent) +MainWindow::MainWindow(const Session::MainWindow &data, QMenu *appMenu, QWidget *parent) : QMainWindow(parent) { Configuration config; @@ -50,8 +50,8 @@ MainWindow::MainWindow(const Session::MainWindow &data, QWidget *parent) this->addToolBarBreak(); this->addToolBar(new BookmarksToolbar(app->bookmarks()->model(), this)); - m_menuBar = new MenuBar(this); - this->setMenuBar(m_menuBar); + m_menuBar = new MenuBar(appMenu, this); + setMenuBar(m_menuBar); // status bar searchBox = new SearchForm(this); @@ -125,10 +125,9 @@ void MainWindow::createTab(const Session::WebView &data) SubWindow *MainWindow::createSubWindow(const Session::SubWindow &data) { - const auto *profileManager = WebProfileManager::instance(); - Q_CHECK_PTR(profileManager); + WebProfileManager profileManager; - auto *profile = profileManager->profile(data.profile); + auto *profile = profileManager.profile(data.profile); if(profile == nullptr) { profile = WebProfile::defaultProfile(); } diff --git a/src/mainwindow/mainwindow.h b/src/mainwindow/mainwindow.h index 2b9f82b..31f5658 100644 --- a/src/mainwindow/mainwindow.h +++ b/src/mainwindow/mainwindow.h @@ -34,9 +34,11 @@ public: ToolsMenu }; - explicit MainWindow(const Session::MainWindow &data, QWidget *parent = nullptr); + explicit MainWindow(const Session::MainWindow &data, QMenu *appMenu, QWidget *parent = nullptr); + MainWindow(const MainWindow &) = delete; ~MainWindow() = default; + [[nodiscard]] Session::MainWindow serialize() const { QVector<Session::SubWindow> subwindows(m_subwindows.size()); diff --git a/src/mainwindow/menubar.cpp b/src/mainwindow/menubar.cpp index 83cafee..f8979de 100644 --- a/src/mainwindow/menubar.cpp +++ b/src/mainwindow/menubar.cpp @@ -12,23 +12,17 @@ #include "configuration.h" #include "downloadswidget.h" #include "mainwindow.h" -#include "session/savesessiondialog.h" -#include "session/sessiondialog.h" #include "subwindow/subwindow.h" #include "webengine/webprofilemanager.h" #include "webengine/webview.h" #include "widgets/menusearch.h" -#include <QApplication> #include <QDir> #include <QFileDialog> -#include <QLineEdit> -#include <QMdiArea> #include <QPrintDialog> #include <QPrinter> #include <QPrinterInfo> #include <QToolBar> #include <QVBoxLayout> -#include <QWidgetAction> #include <functional> inline void run_if(SubWindow *_subwindow, const std::function<void(SubWindow *, int)> &f) @@ -70,7 +64,7 @@ inline QDialog *createDevToolsDialog(QWebEnginePage *page) return popup; } -MenuBar::MenuBar(MainWindow *parent) +MenuBar::MenuBar(QMenu *appMenu, MainWindow *parent) : QMenuBar(parent) { m_parent = parent; @@ -78,86 +72,21 @@ MenuBar::MenuBar(MainWindow *parent) Q_CHECK_PTR(browser); Configuration conf; - smolbote = this->addMenu(qApp->applicationName()); - { - auto *findMenu = smolbote->addMenu(tr("Find in menus")); - - auto *findWidget = new QWidgetAction(this); - auto *find_lineEdit = new MenuSearch(this); - findWidget->setDefaultWidget(find_lineEdit); - findMenu->addAction(findWidget); - - connect(findMenu, &QMenu::aboutToShow, [findMenu, find_lineEdit]() { - find_lineEdit->clear(); - const auto actions = findMenu->actions(); - for(int i = 1; i < actions.length(); i++) { - findMenu->removeAction(actions.at(i)); - } - find_lineEdit->setFocus(); - }); - - connect(find_lineEdit, &QLineEdit::textEdited, [this, findMenu](const QString &text) { - // clear menu - const auto actions = findMenu->actions(); - for(int i = 1; i < actions.length(); i++) - findMenu->removeAction(actions.at(i)); - - if(text.isEmpty()) - return; - - // findChildren - for(QAction *a : findChildren<QAction *>()) { - if(a->text().contains(text)) - findMenu->addAction(a); - } - }); - - smolbote->addSeparator(); - - const QString sessionPath = conf.value<QString>("session.path").value(); - auto *actionSaveSession = smolbote->addAction(tr("Save Session"), parent, [sessionPath]() { - auto *sessionDialog = new SaveSessionDialog(nullptr); - if(sessionDialog->exec() == QDialog::Accepted) - sessionDialog->save(sessionPath); - }); - conf.shortcut<QAction>(*actionSaveSession, "shortcuts.session.save"); - - auto *actionOpenSession = smolbote->addAction(tr("Open Session"), parent, [parent]() { - auto *sessionDialog = new SessionDialog(parent); - sessionDialog->exec(); - }); - conf.shortcut<QAction>(*actionOpenSession, "shortcuts.session.open"); - - smolbote->addSeparator(); - auto *actionBookmarks = smolbote->addAction(tr("Bookmarks"), browser, [browser, parent]() { - browser->showWidget(browser->bookmarks(), parent); - }); - conf.shortcut<QAction>(*actionBookmarks, "shortcuts.window.bookmarks.show"); - - auto *actionDownloads = smolbote->addAction(tr("Downloads"), browser, [browser, parent]() { - browser->showWidget(browser->downloads(), parent); - }); - conf.shortcut<QAction>(*actionDownloads, "shortcuts.window.downloads.show"); - - smolbote->addSeparator(); - smolbote->addAction(tr("Load Plugin"), browser, [browser]() { - const QString path = QFileDialog::getOpenFileName(nullptr, tr("Select Plugin"), QDir::homePath(), tr("Plugins (*.so)")); - browser->loadPlugins(QStringList(path)); - }); - - pluginInsertLocation = smolbote->addSeparator(); - - auto *actionAbout = smolbote->addAction(tr("About"), browser, &Browser::about); - conf.shortcut<QAction>(*actionAbout, "shortcuts.window.about"); - - smolbote->addSeparator(); - - auto *actionQuit = smolbote->addAction(tr("Quit"), qApp, &QApplication::quit); - conf.shortcut<QAction>(*actionQuit, "shortcuts.window.quit"); - } + addMenu(appMenu); window = this->addMenu(tr("&Window")); { + auto *actionBookmarks = window->addAction(tr("Bookmarks"), browser, [browser, parent]() { + browser->showWidget(browser->bookmarks(), parent); + }); + conf.shortcut<QAction>(*actionBookmarks, "shortcuts.window.bookmarks.show"); + + auto *actionDownloads = window->addAction(tr("Downloads"), browser, [browser, parent]() { + browser->showWidget(browser->downloads(), parent); + }); + conf.shortcut<QAction>(*actionDownloads, "shortcuts.window.downloads.show"); + window->addSeparator(); + auto *actionNewWindow = window->addAction(tr("New Window"), browser, [browser]() { const Session::MainWindow window; browser->open({ window }, false); @@ -532,11 +461,6 @@ MenuBar::MenuBar(MainWindow *parent) } } -QAction *MenuBar::insertPlugin(QMenu *menu) -{ - return smolbote->insertMenu(pluginInsertLocation, menu); -} - void MenuBar::insertSubWindow(SubWindow *subwindow) { auto *action = window->addAction(subwindow->windowTitle()); diff --git a/src/mainwindow/menubar.h b/src/mainwindow/menubar.h index f369bef..7795816 100644 --- a/src/mainwindow/menubar.h +++ b/src/mainwindow/menubar.h @@ -18,14 +18,11 @@ class MenuBar : public QMenuBar Q_OBJECT public: - MenuBar(MainWindow *parent = nullptr); - - QAction *insertPlugin(QMenu *menu); + MenuBar(QMenu *appMenu, MainWindow *parent = nullptr); void insertSubWindow(SubWindow *subwindow); private: MainWindow *m_parent = nullptr; - QMenu *smolbote = nullptr; QMenu *window = nullptr; QAction *pluginInsertLocation = nullptr; }; |