diff options
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; |