CCIMXDesktop
 
Loading...
Searching...
No Matches
SideBarWidget.h
1#ifndef SIDEBARWIDGET_H
2#define SIDEBARWIDGET_H
3
4#include <QEasingCurve>
5#include <QWidget>
6
7class QPropertyAnimation;
8class QParallelAnimationGroup;
9
13static constexpr const bool INIT_STATE = false;
14static constexpr const int ANIMATION_DURATION = 500;
15static constexpr const QEasingCurve::Type ANIMATION_CURVE = QEasingCurve::InOutQuad;
16}; // namespace SideBarWidgetStaticConfig
17
18namespace Ui {
19class SideBarWidget;
20}
21
24class SideBarWidget : public QWidget {
25 Q_OBJECT
26
27public:
30 explicit SideBarWidget(QWidget* parent = nullptr);
31
34
36 void inline showSideBar() {
37 setState(false);
38 }
39
41 void inline hideSideBar() {
42 setState(true);
43 }
44
46 enum class Role { SideBar,
47 MainSide };
48
52 void addLayout(const QWidgetList& widgetList, Role r);
53
57
60 void setAnimationDuration(int duration);
61
64 void setAnimationCurve(QEasingCurve::Type curve);
65
68 inline bool current_ui_states() { return hidden_state; }
69
70public slots:
73
74protected:
78 void resizeEvent(QResizeEvent*);
79
80private:
81 QPropertyAnimation* animation_main;
82 QPropertyAnimation* animation_side;
83 QParallelAnimationGroup* group;
84
87 void inline setState(bool st) {
88 hidden_state = st;
89 hidden_state ? do_hide_animations() : do_show_animations();
90 }
91
93 void __initMemory();
94
96 void __initConnection();
97
99 void do_hide_animations();
100
102 void do_show_animations();
103
104 bool hidden_state { SideBarWidgetStaticConfig::INIT_STATE };
105 Ui::SideBarWidget* ui;
106};
107
108#endif // SIDEBARWIDGET_H
A custom widget that implements a slide-in/slide-out sidebar with animation.
Definition SideBarWidget.h:24
~SideBarWidget()
Destructor to release resources.
bool current_ui_states()
Returns the current state of sidebar visibility.
Definition SideBarWidget.h:68
void showSideBar()
Shows the sidebar using animation.
Definition SideBarWidget.h:36
SideBarWidget(QWidget *parent=nullptr)
Constructor to initialize the sidebar widget.
void removeLayout(Role r)
Removes all widgets from the specified layout role.
void setAnimationDuration(int duration)
Sets the animation duration.
void setAnimationCurve(QEasingCurve::Type curve)
Sets the easing curve type for the animation.
void addLayout(const QWidgetList &widgetList, Role r)
Adds widgets to either the sidebar or the main side layout.
void hideSideBar()
Hides the sidebar using animation.
Definition SideBarWidget.h:41
void resizeEvent(QResizeEvent *)
resizeEvent
Role
Defines which layout role to apply widgets to.
Definition SideBarWidget.h:46
void switch_state()
Toggles the sidebar state between visible and hidden.
Contains default configuration constants for SideBarWidget animations.