Skip to content

Commit

Permalink
sync: from linuxdeepin/dtkwidget
Browse files Browse the repository at this point in the history
Synchronize source files from linuxdeepin/dtkwidget.

Source-pull-request: linuxdeepin/dtkwidget#604
  • Loading branch information
deepin-ci-robot committed Sep 23, 2024
1 parent f18b453 commit 5fee29b
Show file tree
Hide file tree
Showing 36 changed files with 1,012 additions and 54 deletions.
31 changes: 31 additions & 0 deletions examples/collections/progressbarexample.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <DWaterProgress>
#include <QPropertyAnimation>
#include <DColoredProgressBar>
#include <DIndeterminateProgressbar>
#include "progressbarexample.h"

DWIDGET_USE_NAMESPACE
Expand All @@ -28,6 +29,7 @@ ProgressBarExampleWindow::ProgressBarExampleWindow(QWidget *parent)
addExampleWindow(new DProgressBarExample(this));
addExampleWindow(new DWaterProgressExample(this));
addExampleWindow(new DColoredProgressBarExample(this));
addExampleWindow(new DIndeterminateProgressBarExample(this));
}

DProgressBarExample::DProgressBarExample(QWidget *parent)
Expand Down Expand Up @@ -181,3 +183,32 @@ int DColoredProgressBarExample::getFixedHeight() const
{
return 200;
}

DIndeterminateProgressBarExample::DIndeterminateProgressBarExample(QWidget *parent)
: ExampleWindowInterface(parent)
{
auto mainLayout = new QVBoxLayout(this);
auto indeterBar = new DIndeterminateProgressbar();
indeterBar->setFixedSize(500, 35);
mainLayout->addWidget(indeterBar, 0, Qt::AlignCenter);
setLayout(mainLayout);
}

QString DIndeterminateProgressBarExample::getTitleName() const
{
return "DIndeterminateProgressbar";
}

QString DIndeterminateProgressBarExample::getDescriptionInfo() const
{
return QString("一个模糊进度条,不展示具体进度值,\n"
"用于等待时间不确定的情况。主要用\n"
"在小工具主窗口内部,作为一个中间状态\n"
"展示给用户,最终的结果往往会跟随成功\n"
"或者失败的图标。");
}

int DIndeterminateProgressBarExample::getFixedHeight() const
{
return 200;
}
12 changes: 12 additions & 0 deletions examples/collections/progressbarexample.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,16 @@ class DColoredProgressBarExample : public ExampleWindowInterface
int getFixedHeight() const override;
};

class DIndeterminateProgressBarExample : public ExampleWindowInterface
{
Q_OBJECT

public:
explicit DIndeterminateProgressBarExample(QWidget *parent = nullptr);

QString getTitleName() const override;
QString getDescriptionInfo() const override;
int getFixedHeight() const override;
};

#endif // PROGRESSBAREXAMPLE_H
1 change: 1 addition & 0 deletions include/DWidget/DBounceAnimation
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#include "dbounceanimation.h"
1 change: 1 addition & 0 deletions include/DWidget/DIndeterminateProgressbar
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#include "dindeterminateprogressbar.h"
31 changes: 31 additions & 0 deletions include/widgets/dbounceanimation.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// SPDX-FileCopyrightText: 2024 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: LGPL-3.0-or-later
#ifndef DBOUNCEANIMATION_H
#define DBOUNCEANIMATION_H

#include <DObject>
#include <QObject>

class QPropertyAnimation;
class QAbstractScrollArea;
class DBounceAnimationPrivate;
class DBounceAnimation : public QObject, public DTK_CORE_NAMESPACE::DObject
{
Q_OBJECT
public:
explicit DBounceAnimation(QObject *parent = nullptr);

void setAnimationTarget(QAbstractScrollArea *w);
void setAniMationEnable(bool enable);

protected:
bool eventFilter(QObject *o, QEvent *e) override;
void bounceBack(Qt::Orientation orientation);

private:
D_DECLARE_PRIVATE(DBounceAnimation)

};

#endif // DBOUNCEANIMATION_H
7 changes: 6 additions & 1 deletion include/widgets/dbuttonbox.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-FileCopyrightText: 2019 - 2022 UnionTech Software Technology Co., Ltd.
// SPDX-FileCopyrightText: 2019 - 2024 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: LGPL-3.0-or-later

Expand Down Expand Up @@ -47,6 +47,8 @@ class DButtonBoxButton : public QAbstractButton, public DCORE_NAMESPACE::DObject
void paintEvent(QPaintEvent *e) override;
void keyPressEvent(QKeyEvent *event) override;
bool event(QEvent *e) override;

friend class DButtonBox;
};

class DButtonBoxPrivate;
Expand Down Expand Up @@ -78,6 +80,9 @@ class DButtonBox : public QWidget, public DCORE_NAMESPACE::DObject
void buttonReleased(QAbstractButton *);
void buttonToggled(QAbstractButton *, bool);

protected:
bool eventFilter(QObject *o, QEvent *e) override;

private:
void paintEvent(QPaintEvent *e) override;

Expand Down
3 changes: 2 additions & 1 deletion include/widgets/dfloatingmessage.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-FileCopyrightText: 2019 - 2023 UnionTech Software Technology Co., Ltd.
// SPDX-FileCopyrightText: 2019 - 2024 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: LGPL-3.0-or-later

Expand Down Expand Up @@ -38,6 +38,7 @@ class DFloatingMessage : public DFloatingWidget

Q_SIGNALS:
void closeButtonClicked();
void messageClosed();

protected:
using DFloatingWidget::setWidget;
Expand Down
26 changes: 26 additions & 0 deletions include/widgets/dindeterminateprogressbar.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// SPDX-FileCopyrightText: 2024 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: LGPL-3.0-or-later

#ifndef DINDETERMINATEPROGRESSBAR_H
#define DINDETERMINATEPROGRESSBAR_H

#include <DObject>
#include <QWidget>

class DIndeterminateProgressbarPrivate;
class DIndeterminateProgressbar : public QWidget, public DTK_CORE_NAMESPACE::DObject
{
Q_OBJECT
public:
explicit DIndeterminateProgressbar(QWidget *parent = nullptr);

protected:
void paintEvent(QPaintEvent *e) override;
void resizeEvent(QResizeEvent *e) override;

private:
D_DECLARE_PRIVATE(DIndeterminateProgressbar)
};

#endif // DINDETERMINATEPROGRESSBAR_H
8 changes: 5 additions & 3 deletions include/widgets/dmessagemanager.h
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// SPDX-FileCopyrightText: 2022 UnionTech Software Technology Co., Ltd.
// SPDX-FileCopyrightText: 2022 - 2024 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: LGPL-3.0-or-later

#ifndef DMESSAGEMANAGER_H
#define DMESSAGEMANAGER_H

#include <QObject>
#include <DObject>
#include <QWidget>
#include <dtkwidget_global.h>
#include <dtkgui_global.h>
Expand All @@ -16,9 +16,11 @@ DGUI_END_NAMESPACE

DWIDGET_BEGIN_NAMESPACE
class DFloatingMessage;
class DMessageManager: public QObject
class DMessageManagerPrivate;
class DMessageManager: public QObject, public DCORE_NAMESPACE::DObject
{
Q_OBJECT
D_DECLARE_PRIVATE(DMessageManager)

private:
DMessageManager(); //构造函数是私有的
Expand Down
15 changes: 13 additions & 2 deletions include/widgets/dtoolbutton.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,34 @@
#ifndef DTOOLBUTTON_H
#define DTOOLBUTTON_H

#include <QToolButton>
#include <dtkwidget_global.h>

#include <QToolButton>

#include <DDciIcon>
#include <DDciIconPlayer>

DWIDGET_BEGIN_NAMESPACE
DGUI_USE_NAMESPACE

class LIBDTKWIDGETSHARED_EXPORT DToolButton : public QToolButton
class DToolButtonPrivate;
class LIBDTKWIDGETSHARED_EXPORT DToolButton : public QToolButton, public DCORE_NAMESPACE::DObject
{
Q_OBJECT
public:
DToolButton(QWidget *parent = nullptr);
void setAlignment(Qt::Alignment flag);
Qt::Alignment alignment() const;
void setDciIcon(const DDciIcon &dciIcon);

protected:
void paintEvent(QPaintEvent *event) override;
void initStyleOption(QStyleOptionToolButton *option) const;
QSize sizeHint() const override;
bool event(QEvent *e) override;

private:
D_DECLARE_PRIVATE(DToolButton)
};

DWIDGET_END_NAMESPACE
Expand Down
Binary file not shown.
Binary file not shown.
Binary file added src/widgets/assets/icons/bloom/radio_checked.dci
Binary file not shown.
Binary file not shown.
Binary file added src/widgets/assets/icons/bloom/switch_off.dci
Binary file not shown.
Binary file added src/widgets/assets/icons/bloom/switch_on.dci
Binary file not shown.
6 changes: 6 additions & 0 deletions src/widgets/assets/icons/dtk-icon-theme.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -72,5 +72,11 @@
<file alias="window_maximize.dci">bloom/window_maximize.dci</file>
<file alias="window_minimize.dci">bloom/window_minimize.dci</file>
<file alias="window_normal.dci">bloom/window_normal.dci</file>
<file alias="switch_on.dci">bloom/switch_on.dci</file>
<file alias="switch_off.dci">bloom/switch_off.dci</file>
<file alias="radio_checked.dci">bloom/radio_checked.dci</file>
<file alias="radio_unchecked.dci">bloom/radio_unchecked.dci</file>
<file alias="checkbox_checked.dci">bloom/checkbox_checked.dci</file>
<file alias="checkbox_unchecked.dci">bloom/checkbox_unchecked.dci</file>
</qresource>
</RCC>
107 changes: 107 additions & 0 deletions src/widgets/dbounceanimation.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
// SPDX-FileCopyrightText: 2024 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: LGPL-3.0-or-later
#include "private/dbounceanimation_p.h"
#include <QPropertyAnimation>
#include <QEvent>
#include <QDebug>
#include <QAbstractScrollArea>
#include <QScrollBar>
#include <QWheelEvent>
#include <QTimer>

DBounceAnimationPrivate::DBounceAnimationPrivate(DBounceAnimation *qq)
: DObjectPrivate (qq)
, m_animation(nullptr)
, m_animationTarget(nullptr)
, m_deltaSum(0)
{
}

DBounceAnimation::DBounceAnimation(QObject *parent)
: QObject(parent)
, DObject(*new DBounceAnimationPrivate(this))
{
}

void DBounceAnimation::setAnimationTarget(QAbstractScrollArea *w)
{
D_D(DBounceAnimation);
if (!w)
return;

if (d->m_animationTarget == w)
return;

d->m_animationTarget = w;
}

void DBounceAnimation::setAniMationEnable(bool enable)
{
D_D(DBounceAnimation);
enable ? d->m_animationTarget->installEventFilter(this)
: d->m_animationTarget->removeEventFilter(this);
}

bool DBounceAnimation::eventFilter(QObject *o, QEvent *e)
{
D_D(DBounceAnimation);
if (e->type() == QEvent::Wheel) {
if (auto absscroll = dynamic_cast<QAbstractScrollArea *>(o)) {
if (auto wheelEvent = dynamic_cast<QWheelEvent *>(e)) {
if (absscroll->verticalScrollBar()->value() <= 0 || absscroll->verticalScrollBar()->value() >= absscroll->verticalScrollBar()->maximum()) {
d->m_deltaSum += wheelEvent->delta();
bounceBack(wheelEvent->angleDelta().x() == 0 ? Qt::Vertical : Qt::Horizontal);
}
}
}
}

return false;
}

void DBounceAnimation::bounceBack(Qt::Orientation orientation)
{
D_D(DBounceAnimation);
if (d->m_animation)
return;

if (orientation & Qt::Vertical && d->m_animationTarget->verticalScrollBar()->maximum() == d->m_animationTarget->verticalScrollBar()->minimum())
return;

if (orientation & Qt::Horizontal && d->m_animationTarget->horizontalScrollBar()->maximum() == d->m_animationTarget->horizontalScrollBar()->minimum())
return;

d->m_animation = new QPropertyAnimation(this);
d->m_animation->setTargetObject(d->m_animationTarget->viewport());
d->m_animation->setPropertyName("pos");
d->m_animation->setDuration(100);
d->m_animation->setEasingCurve(QEasingCurve::InQuart);
d->m_animation->setStartValue(QPoint(d->m_animationTarget->viewport()->x(), d->m_animationTarget->viewport()->y()));

QTimer::singleShot(100, this, [this, d, orientation]() {

if (orientation & Qt::Vertical) {
d->m_animation->setEndValue(
QPoint(d->m_animationTarget->viewport()->x(), d->m_animationTarget->viewport()->y() + d->m_deltaSum / 16));
} else {
d->m_animation->setEndValue(
QPoint(d->m_animationTarget->viewport()->x() + d->m_deltaSum / 16, d->m_animationTarget->viewport()->y()));
}

d->m_animation->start();

connect(d->m_animation, &QPropertyAnimation::finished, this, [d]() {
if (d->m_animation->direction() == QPropertyAnimation::Backward) {
delete d->m_animation;
d->m_animation = nullptr;
return;
}

d->m_animation->setDirection(QPropertyAnimation::Direction::Backward);
d->m_animation->setDuration(1000);
d->m_animation->start(QPropertyAnimation::DeleteWhenStopped);
d->m_deltaSum = 0;
});
});
}
Loading

0 comments on commit 5fee29b

Please sign in to comment.