From a10f84b5c1b1e8e164d0210ce1dd6e271fd3e138 Mon Sep 17 00:00:00 2001 From: Camila Date: Fri, 3 Dec 2021 18:18:55 +0100 Subject: [PATCH] Add scroll area for share links. Signed-off-by: Camila --- src/gui/sharedialog.cpp | 51 +++++++++------ src/gui/sharedialog.h | 4 ++ src/gui/sharedialog.ui | 109 ++++++++++++++++++++++--------- src/gui/sharelinkwidget.cpp | 16 ----- src/gui/sharelinkwidget.h | 3 - src/gui/shareusergroupwidget.cpp | 2 +- 6 files changed, 115 insertions(+), 70 deletions(-) diff --git a/src/gui/sharedialog.cpp b/src/gui/sharedialog.cpp index 0a8da9aab..fb312734b 100644 --- a/src/gui/sharedialog.cpp +++ b/src/gui/sharedialog.cpp @@ -137,13 +137,19 @@ ShareDialog::ShareDialog(QPointer accountState, job->start(); initShareManager(); + + _scrollAreaLinksViewPort = new QWidget(_ui->scrollAreaLinks); + _scrollAreaLinksLayout = new QVBoxLayout(_scrollAreaLinksViewPort); + _scrollAreaLinksLayout->setContentsMargins(6, 6, 6, 6); + _ui->scrollAreaLinks->setWidget(_scrollAreaLinksViewPort); } ShareLinkWidget *ShareDialog::addLinkShareWidget(const QSharedPointer &linkShare) { - _linkWidgetList.append(new ShareLinkWidget(_accountState->account(), _sharePath, _localPath, _maxSharingPermissions, this)); - - const auto linkShareWidget = _linkWidgetList.at(_linkWidgetList.size() - 1); + _linkWidgetList.append(new ShareLinkWidget(_accountState->account(), _sharePath, _localPath, _maxSharingPermissions, _ui->scrollAreaLinks)); + + const auto index = _linkWidgetList.size() - 1; + const auto linkShareWidget = _linkWidgetList.at(index); linkShareWidget->setLinkShare(linkShare); connect(linkShare.data(), &Share::serverError, linkShareWidget, &ShareLinkWidget::slotServerError); @@ -158,33 +164,35 @@ ShareLinkWidget *ShareDialog::addLinkShareWidget(const QSharedPointer connect(linkShareWidget, &ShareLinkWidget::createLinkShare, this, &ShareDialog::slotCreateLinkShare); connect(linkShareWidget, &ShareLinkWidget::deleteLinkShare, this, &ShareDialog::slotDeleteShare); connect(linkShareWidget, &ShareLinkWidget::createPassword, this, &ShareDialog::slotCreatePasswordForLinkShare); - - //connect(_linkWidgetList.at(index), &ShareLinkWidget::resizeRequested, this, &ShareDialog::slotAdjustScrollWidgetSize); - + // Connect styleChanged events to our widget, so it can adapt (Dark-/Light-Mode switching) connect(this, &ShareDialog::styleChanged, linkShareWidget, &ShareLinkWidget::slotStyleChanged); _ui->verticalLayout->insertWidget(_linkWidgetList.size() + 1, linkShareWidget); + _scrollAreaLinksLayout->addWidget(linkShareWidget); + + // TO DO - the count is right but the bkg does not change + //linkShareWidget->setBackgroundRole(_scrollAreaLinksLayout->count() % 2 == 0 ? QPalette::Base : QPalette::AlternateBase); + linkShareWidget->setupUiOptions(); - + return linkShareWidget; } void ShareDialog::initLinkShareWidget() { if(_linkWidgetList.size() == 0) { - _emptyShareLinkWidget = new ShareLinkWidget(_accountState->account(), _sharePath, _localPath, _maxSharingPermissions, this); + _emptyShareLinkWidget = new ShareLinkWidget(_accountState->account(), _sharePath, _localPath, _maxSharingPermissions, _ui->scrollAreaLinks); _linkWidgetList.append(_emptyShareLinkWidget); - - connect(_emptyShareLinkWidget, &ShareLinkWidget::resizeRequested, this, &ShareDialog::slotAdjustScrollWidgetSize); connect(this, &ShareDialog::toggleShareLinkAnimation, _emptyShareLinkWidget, &ShareLinkWidget::slotToggleShareLinkAnimation); connect(_emptyShareLinkWidget, &ShareLinkWidget::createLinkShare, this, &ShareDialog::slotCreateLinkShare); connect(_emptyShareLinkWidget, &ShareLinkWidget::createPassword, this, &ShareDialog::slotCreatePasswordForLinkShare); - + _ui->verticalLayout->insertWidget(_linkWidgetList.size()+1, _emptyShareLinkWidget); + _scrollAreaLinksLayout->addWidget(_emptyShareLinkWidget); _emptyShareLinkWidget->show(); - } else if(_emptyShareLinkWidget) { + } else if (_emptyShareLinkWidget) { _emptyShareLinkWidget->hide(); _ui->verticalLayout->removeWidget(_emptyShareLinkWidget); _linkWidgetList.removeAll(_emptyShareLinkWidget); @@ -197,6 +205,7 @@ void ShareDialog::slotAddLinkShareWidget(const QSharedPointer &linkSh emit toggleShareLinkAnimation(true); const auto addedLinkShareWidget = addLinkShareWidget(linkShare); initLinkShareWidget(); + slotAdjustScrollWidgetSize(); if (linkShare->isPasswordSet()) { addedLinkShareWidget->focusPasswordLineEdit(); } @@ -209,6 +218,7 @@ void ShareDialog::slotSharesFetched(const QList> &shares) const QString versionString = _accountState->account()->serverVersion(); qCInfo(lcSharing) << versionString << "Fetched" << shares.count() << "shares"; + foreach (auto share, shares) { if (share->getShareType() != Share::TypeLink || share->getUidOwner() != share->account()->davUser()) { continue; @@ -217,19 +227,21 @@ void ShareDialog::slotSharesFetched(const QList> &shares) QSharedPointer linkShare = qSharedPointerDynamicCast(share); addLinkShareWidget(linkShare); } - + initLinkShareWidget(); + slotAdjustScrollWidgetSize(); emit toggleShareLinkAnimation(false); } void ShareDialog::slotAdjustScrollWidgetSize() { - int count = this->findChildren().count(); - _ui->scrollArea->setVisible(count > 0); - if (count > 0 && count <= 3) { - _ui->scrollArea->setFixedHeight(_ui->scrollArea->widget()->sizeHint().height()); - } - _ui->scrollArea->setFrameShape(count > 3 ? QFrame::StyledPanel : QFrame::NoFrame); + auto count = this->findChildren().count(); + count = count > 3 ? 3 : count; + auto height = _linkWidgetList.size() > 0 ? _linkWidgetList.at(_linkWidgetList.size() - 1)->sizeHint().height() : 0; + _ui->scrollAreaLinks->setFixedWidth(_ui->verticalLayout->sizeHint().width()); + _ui->scrollAreaLinks->setFixedHeight(height * count); + _ui->scrollAreaLinks->setVisible(height > 0); + _ui->scrollAreaLinks->setFrameShape(count > 3 ? QFrame::StyledPanel : QFrame::NoFrame); } ShareDialog::~ShareDialog() @@ -391,6 +403,7 @@ void ShareDialog::slotDeleteShare() _ui->verticalLayout->removeWidget(sharelinkWidget); _linkWidgetList.removeAll(sharelinkWidget); initLinkShareWidget(); + slotAdjustScrollWidgetSize(); } void ShareDialog::slotThumbnailFetched(const int &statusCode, const QByteArray &reply) diff --git a/src/gui/sharedialog.h b/src/gui/sharedialog.h index b3aa98277..586bedcb7 100644 --- a/src/gui/sharedialog.h +++ b/src/gui/sharedialog.h @@ -26,6 +26,7 @@ #include class QProgressIndicator; +class QVBoxLayout; namespace OCC { @@ -97,6 +98,9 @@ private: ShareLinkWidget* _emptyShareLinkWidget = nullptr; ShareUserGroupWidget *_userGroupWidget = nullptr; QProgressIndicator *_progressIndicator = nullptr; + + QWidget *_scrollAreaLinksViewPort = nullptr; + QVBoxLayout *_scrollAreaLinksLayout = nullptr; }; } // namespace OCC diff --git a/src/gui/sharedialog.ui b/src/gui/sharedialog.ui index cb49c7cb8..6410c5203 100644 --- a/src/gui/sharedialog.ui +++ b/src/gui/sharedialog.ui @@ -6,8 +6,8 @@ 0 0 - 385 - 150 + 400 + 222 @@ -33,6 +33,31 @@ 10 + + + + + 0 + 0 + + + + + 40 + 40 + + + + + 16777215 + 16777215 + + + + Icon + + + @@ -89,44 +114,25 @@ - - - - - 0 - 0 - - - - - 40 - 40 - - - - - 16777215 - 16777215 - - - - Icon - - - - + 0 0 + + + QFrame::NoFrame + + QFrame::Plain + Qt::ScrollBarAlwaysOff @@ -136,13 +142,54 @@ true - + 0 0 - 69 - 69 + 68 + 68 + + + + + + + + + + 0 + 0 + + + + + + + QFrame::NoFrame + + + QFrame::Plain + + + 1 + + + Qt::ScrollBarAlwaysOff + + + QAbstractScrollArea::AdjustIgnored + + + true + + + + + 0 + 0 + 68 + 68 diff --git a/src/gui/sharelinkwidget.cpp b/src/gui/sharelinkwidget.cpp index f0ea3c615..c62a05021 100644 --- a/src/gui/sharelinkwidget.cpp +++ b/src/gui/sharelinkwidget.cpp @@ -411,22 +411,6 @@ void ShareLinkWidget::slotPasswordSetError(const int code, const QString &messag emit createPasswordProcessed(); } -void ShareLinkWidget::startAnimation(const int start, const int end) -{ - auto *animation = new QPropertyAnimation(this, "maximumHeight", this); - - animation->setDuration(500); - animation->setStartValue(start); - animation->setEndValue(end); - - connect(animation, &QAbstractAnimation::finished, this, &ShareLinkWidget::slotAnimationFinished); - if (end < start) // that is to remove the widget, not to show it - connect(animation, &QAbstractAnimation::finished, this, &ShareLinkWidget::slotDeleteAnimationFinished); - connect(animation, &QVariantAnimation::valueChanged, this, &ShareLinkWidget::resizeRequested); - - animation->start(); -} - void ShareLinkWidget::slotDeleteShareFetched() { slotToggleShareLinkAnimation(false); diff --git a/src/gui/sharelinkwidget.h b/src/gui/sharelinkwidget.h index d9c3dec12..cea4070b7 100644 --- a/src/gui/sharelinkwidget.h +++ b/src/gui/sharelinkwidget.h @@ -100,7 +100,6 @@ private slots: signals: void createLinkShare(); void deleteLinkShare(); - void resizeRequested(); void visualDeletionDone(); void createPassword(const QString &password); void createPasswordProcessed(); @@ -119,8 +118,6 @@ private: /** Retrieve a share's name, accounting for _namesSupported */ QString shareName() const; - void startAnimation(const int start, const int end); - void customizeStyle(); void displayShareLinkLabel(); diff --git a/src/gui/shareusergroupwidget.cpp b/src/gui/shareusergroupwidget.cpp index 9c9bc3fc0..b8a42eb81 100644 --- a/src/gui/shareusergroupwidget.cpp +++ b/src/gui/shareusergroupwidget.cpp @@ -159,7 +159,7 @@ ShareUserGroupWidget::ShareUserGroupWidget(AccountPtr account, // Setup the sharee search progress indicator //_ui->shareeHorizontalLayout->addWidget(&_pi_sharee); - _parentScrollArea = parentWidget()->findChild("scrollArea"); + _parentScrollArea = parentWidget()->findChild("scrollAreaUsers"); customizeStyle(); }