Gui: Cap starting height of Preferences dialog

This commit ensures that preference windows does not start taller than available geometry.
This commit is contained in:
Kacper Donat
2023-12-02 17:44:17 +01:00
committed by Chris Hennes
parent d9f680f901
commit cc45f48912
2 changed files with 18 additions and 1 deletions

View File

@@ -13,7 +13,7 @@
<property name="minimumSize">
<size>
<width>1000</width>
<height>600</height>
<height>500</height>
</size>
</property>
<property name="windowTitle">

View File

@@ -39,6 +39,7 @@
# include <QToolTip>
# include <QProcess>
# include <QPushButton>
# include <QWindow>
#endif
#include <App/Application.h>
@@ -690,6 +691,22 @@ void DlgPreferencesImp::restartIfRequired()
void DlgPreferencesImp::showEvent(QShowEvent* ev)
{
QDialog::showEvent(ev);
auto screen = windowHandle()->screen();
auto availableSize = screen->availableSize();
// leave at least 100 px of height so preferences window does not take
// entire screen height. User will still be able to resize the window,
// but it should never start too tall.
auto maxStartHeight = availableSize.height() - 100;
if (height() > maxStartHeight) {
auto heightDifference = availableSize.height() - maxStartHeight;
// resize and reposition window so it is fully visible
resize(width(), maxStartHeight);
move(x(), heightDifference / 2);
}
}
QModelIndex findRootIndex(const QModelIndex& index)