Qt: Implement "Keep Window on top"

This commit is contained in:
spycrab 2018-04-22 10:56:15 +02:00
parent c1dccdc0e5
commit caa18edc79
6 changed files with 33 additions and 4 deletions

View File

@ -165,7 +165,7 @@ void GeneralWidget::LoadSettings()
// Render to Main Window
m_render_main_window->setChecked(SConfig::GetInstance().bRenderToMain);
// Keep Window on Top
m_keep_window_top->setChecked(SConfig::GetInstance().bKeepWindowOnTop);
m_keep_window_top->setChecked(Settings::Instance().IsKeepWindowOnTopEnabled());
// Autoadjust Window size
m_autoadjust_window_size->setChecked(SConfig::GetInstance().bRenderWindowAutoSize);
}
@ -222,7 +222,7 @@ void GeneralWidget::SaveSettings()
// Render to Main Window
SConfig::GetInstance().bRenderToMain = m_render_main_window->isChecked();
// Keep Window on Top
SConfig::GetInstance().bKeepWindowOnTop = m_keep_window_top->isChecked();
Settings::Instance().SetKeepWindowOnTop(m_keep_window_top->isChecked());
// Autoadjust windowsize
SConfig::GetInstance().bRenderWindowAutoSize = m_autoadjust_window_size->isChecked();
}

View File

@ -53,6 +53,9 @@ RenderWidget::RenderWidget(QWidget* parent) : QWidget(parent)
connect(&Settings::Instance(), &Settings::HideCursorChanged, this,
&RenderWidget::OnHideCursorChanged);
OnHideCursorChanged();
connect(&Settings::Instance(), &Settings::KeepWindowOnTopChanged, this,
&RenderWidget::OnKeepOnTopChanged);
OnKeepOnTopChanged(Settings::Instance().IsKeepWindowOnTopEnabled());
m_mouse_timer->start(MOUSE_HIDE_DELAY);
SetFillBackground(true);
@ -70,6 +73,14 @@ void RenderWidget::OnHideCursorChanged()
setCursor(Settings::Instance().GetHideCursor() ? Qt::BlankCursor : Qt::ArrowCursor);
}
void RenderWidget::OnKeepOnTopChanged(bool top)
{
setWindowFlags(top ? windowFlags() | Qt::WindowStaysOnTopHint :
windowFlags() & ~Qt::WindowStaysOnTopHint);
show();
}
void RenderWidget::HandleCursorTimer()
{
if (isActiveWindow())

View File

@ -29,6 +29,7 @@ signals:
private:
void HandleCursorTimer();
void OnHideCursorChanged();
void OnKeepOnTopChanged(bool top);
void SetFillBackground(bool fill);
static constexpr int MOUSE_HIDE_DELAY = 3000;

View File

@ -130,6 +130,20 @@ bool Settings::GetHideCursor() const
return SConfig::GetInstance().bHideCursor;
}
void Settings::SetKeepWindowOnTop(bool top)
{
if (IsKeepWindowOnTopEnabled() == top)
return;
SConfig::GetInstance().bKeepWindowOnTop = top;
emit KeepWindowOnTopChanged(top);
}
bool Settings::IsKeepWindowOnTopEnabled() const
{
return SConfig::GetInstance().bKeepWindowOnTop;
}
int Settings::GetVolume() const
{
return SConfig::GetInstance().m_Volume;

View File

@ -74,6 +74,8 @@ public:
// Graphics
void SetHideCursor(bool hide_cursor);
bool GetHideCursor() const;
void SetKeepWindowOnTop(bool top);
bool IsKeepWindowOnTopEnabled() const;
// Audio
int GetVolume() const;
@ -126,6 +128,7 @@ signals:
void DefaultGameChanged(const QString&);
void PathReloadRequested(const QString&);
void HideCursorChanged();
void KeepWindowOnTopChanged(bool top);
void VolumeChanged(int volume);
void NANDRefresh();
void RegistersVisibilityChanged(bool visible);

View File

@ -178,7 +178,7 @@ void InterfacePane::LoadConfig()
{
const SConfig& startup_params = SConfig::GetInstance();
m_checkbox_auto_window->setChecked(startup_params.bRenderWindowAutoSize);
m_checkbox_top_window->setChecked(startup_params.bKeepWindowOnTop);
m_checkbox_top_window->setChecked(Settings::Instance().IsKeepWindowOnTopEnabled());
m_checkbox_render_to_window->setChecked(startup_params.bRenderToMain);
m_checkbox_use_builtin_title_database->setChecked(startup_params.m_use_builtin_title_database);
m_checkbox_show_debugging_ui->setChecked(Settings::Instance().IsDebugModeEnabled());
@ -200,7 +200,7 @@ void InterfacePane::OnSaveConfig()
{
SConfig& settings = SConfig::GetInstance();
settings.bRenderWindowAutoSize = m_checkbox_auto_window->isChecked();
settings.bKeepWindowOnTop = m_checkbox_top_window->isChecked();
Settings::Instance().SetKeepWindowOnTop(m_checkbox_top_window->isChecked());
settings.bRenderToMain = m_checkbox_render_to_window->isChecked();
settings.m_use_builtin_title_database = m_checkbox_use_builtin_title_database->isChecked();
Settings::Instance().SetDebugModeEnabled(m_checkbox_show_debugging_ui->isChecked());