Share dialog is now resizeable

Signed-off-by: Claudio Cambra <claudio.cambra@gmail.com>
This commit is contained in:
Claudio Cambra 2022-06-22 13:34:39 +02:00
parent d23305f1fa
commit 2fe6e075b6
3 changed files with 52 additions and 25 deletions

View file

@ -35,6 +35,7 @@
#include <QPointer>
#include <QPushButton>
#include <QFrame>
#include <QScrollBar>
namespace {
QString createRandomPassword()
@ -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)
@ -189,6 +192,7 @@ ShareLinkWidget *ShareDialog::addLinkShareWidget(const QSharedPointer<LinkShare>
_scrollAreaLayout->addWidget(linkShareWidget);
linkShareWidget->setupUiOptions();
adjustScrollWidget();
return linkShareWidget;
}
@ -216,6 +220,8 @@ void ShareDialog::initLinkShareWidget()
_linkWidgetList.removeAll(_emptyShareLinkWidget);
_emptyShareLinkWidget = nullptr;
}
adjustScrollWidget();
}
void ShareDialog::slotAddLinkShareWidget(const QSharedPointer<LinkShare> &linkShare)
@ -223,7 +229,6 @@ void ShareDialog::slotAddLinkShareWidget(const QSharedPointer<LinkShare> &linkSh
emit toggleShareLinkAnimation(true);
const auto addedLinkShareWidget = addLinkShareWidget(linkShare);
initLinkShareWidget();
adjustScrollWidgetSize();
if (linkShare->isPasswordSet()) {
addedLinkShareWidget->focusPasswordLineEdit();
}
@ -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()
@ -341,6 +355,8 @@ void ShareDialog::showSharingUi()
_manager->fetchShares(_sharePath);
}
}
adjustScrollWidget();
}
void ShareDialog::initShareManager()
@ -421,7 +437,6 @@ void ShareDialog::slotDeleteShare()
_scrollAreaLayout->removeWidget(sharelinkWidget);
_linkWidgetList.removeAll(sharelinkWidget);
initLinkShareWidget();
adjustScrollWidgetSize();
}
void ShareDialog::slotThumbnailFetched(const int &statusCode, const QByteArray &reply)
@ -470,4 +485,10 @@ void ShareDialog::changeEvent(QEvent *e)
QDialog::changeEvent(e);
}
void ShareDialog::resizeEvent(QResizeEvent *event)
{
adjustScrollWidget();
QDialog::resizeEvent(event);
}
} // namespace OCC

View file

@ -78,13 +78,14 @@ signals:
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;

View file

@ -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">
@ -18,8 +18,8 @@
</property>
<property name="minimumSize">
<size>
<width>480</width>
<height>250</height>
<width>320</width>
<height>240</height>
</size>
</property>
<layout class="QVBoxLayout" name="shareDialogVerticalLayout">
@ -27,7 +27,7 @@
<number>0</number>
</property>
<property name="sizeConstraint">
<enum>QLayout::SetFixedSize</enum>
<enum>QLayout::SetMinimumSize</enum>
</property>
<item>
<layout class="QVBoxLayout" name="verticalLayout">
@ -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">
@ -117,7 +117,6 @@
</property>
<property name="font">
<font>
<weight>50</weight>
<bold>false</bold>
</font>
</property>
@ -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">
@ -162,7 +161,7 @@
<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>
@ -170,7 +169,7 @@
<property name="minimumSize">
<size>
<width>0</width>
<height>200</height>
<height>0</height>
</size>
</property>
<property name="frameShape">
@ -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>