Debian Codegraph @

include/util/ddciiconplayer.h

raw
1 // SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd.
2 //
3 // SPDX-License-Identifier: LGPL-3.0-or-later
4
5 #pragma once
6 #include <dtkgui_global.h>
7 #include <DObject>
8 #include <DDciIcon>
9
10 #include <QObject>
11
12 DGUI_BEGIN_NAMESPACE
13
14 class DDciIconImage;
15 class DDciIconPalette;
16 class DDciIconImagePlayerPrivate;
17 class DDciIconImagePlayer : public QObject, public DCORE_NAMESPACE::DObject
18 {
19 D_DECLARE_PRIVATE(DDciIconImagePlayer)
20 Q_OBJECT
21 Q_PROPERTY(DGUI_NAMESPACE::DDciIconImagePlayer::State state READ state NOTIFY stateChanged)
22
23 public:
24 enum State {
25 NotRunning,
26 WaitingRead,
27 Running
28 };
29 Q_ENUM(State)
30
31 enum Flag {
32 Continue = 1,
33 CacheAll = 2,
34 InvertedOrder = 4,
35 IgnoreLastImageLoop = 8,
36 AllowNonLastImageLoop = 16,
37 ClearCacheOnStop = 32
38 };
39 Q_DECLARE_FLAGS(Flags, Flag)
40
41 explicit DDciIconImagePlayer(QObject *parent = nullptr);
42
43 void setImages(const QVector<DDciIconImage> &images);
44 QVector<DDciIconImage> images() const;
45 const DDciIconImage &currentImage() const;
46 bool currentLoopForever() const;
47
48 bool setPalette(const DDciIconPalette &palette);
49 DDciIconPalette palette() const;
50
51 void setLoopCount(int count);
52 int loopCount() const;
53 void abortLoop();
54
55 QImage readImage();
56 State state() const;
57
58 void clearCache();
59
60 public Q_SLOTS:
61 bool start(float speed = 1.0, DGUI_NAMESPACE::DDciIconImagePlayer::Flags flags = {});
62 void stop();
63
64 Q_SIGNALS:
65 void started();
66 void updated();
67 void finished();
68 void stateChanged();
69
70 private:
71 void timerEvent(QTimerEvent *event) override;
72 };
73
74 class DDciIconPlayerPrivate;
75 class DDciIconPlayer : public QObject, public DCORE_NAMESPACE::DObject
76 {
77 D_DECLARE_PRIVATE(DDciIconPlayer)
78 Q_OBJECT
79 public:
80 enum State {
81 Idle,
82 Busy
83 };
84 Q_ENUM(State)
85
86 explicit DDciIconPlayer(QObject *parent = nullptr);
87
88 State state() const;
89
90 void setIcon(const DDciIcon &icon);
91 DDciIcon icon() const;
92
93 void setTheme(DDciIcon::Theme theme);
94 DDciIcon::Theme theme() const;
95
96 void setMode(DDciIcon::Mode mode);
97 DDciIcon::Mode mode() const;
98
99 void setIconSize(int size);
100 int iconSize() const;
101
102 void setDevicePixelRatio(qreal devicePixelRatio);
103 qreal devicePixelRatio() const;
104
105 void setPalette(const DDciIconPalette &palette);
106
107 QImage currentImage() const;
108 void play(DDciIcon::Mode mode);
109 void stop();
110 void abort();
111
112 Q_SIGNALS:
113 void stateChanged();
114 void updated();
115 void modeChanged(DDciIcon::Mode oldMode, DDciIcon::Mode newMode);
116
117 private:
118 D_PRIVATE_SLOT(void _q_playFromQueue(int))
119 };
120
121 DGUI_END_NAMESPACE
122 Q_DECLARE_OPERATORS_FOR_FLAGS(DTK_GUI_NAMESPACE::DDciIconImagePlayer::Flags)