feat(WideBar): custom context menu actions

Signed-off-by: leo78913 <leo3758@riseup.net>
This commit is contained in:
leo78913 2023-01-10 12:02:02 -03:00
parent 55d4064335
commit f16989bea9
3 changed files with 16 additions and 0 deletions

View File

@ -177,6 +177,10 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi
ui->instanceToolBar->setVisibilityState(instanceToolbarSetting->get().toByteArray());
ui->instanceToolBar->addContextMenuAction(ui->newsToolBar->toggleViewAction());
ui->instanceToolBar->addContextMenuAction(ui->instanceToolBar->toggleViewAction());
ui->instanceToolBar->addContextMenuAction(ui->actionLockToolbars);
}
// set the menu for the folders and help tool buttons

View File

@ -207,6 +207,10 @@ void WideBar::showVisibilityMenu(QPoint const& position)
m_bar_menu->clear();
m_bar_menu->addActions(m_context_menu_actions);
m_bar_menu->addSeparator()->setText(tr("Customize toolbar actions"));
for (auto& entry : m_entries) {
if (entry.type != BarEntry::Type::Action)
continue;
@ -233,6 +237,10 @@ void WideBar::showVisibilityMenu(QPoint const& position)
m_bar_menu->popup(mapToGlobal(position));
}
void WideBar::addContextMenuAction(QAction* action) {
m_context_menu_actions.append(action);
}
[[nodiscard]] QByteArray WideBar::getVisibilityState() const
{
QByteArray state;

View File

@ -30,6 +30,8 @@ class WideBar : public QToolBar {
QMenu* createContextMenu(QWidget* parent = nullptr, const QString& title = QString());
void showVisibilityMenu(const QPoint&);
void addContextMenuAction(QAction* action);
// Ideally we would use a QBitArray for this, but it doesn't support string conversion,
// so using it in settings is very messy.
@ -52,6 +54,8 @@ class WideBar : public QToolBar {
private:
QList<BarEntry> m_entries;
QList<QAction*> m_context_menu_actions;
bool m_use_default_action = false;
// Menu to toggle visibility from buttons in the bar