diff options
author | Aqua-sama <aqua@iserlohn-fortress.net> | 2018-12-13 12:49:28 +0100 |
---|---|---|
committer | Aqua-sama <aqua@iserlohn-fortress.net> | 2018-12-13 13:41:50 +0100 |
commit | 4eedf60d76a047f63b0991eee0b623e9be854c76 (patch) | |
tree | c8b335c8909a309c2bc2765e823bec5da74aa5aa /lib/web | |
parent | Fix crash creating ConfigurationEditorPlugin widget (diff) | |
download | smolbote-4eedf60d76a047f63b0991eee0b623e9be854c76.tar.xz |
MainWindow: rework menu bar
Split off menu bar into its own class out of MainWindow
Menu bar now has a 'Find in menus' function
Diffstat (limited to 'lib/web')
-rw-r--r-- | lib/web/profilemanager.cpp | 20 | ||||
-rw-r--r-- | lib/web/profilemanager.h | 1 |
2 files changed, 21 insertions, 0 deletions
diff --git a/lib/web/profilemanager.cpp b/lib/web/profilemanager.cpp index 14795cd..6e6281b 100644 --- a/lib/web/profilemanager.cpp +++ b/lib/web/profilemanager.cpp @@ -10,6 +10,8 @@ #include "webprofile.h" #include <QFileInfo> #include <QWebEngineSettings> +#include <QWidgetAction> +#include <QRadioButton> ProfileManager::ProfileManager(const QHash<QString, QString> &profileSection, QObject *parent) : QObject(parent) @@ -111,6 +113,24 @@ void ProfileManager::deleteProfile(const QString &id) } } +void ProfileManager::profilePickerMenu(QMenu *menu, WebProfile *current, std::function<void(WebProfile *)> callback) const +{ + for(const auto &profileData : m_profiles) { + WebProfile *profile = profileData.second->profile; + + auto *profileButton = new QRadioButton(profile->name(), menu); + profileButton->setChecked(profile == current); + + auto *action = new QWidgetAction(menu); + action->setDefaultWidget(profileButton); + connect(profileButton, &QRadioButton::clicked, profile, [profile, callback]() { + callback(profile); + }); + + menu->addAction(action); + } +} + QMenu *ProfileManager::createProfileMenu(std::function<void(WebProfile *)> callback, QWidget *parent) const { auto *menu = new QMenu(parent); diff --git a/lib/web/profilemanager.h b/lib/web/profilemanager.h index f5e33b9..e0040a3 100644 --- a/lib/web/profilemanager.h +++ b/lib/web/profilemanager.h @@ -31,6 +31,7 @@ public: WebProfile *loadProfile(const QString &path); void deleteProfile(const QString &id); + void profilePickerMenu(QMenu *menu, WebProfile *current, std::function<void(WebProfile *)> callback) const; QMenu *createProfileMenu(std::function<void(WebProfile *)> callback, QWidget *parent = nullptr) const; const QStringList idList() const; |