From fd8186ff0e7ef01f6fe8833da24fadbf34f7845a Mon Sep 17 00:00:00 2001 From: Camila Date: Mon, 6 Dec 2021 20:29:47 +0100 Subject: [PATCH] ShareDialog: group links and users in one scrollbar. - Remove the scrollbar used only for user shares - Resize share dialog when removing share links - Fix widget margins and max height of the share dialog - slotAdjustScrollWidgetSize => adjustScrollWidgetSize Signed-off-by: Camila --- src/gui/sharedialog.cpp | 70 +++++++-------- src/gui/sharedialog.h | 6 +- src/gui/sharedialog.ui | 147 ++++++++++++------------------- src/gui/sharelinkwidget.ui | 10 ++- src/gui/shareusergroupwidget.cpp | 81 ++++------------- src/gui/shareusergroupwidget.h | 4 +- src/gui/shareusergroupwidget.ui | 15 ++++ src/gui/shareuserline.ui | 17 +++- 8 files changed, 154 insertions(+), 196 deletions(-) diff --git a/src/gui/sharedialog.cpp b/src/gui/sharedialog.cpp index 1330729cd..b88bf5409 100644 --- a/src/gui/sharedialog.cpp +++ b/src/gui/sharedialog.cpp @@ -1,4 +1,4 @@ -/* +/* * Copyright (C) by Roeland Jago Douma * * This program is free software; you can redistribute it and/or modify @@ -138,18 +138,17 @@ ShareDialog::ShareDialog(QPointer accountState, initShareManager(); - _scrollAreaLinksViewPort = new QWidget(_ui->scrollAreaLinks); - _scrollAreaLinksLayout = new QVBoxLayout(_scrollAreaLinksViewPort); - _scrollAreaLinksLayout->setContentsMargins(6, 6, 6, 6); - _ui->scrollAreaLinks->setWidget(_scrollAreaLinksViewPort); + _scrollAreaViewPort = new QWidget(_ui->scrollArea); + _scrollAreaLayout = new QVBoxLayout(_scrollAreaViewPort); + _scrollAreaLayout->setContentsMargins(0, 0, 0, 0); + _ui->scrollArea->setWidget(_scrollAreaViewPort); } ShareLinkWidget *ShareDialog::addLinkShareWidget(const QSharedPointer &linkShare) { - _linkWidgetList.append(new ShareLinkWidget(_accountState->account(), _sharePath, _localPath, _maxSharingPermissions, _ui->scrollAreaLinks)); - - const auto index = _linkWidgetList.size() - 1; - const auto linkShareWidget = _linkWidgetList.at(index); + const auto linkShareWidget = new ShareLinkWidget(_accountState->account(), _sharePath, _localPath, _maxSharingPermissions, _ui->scrollArea); + _linkWidgetList.append(linkShareWidget); + linkShareWidget->setLinkShare(linkShare); connect(linkShare.data(), &Share::serverError, linkShareWidget, &ShareLinkWidget::slotServerError); @@ -169,28 +168,25 @@ ShareLinkWidget *ShareDialog::addLinkShareWidget(const QSharedPointer 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); + _scrollAreaLayout->addWidget(linkShareWidget); linkShareWidget->setupUiOptions(); - + return linkShareWidget; } void ShareDialog::initLinkShareWidget() { if(_linkWidgetList.size() == 0) { - _emptyShareLinkWidget = new ShareLinkWidget(_accountState->account(), _sharePath, _localPath, _maxSharingPermissions, _ui->scrollAreaLinks); + _emptyShareLinkWidget = new ShareLinkWidget(_accountState->account(), _sharePath, _localPath, _maxSharingPermissions, _ui->scrollArea); _linkWidgetList.append(_emptyShareLinkWidget); 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); + _scrollAreaLayout->addWidget(_emptyShareLinkWidget); _emptyShareLinkWidget->show(); } else if (_emptyShareLinkWidget) { _emptyShareLinkWidget->hide(); @@ -205,7 +201,7 @@ void ShareDialog::slotAddLinkShareWidget(const QSharedPointer &linkSh emit toggleShareLinkAnimation(true); const auto addedLinkShareWidget = addLinkShareWidget(linkShare); initLinkShareWidget(); - slotAdjustScrollWidgetSize(); + adjustScrollWidgetSize(); if (linkShare->isPasswordSet()) { addedLinkShareWidget->focusPasswordLineEdit(); } @@ -227,21 +223,22 @@ void ShareDialog::slotSharesFetched(const QList> &shares) QSharedPointer linkShare = qSharedPointerDynamicCast(share); addLinkShareWidget(linkShare); } - + initLinkShareWidget(); - slotAdjustScrollWidgetSize(); + adjustScrollWidgetSize(); emit toggleShareLinkAnimation(false); } -void ShareDialog::slotAdjustScrollWidgetSize() +void ShareDialog::adjustScrollWidgetSize() { - auto count = this->findChildren().count(); - count = count >= 6 ? 6 : 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 > 6 ? QFrame::StyledPanel : QFrame::NoFrame); + 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); } ShareDialog::~ShareDialog() @@ -302,19 +299,15 @@ void ShareDialog::showSharingUi() return; } - // We only do user/group sharing from 8.2.0 - bool userGroupSharing = - theme->userGroupSharing() - && _accountState->account()->serverVersionInt() >= Account::makeServerVersion(8, 2, 0); - - if (userGroupSharing) { - _userGroupWidget = new ShareUserGroupWidget(_accountState->account(), _sharePath, _localPath, _maxSharingPermissions, _privateLinkUrl, this); - + if (theme->userGroupSharing()) { + _userGroupWidget = new ShareUserGroupWidget(_accountState->account(), _sharePath, _localPath, _maxSharingPermissions, _privateLinkUrl, _ui->scrollArea); + _userGroupWidget->getShares(); + // Connect styleChanged events to our widget, so it can adapt (Dark-/Light-Mode switching) connect(this, &ShareDialog::styleChanged, _userGroupWidget, &ShareUserGroupWidget::slotStyleChanged); _ui->verticalLayout->insertWidget(1, _userGroupWidget); - _userGroupWidget->getShares(); + _scrollAreaLayout->addLayout(_userGroupWidget->shareUserGroupLayout()); } initShareManager(); @@ -401,9 +394,10 @@ void ShareDialog::slotDeleteShare() auto sharelinkWidget = dynamic_cast(sender()); sharelinkWidget->hide(); _ui->verticalLayout->removeWidget(sharelinkWidget); + _scrollAreaLayout->removeWidget(sharelinkWidget); _linkWidgetList.removeAll(sharelinkWidget); initLinkShareWidget(); - slotAdjustScrollWidgetSize(); + adjustScrollWidgetSize(); } void ShareDialog::slotThumbnailFetched(const int &statusCode, const QByteArray &reply) diff --git a/src/gui/sharedialog.h b/src/gui/sharedialog.h index 586bedcb7..531998d42 100644 --- a/src/gui/sharedialog.h +++ b/src/gui/sharedialog.h @@ -68,7 +68,6 @@ private slots: void slotCreatePasswordForLinkShare(const QString &password); void slotCreatePasswordForLinkShareProcessed(); void slotLinkShareRequiresPassword(const QString &message); - void slotAdjustScrollWidgetSize(); signals: void toggleShareLinkAnimation(bool start); @@ -82,6 +81,7 @@ private: void initShareManager(); ShareLinkWidget *addLinkShareWidget(const QSharedPointer &linkShare); void initLinkShareWidget(); + void adjustScrollWidgetSize(); Ui::ShareDialog *_ui; @@ -99,8 +99,8 @@ private: ShareUserGroupWidget *_userGroupWidget = nullptr; QProgressIndicator *_progressIndicator = nullptr; - QWidget *_scrollAreaLinksViewPort = nullptr; - QVBoxLayout *_scrollAreaLinksLayout = nullptr; + QWidget *_scrollAreaViewPort = nullptr; + QVBoxLayout *_scrollAreaLayout = nullptr; }; } // namespace OCC diff --git a/src/gui/sharedialog.ui b/src/gui/sharedialog.ui index abaddada2..e90458dbc 100644 --- a/src/gui/sharedialog.ui +++ b/src/gui/sharedialog.ui @@ -6,13 +6,25 @@ 0 0 - 387 - 222 + 480 + 280 + + + 0 + 0 + + + + + 480 + 250 + + - 9 + 0 QLayout::SetFixedSize @@ -20,10 +32,10 @@ - 6 + 0 - QLayout::SetFixedSize + QLayout::SetDefaultConstraint @@ -123,91 +135,48 @@ - - - 12 + + + + 0 + 0 + - - - - - 0 - 0 - - - - - - - QFrame::NoFrame - - - QFrame::Plain - - - Qt::ScrollBarAlwaysOff - - - QAbstractScrollArea::AdjustIgnored - - - true - - - - - 0 - 0 - 365 - 68 - - - - - - - - - - 0 - 0 - - - - - - - QFrame::NoFrame - - - QFrame::Plain - - - 1 - - - Qt::ScrollBarAlwaysOff - - - QAbstractScrollArea::AdjustIgnored - - - true - - - - - 0 - 0 - 365 - 68 - - - - - - - + + + 0 + 200 + + + + QFrame::NoFrame + + + QFrame::Plain + + + Qt::ScrollBarAsNeeded + + + Qt::ScrollBarAlwaysOff + + + QAbstractScrollArea::AdjustToContentsOnFirstShow + + + true + + + + + 0 + 0 + 460 + 200 + + + + diff --git a/src/gui/sharelinkwidget.ui b/src/gui/sharelinkwidget.ui index 4cc42b122..a0d5f3df9 100644 --- a/src/gui/sharelinkwidget.ui +++ b/src/gui/sharelinkwidget.ui @@ -21,10 +21,16 @@ 0 - 6 + 12 + + + 0 - 6 + 20 + + + 0 diff --git a/src/gui/shareusergroupwidget.cpp b/src/gui/shareusergroupwidget.cpp index b8a42eb81..3c2492577 100644 --- a/src/gui/shareusergroupwidget.cpp +++ b/src/gui/shareusergroupwidget.cpp @@ -154,16 +154,18 @@ ShareUserGroupWidget::ShareUserGroupWidget(AccountPtr account, _completionTimer.setInterval(600); _ui->errorLabel->hide(); - - // TODO Progress Indicator where should it go? - // Setup the sharee search progress indicator - //_ui->shareeHorizontalLayout->addWidget(&_pi_sharee); - - _parentScrollArea = parentWidget()->findChild("scrollAreaUsers"); - + + _parentScrollArea = parentWidget()->findChild("scrollArea"); + _shareUserGroup = new QVBoxLayout(_parentScrollArea); + _shareUserGroup->setContentsMargins(0, 0, 0, 0); customizeStyle(); } +QVBoxLayout *ShareUserGroupWidget::shareUserGroupLayout() +{ + return _shareUserGroup; +} + ShareUserGroupWidget::~ShareUserGroupWidget() { delete _ui; @@ -247,17 +249,16 @@ void ShareUserGroupWidget::slotShareCreated(const QSharedPointer &share) void ShareUserGroupWidget::slotSharesFetched(const QList> &shares) { - QScrollArea *scrollArea = _parentScrollArea; - - auto newViewPort = new QWidget(scrollArea); - auto layout = new QVBoxLayout(newViewPort); - layout->setContentsMargins(0, 0, 0, 0); int x = 0; - int height = 0; QList linkOwners({}); ShareUserLine *justCreatedShareThatNeedsPassword = nullptr; - + + while (QLayoutItem *shareUserLine = _shareUserGroup->takeAt(0)) { + delete shareUserLine->widget(); + delete shareUserLine; + } + foreach (const auto &share, shares) { // We don't handle link shares, only TypeUser or TypeGroup if (share->getShareType() == Share::TypeLink) { @@ -278,14 +279,12 @@ void ShareUserGroupWidget::slotSharesFetched(const QList> Q_ASSERT(Share::isShareTypeUserGroupEmailRoomOrRemote(share->getShareType())); auto userGroupShare = qSharedPointerDynamicCast(share); auto *s = new ShareUserLine(_account, userGroupShare, _maxSharingPermissions, _isFile, _parentScrollArea); - connect(s, &ShareUserLine::resizeRequested, this, &ShareUserGroupWidget::slotAdjustScrollWidgetSize); connect(s, &ShareUserLine::visualDeletionDone, this, &ShareUserGroupWidget::getShares); - s->setBackgroundRole(layout->count() % 2 == 0 ? QPalette::Base : QPalette::AlternateBase); + s->setBackgroundRole(_shareUserGroup->count() % 2 == 0 ? QPalette::Base : QPalette::AlternateBase); // Connect styleChanged events to our widget, so it can adapt (Dark-/Light-Mode switching) connect(this, &ShareUserGroupWidget::styleChanged, s, &ShareUserLine::slotStyleChanged); - - layout->addWidget(s); + _shareUserGroup->addWidget(s); if (!_lastCreatedShareId.isEmpty() && share->getId() == _lastCreatedShareId) { _lastCreatedShareId = QString(); @@ -295,27 +294,14 @@ void ShareUserGroupWidget::slotSharesFetched(const QList> } x++; - if (x <= 3) { - height = newViewPort->sizeHint().height(); - } } foreach (const QString &owner, linkOwners) { auto ownerLabel = new QLabel(QString(owner + " shared via link")); - layout->addWidget(ownerLabel); + _shareUserGroup->addWidget(ownerLabel); ownerLabel->setVisible(true); - - x++; - if (x <= 6) { - height = newViewPort->sizeHint().height(); - } } - - scrollArea->setFrameShape(x > 6 ? QFrame::StyledPanel : QFrame::NoFrame); - scrollArea->setVisible(!shares.isEmpty()); - scrollArea->setFixedHeight(height); - scrollArea->setWidget(newViewPort); - + _disableCompleterActivated = false; activateShareeLineEdit(); @@ -325,24 +311,6 @@ void ShareUserGroupWidget::slotSharesFetched(const QList> } } -void ShareUserGroupWidget::slotAdjustScrollWidgetSize() -{ - QScrollArea *scrollArea = _parentScrollArea; - const auto shareUserLineChilds = scrollArea->findChildren(); - - // Ask the child widgets to calculate their size - for (const auto shareUserLineChild : shareUserLineChilds) { - shareUserLineChild->adjustSize(); - } - - const auto shareUserLineChildsCount = shareUserLineChilds.count(); - scrollArea->setVisible(shareUserLineChildsCount > 0); - if (shareUserLineChildsCount > 0 && shareUserLineChildsCount <= 3) { - scrollArea->setFixedHeight(scrollArea->widget()->sizeHint().height()); - } - scrollArea->setFrameShape(shareUserLineChildsCount > 3 ? QFrame::StyledPanel : QFrame::NoFrame); -} - void ShareUserGroupWidget::slotPrivateLinkShare() { auto menu = new QMenu(this); @@ -380,22 +348,11 @@ void ShareUserGroupWidget::slotCompleterActivated(const QModelIndex &index) return; } -// TODO Progress Indicator where should it go? -// auto indicator = new QProgressIndicator(viewPort); -// indicator->startAnimation(); -// if (layout->count() == 1) { -// // No shares yet! Remove the label, add some stretch. -// delete layout->itemAt(0)->widget(); -// layout->addStretch(1); -// } -// layout->insertWidget(layout->count() - 1, indicator); - /* * Don't send the reshare permissions for federated shares for servers <9.1 * https://github.com/owncloud/core/issues/22122#issuecomment-185637344 * https://github.com/owncloud/client/issues/4996 */ - _lastCreatedShareId = QString(); QString password; diff --git a/src/gui/shareusergroupwidget.h b/src/gui/shareusergroupwidget.h index 599ab521b..d8122a489 100644 --- a/src/gui/shareusergroupwidget.h +++ b/src/gui/shareusergroupwidget.h @@ -77,6 +77,8 @@ public: const QString &privateLinkUrl, QWidget *parent = nullptr); ~ShareUserGroupWidget() override; + + QVBoxLayout *shareUserGroupLayout(); signals: void togglePublicLinkShare(bool); @@ -98,7 +100,6 @@ private slots: void slotCompleterActivated(const QModelIndex &index); void slotCompleterHighlighted(const QModelIndex &index); void slotShareesReady(); - void slotAdjustScrollWidgetSize(); void slotPrivateLinkShare(); void displayError(int code, const QString &message); @@ -113,6 +114,7 @@ private: Ui::ShareUserGroupWidget *_ui; QScrollArea *_parentScrollArea; + QVBoxLayout *_shareUserGroup; AccountPtr _account; QString _sharePath; QString _localPath; diff --git a/src/gui/shareusergroupwidget.ui b/src/gui/shareusergroupwidget.ui index 4aa9b1693..38c45a23d 100644 --- a/src/gui/shareusergroupwidget.ui +++ b/src/gui/shareusergroupwidget.ui @@ -17,6 +17,21 @@ + + 6 + + + 6 + + + 6 + + + 6 + + + 6 + diff --git a/src/gui/shareuserline.ui b/src/gui/shareuserline.ui index 9576b41a7..761be94d0 100644 --- a/src/gui/shareuserline.ui +++ b/src/gui/shareuserline.ui @@ -26,13 +26,28 @@ false + + 0 + + + 12 + + + 0 + + + 20 + + + 0 + 6 - 22 + 0 -- 2.30.2