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 Aug 7, 2024
1 parent 63952bc commit 58b51ae
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 28 deletions.
66 changes: 42 additions & 24 deletions qt6/src/qml/FloatingMessage.qml
Original file line number Diff line number Diff line change
Expand Up @@ -23,36 +23,31 @@ D.FloatingMessageContainer {
width: DS.Style.floatingMessage.closeButtonSize
height: DS.Style.floatingMessage.closeButtonSize
}
onClicked: {
floatingPanel.state = "small"
destroyTimer.running = true
}
Timer {
id: destroyTimer
interval: 1200; running: false; repeat: true
onTriggered: D.DTK.closeMessage(control)
}
onClicked: floatingPanel.state = "small"
}


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)
}
}

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 +95,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 +120,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: 300
}
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: 300
}
}
}
}
]
}
}
22 changes: 18 additions & 4 deletions 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)
{
if (m_immediateClose == immediateClose)
return;

m_immediateClose = immediateClose;
}

void FloatingMessageContainer::close()
{
if (auto manager = qobject_cast<MessageManager *>(parent())) {
Expand Down Expand Up @@ -194,9 +207,6 @@ void MessageManager::ensureLayout()
" bottomMargin: 20;\n"
" horizontalCenter: parent.horizontalCenter\n"
" }\n"
" Component.onCompleted: {\n"
" console.log(\"parent onCompleted\", children.length);\n"
" }"
"}\n", QUrl());
auto layout = columnCom.beginCreate(qmlContext(parent()));
setLayout(qobject_cast<QQuickItem *>(layout));
Expand Down Expand Up @@ -311,7 +321,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 58b51ae

Please sign in to comment.