Qt: AlwaysOnTop GBA widget option

This commit is contained in:
Bonta 2021-07-22 18:19:27 +02:00
parent 501868ace0
commit 6fc060bdca
2 changed files with 22 additions and 0 deletions

View File

@ -247,6 +247,19 @@ void GBAWidget::SetBorderless(bool enable)
}
}
bool GBAWidget::IsAlwaysOnTop() const
{
return windowFlags().testFlag(Qt::WindowStaysOnTopHint);
}
void GBAWidget::SetAlwaysOnTop(bool enable)
{
if (windowFlags().testFlag(Qt::WindowStaysOnTopHint) == enable)
return;
setWindowFlag(Qt::WindowStaysOnTopHint, enable);
show();
}
void GBAWidget::UpdateTitle()
{
std::string title = fmt::format("GBA{}", m_core_info.device_number + 1);
@ -366,6 +379,11 @@ void GBAWidget::contextMenuEvent(QContextMenuEvent* event)
borderless_action->setChecked(IsBorderless());
connect(borderless_action, &QAction::triggered, this, [this] { SetBorderless(!IsBorderless()); });
auto* topmost_action = new QAction(tr("Always on &Top"), options_menu);
topmost_action->setCheckable(true);
topmost_action->setChecked(IsAlwaysOnTop());
connect(topmost_action, &QAction::triggered, this, [this] { SetAlwaysOnTop(!IsAlwaysOnTop()); });
menu->addAction(disconnect_action);
menu->addSeparator();
menu->addAction(load_action);
@ -385,6 +403,7 @@ void GBAWidget::contextMenuEvent(QContextMenuEvent* event)
options_menu->addMenu(size_menu);
options_menu->addSeparator();
options_menu->addAction(borderless_action);
options_menu->addAction(topmost_action);
size_menu->addAction(x1_action);
size_menu->addAction(x2_action);

View File

@ -55,6 +55,9 @@ public:
bool IsBorderless() const;
void SetBorderless(bool enable);
bool IsAlwaysOnTop() const;
void SetAlwaysOnTop(bool enable);
private:
void UpdateTitle();
void UpdateVolume();