From fe429b13e4abeed87aae2409626463edb28a0fbe Mon Sep 17 00:00:00 2001 From: Hannah von Reth Date: Mon, 9 Aug 2021 14:26:13 +0200 Subject: [PATCH] Limit window size to 2/3 Fixes: #8366 --- changelog/unreleased/8366 | 6 +++++ src/gui/settingsdialog.cpp | 39 ++++++++++++++++++++----------- src/gui/settingsdialog.h | 4 +++- src/gui/sharedialog.cpp | 8 +++++-- src/gui/sharedialog.h | 2 ++ src/gui/sharedialog.ui | 8 ------- src/gui/wizard/owncloudwizard.cpp | 9 +++++-- src/gui/wizard/owncloudwizard.h | 2 ++ 8 files changed, 51 insertions(+), 27 deletions(-) create mode 100644 changelog/unreleased/8366 diff --git a/changelog/unreleased/8366 b/changelog/unreleased/8366 new file mode 100644 index 00000000000..db1c20fcbd2 --- /dev/null +++ b/changelog/unreleased/8366 @@ -0,0 +1,6 @@ +Bugfix: Limit min window size to 2/3 available + +When scaling was used the window could become bigger than the screen. +The size is now limited to 2/3 of the screen. + +https://github.com/owncloud/client/issues/8366 diff --git a/src/gui/settingsdialog.cpp b/src/gui/settingsdialog.cpp index 9366bd95d42..cc7fba3b502 100644 --- a/src/gui/settingsdialog.cpp +++ b/src/gui/settingsdialog.cpp @@ -30,21 +30,23 @@ #include "protocolwidget.h" #include "owncloudsetupwizard.h" +#include #include -#include -#include +#include +#include +#include +#include +#include #include +#include #include +#include +#include #include #include -#include #include -#include -#include #include -#include -#include -#include +#include #ifdef Q_OS_MAC #include "settingsdialog_mac.h" @@ -250,11 +252,7 @@ SettingsDialog::SettingsDialog(ownCloudGui *gui, QWidget *parent) customizeStyle(); cfg.restoreGeometry(this); - if (size().width() < minimumSizeHint().width() || size().height() < minimumSizeHint().height()) - { - resize(minimumSizeHint()); - } - + setMinimumSize(minimumSizeHint()); #ifdef Q_OS_MAC setActivationPolicy(ActivationPolicy::Accessory); #endif @@ -267,7 +265,20 @@ SettingsDialog::~SettingsDialog() QSize SettingsDialog::minimumSizeHint() const { - return {800, 500}; + const auto screen = windowHandle() ? windowHandle()->screen() : QApplication::screenAt(QCursor::pos()); + const auto geometry = screen->availableSize(); + const QSize min { 800, 600 }; + const QSize currentMin { static_cast(geometry.width() * 0.75), static_cast(geometry.height() * 0.75) }; + if (currentMin.width() < min.width() || currentMin.height() < min.height()) { + return currentMin; + } + return min; +} + +QSize SettingsDialog::sizeHintForChild() const +{ + auto size = ocApp()->gui()->settingsDialog()->size(); + return { static_cast(size.width() * 0.9), static_cast(size.height() * 0.9) }; } QWidget* SettingsDialog::currentPage() diff --git a/src/gui/settingsdialog.h b/src/gui/settingsdialog.h index f977ffe6d78..b71664d74ae 100644 --- a/src/gui/settingsdialog.h +++ b/src/gui/settingsdialog.h @@ -51,8 +51,10 @@ class SettingsDialog : public QMainWindow public: explicit SettingsDialog(ownCloudGui *gui, QWidget *parent = nullptr); - ~SettingsDialog() override; + ~SettingsDialog() override; + QSize minimumSizeHint() const override; + QSize sizeHintForChild() const; QWidget* currentPage(); diff --git a/src/gui/sharedialog.cpp b/src/gui/sharedialog.cpp index b68756a0e74..87bf2c7c688 100644 --- a/src/gui/sharedialog.cpp +++ b/src/gui/sharedialog.cpp @@ -137,8 +137,7 @@ ShareDialog::ShareDialog(QPointer accountState, connect(job, &PropfindJob::finishedWithError, this, &ShareDialog::slotPropfindError); job->start(); - auto size = ocApp()->gui()->settingsDialog()->minimumSizeHint(); - resize(size.width() - 50, size.height() - 50); + setMinimumSize(minimumSizeHint()); } ShareDialog::~ShareDialog() @@ -219,6 +218,11 @@ void ShareDialog::showSharingUi() } } +QSize ShareDialog::minimumSizeHint() const +{ + return ocApp()->gui()->settingsDialog()->sizeHintForChild(); +} + void ShareDialog::slotThumbnailFetched(const int &statusCode, const QByteArray &reply) { if (statusCode != 200) { diff --git a/src/gui/sharedialog.h b/src/gui/sharedialog.h index a757e6740b2..67e24c0a32e 100644 --- a/src/gui/sharedialog.h +++ b/src/gui/sharedialog.h @@ -48,6 +48,8 @@ class ShareDialog : public QDialog QWidget *parent); ~ShareDialog() override; + QSize minimumSizeHint() const override; + private slots: void done(int r) override; void slotPropfindReceived(const QMap &result); diff --git a/src/gui/sharedialog.ui b/src/gui/sharedialog.ui index 10ed70e1ce8..eccf643be3f 100644 --- a/src/gui/sharedialog.ui +++ b/src/gui/sharedialog.ui @@ -2,14 +2,6 @@ OCC::ShareDialog - - - 0 - 0 - 408 - 281 - - Dialog diff --git a/src/gui/wizard/owncloudwizard.cpp b/src/gui/wizard/owncloudwizard.cpp index 3bfc7af2c65..f398e07b968 100644 --- a/src/gui/wizard/owncloudwizard.cpp +++ b/src/gui/wizard/owncloudwizard.cpp @@ -54,8 +54,6 @@ OwncloudWizard::OwncloudWizard(QWidget *parent) , _credentialsPage(nullptr) { setObjectName("owncloudWizard"); - auto size = ocApp()->gui()->settingsDialog()->minimumSizeHint(); - resize(size.width() - 50, size.height() - 50); setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint); setPage(WizardCommon::Page_ServerSetup, _setupPage); @@ -89,6 +87,8 @@ OwncloudWizard::OwncloudWizard(QWidget *parent) setOption(QWizard::CancelButtonOnLeft); setTitleFormat(Qt::RichText); setSubTitleFormat(Qt::RichText); + + setMinimumSize(minimumSizeHint()); } void OwncloudWizard::setAccount(AccountPtr account) @@ -276,4 +276,9 @@ void OwncloudWizard::askExperimentalVirtualFilesFeature(QWidget *receiver, const msgBox->open(); } +QSize OCC::OwncloudWizard::minimumSizeHint() const +{ + return ocApp()->gui()->settingsDialog()->sizeHintForChild(); +} + } // end namespace diff --git a/src/gui/wizard/owncloudwizard.h b/src/gui/wizard/owncloudwizard.h index 2fd6a446712..69107c3d147 100644 --- a/src/gui/wizard/owncloudwizard.h +++ b/src/gui/wizard/owncloudwizard.h @@ -72,6 +72,8 @@ class OwncloudWizard : public QWizard DetermineAuthTypeJob::AuthType authType() const; + QSize minimumSizeHint() const override; + public slots: void setAuthType(DetermineAuthTypeJob::AuthType type); void setRemoteFolder(const QString &);