From 459e200ac0118081bae44d714414ef431d39b6d8 Mon Sep 17 00:00:00 2001 From: Olivier Goffart Date: Mon, 16 Nov 2015 17:59:24 +0100 Subject: [PATCH] ShareDialog: add a QScrollArea (issue #4125 ) --- src/gui/sharedialog.cpp | 1 + src/gui/sharedialog.ui | 13 ---------- src/gui/shareusergroupwidget.cpp | 41 +++++++++++++++++++++----------- src/gui/shareusergroupwidget.ui | 29 +++++++++++++++++++++- 4 files changed, 56 insertions(+), 28 deletions(-) diff --git a/src/gui/sharedialog.cpp b/src/gui/sharedialog.cpp index 7be123e5a..0177e8efe 100644 --- a/src/gui/sharedialog.cpp +++ b/src/gui/sharedialog.cpp @@ -89,6 +89,7 @@ ShareDialog::ShareDialog(AccountPtr account, const QString &sharePath, const QSt } _linkWidget = new ShareLinkWidget(account, sharePath, localPath, resharingAllowed, autoShare, this); + _linkWidget->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Preferred); _ui->shareWidgetsLayout->addWidget(_linkWidget); } diff --git a/src/gui/sharedialog.ui b/src/gui/sharedialog.ui index 75359d441..6f829130c 100644 --- a/src/gui/sharedialog.ui +++ b/src/gui/sharedialog.ui @@ -66,19 +66,6 @@ - - - - Qt::Vertical - - - - 20 - 40 - - - - diff --git a/src/gui/shareusergroupwidget.cpp b/src/gui/shareusergroupwidget.cpp index aa75b036f..92357b80b 100644 --- a/src/gui/shareusergroupwidget.cpp +++ b/src/gui/shareusergroupwidget.cpp @@ -34,6 +34,8 @@ #include #include #include +#include +#include #include namespace OCC { @@ -77,6 +79,8 @@ ShareUserGroupWidget::ShareUserGroupWidget(AccountPtr account, const QString &sh connect(&_completionTimer, SIGNAL(timeout()), this, SLOT(on_searchPushButton_clicked())); _completionTimer.setSingleShot(true); _completionTimer.setInterval(600); + + setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Expanding); } ShareUserGroupWidget::~ShareUserGroupWidget() @@ -113,11 +117,8 @@ void ShareUserGroupWidget::on_searchPushButton_clicked() QSharedPointer currentUser(new Sharee(_account->credentials()->user(), "", Sharee::Type::User)); blacklist << currentUser; - for(int i = 0; i < _ui->sharesLayout->count(); i++) { - QWidget *w = _ui->sharesLayout->itemAt(i)->widget(); - if (auto sw = qobject_cast(w)) { - blacklist << sw->share()->getShareWith(); - } + foreach (auto sw, _ui->scrollArea->findChildren()) { + blacklist << sw->share()->getShareWith(); } _completerModel->fetch(_ui->shareeLineEdit->text(), blacklist); @@ -131,13 +132,14 @@ void ShareUserGroupWidget::getShares() void ShareUserGroupWidget::slotSharesFetched(const QList> &shares) { - /* - * Delete all current widgets - */ - QLayoutItem *child; - while ((child = _ui->sharesLayout->takeAt(0)) != 0) { - delete child->widget(); - } + QScrollArea *scrollArea = _ui->scrollArea; + + + auto newViewPort = new QWidget(scrollArea); + auto layout = new QVBoxLayout(newViewPort); + + QSize minimumSize = newViewPort->sizeHint(); + int x = 0; foreach(const auto &share, shares) { // We don't handle link shares @@ -145,9 +147,20 @@ void ShareUserGroupWidget::slotSharesFetched(const QList> continue; } - ShareWidget *s = new ShareWidget(share, this); - _ui->sharesLayout->addWidget(s); + ShareWidget *s = new ShareWidget(share, _ui->scrollArea); + layout->addWidget(s); + + x++; + if (x <= 3) { + minimumSize = newViewPort->sizeHint(); + } } + + minimumSize.rwidth() += layout->spacing(); + minimumSize.rheight() += layout->spacing(); + scrollArea->setMinimumSize(minimumSize); + scrollArea->setVisible(!shares.isEmpty()); + scrollArea->setWidget(newViewPort); } void ShareUserGroupWidget::slotShareesReady() diff --git a/src/gui/shareusergroupwidget.ui b/src/gui/shareusergroupwidget.ui index b872fb5b0..5b8e0f0e3 100644 --- a/src/gui/shareusergroupwidget.ui +++ b/src/gui/shareusergroupwidget.ui @@ -39,7 +39,34 @@ - + + + + 0 + 0 + + + + Qt::ScrollBarAlwaysOff + + + QAbstractScrollArea::AdjustToContents + + + true + + + + + 0 + 0 + 441 + 124 + + + + +