Skip to content

Commit

Permalink
chore: add the animation for ProgressBar
Browse files Browse the repository at this point in the history
add the animation for ProgressBar

Log:
  • Loading branch information
FeiWang1119 committed Jul 31, 2024
1 parent 599d329 commit 572a9c4
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 25 deletions.
64 changes: 43 additions & 21 deletions qt6/src/qml/FloatingMessage.qml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import org.deepin.dtk.style 1.0 as DS

D.FloatingMessageContainer {
id: control
immediateClose: false

property Component contentItem: Label {
verticalAlignment: Text.AlignVCenter
Expand All @@ -25,34 +26,32 @@ D.FloatingMessageContainer {
}
onClicked: {
floatingPanel.state = "small"
destroyTimer.running = true
}
Timer {
id: destroyTimer
interval: 1200; running: false; repeat: true
onTriggered: D.DTK.closeMessage(control)
}
}


onDelayClose: floatingPanel.state = "small"
duration: 4000
panel: FloatingPanel {
id: floatingPanel
property bool animationFinished: false
implicitWidth: DS.Style.control.contentImplicitWidth(floatingPanel)
leftPadding: 10
rightPadding: 10
topPadding: 0
bottomPadding: 0
opacity: 0.0
state: "small"
onAnimationFinishedChanged: (finished) => {
if (floatingPanel.animationFinished === true) {
D.DTK.closeMessage(control)
console.log("11111111111")
}
}

Timer {
id: timer
interval: 100; running: false; repeat: false
onTriggered: {
floatingPanel.y = floatingPanel.parent.height
floatingPanel.state = "normal"
console.log("onCompleted", floatingPanel.y, floatingPanel.parent.width, floatingPanel.parent.height)
}
onTriggered: floatingPanel.state = "normal"
}
Component.onCompleted: {
timer.running = true
Expand Down Expand Up @@ -100,12 +99,12 @@ D.FloatingMessageContainer {
}

ParallelAnimation {
running: closeButton.item.hovered
running: closeButton.item ? closeButton.item.hovered : false
NumberAnimation { target: closeButton; property: "scale"; to: 1.25; duration: 500 }
NumberAnimation { target: closeButton; property: "rotation"; to: 90; duration: 500 }
}
ParallelAnimation {
running: !closeButton.item.hovered
running: closeButton.item ? !closeButton.item.hovered : false
NumberAnimation { target: closeButton; property: "scale"; to: 1; duration: 500 }
NumberAnimation { target: closeButton; property: "rotation"; to: 0; duration: 500 }
}
Expand All @@ -125,19 +124,42 @@ D.FloatingMessageContainer {
name: "small"
PropertyChanges {
target: floatingPanel
y: floatingPanel.parent.height
y: floatingPanel.parent ? floatingPanel.parent.height : 0
opacity: 0.0
scale: 0.2
}
}
]

transitions: Transition {
NumberAnimation {
properties: "y, opacity, scale"
easing.type: Easing.Linear
duration: 1000
transitions: [
Transition {
from: "normal"
to: "small"
SequentialAnimation {
NumberAnimation {
properties: "y, opacity, scale"
easing.type: Easing.Linear
duration: 1000
}
PropertyAction { target: floatingPanel; property: "animationFinished"; value: true; }
}
},
Transition {
from: "small"
to: "normal"
SequentialAnimation {
PropertyAction {
target: floatingPanel
property: "y"
value: floatingPanel.parent ? floatingPanel.parent.height : 0
}
NumberAnimation {
properties: "y, opacity, scale"
easing.type: Easing.Linear
duration: 1000
}
}
}
}
]
}
}
28 changes: 25 additions & 3 deletions qt6/src/qml/private/ProgressBarImpl.qml
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,34 @@ Item {
visible: progressBar.visualPosition > 0

Rectangle {
id: rect
anchors.fill: parent
radius: parent.cornerRadius
property int count
property real lightPosition
gradient: Gradient {
GradientStop { position: 1 - 1 / progressBar.visualPosition; color: progressBar.palette.highlight }
GradientStop {position: 1 - 0.28 / progressBar.visualPosition; color: progressBar.palette.highlight }
GradientStop { position: 1; color: control.D.ColorSelector.handleGradientColor }
GradientStop { position: 0; color: progressBar.palette.highlight }
GradientStop { position: rect.lightPosition; color: control.D.ColorSelector.handleGradientColor }
GradientStop { position: 1; color: progressBar.palette.highlight }
}
Timer {
id: moveTimer
interval: 200
repeat: true
onTriggered: {
console.log("111111", rect.lightPosition)
moveTimer.interval = 200
if (rect.count === 10) {
rect.count = 0
moveTimer.interval = 2000
return;
}
rect.count += 1
rect.lightPosition = (rect.count % 10) * 0.1
}
}
Component.onCompleted: {
moveTimer.start()
}
}
}
Expand Down
19 changes: 18 additions & 1 deletion src/private/dmessagemanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,19 @@ void FloatingMessageContainer::setDuration(int duration)
Q_EMIT durationChanged();
}

bool FloatingMessageContainer::immediateClose() const
{
return m_immediateClose;
}

void FloatingMessageContainer::setImmediateClose(bool immediateClose)

Check warning on line 62 in src/private/dmessagemanager.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

The function 'setImmediateClose' is never used.
{
if (m_immediateClose == immediateClose)
return;

m_immediateClose = immediateClose;
}

void FloatingMessageContainer::close()
{
if (auto manager = qobject_cast<MessageManager *>(parent())) {
Expand Down Expand Up @@ -311,7 +324,11 @@ void MessageManager::timerEvent(QTimerEvent *e)
killTimer(e->timerId());
e->accept();
if (auto container = item.second) {
close(container);
if (container->immediateClose()) {
close(container);
} else {
Q_EMIT container->delayClose();
}
}
break;
}
Expand Down
5 changes: 5 additions & 0 deletions src/private/dmessagemanager_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class FloatingMessageContainer : public QObject
Q_PROPERTY(QQuickItem *panel READ panel WRITE setPanel)
Q_PROPERTY(QVariant message READ message WRITE setMessage NOTIFY messageChanged)
Q_PROPERTY(int duration READ duration WRITE setDuration NOTIFY durationChanged)
Q_PROPERTY(bool immediateClose READ immediateClose WRITE setImmediateClose)
Q_CLASSINFO("DefaultProperty", "panel")
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
QML_NAMED_ELEMENT(FloatingMessageContainer)
Expand All @@ -33,13 +34,16 @@ class FloatingMessageContainer : public QObject
void setMessageId(const QString &msgId);
int duration() const;
void setDuration(int duration);
bool immediateClose() const;
void setImmediateClose(bool immediateClose);

public Q_SLOT:
void close();

Q_SIGNALS:
void messageChanged();
void durationChanged();
void delayClose();

private:
friend MessageManager;
Expand All @@ -48,6 +52,7 @@ public Q_SLOT:
QVariant m_message;
QString m_msgId;
int m_duration = 4000;
bool m_immediateClose = false;
};

class MessageManager : public QObject
Expand Down

0 comments on commit 572a9c4

Please sign in to comment.