From 2fe6e075b6dd9cdd4d418ea50ef7cde20813ecc7 Mon Sep 17 00:00:00 2001 From: Claudio Cambra Date: Wed, 22 Jun 2022 13:34:39 +0200 Subject: [PATCH] Share dialog is now resizeable Signed-off-by: Claudio Cambra --- src/gui/sharedialog.cpp | 45 ++++++++++++++++++++++++++++++----------- src/gui/sharedialog.h | 3 ++- src/gui/sharedialog.ui | 29 +++++++++++++++----------- 3 files changed, 52 insertions(+), 25 deletions(-) diff --git a/src/gui/sharedialog.cpp b/src/gui/sharedialog.cpp index 5dd07466d8535..99a0b83568a24 100644 --- a/src/gui/sharedialog.cpp +++ b/src/gui/sharedialog.cpp @@ -35,6 +35,7 @@ #include #include #include +#include namespace { QString createRandomPassword() @@ -160,6 +161,8 @@ ShareDialog::ShareDialog(QPointer accountState, _ui->verticalLayout->addWidget(_internalLinkWidget); _internalLinkWidget->setupUiOptions(); connect(this, &ShareDialog::styleChanged, _internalLinkWidget, &InternalLinkWidget::slotStyleChanged); + + adjustScrollWidget(); } ShareLinkWidget *ShareDialog::addLinkShareWidget(const QSharedPointer &linkShare) @@ -189,6 +192,7 @@ ShareLinkWidget *ShareDialog::addLinkShareWidget(const QSharedPointer _scrollAreaLayout->addWidget(linkShareWidget); linkShareWidget->setupUiOptions(); + adjustScrollWidget(); return linkShareWidget; } @@ -216,6 +220,8 @@ void ShareDialog::initLinkShareWidget() _linkWidgetList.removeAll(_emptyShareLinkWidget); _emptyShareLinkWidget = nullptr; } + + adjustScrollWidget(); } void ShareDialog::slotAddLinkShareWidget(const QSharedPointer &linkShare) @@ -223,7 +229,6 @@ void ShareDialog::slotAddLinkShareWidget(const QSharedPointer &linkSh emit toggleShareLinkAnimation(true); const auto addedLinkShareWidget = addLinkShareWidget(linkShare); initLinkShareWidget(); - adjustScrollWidgetSize(); if (linkShare->isPasswordSet()) { addedLinkShareWidget->focusPasswordLineEdit(); } @@ -247,20 +252,29 @@ void ShareDialog::slotSharesFetched(const QList> &shares) } initLinkShareWidget(); - adjustScrollWidgetSize(); emit toggleShareLinkAnimation(false); } -void ShareDialog::adjustScrollWidgetSize() +void ShareDialog::adjustScrollWidget() { - const auto count = _scrollAreaLayout->count(); - const auto margin = 10; - const auto height = _linkWidgetList.empty() ? 0 : _linkWidgetList.last()->sizeHint().height() + margin; - const auto totalHeight = height * count; - _ui->scrollArea->setFixedWidth(_ui->verticalLayout->sizeHint().width()); - _ui->scrollArea->setFixedHeight(totalHeight > 400 ? 400 : totalHeight); - _ui->scrollArea->setVisible(height > 0); - _ui->scrollArea->setFrameShape(count > 6 ? QFrame::StyledPanel : QFrame::NoFrame); + _ui->scrollArea->setVisible(_scrollAreaLayout->count() > 0); + + // Sometimes the contentRect returns a height of 0, so we need a backup plan + const auto scrollAreaContentHeight = _scrollAreaLayout->contentsRect().height(); + + auto linkWidgetHeights = 0; + + if(scrollAreaContentHeight == 0 && !_linkWidgetList.empty()) { + for (const auto linkWidget : _linkWidgetList) { + linkWidgetHeights += linkWidget->height() - 10; + } + } + + const auto overAvailableHeight = scrollAreaContentHeight > _ui->scrollArea->height() || + linkWidgetHeights > _ui->scrollArea->height(); + + _ui->scrollArea->setFrameShape(overAvailableHeight ? QFrame::StyledPanel : QFrame::NoFrame); + _ui->verticalLayout->setSpacing(overAvailableHeight ? 10 : 0); } ShareDialog::~ShareDialog() @@ -341,6 +355,8 @@ void ShareDialog::showSharingUi() _manager->fetchShares(_sharePath); } } + + adjustScrollWidget(); } void ShareDialog::initShareManager() @@ -421,7 +437,6 @@ void ShareDialog::slotDeleteShare() _scrollAreaLayout->removeWidget(sharelinkWidget); _linkWidgetList.removeAll(sharelinkWidget); initLinkShareWidget(); - adjustScrollWidgetSize(); } void ShareDialog::slotThumbnailFetched(const int &statusCode, const QByteArray &reply) @@ -470,4 +485,10 @@ void ShareDialog::changeEvent(QEvent *e) QDialog::changeEvent(e); } +void ShareDialog::resizeEvent(QResizeEvent *event) +{ + adjustScrollWidget(); + QDialog::resizeEvent(event); +} + } // namespace OCC diff --git a/src/gui/sharedialog.h b/src/gui/sharedialog.h index c9309775f3bf4..89bb2ef708efb 100644 --- a/src/gui/sharedialog.h +++ b/src/gui/sharedialog.h @@ -78,13 +78,14 @@ private slots: protected: void changeEvent(QEvent *) override; + void resizeEvent(QResizeEvent *event) override; private: void showSharingUi(); void initShareManager(); ShareLinkWidget *addLinkShareWidget(const QSharedPointer &linkShare); void initLinkShareWidget(); - void adjustScrollWidgetSize(); + void adjustScrollWidget(); Ui::ShareDialog *_ui; diff --git a/src/gui/sharedialog.ui b/src/gui/sharedialog.ui index cd207fbb25863..8e4bbbfd8dd7b 100644 --- a/src/gui/sharedialog.ui +++ b/src/gui/sharedialog.ui @@ -6,8 +6,8 @@ 0 0 - 480 - 280 + 385 + 400 @@ -18,8 +18,8 @@ - 480 - 250 + 320 + 240 @@ -27,7 +27,7 @@ 0 - QLayout::SetFixedSize + QLayout::SetMinimumSize @@ -49,7 +49,7 @@ 0 - 2 + 2 @@ -117,7 +117,6 @@ - 50 false @@ -132,7 +131,7 @@ - + @@ -162,7 +161,7 @@ - + 0 0 @@ -170,7 +169,7 @@ 0 - 200 + 0 @@ -196,10 +195,16 @@ 0 0 - 460 - 200 + 359 + 320 + + + 0 + 0 + +