diff options
-rw-r--r-- | src/mainwindow/widgets/tabwidget.cpp | 18 | ||||
-rw-r--r-- | src/webengine/widgets/pagemenu.cpp | 25 | ||||
-rw-r--r-- | src/webengine/widgets/pagemenu.h | 7 |
3 files changed, 32 insertions, 18 deletions
diff --git a/src/mainwindow/widgets/tabwidget.cpp b/src/mainwindow/widgets/tabwidget.cpp index a3fcbdd..4bc57ce 100644 --- a/src/mainwindow/widgets/tabwidget.cpp +++ b/src/mainwindow/widgets/tabwidget.cpp @@ -56,24 +56,6 @@ TabWidget::TabWidget(QWidget *parent) deleteTab(i); } }); - - auto *loadProfile_menu = tabContextMenu->addMenu(tr("Load Profile")); - { - auto *browser = qobject_cast<Browser *>(qApp); - Q_CHECK_PTR(browser); - - for(const QString &name : browser->profiles()) { - auto *profile = browser->profile(name); - Q_CHECK_PTR(profile); - - auto *profileAction = loadProfile_menu->addAction(profile->name()); - connect(profileAction, &QAction::triggered, this, [this, profile]() { - int index = this->tabBar()->tabAt(mapFromGlobal(tabContextMenu->pos())); - auto *view = qobject_cast<WebView *>(this->widget(index)); - view->setProfile(profile); - }); - } - } } TabWidget::~TabWidget() diff --git a/src/webengine/widgets/pagemenu.cpp b/src/webengine/widgets/pagemenu.cpp index c435d34..9cfeb71 100644 --- a/src/webengine/widgets/pagemenu.cpp +++ b/src/webengine/widgets/pagemenu.cpp @@ -18,11 +18,13 @@ #include <QToolButton> #include <QVBoxLayout> #include <QWidgetAction> +#include "browser.h" PageMenu::PageMenu(WebView *parent) : QMenu(tr("Page"), parent) { setMinimumWidth(240); + view = parent; auto *bookmarkAction = addAction(tr("Bookmark page")); connect(bookmarkAction, &QAction::triggered, parent, [parent]() { @@ -89,4 +91,27 @@ PageMenu::PageMenu(WebView *parent) } addAction(zoomWidgetAction); + addSeparator(); + + loadProfile_menu = addMenu(tr("Load Profile")); + connect(this, &PageMenu::aboutToShow, this, &PageMenu::updateLoadProfileMenu); +} + +void PageMenu::updateLoadProfileMenu() +{ + Q_CHECK_PTR(loadProfile_menu); + loadProfile_menu->clear(); + + auto *browser = qobject_cast<Browser *>(qApp); + Q_CHECK_PTR(browser); + + for(const QString &name : browser->profiles()) { + auto *profile = browser->profile(name); + Q_CHECK_PTR(profile); + + auto *profileAction = loadProfile_menu->addAction(profile->name()); + connect(profileAction, &QAction::triggered, this, [this, profile]() { + view->setProfile(profile); + }); + } } diff --git a/src/webengine/widgets/pagemenu.h b/src/webengine/widgets/pagemenu.h index 91f35e0..23e0e20 100644 --- a/src/webengine/widgets/pagemenu.h +++ b/src/webengine/widgets/pagemenu.h @@ -17,6 +17,13 @@ class PageMenu : public QMenu Q_OBJECT public: explicit PageMenu(WebView *parent = nullptr); + +private slots: + void updateLoadProfileMenu(); + +private: + QMenu *loadProfile_menu = nullptr; + WebView *view = nullptr; }; #endif //SMOLBOTE_PAGEMENU_H |