reafctor(WideBar): connect to signal instead of overriding menu method

This makes stuff more standard and closer to what we do in other places
in the codebase.

Signed-off-by: flow <flowlnlnln@gmail.com>
This commit is contained in:
flow 2022-11-25 09:33:05 -03:00
parent 20c281d6f8
commit 4a1d082614
No known key found for this signature in database
GPG Key ID: 8D0F221F0A59F469
2 changed files with 10 additions and 5 deletions

View File

@ -38,7 +38,8 @@ WideBar::WideBar(const QString& title, QWidget* parent) : QToolBar(title, parent
setFloatable(false);
setMovable(false);
m_bar_menu = std::make_unique<QMenu>(this);
setContextMenuPolicy(Qt::ContextMenuPolicy::CustomContextMenu);
connect(this, &QToolBar::customContextMenuRequested, this, &WideBar::showVisibilityMenu);
}
WideBar::WideBar(QWidget* parent) : QToolBar(parent)
@ -46,7 +47,8 @@ WideBar::WideBar(QWidget* parent) : QToolBar(parent)
setFloatable(false);
setMovable(false);
m_bar_menu = std::make_unique<QMenu>(this);
setContextMenuPolicy(Qt::ContextMenuPolicy::CustomContextMenu);
connect(this, &QToolBar::customContextMenuRequested, this, &WideBar::showVisibilityMenu);
}
void WideBar::addAction(QAction* action)
@ -167,8 +169,11 @@ static void copyAction(QAction* from, QAction* to)
to->setToolTip(from->toolTip());
}
void WideBar::contextMenuEvent(QContextMenuEvent* event)
void WideBar::showVisibilityMenu(QPoint const& position)
{
if (!m_bar_menu)
m_bar_menu = std::make_unique<QMenu>(this);
if (m_menu_state == MenuState::Dirty) {
for (auto* old_action : m_bar_menu->actions())
old_action->deleteLater();
@ -198,7 +203,7 @@ void WideBar::contextMenuEvent(QContextMenuEvent* event)
m_menu_state = MenuState::Fresh;
}
m_bar_menu->popup(event->globalPos());
m_bar_menu->popup(mapToGlobal(position));
}
[[nodiscard]] QByteArray WideBar::getVisibilityState() const

View File

@ -24,7 +24,7 @@ class WideBar : public QToolBar {
void insertActionAfter(QAction* after, QAction* action);
QMenu* createContextMenu(QWidget* parent = nullptr, const QString& title = QString());
void contextMenuEvent(QContextMenuEvent*) override;
void showVisibilityMenu(const QPoint&);
// Ideally we would use a QBitArray for this, but it doesn't support string conversion,
// so using it in settings is very messy.