feat(WideBar): allow loading/unloading visibility via a byte array

I really wanted to use a QBitArray :c

Signed-off-by: flow <flowlnlnln@gmail.com>
This commit is contained in:
flow
2022-11-19 17:10:43 -03:00
parent 6e1639551b
commit 479843f56b
2 changed files with 36 additions and 0 deletions

View File

@ -200,4 +200,34 @@ void WideBar::contextMenuEvent(QContextMenuEvent* event)
m_bar_menu->popup(event->globalPos());
}
[[nodiscard]] QByteArray WideBar::getVisibilityState() const
{
QByteArray state;
for (auto const& entry : m_entries) {
if (entry.type != BarEntry::Type::Action)
continue;
state.append(entry.bar_action->isVisible() ? '1' : '0');
}
return state;
}
void WideBar::setVisibilityState(QByteArray&& state)
{
qsizetype i = 0;
for (auto& entry : m_entries) {
if (entry.type != BarEntry::Type::Action)
continue;
if (i == state.size())
break;
entry.bar_action->setVisible(state.at(i++) == '1');
// NOTE: This is needed so that disabled actions get reflected on the button when it is made visible.
static_cast<ActionButton*>(widgetForAction(entry.bar_action))->actionChanged();
}
}
#include "WideBar.moc"