From e3f8102a9d0ddb0a9c98818ed73013a5412b4996 Mon Sep 17 00:00:00 2001 From: Noah Colberg Date: Mon, 18 Oct 2021 11:11:01 +0200 Subject: [PATCH] Implementation of sizeHint based on systemsettings BUG: 397678 --- part/preferencesdialog.cpp | 16 ++++++++++++++++ part/preferencesdialog.h | 2 ++ 2 files changed, 18 insertions(+) diff --git a/part/preferencesdialog.cpp b/part/preferencesdialog.cpp index 217b62479..f353dcf92 100644 --- a/part/preferencesdialog.cpp +++ b/part/preferencesdialog.cpp @@ -9,6 +9,10 @@ #include +#include +#include +#include + // single config pages #include "dlgaccessibility.h" #include "dlgannotations.h" @@ -21,6 +25,7 @@ PreferencesDialog::PreferencesDialog(QWidget *parent, KConfigSkeleton *skeleton, Okular::EmbedMode embedMode) : KConfigDialog(parent, QStringLiteral("preferences"), skeleton) { + setMinimumSize(PreferencesDialog::sizeHint()); setWindowModality(Qt::ApplicationModal); m_general = new DlgGeneral(this, embedMode); @@ -66,3 +71,14 @@ void PreferencesDialog::switchToAnnotationsPage() if (m_annotationsPage) setCurrentPage(m_annotationsPage); } + +QSize PreferencesDialog::sizeHint() const +{ // Code based on the implementation of sizeHint of the systemsettings project + // Take the font size into account for the window size, as we do for UI elements + const float fontSize = QFontDatabase::systemFont(QFontDatabase::GeneralFont).pointSizeF(); + const QSize targetSize = QSize(qRound(102 * fontSize), qRound(70 * fontSize)); + + // on smaller or portrait-rotated screens, do not max out height and/or width + const QSize screenSize = (QGuiApplication::primaryScreen()->availableSize() * 0.9); + return targetSize.boundedTo(screenSize); +} diff --git a/part/preferencesdialog.h b/part/preferencesdialog.h index bc57a04f7..a3daa6bc7 100644 --- a/part/preferencesdialog.h +++ b/part/preferencesdialog.h @@ -33,7 +33,9 @@ public: void switchToAccessibilityPage(); void switchToAnnotationsPage(); + protected: + QSize sizeHint() const override; // void updateSettings(); // Called when OK/Apply is pressed. // void updateWidgets(); // Called upon construction or when Reset is pressed // void updateWidgetsDefault(); // Called when Defaults button is pressed