From 4eedf60d76a047f63b0991eee0b623e9be854c76 Mon Sep 17 00:00:00 2001 From: Aqua-sama Date: Thu, 13 Dec 2018 12:49:28 +0100 Subject: MainWindow: rework menu bar Split off menu bar into its own class out of MainWindow Menu bar now has a 'Find in menus' function --- lib/web/profilemanager.cpp | 20 ++++++++++++++++++++ lib/web/profilemanager.h | 1 + 2 files changed, 21 insertions(+) (limited to 'lib') 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 #include +#include +#include ProfileManager::ProfileManager(const QHash &profileSection, QObject *parent) : QObject(parent) @@ -111,6 +113,24 @@ void ProfileManager::deleteProfile(const QString &id) } } +void ProfileManager::profilePickerMenu(QMenu *menu, WebProfile *current, std::function 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 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 callback) const; QMenu *createProfileMenu(std::function callback, QWidget *parent = nullptr) const; const QStringList idList() const; -- cgit v1.2.1