CCIMXDesktop
 
Loading...
Searching...
No Matches
WallPaperEngine.h
1#ifndef WALLPAPERENGINE_H
2#define WALLPAPERENGINE_H
3
4#include <QEasingCurve>
5#include <QMap>
6#include <QObject>
7#include <QStringList>
8class QMainWindow;
9class QWidget;
10class QLabel;
11class QTimer;
13
20class WallPaperEngine : public QObject {
21 Q_OBJECT
22
23public:
27 enum class SwitchingMode {
28 Gradient,
29 Fixed,
31 };
32
36 struct ModeMapping {
40 const QMap<QString, WallPaperEngine::SwitchingMode> mappings = {
41 { "Fixed WallPaper", SwitchingMode::Fixed },
42 { "Gradient Switch", SwitchingMode::Gradient },
43 { "Movement Sessions", SwitchingMode::Movement },
44 };
45
50 inline QStringList values() const {
51 return mappings.keys();
52 }
53
59 inline QString toString(const WallPaperEngine::SwitchingMode mode) {
60 return mappings.key(mode);
61 }
62
69 inline WallPaperEngine::SwitchingMode fromString(const QString& l) {
70 auto finder = mappings.find(l);
71 if (finder == mappings.end()) {
72 throw std::runtime_error("Invalid Name");
73 }
74 return finder.value();
75 }
77
78private:
79 static constexpr unsigned int SWITCH_INTERVAL = 20000;
80 static constexpr unsigned int ANIMATION_DURATION = 2000;
81 static constexpr SwitchingMode DEF_MODE = SwitchingMode::Movement;
82
83public:
84 friend class WallPaperAnimationHandler;
85
89 WallPaperEngine() = delete;
90
95 explicit WallPaperEngine(DesktopMainWindow* window);
96
101 void process_resize(DesktopMainWindow* window);
102
107 void set_switch_interval(int new_interval);
108
113 int switch_interval() const;
114
119 void set_animation_speed(int msspeed) { animation_durations = msspeed; }
120
125 int animation_speed() const { return animation_durations; }
126
131 void set_mode(const SwitchingMode mode);
132
137 QPixmap get_current_pixmap() const;
138
143 SwitchingMode current_mode() const { return mode; }
144
149 void set_showing_pictures(const QPixmap& map);
150
155 void set_animation_duration_second(int secs);
156
161 int duration_seconds() const;
162
167 QStringList& get_image_list();
168
173 void set_image_list(const QStringList& l);
174
178 void reset_defaults();
183 QEasingCurve get_easingcurve() const;
184
189 void set_easingcurve(const QEasingCurve curveType);
190
195
196signals:
201 void imagelist_changed(const QStringList& l);
202
207 void wallpaperChanged(const QPixmap& pixmap);
208
209private:
210 QWidget* shoule_be_lower;
211 QLabel* wallpaperLabel { nullptr };
212 QLabel* bufferpaperLabel { nullptr };
213 QTimer* invoke_switch_timer;
214 QStringList image_lists;
215
219 void process_internal_timer_hook();
220
224 void default_behaviour_of_flush();
225
226 SwitchingMode mode { DEF_MODE };
227 int animation_durations { ANIMATION_DURATION };
228 QEasingCurve curve { QEasingCurve::InOutCubic }; // current curse;
229};
230
231#endif // WALLPAPERENGINE_H
DesktopMainWindow is the main frontend window of the application. For beginners, this is the starting...
Definition desktopmainwindow.h:33
Engine managing desktop wallpaper switching and animations.
Definition WallPaperEngine.h:20
void fallback_empty_session()
Handles fallback behavior when no wallpaper images are available.
Definition WallPaperEngine.cpp:107
QEasingCurve get_easingcurve() const
get_easingcurve
Definition WallPaperEngine.cpp:99
int animation_speed() const
Gets the current animation speed duration.
Definition WallPaperEngine.h:125
int switch_interval() const
Gets the current wallpaper switch interval.
Definition WallPaperEngine.cpp:41
void reset_defaults()
Resets all settings to default values.
Definition WallPaperEngine.cpp:92
void imagelist_changed(const QStringList &l)
Signal emitted when the wallpaper image list changes.
void process_resize(DesktopMainWindow *window)
Handles resizing events, adjusting wallpaper display accordingly.
Definition WallPaperEngine.cpp:31
void set_animation_duration_second(int secs)
Sets the animation duration in seconds.
Definition WallPaperEngine.cpp:74
void wallpaperChanged(const QPixmap &pixmap)
Signal emitted when the wallpaper pixmap changes.
void set_animation_speed(int msspeed)
Sets the animation speed duration in milliseconds.
Definition WallPaperEngine.h:119
void set_switch_interval(int new_interval)
Sets the interval between wallpaper switches.
Definition WallPaperEngine.cpp:37
void set_image_list(const QStringList &l)
Sets the list of wallpaper image file paths.
Definition WallPaperEngine.cpp:86
SwitchingMode current_mode() const
Gets the current switching mode.
Definition WallPaperEngine.h:143
struct WallPaperEngine::ModeMapping modeMappings
mode mappings for the string <=> mode transfer
void set_easingcurve(const QEasingCurve curveType)
set_easingcurve
Definition WallPaperEngine.cpp:103
SwitchingMode
Enum for wallpaper switching modes.
Definition WallPaperEngine.h:27
@ Fixed
Fixed wallpaper without switching.
@ Movement
Wallpaper switches with movement animation.
@ Gradient
Wallpaper switches with gradient effect.
QPixmap get_current_pixmap() const
Retrieves the currently displayed wallpaper pixmap.
Definition WallPaperEngine.cpp:60
int duration_seconds() const
Gets the animation duration in seconds.
Definition WallPaperEngine.cpp:78
WallPaperEngine()=delete
Deleted default constructor.
void set_showing_pictures(const QPixmap &map)
Sets the pixmap currently showing as wallpaper.
Definition WallPaperEngine.cpp:69
void set_mode(const SwitchingMode mode)
Sets the wallpaper switching mode.
Definition WallPaperEngine.cpp:45
QStringList & get_image_list()
Returns a reference to the wallpaper image file path list.
Definition WallPaperEngine.cpp:82
The WallPaperAnimationHandler class is the animation holder for the wallpaper, it is used to animate ...
Definition wallpaperanimationhandler.h:15
Helper struct for mapping between mode names and enum values.
Definition WallPaperEngine.h:36
QStringList values() const
Returns all mode names as a QStringList.
Definition WallPaperEngine.h:50
QString toString(const WallPaperEngine::SwitchingMode mode)
Converts a SwitchingMode enum to its string representation.
Definition WallPaperEngine.h:59
WallPaperEngine::SwitchingMode fromString(const QString &l)
Converts a string name to the corresponding SwitchingMode enum.
Definition WallPaperEngine.h:69
const QMap< QString, WallPaperEngine::SwitchingMode > mappings
Mapping from string names to SwitchingMode values.
Definition WallPaperEngine.h:40