Skip to content

Commit

Permalink
Merge pull request #4663 from nextcloud/feature/resizeable-share-dialog
Browse files Browse the repository at this point in the history
Make the share dialog resizeable
  • Loading branch information
claucambra authored Jun 24, 2022
2 parents d23305f + 2fe6e07 commit f27aa4f
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 25 deletions.
45 changes: 33 additions & 12 deletions src/gui/sharedialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include <QPointer>
#include <QPushButton>
#include <QFrame>
#include <QScrollBar>

namespace {
QString createRandomPassword()
Expand Down Expand Up @@ -160,6 +161,8 @@ ShareDialog::ShareDialog(QPointer<AccountState> accountState,
_ui->verticalLayout->addWidget(_internalLinkWidget);
_internalLinkWidget->setupUiOptions();
connect(this, &ShareDialog::styleChanged, _internalLinkWidget, &InternalLinkWidget::slotStyleChanged);

adjustScrollWidget();
}

ShareLinkWidget *ShareDialog::addLinkShareWidget(const QSharedPointer<LinkShare> &linkShare)
Expand Down Expand Up @@ -189,6 +192,7 @@ ShareLinkWidget *ShareDialog::addLinkShareWidget(const QSharedPointer<LinkShare>
_scrollAreaLayout->addWidget(linkShareWidget);

linkShareWidget->setupUiOptions();
adjustScrollWidget();

return linkShareWidget;
}
Expand Down Expand Up @@ -216,14 +220,15 @@ void ShareDialog::initLinkShareWidget()
_linkWidgetList.removeAll(_emptyShareLinkWidget);
_emptyShareLinkWidget = nullptr;
}

adjustScrollWidget();
}

void ShareDialog::slotAddLinkShareWidget(const QSharedPointer<LinkShare> &linkShare)
{
emit toggleShareLinkAnimation(true);
const auto addedLinkShareWidget = addLinkShareWidget(linkShare);
initLinkShareWidget();
adjustScrollWidgetSize();
if (linkShare->isPasswordSet()) {
addedLinkShareWidget->focusPasswordLineEdit();
}
Expand All @@ -247,20 +252,29 @@ void ShareDialog::slotSharesFetched(const QList<QSharedPointer<Share>> &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()
Expand Down Expand Up @@ -341,6 +355,8 @@ void ShareDialog::showSharingUi()
_manager->fetchShares(_sharePath);
}
}

adjustScrollWidget();
}

void ShareDialog::initShareManager()
Expand Down Expand Up @@ -421,7 +437,6 @@ void ShareDialog::slotDeleteShare()
_scrollAreaLayout->removeWidget(sharelinkWidget);
_linkWidgetList.removeAll(sharelinkWidget);
initLinkShareWidget();
adjustScrollWidgetSize();
}

void ShareDialog::slotThumbnailFetched(const int &statusCode, const QByteArray &reply)
Expand Down Expand Up @@ -470,4 +485,10 @@ void ShareDialog::changeEvent(QEvent *e)
QDialog::changeEvent(e);
}

void ShareDialog::resizeEvent(QResizeEvent *event)
{
adjustScrollWidget();
QDialog::resizeEvent(event);
}

} // namespace OCC
3 changes: 2 additions & 1 deletion src/gui/sharedialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -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> &linkShare);
void initLinkShareWidget();
void adjustScrollWidgetSize();
void adjustScrollWidget();

Ui::ShareDialog *_ui;

Expand Down
29 changes: 17 additions & 12 deletions src/gui/sharedialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>480</width>
<height>280</height>
<width>385</width>
<height>400</height>
</rect>
</property>
<property name="sizePolicy">
Expand All @@ -18,16 +18,16 @@
</property>
<property name="minimumSize">
<size>
<width>480</width>
<height>250</height>
<width>320</width>
<height>240</height>
</size>
</property>
<layout class="QVBoxLayout" name="shareDialogVerticalLayout">
<property name="spacing">
<number>0</number>
</property>
<property name="sizeConstraint">
<enum>QLayout::SetFixedSize</enum>
<enum>QLayout::SetMinimumSize</enum>
</property>
<item>
<layout class="QVBoxLayout" name="verticalLayout">
Expand All @@ -49,7 +49,7 @@
<number>0</number>
</property>
<property name="spacing">
<number>2</number>
<number>2</number>
</property>
<item row="0" column="1">
<widget class="QLabel" name="label_name">
Expand Down Expand Up @@ -117,7 +117,6 @@
</property>
<property name="font">
<font>
<weight>50</weight>
<bold>false</bold>
</font>
</property>
Expand All @@ -132,7 +131,7 @@
</property>
</widget>
</item>
<item row="0" column="0" rowspan="3">
<item row="0" column="0" rowspan="4">
<widget class="QLabel" name="label_icon">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Maximum">
Expand Down Expand Up @@ -162,15 +161,15 @@
<item>
<widget class="QScrollArea" name="scrollArea">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Minimum">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="MinimumExpanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>0</width>
<height>200</height>
<height>0</height>
</size>
</property>
<property name="frameShape">
Expand All @@ -196,10 +195,16 @@
<rect>
<x>0</x>
<y>0</y>
<width>460</width>
<height>200</height>
<width>359</width>
<height>320</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="MinimumExpanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</widget>
</item>
Expand Down

0 comments on commit f27aa4f

Please sign in to comment.