Gui: Ensure minimum size of preferences dialog (#16019)

* Gui: Ensure minimum size of preferences dialog

This will ensure that the width of preferences dialog is resized to fit
all pages properly but not take more than 80% of screen.

* Gui: Use consts for resizing preferences dialog
This commit is contained in:
Kacper Donat
2024-08-26 17:48:49 +02:00
committed by GitHub
parent e1f65ee831
commit f10a8b63d1
2 changed files with 7 additions and 6 deletions

View File

@@ -761,10 +761,10 @@ void DlgPreferencesImp::showEvent(QShowEvent* ev)
auto screen = windowHandle()->screen();
auto availableSize = screen->availableSize();
// leave at least 100 px of height so preferences window does not take
// leave some portion 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;
auto maxStartHeight = availableSize.height() - minVerticalEmptySpace;
if (height() > maxStartHeight) {
auto heightDifference = availableSize.height() - maxStartHeight;
@@ -782,11 +782,9 @@ void DlgPreferencesImp::expandToMinimumDialogWidth()
auto screen = windowHandle()->screen();
auto availableSize = screen->availableSize();
// if the expanded dialog occupies less than 50% of the screen
int mw = minimumDialogWidth(minimumPageWidth());
if (availableSize.width() > 2 * mw) {
resize(mw, height());
}
// expand dialog to minimum size required but do not use more than specified width portion
resize(std::min(int(maxScreenWidthCoveragePercent * availableSize.width()), mw), height());
}
void DlgPreferencesImp::onPageSelected(const QModelIndex& index)

View File

@@ -130,6 +130,9 @@ class GuiExport DlgPreferencesImp : public QDialog
{
Q_OBJECT
static constexpr double maxScreenWidthCoveragePercent = 0.8; // maximum % of screen width taken by the dialog
static constexpr int minVerticalEmptySpace = 100; // px of vertical space to leave
public:
static void addPage(const std::string& className, const std::string& group);
static void removePage(const std::string& className, const std::string& group);