Add scroll area for share links.
authorCamila <hello@camila.codes>
Fri, 3 Dec 2021 17:18:55 +0000 (18:18 +0100)
committerMatthieu Gallien (Rebase PR Action) <matthieu_gallien@yahoo.fr>
Thu, 13 Jan 2022 10:39:11 +0000 (10:39 +0000)
Signed-off-by: Camila <hello@camila.codes>
src/gui/sharedialog.cpp
src/gui/sharedialog.h
src/gui/sharedialog.ui
src/gui/sharelinkwidget.cpp
src/gui/sharelinkwidget.h
src/gui/shareusergroupwidget.cpp

index 0a8da9aab7f03b31e946d14495071ca2242352ab..fb312734b23f004cae5d9c207310d5207821a69a 100644 (file)
@@ -137,13 +137,19 @@ ShareDialog::ShareDialog(QPointer<AccountState> 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> &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<LinkShare>
     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<LinkShare> &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<QSharedPointer<Share>> &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<QSharedPointer<Share>> &shares)
         QSharedPointer<LinkShare> linkShare = qSharedPointerDynamicCast<LinkShare>(share);
         addLinkShareWidget(linkShare);
     }
-
+    
     initLinkShareWidget();
+    slotAdjustScrollWidgetSize();
     emit toggleShareLinkAnimation(false);
 }
 
 void ShareDialog::slotAdjustScrollWidgetSize()
 {
-    int count = this->findChildren<ShareLinkWidget *>().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<ShareLinkWidget *>().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)
index b3aa9827721fdbce7cea223d68fc7b0aa978b06c..586bedcb76bf91089bdf6044070526b707bfd65c 100644 (file)
@@ -26,6 +26,7 @@
 #include <QWidget>
 
 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
index cb49c7cb8f2a84a53b4b13ccf1d9185de1718aa4..6410c5203b8cc351ee66f89037b2ac76859c8738 100644 (file)
@@ -6,8 +6,8 @@
    <rect>
     <x>0</x>
     <y>0</y>
-    <width>385</width>
-    <height>150</height>
+    <width>400</width>
+    <height>222</height>
    </rect>
   </property>
   <layout class="QVBoxLayout" name="shareDialogVerticalLayout">
        <property name="spacing">
         <number>10</number>
        </property>
+       <item row="0" column="0" rowspan="2">
+        <widget class="QLabel" name="label_icon">
+         <property name="sizePolicy">
+          <sizepolicy hsizetype="Maximum" vsizetype="Maximum">
+           <horstretch>0</horstretch>
+           <verstretch>0</verstretch>
+          </sizepolicy>
+         </property>
+         <property name="minimumSize">
+          <size>
+           <width>40</width>
+           <height>40</height>
+          </size>
+         </property>
+         <property name="maximumSize">
+          <size>
+           <width>16777215</width>
+           <height>16777215</height>
+          </size>
+         </property>
+         <property name="text">
+          <string>Icon</string>
+         </property>
+        </widget>
+       </item>
        <item row="0" column="1">
         <widget class="QLabel" name="label_name">
          <property name="sizePolicy">
          </property>
         </widget>
        </item>
-       <item row="0" column="0" rowspan="2">
-        <widget class="QLabel" name="label_icon">
-         <property name="sizePolicy">
-          <sizepolicy hsizetype="Maximum" vsizetype="Maximum">
-           <horstretch>0</horstretch>
-           <verstretch>0</verstretch>
-          </sizepolicy>
-         </property>
-         <property name="minimumSize">
-          <size>
-           <width>40</width>
-           <height>40</height>
-          </size>
-         </property>
-         <property name="maximumSize">
-          <size>
-           <width>16777215</width>
-           <height>16777215</height>
-          </size>
-         </property>
-         <property name="text">
-          <string>Icon</string>
-         </property>
-        </widget>
-       </item>
       </layout>
      </item>
      <item>
-      <widget class="QScrollArea" name="scrollArea">
+      <widget class="QScrollArea" name="scrollAreaLinks">
        <property name="sizePolicy">
         <sizepolicy hsizetype="Fixed" vsizetype="Fixed">
          <horstretch>0</horstretch>
          <verstretch>0</verstretch>
         </sizepolicy>
        </property>
+       <property name="styleSheet">
+        <string notr="true"/>
+       </property>
        <property name="frameShape">
         <enum>QFrame::NoFrame</enum>
        </property>
+       <property name="frameShadow">
+        <enum>QFrame::Plain</enum>
+       </property>
+       <property name="horizontalScrollBarPolicy">
+        <enum>Qt::ScrollBarAlwaysOff</enum>
+       </property>
+       <property name="sizeAdjustPolicy">
+        <enum>QAbstractScrollArea::AdjustIgnored</enum>
+       </property>
+       <property name="widgetResizable">
+        <bool>true</bool>
+       </property>
+       <widget class="QWidget" name="scrollAreaWidgetContentsLinks">
+        <property name="geometry">
+         <rect>
+          <x>0</x>
+          <y>0</y>
+          <width>68</width>
+          <height>68</height>
+         </rect>
+        </property>
+       </widget>
+      </widget>
+     </item>
+     <item>
+      <widget class="QScrollArea" name="scrollAreaUsers">
+       <property name="sizePolicy">
+        <sizepolicy hsizetype="Fixed" vsizetype="Fixed">
+         <horstretch>0</horstretch>
+         <verstretch>0</verstretch>
+        </sizepolicy>
+       </property>
+       <property name="styleSheet">
+        <string notr="true"/>
+       </property>
+       <property name="frameShape">
+        <enum>QFrame::NoFrame</enum>
+       </property>
+       <property name="frameShadow">
+        <enum>QFrame::Plain</enum>
+       </property>
+       <property name="lineWidth">
+        <number>1</number>
+       </property>
        <property name="horizontalScrollBarPolicy">
         <enum>Qt::ScrollBarAlwaysOff</enum>
        </property>
        <property name="widgetResizable">
         <bool>true</bool>
        </property>
-       <widget class="QWidget" name="scrollAreaWidgetContents">
+       <widget class="QWidget" name="scrollAreaWidgetContentsUsers">
         <property name="geometry">
          <rect>
           <x>0</x>
           <y>0</y>
-          <width>69</width>
-          <height>69</height>
+          <width>68</width>
+          <height>68</height>
          </rect>
         </property>
         <layout class="QVBoxLayout" name="scrollAreaVerticalLayout"/>
index f0ea3c615799b1f4d4c502c20d77c577890fded6..c62a050216964d299fef548d36ff11c7949423eb 100644 (file)
@@ -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);
index d9c3dec123cfc2d58e8df892191155eee4be340b..cea4070b7b8f238d710c9a00d4ed1666001b3d05 100644 (file)
@@ -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();
index 9c9bc3fc06275b6102d56da6b2af5bfff461a49b..b8a42eb819f1d4d4c498a01c23707c2c2bc24737 100644 (file)
@@ -159,7 +159,7 @@ ShareUserGroupWidget::ShareUserGroupWidget(AccountPtr account,
     // Setup the sharee search progress indicator
     //_ui->shareeHorizontalLayout->addWidget(&_pi_sharee);
 
-    _parentScrollArea = parentWidget()->findChild<QScrollArea*>("scrollArea");
+    _parentScrollArea = parentWidget()->findChild<QScrollArea*>("scrollAreaUsers");
 
     customizeStyle();
 }