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 <QPointer>
#include <QPushButton> #include <QPushButton>
#include <QFrame> #include <QFrame>
#include <QScrollBar>
namespace { namespace {
QString createRandomPassword() QString createRandomPassword()
@ -160,6 +161,8 @@ ShareDialog::ShareDialog(QPointer<AccountState> accountState,
_ui->verticalLayout->addWidget(_internalLinkWidget); _ui->verticalLayout->addWidget(_internalLinkWidget);
_internalLinkWidget->setupUiOptions(); _internalLinkWidget->setupUiOptions();
connect(this, &ShareDialog::styleChanged, _internalLinkWidget, &InternalLinkWidget::slotStyleChanged); connect(this, &ShareDialog::styleChanged, _internalLinkWidget, &InternalLinkWidget::slotStyleChanged);
adjustScrollWidget();
} }
ShareLinkWidget *ShareDialog::addLinkShareWidget(const QSharedPointer<LinkShare> &linkShare) ShareLinkWidget *ShareDialog::addLinkShareWidget(const QSharedPointer<LinkShare> &linkShare)
@ -189,6 +192,7 @@ ShareLinkWidget *ShareDialog::addLinkShareWidget(const QSharedPointer<LinkShare>
_scrollAreaLayout->addWidget(linkShareWidget); _scrollAreaLayout->addWidget(linkShareWidget);
linkShareWidget->setupUiOptions(); linkShareWidget->setupUiOptions();
adjustScrollWidget();
return linkShareWidget; return linkShareWidget;
} }
@ -216,6 +220,8 @@ void ShareDialog::initLinkShareWidget()
_linkWidgetList.removeAll(_emptyShareLinkWidget); _linkWidgetList.removeAll(_emptyShareLinkWidget);
_emptyShareLinkWidget = nullptr; _emptyShareLinkWidget = nullptr;
} }
adjustScrollWidget();
} }
void ShareDialog::slotAddLinkShareWidget(const QSharedPointer<LinkShare> &linkShare) void ShareDialog::slotAddLinkShareWidget(const QSharedPointer<LinkShare> &linkShare)
@ -223,7 +229,6 @@ void ShareDialog::slotAddLinkShareWidget(const QSharedPointer<LinkShare> &linkSh
emit toggleShareLinkAnimation(true); emit toggleShareLinkAnimation(true);
const auto addedLinkShareWidget = addLinkShareWidget(linkShare); const auto addedLinkShareWidget = addLinkShareWidget(linkShare);
initLinkShareWidget(); initLinkShareWidget();
adjustScrollWidgetSize();
if (linkShare->isPasswordSet()) { if (linkShare->isPasswordSet()) {
addedLinkShareWidget->focusPasswordLineEdit(); addedLinkShareWidget->focusPasswordLineEdit();
} }
@ -247,20 +252,29 @@ void ShareDialog::slotSharesFetched(const QList<QSharedPointer<Share>> &shares)
} }
initLinkShareWidget(); initLinkShareWidget();
adjustScrollWidgetSize();
emit toggleShareLinkAnimation(false); emit toggleShareLinkAnimation(false);
} }
void ShareDialog::adjustScrollWidgetSize() void ShareDialog::adjustScrollWidget()
{ {
const auto count = _scrollAreaLayout->count(); _ui->scrollArea->setVisible(_scrollAreaLayout->count() > 0);
const auto margin = 10;
const auto height = _linkWidgetList.empty() ? 0 : _linkWidgetList.last()->sizeHint().height() + margin; // Sometimes the contentRect returns a height of 0, so we need a backup plan
const auto totalHeight = height * count; const auto scrollAreaContentHeight = _scrollAreaLayout->contentsRect().height();
_ui->scrollArea->setFixedWidth(_ui->verticalLayout->sizeHint().width());
_ui->scrollArea->setFixedHeight(totalHeight > 400 ? 400 : totalHeight); auto linkWidgetHeights = 0;
_ui->scrollArea->setVisible(height > 0);
_ui->scrollArea->setFrameShape(count > 6 ? QFrame::StyledPanel : QFrame::NoFrame); 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() ShareDialog::~ShareDialog()
@ -341,6 +355,8 @@ void ShareDialog::showSharingUi()
_manager->fetchShares(_sharePath); _manager->fetchShares(_sharePath);
} }
} }
adjustScrollWidget();
} }
void ShareDialog::initShareManager() void ShareDialog::initShareManager()
@ -421,7 +437,6 @@ void ShareDialog::slotDeleteShare()
_scrollAreaLayout->removeWidget(sharelinkWidget); _scrollAreaLayout->removeWidget(sharelinkWidget);
_linkWidgetList.removeAll(sharelinkWidget); _linkWidgetList.removeAll(sharelinkWidget);
initLinkShareWidget(); initLinkShareWidget();
adjustScrollWidgetSize();
} }
void ShareDialog::slotThumbnailFetched(const int &statusCode, const QByteArray &reply) void ShareDialog::slotThumbnailFetched(const int &statusCode, const QByteArray &reply)
@ -470,4 +485,10 @@ void ShareDialog::changeEvent(QEvent *e)
QDialog::changeEvent(e); QDialog::changeEvent(e);
} }
void ShareDialog::resizeEvent(QResizeEvent *event)
{
adjustScrollWidget();
QDialog::resizeEvent(event);
}
} // namespace OCC } // namespace OCC

View file

@ -78,13 +78,14 @@ signals:
protected: protected:
void changeEvent(QEvent *) override; void changeEvent(QEvent *) override;
void resizeEvent(QResizeEvent *event) override;
private: private:
void showSharingUi(); void showSharingUi();
void initShareManager(); void initShareManager();
ShareLinkWidget *addLinkShareWidget(const QSharedPointer<LinkShare> &linkShare); ShareLinkWidget *addLinkShareWidget(const QSharedPointer<LinkShare> &linkShare);
void initLinkShareWidget(); void initLinkShareWidget();
void adjustScrollWidgetSize(); void adjustScrollWidget();
Ui::ShareDialog *_ui; Ui::ShareDialog *_ui;

View file

@ -6,8 +6,8 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>480</width> <width>385</width>
<height>280</height> <height>400</height>
</rect> </rect>
</property> </property>
<property name="sizePolicy"> <property name="sizePolicy">
@ -18,8 +18,8 @@
</property> </property>
<property name="minimumSize"> <property name="minimumSize">
<size> <size>
<width>480</width> <width>320</width>
<height>250</height> <height>240</height>
</size> </size>
</property> </property>
<layout class="QVBoxLayout" name="shareDialogVerticalLayout"> <layout class="QVBoxLayout" name="shareDialogVerticalLayout">
@ -27,7 +27,7 @@
<number>0</number> <number>0</number>
</property> </property>
<property name="sizeConstraint"> <property name="sizeConstraint">
<enum>QLayout::SetFixedSize</enum> <enum>QLayout::SetMinimumSize</enum>
</property> </property>
<item> <item>
<layout class="QVBoxLayout" name="verticalLayout"> <layout class="QVBoxLayout" name="verticalLayout">
@ -117,7 +117,6 @@
</property> </property>
<property name="font"> <property name="font">
<font> <font>
<weight>50</weight>
<bold>false</bold> <bold>false</bold>
</font> </font>
</property> </property>
@ -132,7 +131,7 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="0" column="0" rowspan="3"> <item row="0" column="0" rowspan="4">
<widget class="QLabel" name="label_icon"> <widget class="QLabel" name="label_icon">
<property name="sizePolicy"> <property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Maximum"> <sizepolicy hsizetype="Maximum" vsizetype="Maximum">
@ -162,7 +161,7 @@
<item> <item>
<widget class="QScrollArea" name="scrollArea"> <widget class="QScrollArea" name="scrollArea">
<property name="sizePolicy"> <property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Minimum"> <sizepolicy hsizetype="MinimumExpanding" vsizetype="MinimumExpanding">
<horstretch>0</horstretch> <horstretch>0</horstretch>
<verstretch>0</verstretch> <verstretch>0</verstretch>
</sizepolicy> </sizepolicy>
@ -170,7 +169,7 @@
<property name="minimumSize"> <property name="minimumSize">
<size> <size>
<width>0</width> <width>0</width>
<height>200</height> <height>0</height>
</size> </size>
</property> </property>
<property name="frameShape"> <property name="frameShape">
@ -196,10 +195,16 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>460</width> <width>359</width>
<height>200</height> <height>320</height>
</rect> </rect>
</property> </property>
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="MinimumExpanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget> </widget>
</widget> </widget>
</item> </item>