├── Images ├── checkBox_checked.png ├── checkBox_uncheck.png ├── radioBtn_deselect.png └── radioBtn_selected.png ├── README.md ├── components.pro ├── components.pro.user ├── components ├── layouts │ ├── qtmaterialsnackbarlayout.cpp │ ├── qtmaterialsnackbarlayout.h │ └── qtmaterialsnackbarlayout_p.h ├── lib │ ├── qtmaterialcheckable.cpp │ ├── qtmaterialcheckable.h │ ├── qtmaterialcheckable_internal.cpp │ ├── qtmaterialcheckable_internal.h │ ├── qtmaterialcheckable_p.h │ ├── qtmaterialhoverstatemachine.cpp │ ├── qtmaterialhoverstatemachine.h │ ├── qtmaterialoverlaywidget.cpp │ ├── qtmaterialoverlaywidget.h │ ├── qtmaterialripple.cpp │ ├── qtmaterialripple.h │ ├── qtmaterialrippleoverlay.cpp │ ├── qtmaterialrippleoverlay.h │ ├── qtmaterialstatetransition.cpp │ ├── qtmaterialstatetransition.h │ ├── qtmaterialstatetransitionevent.h │ ├── qtmaterialstyle.cpp │ ├── qtmaterialstyle.h │ ├── qtmaterialstyle_p.h │ ├── qtmaterialtheme.cpp │ ├── qtmaterialtheme.h │ ├── qtmaterialtheme_p.h │ ├── soroushthemeextention.cpp │ └── soroushthemeextention.h ├── qtmaterialappbar.cpp ├── qtmaterialappbar.h ├── qtmaterialappbar_p.h ├── qtmaterialautocomplete.cpp ├── qtmaterialautocomplete.h ├── qtmaterialautocomplete_internal.cpp ├── qtmaterialautocomplete_internal.h ├── qtmaterialautocomplete_p.h ├── qtmaterialavatar.cpp ├── qtmaterialavatar.h ├── qtmaterialavatar_p.h ├── qtmaterialbadge.cpp ├── qtmaterialbadge.h ├── qtmaterialbadge_p.h ├── qtmaterialcheckbox.cpp ├── qtmaterialcheckbox.h ├── qtmaterialcheckbox_p.h ├── qtmaterialcircularprogress.cpp ├── qtmaterialcircularprogress.h ├── qtmaterialcircularprogress_internal.cpp ├── qtmaterialcircularprogress_internal.h ├── qtmaterialcircularprogress_p.h ├── qtmaterialdialog.cpp ├── qtmaterialdialog.h ├── qtmaterialdialog_internal.cpp ├── qtmaterialdialog_internal.h ├── qtmaterialdialog_p.h ├── qtmaterialdrawer.cpp ├── qtmaterialdrawer.h ├── qtmaterialdrawer_internal.cpp ├── qtmaterialdrawer_internal.h ├── qtmaterialdrawer_p.h ├── qtmaterialfab.cpp ├── qtmaterialfab.h ├── qtmaterialfab_p.h ├── qtmaterialflatbutton.cpp ├── qtmaterialflatbutton.h ├── qtmaterialflatbutton_internal.cpp ├── qtmaterialflatbutton_internal.h ├── qtmaterialflatbutton_p.h ├── qtmaterialiconbutton.cpp ├── qtmaterialiconbutton.h ├── qtmaterialiconbutton_internal.cpp ├── qtmaterialiconbutton_internal.h ├── qtmaterialiconbutton_p.h ├── qtmateriallist.cpp ├── qtmateriallist.h ├── qtmateriallist_p.h ├── qtmateriallistitem.cpp ├── qtmateriallistitem.h ├── qtmateriallistitem_p.h ├── qtmaterialmenu.cpp ├── qtmaterialmenu.h ├── qtmaterialmenu_internal.cpp ├── qtmaterialmenu_internal.h ├── qtmaterialmenu_p.h ├── qtmaterialpaper.cpp ├── qtmaterialpaper.h ├── qtmaterialpaper_p.h ├── qtmaterialprogress.cpp ├── qtmaterialprogress.h ├── qtmaterialprogress_internal.cpp ├── qtmaterialprogress_internal.h ├── qtmaterialprogress_p.h ├── qtmaterialradiobutton.cpp ├── qtmaterialradiobutton.h ├── qtmaterialradiobutton_p.h ├── qtmaterialraisedbutton.cpp ├── qtmaterialraisedbutton.h ├── qtmaterialraisedbutton_p.h ├── qtmaterialscrollbar.cpp ├── qtmaterialscrollbar.h ├── qtmaterialscrollbar_internal.cpp ├── qtmaterialscrollbar_internal.h ├── qtmaterialscrollbar_p.h ├── qtmaterialslider.cpp ├── qtmaterialslider.h ├── qtmaterialslider_internal.cpp ├── qtmaterialslider_internal.h ├── qtmaterialslider_p.h ├── qtmaterialsnackbar.cpp ├── qtmaterialsnackbar.h ├── qtmaterialsnackbar_internal.cpp ├── qtmaterialsnackbar_internal.h ├── qtmaterialsnackbar_p.h ├── qtmaterialtable.cpp ├── qtmaterialtable.h ├── qtmaterialtable_p.h ├── qtmaterialtabs.cpp ├── qtmaterialtabs.h ├── qtmaterialtabs_internal.cpp ├── qtmaterialtabs_internal.h ├── qtmaterialtabs_p.h ├── qtmaterialtextfield.cpp ├── qtmaterialtextfield.h ├── qtmaterialtextfield_internal.cpp ├── qtmaterialtextfield_internal.h ├── qtmaterialtextfield_p.h ├── qtmaterialtoggle.cpp ├── qtmaterialtoggle.h ├── qtmaterialtoggle_internal.cpp ├── qtmaterialtoggle_internal.h └── qtmaterialtoggle_p.h └── resources.qrc /Images/checkBox_checked.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/miangoleh/QtMaterial/8ceb913a9eee9cb0f40b00348c7b9423e37e4cb2/Images/checkBox_checked.png -------------------------------------------------------------------------------- /Images/checkBox_uncheck.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/miangoleh/QtMaterial/8ceb913a9eee9cb0f40b00348c7b9423e37e4cb2/Images/checkBox_uncheck.png -------------------------------------------------------------------------------- /Images/radioBtn_deselect.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/miangoleh/QtMaterial/8ceb913a9eee9cb0f40b00348c7b9423e37e4cb2/Images/radioBtn_deselect.png -------------------------------------------------------------------------------- /Images/radioBtn_selected.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/miangoleh/QtMaterial/8ceb913a9eee9cb0f40b00348c7b9423e37e4cb2/Images/radioBtn_selected.png -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## Functionalities 2 | 3 | I have added several functionalities to enhance the user experience and make the UI more interactive. Here are the key additions: 4 | 5 | - **IconButtons:** Added support for setting the icon size and implemented a hover option for better visual feedback. 6 | - **CheckButtons and RadioButtons:** Introduced right-to-left (RTL) language support for improved usability. 7 | - **ToggleButtons:** Implemented the ability to set a custom background color. 8 | - **FlatButton:** Added the functionality to set content margins. 9 | - **Theme Enhancements:** Introduced extra theme Role enums to provide more options for customization. 10 | 11 | ## UI/UX Improvements 12 | 13 | In addition to the added functionalities, I have also made several UI/UX improvements to enhance the overall user experience. These improvements include: 14 | 15 | - **Hover Features for Icons:** Implemented hover effects for icons to provide better visual cues and feedback. 16 | - **Improved Animation Support:** Created a new class called `hoverStateMachine`, which can be utilized in any other class to perform animations on events like mouse enter/leave or show/hide events. 17 | - **Fixes:** Resolved the click issue in IconButton for smoother interaction. 18 | 19 | Feel free to explore the repository and take advantage of these enhancements and improvements in your projects. 20 | -------------------------------------------------------------------------------- /components.pro: -------------------------------------------------------------------------------- 1 | #------------------------------------------------- 2 | # 3 | # Project created by QtCreator 2019-01-22T15:07:57 4 | # 5 | #------------------------------------------------- 6 | TARGET = QtMaterial 7 | TEMPLATE = lib 8 | 9 | CONFIG += c++11 10 | CONFIG += staticlib 11 | 12 | SOURCES += \ 13 | components/qtmaterialavatar.cpp \ 14 | components/lib/qtmaterialstyle.cpp \ 15 | components/lib/qtmaterialtheme.cpp \ 16 | components/qtmaterialbadge.cpp \ 17 | components/lib/qtmaterialoverlaywidget.cpp \ 18 | components/qtmaterialcheckbox.cpp \ 19 | components/lib/qtmaterialcheckable_internal.cpp \ 20 | components/lib/qtmaterialcheckable.cpp \ 21 | components/lib/qtmaterialripple.cpp \ 22 | components/lib/qtmaterialrippleoverlay.cpp \ 23 | components/qtmaterialfab.cpp \ 24 | components/qtmaterialraisedbutton.cpp \ 25 | components/qtmaterialflatbutton_internal.cpp \ 26 | components/qtmaterialflatbutton.cpp \ 27 | components/lib/qtmaterialstatetransition.cpp \ 28 | components/qtmaterialiconbutton.cpp \ 29 | components/qtmaterialprogress_internal.cpp \ 30 | components/qtmaterialprogress.cpp \ 31 | components/qtmaterialcircularprogress_internal.cpp \ 32 | components/qtmaterialcircularprogress.cpp \ 33 | components/qtmaterialslider_internal.cpp \ 34 | components/qtmaterialslider.cpp \ 35 | components/qtmaterialsnackbar_internal.cpp \ 36 | components/qtmaterialsnackbar.cpp \ 37 | components/qtmaterialradiobutton.cpp \ 38 | components/qtmaterialtoggle_internal.cpp \ 39 | components/qtmaterialtoggle.cpp \ 40 | components/qtmaterialtextfield_internal.cpp \ 41 | components/qtmaterialtextfield.cpp \ 42 | components/qtmaterialtabs_internal.cpp \ 43 | components/qtmaterialtabs.cpp \ 44 | components/qtmaterialscrollbar_internal.cpp \ 45 | components/qtmaterialscrollbar.cpp \ 46 | components/qtmaterialdialog_internal.cpp \ 47 | components/qtmaterialdialog.cpp \ 48 | components/qtmaterialdrawer_internal.cpp \ 49 | components/qtmaterialdrawer.cpp \ 50 | components/qtmaterialappbar.cpp \ 51 | components/qtmaterialautocomplete.cpp \ 52 | components/qtmaterialpaper.cpp \ 53 | components/qtmaterialtable.cpp \ 54 | components/layouts/qtmaterialsnackbarlayout.cpp \ 55 | components/qtmaterialautocomplete_internal.cpp \ 56 | components/qtmaterialmenu.cpp \ 57 | components/qtmaterialmenu_internal.cpp \ 58 | components/qtmateriallist.cpp \ 59 | components/qtmateriallistitem.cpp \ 60 | components/qtmaterialiconbutton_internal.cpp \ 61 | components/lib/qtmaterialhoverstatemachine.cpp 62 | 63 | 64 | HEADERS += \ 65 | components/qtmaterialavatar_p.h \ 66 | components/qtmaterialavatar.h \ 67 | components/lib/qtmaterialstyle_p.h \ 68 | components/lib/qtmaterialstyle.h \ 69 | components/lib/qtmaterialtheme_p.h \ 70 | components/lib/qtmaterialtheme.h \ 71 | components/qtmaterialbadge_p.h \ 72 | components/qtmaterialbadge.h \ 73 | components/lib/qtmaterialoverlaywidget.h \ 74 | components/qtmaterialcheckbox_p.h \ 75 | components/qtmaterialcheckbox.h \ 76 | components/lib/qtmaterialcheckable_internal.h \ 77 | components/lib/qtmaterialcheckable_p.h \ 78 | components/lib/qtmaterialripple.h \ 79 | components/lib/qtmaterialrippleoverlay.h \ 80 | components/lib/qtmaterialcheckable.h \ 81 | components/qtmaterialfab_p.h \ 82 | components/qtmaterialfab.h \ 83 | components/qtmaterialraisedbutton_p.h \ 84 | components/qtmaterialraisedbutton.h \ 85 | components/qtmaterialflatbutton_internal.h \ 86 | components/qtmaterialflatbutton_p.h \ 87 | components/qtmaterialflatbutton.h \ 88 | components/lib/qtmaterialstatetransition.h \ 89 | components/lib/qtmaterialstatetransitionevent.h \ 90 | components/qtmaterialiconbutton_p.h \ 91 | components/qtmaterialiconbutton.h \ 92 | components/qtmaterialprogress_internal.h \ 93 | components/qtmaterialprogress_p.h \ 94 | components/qtmaterialprogress.h \ 95 | components/qtmaterialcircularprogress_internal.h \ 96 | components/qtmaterialcircularprogress_p.h \ 97 | components/qtmaterialcircularprogress.h \ 98 | components/qtmaterialslider_internal.h \ 99 | components/qtmaterialslider_p.h \ 100 | components/qtmaterialslider.h \ 101 | components/qtmaterialsnackbar_internal.h \ 102 | components/qtmaterialsnackbar_p.h \ 103 | components/qtmaterialsnackbar.h \ 104 | components/qtmaterialradiobutton_p.h \ 105 | components/qtmaterialradiobutton.h \ 106 | components/qtmaterialtoggle_internal.h \ 107 | components/qtmaterialtoggle_p.h \ 108 | components/qtmaterialtoggle.h \ 109 | components/qtmaterialtextfield_internal.h \ 110 | components/qtmaterialtextfield_p.h \ 111 | components/qtmaterialtextfield.h \ 112 | components/qtmaterialtabs_internal.h \ 113 | components/qtmaterialtabs_p.h \ 114 | components/qtmaterialtabs.h \ 115 | components/qtmaterialscrollbar_internal.h \ 116 | components/qtmaterialscrollbar_p.h \ 117 | components/qtmaterialscrollbar.h \ 118 | components/qtmaterialdialog_internal.h \ 119 | components/qtmaterialdialog_p.h \ 120 | components/qtmaterialdialog.h \ 121 | components/qtmaterialdrawer_internal.h \ 122 | components/qtmaterialdrawer_p.h \ 123 | components/qtmaterialdrawer.h \ 124 | components/qtmaterialappbar.h \ 125 | components/qtmaterialappbar_p.h \ 126 | components/qtmaterialautocomplete.h \ 127 | components/qtmaterialautocomplete_p.h \ 128 | components/qtmaterialpaper.h \ 129 | components/qtmaterialpaper_p.h \ 130 | components/qtmaterialtable.h \ 131 | components/qtmaterialtable_p.h \ 132 | components/layouts/qtmaterialsnackbarlayout.h \ 133 | components/layouts/qtmaterialsnackbarlayout_p.h \ 134 | components/qtmaterialautocomplete_internal.h \ 135 | components/qtmaterialmenu.h \ 136 | components/qtmaterialmenu_p.h \ 137 | components/qtmaterialmenu_internal.h \ 138 | components/qtmateriallist.h \ 139 | components/qtmateriallist_p.h \ 140 | components/qtmateriallistitem.h \ 141 | components/qtmateriallistitem_p.h \ 142 | components/qtmaterialiconbutton_internal.h \ 143 | components/lib/qtmaterialhoverstatemachine.h 144 | 145 | RESOURCES += \ 146 | resources.qrc 147 | 148 | DISTFILES += 149 | 150 | 151 | 152 | -------------------------------------------------------------------------------- /components/layouts/qtmaterialsnackbarlayout.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/miangoleh/QtMaterial/8ceb913a9eee9cb0f40b00348c7b9423e37e4cb2/components/layouts/qtmaterialsnackbarlayout.cpp -------------------------------------------------------------------------------- /components/layouts/qtmaterialsnackbarlayout.h: -------------------------------------------------------------------------------- 1 | #ifndef QTMATERIALSNACKBARLAYOUT_H 2 | #define QTMATERIALSNACKBARLAYOUT_H 3 | 4 | #endif // QTMATERIALSNACKBARLAYOUT_H 5 | -------------------------------------------------------------------------------- /components/layouts/qtmaterialsnackbarlayout_p.h: -------------------------------------------------------------------------------- 1 | #ifndef QTMATERIALSNACKBARLAYOUT_P_H 2 | #define QTMATERIALSNACKBARLAYOUT_P_H 3 | 4 | #endif // QTMATERIALSNACKBARLAYOUT_P_H 5 | -------------------------------------------------------------------------------- /components/lib/qtmaterialcheckable.h: -------------------------------------------------------------------------------- 1 | #ifndef QTMATERIALCHECKABLE_H 2 | #define QTMATERIALCHECKABLE_H 3 | 4 | #include 5 | #include 6 | 7 | class QtMaterialCheckablePrivate; 8 | 9 | class QtMaterialCheckable : public QAbstractButton 10 | { 11 | Q_OBJECT 12 | 13 | public: 14 | enum LabelPosition { 15 | LabelPositionLeft, 16 | LabelPositionRight, 17 | }; 18 | 19 | explicit QtMaterialCheckable(QWidget *parent = 0); 20 | ~QtMaterialCheckable(); 21 | 22 | void setLabelPosition(LabelPosition placement); 23 | LabelPosition labelPosition() const; 24 | 25 | void setUseThemeColors(bool value); 26 | bool useThemeColors() const; 27 | 28 | void setCheckedColor(const QColor &color); 29 | QColor checkedColor() const; 30 | 31 | void setUncheckedColor(const QColor &color); 32 | QColor uncheckedColor() const; 33 | 34 | void setTextColor(const QColor &color); 35 | QColor textColor() const; 36 | 37 | void setDisabledColor(const QColor &color); 38 | QColor disabledColor() const; 39 | 40 | void setCheckedIcon(const QIcon &icon); 41 | QIcon checkedIcon() const; 42 | 43 | void setUncheckedIcon(const QIcon &icon); 44 | QIcon uncheckedIcon() const; 45 | 46 | void setIconSize(const qreal &size); 47 | qreal iconSize() const; 48 | 49 | void setSpacing(const int &spacing); 50 | int spacing() const; 51 | 52 | QSize sizeHint() const Q_DECL_OVERRIDE; 53 | 54 | protected: 55 | QtMaterialCheckable(QtMaterialCheckablePrivate &d, QWidget *parent = 0); 56 | 57 | bool event(QEvent *event) Q_DECL_OVERRIDE; 58 | bool eventFilter(QObject *obj, QEvent *event) Q_DECL_OVERRIDE; 59 | void mousePressEvent(QMouseEvent *event) Q_DECL_OVERRIDE; 60 | void paintEvent(QPaintEvent *event) Q_DECL_OVERRIDE; 61 | 62 | virtual void setupProperties(); 63 | 64 | 65 | const QScopedPointer d_ptr; 66 | signals: 67 | void mousepressed(); 68 | private: 69 | Q_DISABLE_COPY(QtMaterialCheckable) 70 | Q_DECLARE_PRIVATE(QtMaterialCheckable) 71 | }; 72 | 73 | #endif // QTMATERIALCHECKABLE_H 74 | -------------------------------------------------------------------------------- /components/lib/qtmaterialcheckable_internal.cpp: -------------------------------------------------------------------------------- 1 | #include "components/lib/qtmaterialcheckable_internal.h" 2 | #include 3 | #include 4 | #include 5 | #include "components/lib/qtmaterialcheckable.h" 6 | 7 | /*! 8 | * \class QtMaterialCheckableIcon 9 | * \internal 10 | */ 11 | 12 | QtMaterialCheckableIcon::QtMaterialCheckableIcon(const QIcon &icon, QtMaterialCheckable *parent) 13 | : QWidget(parent), 14 | m_checkable(parent), 15 | m_color(Qt::black), 16 | m_icon(icon), 17 | m_iconSize(24), 18 | m_opacity(1.0) 19 | { 20 | Q_ASSERT(parent); 21 | 22 | setAttribute(Qt::WA_TransparentForMouseEvents); 23 | } 24 | 25 | QtMaterialCheckableIcon::~QtMaterialCheckableIcon() 26 | { 27 | } 28 | 29 | QSize QtMaterialCheckableIcon::sizeHint() const 30 | { 31 | return QSize(m_iconSize, m_iconSize); 32 | } 33 | 34 | void QtMaterialCheckableIcon::paintEvent(QPaintEvent *event) 35 | { 36 | Q_UNUSED(event) 37 | 38 | QPainter painter(this); 39 | painter.setRenderHint(QPainter::Antialiasing); 40 | painter.setOpacity(m_opacity); 41 | 42 | int pixmapSize; 43 | if(m_iconSize == icon().pixmap(m_iconSize,m_iconSize).width()) 44 | pixmapSize = m_iconSize; 45 | else 46 | pixmapSize = 24; 47 | QPixmap pixmap = icon().pixmap(pixmapSize, pixmapSize); 48 | 49 | if (!pixmap.isNull()) 50 | { 51 | const qreal p = static_cast((height())-m_iconSize)/2; 52 | const qreal z = m_iconSize/pixmapSize; 53 | 54 | QTransform t; 55 | if (QtMaterialCheckable::LabelPositionLeft == m_checkable->labelPosition()) { 56 | t.translate(p+ width() - (m_checkable->iconSize()), p); 57 | } else { 58 | t.translate(p, p); 59 | } 60 | t.scale(z, z); 61 | painter.setTransform(t); 62 | 63 | QPainter icon(&pixmap); 64 | icon.setCompositionMode(QPainter::CompositionMode_SourceIn); 65 | icon.fillRect(pixmap.rect(), color()); 66 | painter.drawPixmap(0, 0, pixmap); 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /components/lib/qtmaterialcheckable_internal.h: -------------------------------------------------------------------------------- 1 | #ifndef QTMATERIALCHECKABLE_INTERNAL_H 2 | #define QTMATERIALCHECKABLE_INTERNAL_H 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | class QtMaterialCheckable; 9 | 10 | class QtMaterialCheckableIcon : public QWidget 11 | { 12 | Q_OBJECT 13 | 14 | Q_PROPERTY(QColor color READ color WRITE setColor) 15 | Q_PROPERTY(qreal iconSize READ iconSize WRITE setIconSize) 16 | Q_PROPERTY(qreal opacity READ opacity WRITE setOpacity) 17 | 18 | public: 19 | QtMaterialCheckableIcon(const QIcon &icon, QtMaterialCheckable *parent); 20 | ~QtMaterialCheckableIcon(); 21 | 22 | QSize sizeHint() const Q_DECL_OVERRIDE; 23 | 24 | inline void setIcon(const QIcon &icon); 25 | inline QIcon icon() const; 26 | 27 | inline void setColor(const QColor &color); 28 | inline QColor color() const; 29 | 30 | inline void setIconSize(qreal size); 31 | inline qreal iconSize() const; 32 | 33 | inline void setOpacity(qreal opacity); 34 | inline qreal opacity() const; 35 | 36 | protected: 37 | void paintEvent(QPaintEvent *event) Q_DECL_OVERRIDE; 38 | 39 | private: 40 | Q_DISABLE_COPY(QtMaterialCheckableIcon) 41 | 42 | QtMaterialCheckable *const m_checkable; 43 | QColor m_color; 44 | QIcon m_icon; 45 | qreal m_iconSize; 46 | qreal m_opacity; 47 | }; 48 | 49 | inline void QtMaterialCheckableIcon::setIcon(const QIcon &icon) 50 | { 51 | m_icon = icon; 52 | update(); 53 | } 54 | 55 | inline QIcon QtMaterialCheckableIcon::icon() const 56 | { 57 | return m_icon; 58 | } 59 | 60 | inline void QtMaterialCheckableIcon::setColor(const QColor &color) 61 | { 62 | m_color = color; 63 | update(); 64 | } 65 | 66 | inline QColor QtMaterialCheckableIcon::color() const 67 | { 68 | return m_color; 69 | } 70 | 71 | inline void QtMaterialCheckableIcon::setIconSize(qreal size) 72 | { 73 | m_iconSize = size; 74 | update(); 75 | } 76 | 77 | inline qreal QtMaterialCheckableIcon::iconSize() const 78 | { 79 | return m_iconSize; 80 | } 81 | 82 | inline void QtMaterialCheckableIcon::setOpacity(qreal opacity) 83 | { 84 | m_opacity = opacity; 85 | update(); 86 | } 87 | 88 | inline qreal QtMaterialCheckableIcon::opacity() const 89 | { 90 | return m_opacity; 91 | } 92 | 93 | #endif // QTMATERIALCHECKABLE_INTERNAL_H 94 | -------------------------------------------------------------------------------- /components/lib/qtmaterialcheckable_p.h: -------------------------------------------------------------------------------- 1 | #ifndef QTMATERIALCHECKABLE_P_H 2 | #define QTMATERIALCHECKABLE_P_H 3 | 4 | #include 5 | #include "components/lib/qtmaterialcheckable.h" 6 | 7 | class QStateMachine; 8 | class QState; 9 | class QSignalTransition; 10 | class QtMaterialRippleOverlay; 11 | class QtMaterialCheckableIcon; 12 | 13 | class QtMaterialCheckablePrivate 14 | { 15 | Q_DISABLE_COPY(QtMaterialCheckablePrivate) 16 | Q_DECLARE_PUBLIC(QtMaterialCheckable) 17 | 18 | public: 19 | QtMaterialCheckablePrivate(QtMaterialCheckable *q); 20 | virtual ~QtMaterialCheckablePrivate(); 21 | 22 | void init(); 23 | 24 | QtMaterialCheckable *const q_ptr; 25 | QtMaterialRippleOverlay *rippleOverlay; 26 | QtMaterialCheckableIcon *checkedIcon; 27 | QtMaterialCheckableIcon *uncheckedIcon; 28 | QStateMachine *stateMachine; 29 | QState *uncheckedState; 30 | QState *checkedState; 31 | QState *disabledUncheckedState; 32 | QState *disabledCheckedState; 33 | QSignalTransition *uncheckedTransition; 34 | QSignalTransition *checkedTransition; 35 | QtMaterialCheckable::LabelPosition labelPosition; 36 | QColor checkedColor; 37 | QColor uncheckedColor; 38 | QColor textColor; 39 | QColor disabledColor; 40 | bool useThemeColors; 41 | qreal iconSize; 42 | int spacing; 43 | }; 44 | 45 | #endif // QTMATERIALCHECKABLE_P_H 46 | -------------------------------------------------------------------------------- /components/lib/qtmaterialhoverstatemachine.cpp: -------------------------------------------------------------------------------- 1 | #include "qtmaterialhoverstatemachine.h" 2 | 3 | QtMaterialHoverStateMachine::QtMaterialHoverStateMachine(QWidget *widget, Material::hoverActiveState state, int animationDutation) 4 | : QStateMachine (widget), 5 | b_widget(widget), 6 | m_hoveredState(new QState(ExclusiveStates)), 7 | m_neutralState(new QState(ExclusiveStates)), 8 | m_overlayOpacity(0), 9 | m_baseOpacity(0.2), 10 | m_animationDuration(animationDutation) 11 | { 12 | Q_ASSERT(widget); 13 | 14 | widget->installEventFilter(this); 15 | 16 | addState(m_neutralState); 17 | addState(m_hoveredState); 18 | setInitialState(m_neutralState); 19 | 20 | if(state == Material::EnterLeave) 21 | { 22 | addTransition(b_widget, QEvent::Enter, m_neutralState, m_hoveredState); 23 | addTransition(b_widget, QEvent::Leave, m_hoveredState, m_neutralState); 24 | } 25 | else if(state == Material::HideShow) 26 | { 27 | addTransition(b_widget, QEvent::Show, m_neutralState, m_hoveredState); 28 | addTransition(b_widget, QEvent::Hide, m_hoveredState, m_neutralState); 29 | } 30 | } 31 | QtMaterialHoverStateMachine::~QtMaterialHoverStateMachine() 32 | { 33 | 34 | } 35 | 36 | void QtMaterialHoverStateMachine::setOverlayOpacity(qreal opacity) 37 | { 38 | m_overlayOpacity = opacity; 39 | b_widget->update(); 40 | } 41 | 42 | void QtMaterialHoverStateMachine::setBaseOpacity(const qreal baseopacity) 43 | { 44 | m_baseOpacity = baseopacity; 45 | setupProperties(); 46 | } 47 | 48 | qreal QtMaterialHoverStateMachine::baseOpacity() const 49 | { 50 | return m_baseOpacity; 51 | } 52 | 53 | void QtMaterialHoverStateMachine::setNeutral2HoverTransition(QObject *object, QEvent::Type eventType) 54 | { 55 | addTransition(object, eventType, m_neutralState, m_hoveredState); 56 | } 57 | 58 | void QtMaterialHoverStateMachine::setHover2NeutralTransition(QObject *object, QEvent::Type eventType) 59 | { 60 | addTransition(object, eventType, m_hoveredState, m_neutralState); 61 | } 62 | 63 | void QtMaterialHoverStateMachine::addTransition(QObject *object, 64 | QEvent::Type eventType, 65 | QState *fromState, 66 | QState *toState) 67 | { 68 | addTransition(new QEventTransition(object, eventType), fromState, toState); 69 | } 70 | 71 | void QtMaterialHoverStateMachine::addTransition(QAbstractTransition *transition, 72 | QState *fromState, 73 | QState *toState) 74 | { 75 | transition->setTargetState(toState); 76 | 77 | QPropertyAnimation *animation; 78 | 79 | animation = new QPropertyAnimation(this, "overlayOpacity", this); 80 | animation->setDuration(m_animationDuration); 81 | transition->addAnimation(animation); 82 | 83 | fromState->addTransition(transition); 84 | } 85 | 86 | void QtMaterialHoverStateMachine::setupProperties() 87 | { 88 | m_neutralState->assignProperty(this, "overlayOpacity", 0); 89 | m_hoveredState->assignProperty(this, "overlayOpacity", m_baseOpacity); 90 | 91 | b_widget->update(); 92 | } 93 | -------------------------------------------------------------------------------- /components/lib/qtmaterialhoverstatemachine.h: -------------------------------------------------------------------------------- 1 | #ifndef QTMATERIALHOVERSTATEMACHINE_H 2 | #define QTMATERIALHOVERSTATEMACHINE_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include "components/lib/qtmaterialtheme.h" 8 | 9 | 10 | class QtMaterialHoverStateMachine : public QStateMachine 11 | { 12 | Q_OBJECT 13 | 14 | Q_PROPERTY(qreal overlayOpacity WRITE setOverlayOpacity READ overlayOpacity) 15 | 16 | public: 17 | explicit QtMaterialHoverStateMachine(QWidget *widget,Material::hoverActiveState state = Material::EnterLeave,int animationDutation = 150); 18 | ~QtMaterialHoverStateMachine(); 19 | 20 | void setOverlayOpacity(qreal opacity); 21 | inline qreal overlayOpacity() const; 22 | 23 | void setBaseOpacity(const qreal baseopacity); 24 | qreal baseOpacity() const; 25 | 26 | void setNeutral2HoverTransition(QObject *object, QEvent::Type eventType); 27 | void setHover2NeutralTransition(QObject *object, QEvent::Type eventType); 28 | 29 | void setupProperties(); 30 | 31 | int getAnimationDuration() const; 32 | 33 | private: 34 | Q_DISABLE_COPY(QtMaterialHoverStateMachine) 35 | 36 | void addTransition(QObject *object, QEvent::Type eventType, QState *fromState, QState *toState); 37 | void addTransition(QAbstractTransition *transition, QState *fromState, QState *toState); 38 | 39 | QWidget *const b_widget; 40 | QState *const m_hoveredState; 41 | QState *const m_neutralState; 42 | qreal m_overlayOpacity; 43 | qreal m_baseOpacity; 44 | int m_animationDuration; 45 | }; 46 | 47 | inline qreal QtMaterialHoverStateMachine::overlayOpacity() const 48 | { 49 | return m_overlayOpacity; 50 | } 51 | 52 | #endif // QTMATERIALHOVERSTATEMACHINE_H 53 | -------------------------------------------------------------------------------- /components/lib/qtmaterialoverlaywidget.cpp: -------------------------------------------------------------------------------- 1 | #include "components/lib/qtmaterialoverlaywidget.h" 2 | #include 3 | 4 | /*! 5 | * \class QtMaterialOverlayWidget 6 | * \internal 7 | */ 8 | 9 | QtMaterialOverlayWidget::QtMaterialOverlayWidget(QWidget *parent) 10 | : QWidget(parent) 11 | { 12 | if (parent) { 13 | parent->installEventFilter(this); 14 | } 15 | } 16 | 17 | QtMaterialOverlayWidget::~QtMaterialOverlayWidget() 18 | { 19 | } 20 | 21 | /*! 22 | * \reimp 23 | */ 24 | bool QtMaterialOverlayWidget::event(QEvent *event) 25 | { 26 | if (!parent()) { 27 | return QWidget::event(event); 28 | } 29 | switch (event->type()) 30 | { 31 | case QEvent::ParentChange: 32 | { 33 | parent()->installEventFilter(this); 34 | setGeometry(overlayGeometry()); 35 | break; 36 | } 37 | case QEvent::ParentAboutToChange: 38 | { 39 | parent()->removeEventFilter(this); 40 | break; 41 | } 42 | default: 43 | break; 44 | } 45 | return QWidget::event(event); 46 | } 47 | 48 | /*! 49 | * \reimp 50 | */ 51 | bool QtMaterialOverlayWidget::eventFilter(QObject *obj, QEvent *event) 52 | { 53 | switch (event->type()) 54 | { 55 | case QEvent::Move: 56 | case QEvent::Resize: 57 | setGeometry(overlayGeometry()); 58 | break; 59 | default: 60 | break; 61 | } 62 | return QWidget::eventFilter(obj, event); 63 | } 64 | 65 | QRect QtMaterialOverlayWidget::overlayGeometry() const 66 | { 67 | QWidget *widget = parentWidget(); 68 | if (!widget) { 69 | return QRect(); 70 | } 71 | return widget->rect(); 72 | } 73 | -------------------------------------------------------------------------------- /components/lib/qtmaterialoverlaywidget.h: -------------------------------------------------------------------------------- 1 | #ifndef QTMATERIALOVERLAYWIDGET_H 2 | #define QTMATERIALOVERLAYWIDGET_H 3 | 4 | #include 5 | 6 | class QtMaterialOverlayWidget : public QWidget 7 | { 8 | Q_OBJECT 9 | 10 | public: 11 | explicit QtMaterialOverlayWidget(QWidget *parent = 0); 12 | ~QtMaterialOverlayWidget(); 13 | 14 | protected: 15 | bool event(QEvent *event) Q_DECL_OVERRIDE; 16 | bool eventFilter(QObject *obj, QEvent *event) Q_DECL_OVERRIDE; 17 | 18 | virtual QRect overlayGeometry() const; 19 | 20 | private: 21 | Q_DISABLE_COPY(QtMaterialOverlayWidget) 22 | }; 23 | 24 | #endif // QTMATERIALOVERLAYWIDGET_H 25 | -------------------------------------------------------------------------------- /components/lib/qtmaterialripple.cpp: -------------------------------------------------------------------------------- 1 | #include "qtmaterialripple.h" 2 | #include "components/lib/qtmaterialrippleoverlay.h" 3 | 4 | /*! 5 | * \class QtMaterialRipple 6 | * \internal 7 | */ 8 | 9 | QtMaterialRipple::QtMaterialRipple(const QPoint ¢er, QObject *parent) 10 | : QParallelAnimationGroup(parent), 11 | m_overlay(0), 12 | m_radiusAnimation(animate("radius")), 13 | m_opacityAnimation(animate("opacity")), 14 | m_radius(0), 15 | m_opacity(0), 16 | m_center(center) 17 | { 18 | init(); 19 | } 20 | 21 | QtMaterialRipple::QtMaterialRipple(const QPoint ¢er, 22 | QtMaterialRippleOverlay *overlay, 23 | QObject *parent) 24 | : QParallelAnimationGroup(parent), 25 | m_overlay(overlay), 26 | m_radiusAnimation(animate("radius")), 27 | m_opacityAnimation(animate("opacity")), 28 | m_radius(0), 29 | m_opacity(0), 30 | m_center(center) 31 | { 32 | init(); 33 | } 34 | 35 | QtMaterialRipple::~QtMaterialRipple() 36 | { 37 | } 38 | 39 | void QtMaterialRipple::setRadius(qreal radius) 40 | { 41 | Q_ASSERT(m_overlay); 42 | 43 | if (m_radius == radius) { 44 | return; 45 | } 46 | m_radius = radius; 47 | m_overlay->update(); 48 | } 49 | 50 | void QtMaterialRipple::setOpacity(qreal opacity) 51 | { 52 | Q_ASSERT(m_overlay); 53 | 54 | if (m_opacity == opacity) { 55 | return; 56 | } 57 | m_opacity = opacity; 58 | m_overlay->update(); 59 | } 60 | 61 | void QtMaterialRipple::setColor(const QColor &color) 62 | { 63 | if (m_brush.color() == color) { 64 | return; 65 | } 66 | m_brush.setColor(color); 67 | 68 | if (m_overlay) { 69 | m_overlay->update(); 70 | } 71 | } 72 | 73 | void QtMaterialRipple::setBrush(const QBrush &brush) 74 | { 75 | m_brush = brush; 76 | 77 | if (m_overlay) { 78 | m_overlay->update(); 79 | } 80 | } 81 | 82 | void QtMaterialRipple::destroy() 83 | { 84 | Q_ASSERT(m_overlay); 85 | 86 | m_overlay->removeRipple(this); 87 | } 88 | 89 | /*! 90 | * \internal 91 | */ 92 | QPropertyAnimation *QtMaterialRipple::animate(const QByteArray &property, 93 | const QEasingCurve &easing, 94 | int duration) 95 | { 96 | QPropertyAnimation *animation = new QPropertyAnimation; 97 | animation->setTargetObject(this); 98 | animation->setPropertyName(property); 99 | animation->setEasingCurve(easing); 100 | animation->setDuration(duration); 101 | addAnimation(animation); 102 | return animation; 103 | } 104 | 105 | /*! 106 | * \internal 107 | */ 108 | void QtMaterialRipple::init() 109 | { 110 | setOpacityStartValue(0.5); 111 | setOpacityEndValue(0); 112 | setRadiusStartValue(0); 113 | setRadiusEndValue(300); 114 | 115 | QColor grayColor = QtMaterialStyle::instance().themeColor("hover"); 116 | grayColor.setAlpha(255); 117 | 118 | m_brush.setColor(grayColor); 119 | m_brush.setStyle(Qt::SolidPattern); 120 | 121 | connect(this, SIGNAL(finished()), this, SLOT(destroy())); 122 | } 123 | -------------------------------------------------------------------------------- /components/lib/qtmaterialripple.h: -------------------------------------------------------------------------------- 1 | #ifndef QTMATERIALRIPPLE_H 2 | #define QTMATERIALRIPPLE_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | #include "components/lib/qtmaterialstyle.h" 11 | 12 | class QtMaterialRippleOverlay; 13 | 14 | class QtMaterialRipple : public QParallelAnimationGroup 15 | { 16 | Q_OBJECT 17 | 18 | Q_PROPERTY(qreal radius WRITE setRadius READ radius) 19 | Q_PROPERTY(qreal opacity WRITE setOpacity READ opacity) 20 | 21 | public: 22 | explicit QtMaterialRipple(const QPoint ¢er, QObject *parent = 0); 23 | QtMaterialRipple(const QPoint ¢er, QtMaterialRippleOverlay *overlay, QObject *parent = 0); 24 | ~QtMaterialRipple(); 25 | 26 | inline void setOverlay(QtMaterialRippleOverlay *overlay); 27 | 28 | void setRadius(qreal radius); 29 | inline qreal radius() const; 30 | 31 | void setOpacity(qreal opacity); 32 | inline qreal opacity() const; 33 | 34 | void setColor(const QColor &color); 35 | inline QColor color() const; 36 | 37 | void setBrush(const QBrush &brush); 38 | inline QBrush brush() const; 39 | 40 | inline QPoint center() const; 41 | 42 | inline QPropertyAnimation *radiusAnimation() const; 43 | inline QPropertyAnimation *opacityAnimation() const; 44 | 45 | inline void setOpacityStartValue(qreal value); 46 | inline void setOpacityEndValue(qreal value); 47 | inline void setRadiusStartValue(qreal value); 48 | inline void setRadiusEndValue(qreal value); 49 | inline void setDuration(int msecs); 50 | 51 | protected slots: 52 | void destroy(); 53 | 54 | private: 55 | Q_DISABLE_COPY(QtMaterialRipple) 56 | 57 | QPropertyAnimation *animate(const QByteArray &property, 58 | const QEasingCurve &easing = QEasingCurve::OutQuad, 59 | int duration = 800); 60 | 61 | void init(); 62 | 63 | QtMaterialRippleOverlay *m_overlay; 64 | QPropertyAnimation *const m_radiusAnimation; 65 | QPropertyAnimation *const m_opacityAnimation; 66 | qreal m_radius; 67 | qreal m_opacity; 68 | QPoint m_center; 69 | QBrush m_brush; 70 | }; 71 | 72 | inline void QtMaterialRipple::setOverlay(QtMaterialRippleOverlay *overlay) 73 | { 74 | m_overlay = overlay; 75 | } 76 | 77 | inline qreal QtMaterialRipple::radius() const 78 | { 79 | return m_radius; 80 | } 81 | 82 | inline qreal QtMaterialRipple::opacity() const 83 | { 84 | return m_opacity; 85 | } 86 | 87 | inline QColor QtMaterialRipple::color() const 88 | { 89 | return m_brush.color(); 90 | } 91 | 92 | inline QBrush QtMaterialRipple::brush() const 93 | { 94 | return m_brush; 95 | } 96 | 97 | inline QPoint QtMaterialRipple::center() const 98 | { 99 | return m_center; 100 | } 101 | 102 | inline QPropertyAnimation *QtMaterialRipple::radiusAnimation() const 103 | { 104 | return m_radiusAnimation; 105 | } 106 | 107 | inline QPropertyAnimation *QtMaterialRipple::opacityAnimation() const 108 | { 109 | return m_opacityAnimation; 110 | } 111 | 112 | inline void QtMaterialRipple::setOpacityStartValue(qreal value) 113 | { 114 | m_opacityAnimation->setStartValue(value); 115 | } 116 | 117 | inline void QtMaterialRipple::setOpacityEndValue(qreal value) 118 | { 119 | m_opacityAnimation->setEndValue(value); 120 | } 121 | 122 | inline void QtMaterialRipple::setRadiusStartValue(qreal value) 123 | { 124 | m_radiusAnimation->setStartValue(value); 125 | } 126 | 127 | inline void QtMaterialRipple::setRadiusEndValue(qreal value) 128 | { 129 | m_radiusAnimation->setEndValue(value); 130 | } 131 | 132 | inline void QtMaterialRipple::setDuration(int msecs) 133 | { 134 | m_radiusAnimation->setDuration(msecs); 135 | m_opacityAnimation->setDuration(msecs); 136 | } 137 | 138 | #endif // QTMATERIALRIPPLE_H 139 | -------------------------------------------------------------------------------- /components/lib/qtmaterialrippleoverlay.cpp: -------------------------------------------------------------------------------- 1 | #include "components/lib/qtmaterialrippleoverlay.h" 2 | #include 3 | #include "components/lib/qtmaterialripple.h" 4 | 5 | /*! 6 | * \class QtMaterialRippleOverlay 7 | * \internal 8 | */ 9 | 10 | QtMaterialRippleOverlay::QtMaterialRippleOverlay(QWidget *parent) 11 | : QtMaterialOverlayWidget(parent), 12 | m_useClip(false) 13 | { 14 | setAttribute(Qt::WA_TransparentForMouseEvents); 15 | setAttribute(Qt::WA_NoSystemBackground); 16 | } 17 | 18 | QtMaterialRippleOverlay::~QtMaterialRippleOverlay() 19 | { 20 | } 21 | 22 | void QtMaterialRippleOverlay::addRipple(QtMaterialRipple *ripple) 23 | { 24 | ripple->setOverlay(this); 25 | m_ripples.push_back(ripple); 26 | ripple->start(); 27 | 28 | connect(this, SIGNAL(destroyed(QObject*)), ripple, SLOT(stop())); 29 | connect(this, SIGNAL(destroyed(QObject*)), ripple, SLOT(deleteLater())); 30 | } 31 | 32 | void QtMaterialRippleOverlay::addRipple(const QPoint &position, qreal radius) 33 | { 34 | QtMaterialRipple *ripple = new QtMaterialRipple(position); 35 | ripple->setRadiusEndValue(radius); 36 | addRipple(ripple); 37 | } 38 | 39 | void QtMaterialRippleOverlay::removeRipple(QtMaterialRipple *ripple) 40 | { 41 | if (m_ripples.removeOne(ripple)) { 42 | delete ripple; 43 | update(); 44 | } 45 | } 46 | 47 | /*! 48 | * \reimp 49 | */ 50 | void QtMaterialRippleOverlay::paintEvent(QPaintEvent *event) 51 | { 52 | Q_UNUSED(event) 53 | 54 | QPainter painter(this); 55 | painter.setRenderHint(QPainter::Antialiasing); 56 | painter.setPen(Qt::NoPen); 57 | 58 | if (m_useClip) { 59 | painter.setClipPath(m_clipPath); 60 | } 61 | 62 | QList::const_iterator i; 63 | for (i = m_ripples.begin(); i != m_ripples.end(); ++i) { 64 | paintRipple(&painter, *i); 65 | } 66 | } 67 | 68 | void QtMaterialRippleOverlay::paintRipple(QPainter *painter, QtMaterialRipple *ripple) 69 | { 70 | const qreal radius = ripple->radius(); 71 | const QPointF center = ripple->center(); 72 | painter->setOpacity(ripple->opacity()); 73 | painter->setBrush(ripple->brush()); 74 | painter->drawEllipse(center, radius, radius); 75 | } 76 | -------------------------------------------------------------------------------- /components/lib/qtmaterialrippleoverlay.h: -------------------------------------------------------------------------------- 1 | #ifndef QTMATERIALRIPPLEOVERLAY_H 2 | #define QTMATERIALRIPPLEOVERLAY_H 3 | 4 | #include 5 | #include "components/lib/qtmaterialoverlaywidget.h" 6 | 7 | class QtMaterialRipple; 8 | 9 | class QtMaterialRippleOverlay : public QtMaterialOverlayWidget 10 | { 11 | Q_OBJECT 12 | 13 | public: 14 | explicit QtMaterialRippleOverlay(QWidget *parent = 0); 15 | ~QtMaterialRippleOverlay(); 16 | 17 | void addRipple(QtMaterialRipple *ripple); 18 | void addRipple(const QPoint &position, qreal radius = 300); 19 | 20 | void removeRipple(QtMaterialRipple *ripple); 21 | 22 | inline void setClipping(bool enable); 23 | inline bool hasClipping() const; 24 | 25 | inline void setClipPath(const QPainterPath &path); 26 | 27 | protected: 28 | void paintEvent(QPaintEvent *event) Q_DECL_OVERRIDE; 29 | 30 | inline QList ripples() const; 31 | 32 | private: 33 | Q_DISABLE_COPY(QtMaterialRippleOverlay) 34 | 35 | void paintRipple(QPainter *painter, QtMaterialRipple *ripple); 36 | 37 | QList m_ripples; 38 | QPainterPath m_clipPath; 39 | bool m_useClip; 40 | }; 41 | 42 | inline void QtMaterialRippleOverlay::setClipping(bool enable) 43 | { 44 | m_useClip = enable; 45 | update(); 46 | } 47 | 48 | inline bool QtMaterialRippleOverlay::hasClipping() const 49 | { 50 | return m_useClip; 51 | } 52 | 53 | inline void QtMaterialRippleOverlay::setClipPath(const QPainterPath &path) 54 | { 55 | m_clipPath = path; 56 | update(); 57 | } 58 | 59 | inline QList QtMaterialRippleOverlay::ripples() const 60 | { 61 | return m_ripples; 62 | } 63 | 64 | #endif // QTMATERIALRIPPLEOVERLAY_H 65 | -------------------------------------------------------------------------------- /components/lib/qtmaterialstatetransition.cpp: -------------------------------------------------------------------------------- 1 | #include "components/lib/qtmaterialstatetransition.h" 2 | 3 | QtMaterialStateTransition::QtMaterialStateTransition(QtMaterialStateTransitionType type) 4 | : m_type(type) 5 | { 6 | } 7 | 8 | bool QtMaterialStateTransition::eventTest(QEvent *event) 9 | { 10 | if (event->type() != QEvent::Type(QEvent::User + 1)) { 11 | return false; 12 | } 13 | QtMaterialStateTransitionEvent *transition = static_cast(event); 14 | return (m_type == transition->type); 15 | } 16 | 17 | void QtMaterialStateTransition::onTransition(QEvent *) 18 | { 19 | } 20 | -------------------------------------------------------------------------------- /components/lib/qtmaterialstatetransition.h: -------------------------------------------------------------------------------- 1 | #ifndef QTMATERIALSTATETRANSITION_H 2 | #define QTMATERIALSTATETRANSITION_H 3 | 4 | #include 5 | #include "components/lib/qtmaterialstatetransitionevent.h" 6 | 7 | class QtMaterialStateTransition : public QAbstractTransition 8 | { 9 | Q_OBJECT 10 | 11 | public: 12 | QtMaterialStateTransition(QtMaterialStateTransitionType type); 13 | 14 | protected: 15 | virtual bool eventTest(QEvent *event); 16 | virtual void onTransition(QEvent *); 17 | 18 | private: 19 | QtMaterialStateTransitionType m_type; 20 | }; 21 | 22 | #endif // QTMATERIALSTATETRANSITION_H 23 | -------------------------------------------------------------------------------- /components/lib/qtmaterialstatetransitionevent.h: -------------------------------------------------------------------------------- 1 | #ifndef QTMATERIALSTATETRANSITIONEVENT_H 2 | #define QTMATERIALSTATETRANSITIONEVENT_H 3 | 4 | #include 5 | 6 | enum QtMaterialStateTransitionType { 7 | // Snackbar 8 | SnackbarShowTransition = 1, 9 | SnackbarHideTransition, 10 | SnackbarWaitTransition, 11 | SnackbarNextTransition, 12 | // FlatButton 13 | FlatButtonPressedTransition, 14 | FlatButtonCheckedTransition, 15 | FlatButtonUncheckedTransition, 16 | // CollapsibleMenu 17 | CollapsibleMenuExpand, 18 | CollapsibleMenuCollapse, 19 | // Slider 20 | SliderChangedToMinimum, 21 | SliderChangedFromMinimum, 22 | SliderNoFocusMouseEnter, 23 | SliderNoFocusMouseLeave, 24 | // Dialog 25 | DialogShowTransition, 26 | DialogHideTransition, 27 | // 28 | MaxTransitionType = 65535 29 | }; 30 | 31 | struct QtMaterialStateTransitionEvent : public QEvent 32 | { 33 | QtMaterialStateTransitionEvent(QtMaterialStateTransitionType type) 34 | : QEvent(QEvent::Type(QEvent::User + 1)), 35 | type(type) 36 | { 37 | } 38 | 39 | QtMaterialStateTransitionType type; 40 | }; 41 | 42 | #endif // QTMATERIALSTATETRANSITIONEVENT_H 43 | -------------------------------------------------------------------------------- /components/lib/qtmaterialstyle.cpp: -------------------------------------------------------------------------------- 1 | #include "components/lib/qtmaterialstyle.h" 2 | #include 3 | #include "components/lib/qtmaterialtheme.h" 4 | 5 | /*! 6 | * \class QtMaterialStylePrivate 7 | * \internal 8 | */ 9 | 10 | QtMaterialStylePrivate::QtMaterialStylePrivate(QtMaterialStyle *q) 11 | : q_ptr(q) 12 | { 13 | } 14 | 15 | QtMaterialStylePrivate::~QtMaterialStylePrivate() 16 | { 17 | } 18 | 19 | void QtMaterialStylePrivate::init() 20 | { 21 | Q_Q(QtMaterialStyle); 22 | 23 | QFontDatabase::addApplicationFont(":/fonts/roboto_regular"); 24 | QFontDatabase::addApplicationFont(":/fonts/roboto_medium"); 25 | QFontDatabase::addApplicationFont(":/fonts/roboto_bold"); 26 | 27 | q->setTheme(new QtMaterialTheme); 28 | } 29 | 30 | /*! 31 | * \class QtMaterialStyle 32 | * \internal 33 | */ 34 | 35 | void QtMaterialStyle::setTheme(QtMaterialTheme *theme) 36 | { 37 | Q_D(QtMaterialStyle); 38 | 39 | d->theme = theme; 40 | theme->setParent(this); 41 | } 42 | 43 | QColor QtMaterialStyle::themeColor(const QString &key) const 44 | { 45 | Q_D(const QtMaterialStyle); 46 | 47 | Q_ASSERT(d->theme); 48 | 49 | return d->theme->getColor(key); 50 | } 51 | 52 | QtMaterialStyle::QtMaterialStyle() 53 | : QCommonStyle(), 54 | d_ptr(new QtMaterialStylePrivate(this)) 55 | { 56 | d_func()->init(); 57 | } 58 | -------------------------------------------------------------------------------- /components/lib/qtmaterialstyle.h: -------------------------------------------------------------------------------- 1 | #ifndef QTMATERIALSTYLE_H 2 | #define QTMATERIALSTYLE_H 3 | 4 | #include 5 | #include "components/lib/qtmaterialstyle_p.h" 6 | 7 | #define MATERIAL_DISABLE_THEME_COLORS \ 8 | if (d->useThemeColors == true) { d->useThemeColors = false; } 9 | 10 | class QtMaterialTheme; 11 | 12 | class QtMaterialStyle : public QCommonStyle 13 | { 14 | Q_OBJECT 15 | 16 | public: 17 | inline static QtMaterialStyle &instance(); 18 | 19 | void setTheme(QtMaterialTheme *theme); 20 | QColor themeColor(const QString &key) const; 21 | 22 | protected: 23 | const QScopedPointer d_ptr; 24 | 25 | private: 26 | Q_DECLARE_PRIVATE(QtMaterialStyle) 27 | 28 | QtMaterialStyle(); 29 | 30 | QtMaterialStyle(QtMaterialStyle const &); 31 | void operator=(QtMaterialStyle const &); 32 | }; 33 | 34 | inline QtMaterialStyle &QtMaterialStyle::instance() 35 | { 36 | static QtMaterialStyle instance; 37 | return instance; 38 | } 39 | 40 | #endif // QTMATERIALSTYLE_H 41 | -------------------------------------------------------------------------------- /components/lib/qtmaterialstyle_p.h: -------------------------------------------------------------------------------- 1 | #ifndef QTMATERIALSTYLE_P_H 2 | #define QTMATERIALSTYLE_P_H 3 | 4 | #include 5 | 6 | class QtMaterialStyle; 7 | class QtMaterialTheme; 8 | 9 | class QtMaterialStylePrivate 10 | { 11 | Q_DISABLE_COPY(QtMaterialStylePrivate) 12 | Q_DECLARE_PUBLIC(QtMaterialStyle) 13 | 14 | public: 15 | QtMaterialStylePrivate(QtMaterialStyle *q); 16 | ~QtMaterialStylePrivate(); 17 | 18 | void init(); 19 | 20 | QtMaterialStyle *const q_ptr; 21 | QtMaterialTheme *theme; 22 | }; 23 | 24 | #endif // QTMATERIALSTYLE_P_H 25 | -------------------------------------------------------------------------------- /components/lib/qtmaterialtheme_p.h: -------------------------------------------------------------------------------- 1 | #ifndef QTMATERIALTHEME_P_H 2 | #define QTMATERIALTHEME_P_H 3 | 4 | #include 5 | #include 6 | 7 | class QtMaterialTheme; 8 | 9 | class QtMaterialThemePrivate 10 | { 11 | Q_DISABLE_COPY(QtMaterialThemePrivate) 12 | Q_DECLARE_PUBLIC(QtMaterialTheme) 13 | 14 | public: 15 | QtMaterialThemePrivate(QtMaterialTheme *q); 16 | ~QtMaterialThemePrivate(); 17 | 18 | QColor rgba(int r, int g, int b, qreal a) const; 19 | 20 | QtMaterialTheme *const q_ptr; 21 | QHash colors; 22 | }; 23 | 24 | #endif // QTMATERIALTHEME_P_H 25 | -------------------------------------------------------------------------------- /components/lib/soroushthemeextention.cpp: -------------------------------------------------------------------------------- 1 | #include "soroushthemeextention.h" 2 | 3 | SoroushThemeExtention::SoroushThemeExtention(QObject *parent) : QObject(parent) 4 | { 5 | 6 | } 7 | -------------------------------------------------------------------------------- /components/lib/soroushthemeextention.h: -------------------------------------------------------------------------------- 1 | #ifndef SOROUSHTHEMEEXTENTION_H 2 | #define SOROUSHTHEMEEXTENTION_H 3 | 4 | #include 5 | 6 | class SoroushThemeExtention : public QObject 7 | { 8 | Q_OBJECT 9 | public: 10 | explicit SoroushThemeExtention(QObject *parent = nullptr); 11 | 12 | signals: 13 | 14 | public slots: 15 | }; 16 | 17 | #endif // SOROUSHTHEMEEXTENTION_H -------------------------------------------------------------------------------- /components/qtmaterialappbar.cpp: -------------------------------------------------------------------------------- 1 | #include "qtmaterialappbar.h" 2 | #include "qtmaterialappbar_p.h" 3 | #include 4 | #include 5 | #include "components/lib/qtmaterialstyle.h" 6 | 7 | /*! 8 | * \class QtMaterialAppBarPrivate 9 | * \internal 10 | */ 11 | 12 | /*! 13 | * \internal 14 | */ 15 | QtMaterialAppBarPrivate::QtMaterialAppBarPrivate(QtMaterialAppBar *q) 16 | : q_ptr(q) 17 | { 18 | } 19 | 20 | /*! 21 | * \internal 22 | */ 23 | QtMaterialAppBarPrivate::~QtMaterialAppBarPrivate() 24 | { 25 | } 26 | 27 | /*! 28 | * \internal 29 | */ 30 | void QtMaterialAppBarPrivate::init() 31 | { 32 | Q_Q(QtMaterialAppBar); 33 | 34 | useThemeColors = true; 35 | 36 | QGraphicsDropShadowEffect *effect = new QGraphicsDropShadowEffect; 37 | effect->setBlurRadius(11); 38 | effect->setColor(QColor(0, 0, 0, 50)); 39 | effect->setOffset(0, 3); 40 | 41 | q->setGraphicsEffect(effect); 42 | 43 | QHBoxLayout *layout = new QHBoxLayout; 44 | q->setLayout(layout); 45 | } 46 | 47 | /*! 48 | * \class QtMaterialAppBar 49 | */ 50 | 51 | QtMaterialAppBar::QtMaterialAppBar(QWidget *parent) 52 | : QWidget(parent), 53 | d_ptr(new QtMaterialAppBarPrivate(this)) 54 | { 55 | d_func()->init(); 56 | } 57 | 58 | QtMaterialAppBar::~QtMaterialAppBar() 59 | { 60 | } 61 | 62 | QSize QtMaterialAppBar::sizeHint() const 63 | { 64 | return QSize(-1, 64); 65 | } 66 | 67 | void QtMaterialAppBar::paintEvent(QPaintEvent *event) 68 | { 69 | Q_UNUSED(event) 70 | 71 | QPainter painter(this); 72 | 73 | painter.fillRect(rect(), backgroundColor()); 74 | } 75 | 76 | void QtMaterialAppBar::setUseThemeColors(bool value) 77 | { 78 | Q_D(QtMaterialAppBar); 79 | 80 | if (d->useThemeColors == value) { 81 | return; 82 | } 83 | 84 | d->useThemeColors = value; 85 | update(); 86 | } 87 | 88 | bool QtMaterialAppBar::useThemeColors() const 89 | { 90 | Q_D(const QtMaterialAppBar); 91 | 92 | return d->useThemeColors; 93 | } 94 | 95 | void QtMaterialAppBar::setForegroundColor(const QColor &color) 96 | { 97 | Q_D(QtMaterialAppBar); 98 | 99 | d->foregroundColor = color; 100 | 101 | if (d->useThemeColors == true) { 102 | d->useThemeColors = false; 103 | } 104 | update(); 105 | } 106 | 107 | QColor QtMaterialAppBar::foregroundColor() const 108 | { 109 | Q_D(const QtMaterialAppBar); 110 | 111 | if (d->useThemeColors || !d->foregroundColor.isValid()) { 112 | return QtMaterialStyle::instance().themeColor("primary1"); 113 | } else { 114 | return d->foregroundColor; 115 | } 116 | } 117 | 118 | void QtMaterialAppBar::setBackgroundColor(const QColor &color) 119 | { 120 | Q_D(QtMaterialAppBar); 121 | 122 | d->backgroundColor = color; 123 | 124 | if (d->useThemeColors == true) { 125 | d->useThemeColors = false; 126 | } 127 | update(); 128 | } 129 | 130 | QColor QtMaterialAppBar::backgroundColor() const 131 | { 132 | Q_D(const QtMaterialAppBar); 133 | 134 | if (d->useThemeColors || !d->backgroundColor.isValid()) { 135 | return QtMaterialStyle::instance().themeColor("primary1"); 136 | } else { 137 | return d->backgroundColor; 138 | } 139 | } 140 | -------------------------------------------------------------------------------- /components/qtmaterialappbar.h: -------------------------------------------------------------------------------- 1 | #ifndef QTMATERIALAPPBAR_H 2 | #define QTMATERIALAPPBAR_H 3 | 4 | #include 5 | #include 6 | 7 | class QtMaterialAppBarPrivate; 8 | 9 | class QtMaterialAppBar : public QWidget 10 | { 11 | Q_OBJECT 12 | 13 | Q_PROPERTY(QColor foregroundColor WRITE setForegroundColor READ foregroundColor) 14 | Q_PROPERTY(QColor backgroundColor WRITE setBackgroundColor READ backgroundColor) 15 | 16 | public: 17 | explicit QtMaterialAppBar(QWidget *parent = 0); 18 | ~QtMaterialAppBar(); 19 | 20 | QSize sizeHint() const Q_DECL_OVERRIDE; 21 | 22 | void setUseThemeColors(bool value); 23 | bool useThemeColors() const; 24 | 25 | void setForegroundColor(const QColor &color); 26 | QColor foregroundColor() const; 27 | 28 | void setBackgroundColor(const QColor &color); 29 | QColor backgroundColor() const; 30 | 31 | inline QHBoxLayout *appBarLayout() const; 32 | 33 | protected: 34 | void paintEvent(QPaintEvent *event) Q_DECL_OVERRIDE; 35 | 36 | const QScopedPointer d_ptr; 37 | 38 | private: 39 | Q_DISABLE_COPY(QtMaterialAppBar) 40 | Q_DECLARE_PRIVATE(QtMaterialAppBar) 41 | }; 42 | 43 | inline QHBoxLayout *QtMaterialAppBar::appBarLayout() const 44 | { 45 | return static_cast(layout()); 46 | } 47 | 48 | #endif // QTMATERIALAPPBAR_H 49 | -------------------------------------------------------------------------------- /components/qtmaterialappbar_p.h: -------------------------------------------------------------------------------- 1 | #ifndef QTMATERIALAPPBAR_P_H 2 | #define QTMATERIALAPPBAR_P_H 3 | 4 | #include 5 | #include 6 | 7 | class QtMaterialAppBar; 8 | 9 | class QtMaterialAppBarPrivate 10 | { 11 | Q_DISABLE_COPY(QtMaterialAppBarPrivate) 12 | Q_DECLARE_PUBLIC(QtMaterialAppBar) 13 | 14 | public: 15 | QtMaterialAppBarPrivate(QtMaterialAppBar *q); 16 | ~QtMaterialAppBarPrivate(); 17 | 18 | void init(); 19 | 20 | QtMaterialAppBar *const q_ptr; 21 | bool useThemeColors; 22 | QColor foregroundColor; 23 | QColor backgroundColor; 24 | }; 25 | 26 | #endif // QTMATERIALAPPBAR_P_H 27 | -------------------------------------------------------------------------------- /components/qtmaterialautocomplete.h: -------------------------------------------------------------------------------- 1 | #ifndef QTMATERIALAUTOCOMPLETE_H 2 | #define QTMATERIALAUTOCOMPLETE_H 3 | 4 | #include "qtmaterialtextfield.h" 5 | 6 | class QtMaterialAutoCompletePrivate; 7 | 8 | class QtMaterialAutoComplete : public QtMaterialTextField 9 | { 10 | Q_OBJECT 11 | 12 | public: 13 | explicit QtMaterialAutoComplete(QWidget *parent = 0); 14 | ~QtMaterialAutoComplete(); 15 | 16 | void setDataSource(const QStringList &data); 17 | 18 | signals: 19 | void itemSelected(QString); 20 | 21 | protected slots: 22 | void updateResults(QString text); 23 | 24 | protected: 25 | bool event(QEvent *event) Q_DECL_OVERRIDE; 26 | bool eventFilter(QObject *watched, QEvent *event) Q_DECL_OVERRIDE; 27 | 28 | private: 29 | Q_DISABLE_COPY(QtMaterialAutoComplete) 30 | Q_DECLARE_PRIVATE(QtMaterialAutoComplete) 31 | }; 32 | 33 | #endif // QTMATERIALAUTOCOMPLETE_H 34 | -------------------------------------------------------------------------------- /components/qtmaterialautocomplete_internal.cpp: -------------------------------------------------------------------------------- 1 | #include "qtmaterialautocomplete_internal.h" 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | /*! 8 | * \class QtMaterialAutoCompleteStateMachine 9 | * \internal 10 | */ 11 | 12 | /*! 13 | * \internal 14 | */ 15 | QtMaterialAutoCompleteStateMachine::QtMaterialAutoCompleteStateMachine(QWidget *menu) 16 | : QStateMachine(menu), 17 | m_menu(menu), 18 | m_closedState(new QState), 19 | m_openState(new QState), 20 | m_closingState(new QState) 21 | { 22 | Q_ASSERT(menu); 23 | 24 | addState(m_closedState); 25 | addState(m_openState); 26 | addState(m_closingState); 27 | setInitialState(m_closedState); 28 | 29 | QSignalTransition *transition; 30 | 31 | transition = new QSignalTransition(this, SIGNAL(shouldOpen())); 32 | transition->setTargetState(m_openState); 33 | m_closedState->addTransition(transition); 34 | 35 | transition = new QSignalTransition(this, SIGNAL(shouldClose())); 36 | transition->setTargetState(m_closedState); 37 | m_openState->addTransition(transition); 38 | 39 | transition = new QSignalTransition(this, SIGNAL(shouldFade())); 40 | transition->setTargetState(m_closingState); 41 | m_openState->addTransition(transition); 42 | 43 | m_closedState->assignProperty(menu, "visible", false); 44 | m_openState->assignProperty(menu, "visible", true); 45 | 46 | QGraphicsOpacityEffect *effect = new QGraphicsOpacityEffect; 47 | menu->setGraphicsEffect(effect); 48 | 49 | m_openState->assignProperty(effect, "opacity", 1); 50 | m_closingState->assignProperty(effect, "opacity", 0); 51 | m_closedState->assignProperty(effect, "opacity", 0); 52 | 53 | QPropertyAnimation *animation; 54 | 55 | animation = new QPropertyAnimation(effect, "opacity", this); 56 | animation->setDuration(240); 57 | addDefaultAnimation(animation); 58 | 59 | transition = new QSignalTransition(animation, SIGNAL(finished())); 60 | transition->setTargetState(m_closedState); 61 | m_closingState->addTransition(transition); 62 | } 63 | 64 | /*! 65 | * \internal 66 | */ 67 | QtMaterialAutoCompleteStateMachine::~QtMaterialAutoCompleteStateMachine() 68 | { 69 | } 70 | -------------------------------------------------------------------------------- /components/qtmaterialautocomplete_internal.h: -------------------------------------------------------------------------------- 1 | #ifndef QTMATERIALAUTOCOMPLETESTATEMACHINE_H 2 | #define QTMATERIALAUTOCOMPLETESTATEMACHINE_H 3 | 4 | #include 5 | #include "qtmaterialautocomplete.h" 6 | 7 | class QtMaterialAutoCompleteStateMachine : public QStateMachine 8 | { 9 | Q_OBJECT 10 | 11 | public: 12 | explicit QtMaterialAutoCompleteStateMachine(QWidget *menu); 13 | ~QtMaterialAutoCompleteStateMachine(); 14 | 15 | signals: 16 | void shouldOpen(); 17 | void shouldClose(); 18 | void shouldFade(); 19 | 20 | private: 21 | Q_DISABLE_COPY(QtMaterialAutoCompleteStateMachine) 22 | 23 | QWidget *const m_menu; 24 | QState *const m_closedState; 25 | QState *const m_openState; 26 | QState *const m_closingState; 27 | }; 28 | 29 | #endif // QTMATERIALAUTOCOMPLETESTATEMACHINE_H 30 | -------------------------------------------------------------------------------- /components/qtmaterialautocomplete_p.h: -------------------------------------------------------------------------------- 1 | #ifndef QTMATERIALAUTOCOMPLETE_P_H 2 | #define QTMATERIALAUTOCOMPLETE_P_H 3 | 4 | #include "qtmaterialtextfield_p.h" 5 | 6 | class QWidget; 7 | class QVBoxLayout; 8 | class QtMaterialAutoCompleteOverlay; 9 | class QtMaterialAutoCompleteStateMachine; 10 | 11 | class QtMaterialAutoCompletePrivate : public QtMaterialTextFieldPrivate 12 | { 13 | Q_DISABLE_COPY(QtMaterialAutoCompletePrivate) 14 | Q_DECLARE_PUBLIC(QtMaterialAutoComplete) 15 | 16 | public: 17 | QtMaterialAutoCompletePrivate(QtMaterialAutoComplete *q); 18 | virtual ~QtMaterialAutoCompletePrivate(); 19 | 20 | void init(); 21 | 22 | QWidget *menu; 23 | QWidget *frame; 24 | QtMaterialAutoCompleteStateMachine *stateMachine; 25 | QVBoxLayout *menuLayout; 26 | QStringList dataSource; 27 | int maxWidth; 28 | }; 29 | 30 | #endif // QTMATERIALAUTOCOMPLETE_P_H 31 | -------------------------------------------------------------------------------- /components/qtmaterialavatar.h: -------------------------------------------------------------------------------- 1 | #ifndef QTMATERIALAVATAR_H 2 | #define QTMATERIALAVATAR_H 3 | 4 | #include 5 | #include "components/lib/qtmaterialtheme.h" 6 | 7 | class QtMaterialAvatarPrivate; 8 | 9 | class QtMaterialAvatar : public QWidget 10 | { 11 | Q_OBJECT 12 | 13 | public: 14 | explicit QtMaterialAvatar(QWidget *parent = 0); 15 | explicit QtMaterialAvatar(const QIcon &icon, QWidget *parent = 0); 16 | explicit QtMaterialAvatar(const QChar &letter, QWidget *parent = 0); 17 | explicit QtMaterialAvatar(const QImage &image, QWidget *parent = 0); 18 | ~QtMaterialAvatar(); 19 | 20 | void setUseThemeColors(bool value); 21 | bool useThemeColors() const; 22 | 23 | void setTextColor(const QColor &color); 24 | QColor textColor() const; 25 | 26 | void setBackgroundColor(const QColor &color); 27 | QColor backgroundColor() const; 28 | 29 | QSize sizeHint() const Q_DECL_OVERRIDE; 30 | 31 | void setSize(int size); 32 | int size() const; 33 | 34 | void setLetter(const QChar &letter); 35 | void setImage(const QImage &image); 36 | void setIcon(const QIcon &icon); 37 | 38 | Material::AvatarType type() const; 39 | 40 | protected: 41 | void paintEvent(QPaintEvent *event) Q_DECL_OVERRIDE; 42 | 43 | const QScopedPointer d_ptr; 44 | 45 | private: 46 | Q_DISABLE_COPY(QtMaterialAvatar) 47 | Q_DECLARE_PRIVATE(QtMaterialAvatar) 48 | }; 49 | 50 | #endif // QTMATERIALAVATAR_H 51 | -------------------------------------------------------------------------------- /components/qtmaterialavatar_p.h: -------------------------------------------------------------------------------- 1 | #ifndef QTMATERIALAVATAR_P_H 2 | #define QTMATERIALAVATAR_P_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include "components/lib/qtmaterialtheme.h" 11 | 12 | class QtMaterialAvatar; 13 | 14 | class QtMaterialAvatarPrivate 15 | { 16 | Q_DISABLE_COPY(QtMaterialAvatarPrivate) 17 | Q_DECLARE_PUBLIC(QtMaterialAvatar) 18 | 19 | public: 20 | QtMaterialAvatarPrivate(QtMaterialAvatar *q); 21 | ~QtMaterialAvatarPrivate(); 22 | 23 | void init(); 24 | 25 | QtMaterialAvatar *const q_ptr; 26 | int size; 27 | Material::AvatarType type; 28 | QChar letter; 29 | QImage image; 30 | QIcon icon; 31 | QPixmap pixmap; 32 | bool useThemeColors; 33 | QColor textColor; 34 | QColor backgroundColor; 35 | }; 36 | 37 | #endif // QTMATERIALAVATAR_P_H 38 | -------------------------------------------------------------------------------- /components/qtmaterialbadge.cpp: -------------------------------------------------------------------------------- 1 | #include "qtmaterialbadge.h" 2 | #include "qtmaterialbadge_p.h" 3 | #include 4 | #include "components/lib/qtmaterialstyle.h" 5 | 6 | /*! 7 | * \class QtMaterialBadgePrivate 8 | * \internal 9 | */ 10 | 11 | /*! 12 | * \internal 13 | */ 14 | QtMaterialBadgePrivate::QtMaterialBadgePrivate(QtMaterialBadge *q) 15 | : q_ptr(q) 16 | { 17 | } 18 | 19 | /*! 20 | * \internal 21 | */ 22 | QtMaterialBadgePrivate::~QtMaterialBadgePrivate() 23 | { 24 | } 25 | 26 | /*! 27 | * \internal 28 | */ 29 | void QtMaterialBadgePrivate::init() 30 | { 31 | Q_Q(QtMaterialBadge); 32 | 33 | x = 0; 34 | y = 0; 35 | padding = 10; 36 | useThemeColors = true; 37 | 38 | q->setAttribute(Qt::WA_TransparentForMouseEvents); 39 | 40 | QFont font(q->font()); 41 | font.setPointSizeF(10); 42 | font.setStyleName("Bold"); 43 | q->setFont(font); 44 | 45 | q->setText("+1"); 46 | } 47 | 48 | /*! 49 | * \class QtMaterialBadge 50 | */ 51 | 52 | QtMaterialBadge::QtMaterialBadge(QWidget *parent) 53 | : QtMaterialOverlayWidget(parent), 54 | d_ptr(new QtMaterialBadgePrivate(this)) 55 | { 56 | d_func()->init(); 57 | } 58 | 59 | QtMaterialBadge::QtMaterialBadge(const QIcon &icon, QWidget *parent) 60 | : QtMaterialOverlayWidget(parent), 61 | d_ptr(new QtMaterialBadgePrivate(this)) 62 | { 63 | d_func()->init(); 64 | 65 | setIcon(icon); 66 | } 67 | 68 | QtMaterialBadge::QtMaterialBadge(const QString &text, QWidget *parent) 69 | : QtMaterialOverlayWidget(parent), 70 | d_ptr(new QtMaterialBadgePrivate(this)) 71 | { 72 | d_func()->init(); 73 | 74 | setText(text); 75 | } 76 | 77 | QtMaterialBadge::~QtMaterialBadge() 78 | { 79 | } 80 | 81 | void QtMaterialBadge::setUseThemeColors(bool value) 82 | { 83 | Q_D(QtMaterialBadge); 84 | 85 | if (d->useThemeColors == value) { 86 | return; 87 | } 88 | 89 | d->useThemeColors = value; 90 | update(); 91 | } 92 | 93 | bool QtMaterialBadge::useThemeColors() const 94 | { 95 | Q_D(const QtMaterialBadge); 96 | 97 | return d->useThemeColors; 98 | } 99 | 100 | void QtMaterialBadge::setTextColor(const QColor &color) 101 | { 102 | Q_D(QtMaterialBadge); 103 | 104 | d->textColor = color; 105 | 106 | MATERIAL_DISABLE_THEME_COLORS 107 | update(); 108 | } 109 | 110 | QColor QtMaterialBadge::textColor() const 111 | { 112 | Q_D(const QtMaterialBadge); 113 | 114 | if (d->useThemeColors || !d->textColor.isValid()) { 115 | return QtMaterialStyle::instance().themeColor("canvas"); 116 | } else { 117 | return d->textColor; 118 | } 119 | } 120 | 121 | void QtMaterialBadge::setBackgroundColor(const QColor &color) 122 | { 123 | Q_D(QtMaterialBadge); 124 | 125 | d->backgroundColor = color; 126 | 127 | MATERIAL_DISABLE_THEME_COLORS 128 | update(); 129 | } 130 | 131 | QColor QtMaterialBadge::backgroundColor() const 132 | { 133 | Q_D(const QtMaterialBadge); 134 | 135 | if (d->useThemeColors || !d->backgroundColor.isValid()) { 136 | return QtMaterialStyle::instance().themeColor("accent1"); 137 | } else { 138 | return d->backgroundColor; 139 | } 140 | } 141 | 142 | void QtMaterialBadge::setRelativePosition(const QPointF &pos) 143 | { 144 | setRelativePosition(pos.x(), pos.y()); 145 | } 146 | 147 | void QtMaterialBadge::setRelativePosition(qreal x, qreal y) 148 | { 149 | Q_D(QtMaterialBadge); 150 | 151 | d->x = x; 152 | d->y = y; 153 | update(); 154 | } 155 | 156 | QPointF QtMaterialBadge::relativePosition() const 157 | { 158 | Q_D(const QtMaterialBadge); 159 | 160 | return QPointF(d->x, d->y); 161 | } 162 | 163 | void QtMaterialBadge::setRelativeXPosition(qreal x) 164 | { 165 | Q_D(QtMaterialBadge); 166 | 167 | d->x = x; 168 | update(); 169 | } 170 | 171 | qreal QtMaterialBadge::relativeXPosition() const 172 | { 173 | Q_D(const QtMaterialBadge); 174 | 175 | return d->x; 176 | } 177 | 178 | void QtMaterialBadge::setRelativeYPosition(qreal y) 179 | { 180 | Q_D(QtMaterialBadge); 181 | 182 | d->y = y; 183 | update(); 184 | } 185 | 186 | qreal QtMaterialBadge::relativeYPosition() const 187 | { 188 | Q_D(const QtMaterialBadge); 189 | 190 | return d->y; 191 | } 192 | 193 | /*! 194 | * \reimp 195 | */ 196 | QSize QtMaterialBadge::sizeHint() const 197 | { 198 | const int s = getDiameter(); 199 | return QSize(s+4, s+4); 200 | } 201 | 202 | void QtMaterialBadge::setIcon(const QIcon &icon) 203 | { 204 | Q_D(QtMaterialBadge); 205 | 206 | d->icon = icon; 207 | update(); 208 | } 209 | 210 | QIcon QtMaterialBadge::icon() const 211 | { 212 | Q_D(const QtMaterialBadge); 213 | 214 | return d->icon; 215 | } 216 | 217 | void QtMaterialBadge::setText(const QString &text) 218 | { 219 | Q_D(QtMaterialBadge); 220 | 221 | d->text = text; 222 | 223 | if (!d->icon.isNull()) { 224 | d->icon = QIcon(); 225 | } 226 | 227 | d->size = fontMetrics().size(Qt::TextShowMnemonic, text); 228 | 229 | update(); 230 | } 231 | 232 | QString QtMaterialBadge::text() const 233 | { 234 | Q_D(const QtMaterialBadge); 235 | 236 | return d->text; 237 | } 238 | 239 | /*! 240 | * \reimp 241 | */ 242 | void QtMaterialBadge::paintEvent(QPaintEvent *event) 243 | { 244 | Q_UNUSED(event) 245 | 246 | Q_D(QtMaterialBadge); 247 | 248 | QPainter painter(this); 249 | painter.setRenderHint(QPainter::Antialiasing); 250 | 251 | painter.translate(d->x, d->y); 252 | 253 | QBrush brush; 254 | brush.setStyle(Qt::SolidPattern); 255 | brush.setColor(isEnabled() ? backgroundColor() 256 | : QtMaterialStyle::instance().themeColor("disabled")); 257 | painter.setBrush(brush); 258 | painter.setPen(Qt::NoPen); 259 | 260 | const int s = getDiameter(); 261 | 262 | QRectF r(0, 0, s, s); 263 | r.translate(QPointF((width()-s), (height()-s))/2); 264 | 265 | if (d->icon.isNull()) 266 | { 267 | painter.drawEllipse(r); 268 | painter.setPen(textColor()); 269 | painter.setBrush(Qt::NoBrush); 270 | painter.drawText(r.translated(0, -0.5), Qt::AlignCenter, d->text); 271 | } 272 | else 273 | { 274 | painter.drawEllipse(r); 275 | QRectF q(0, 0, 16, 16); 276 | q.moveCenter(r.center()); 277 | QPixmap pixmap = icon().pixmap(16, 16); 278 | QPainter icon(&pixmap); 279 | icon.setCompositionMode(QPainter::CompositionMode_SourceIn); 280 | icon.fillRect(pixmap.rect(), textColor()); 281 | painter.drawPixmap(q.toRect(), pixmap); 282 | } 283 | } 284 | 285 | int QtMaterialBadge::getDiameter() const 286 | { 287 | Q_D(const QtMaterialBadge); 288 | 289 | if (d->icon.isNull()) { 290 | return qMax(d->size.width(), d->size.height()) + d->padding; 291 | } else { 292 | return 24; 293 | } 294 | } 295 | -------------------------------------------------------------------------------- /components/qtmaterialbadge.h: -------------------------------------------------------------------------------- 1 | #ifndef QTMATERIALBADGE_H 2 | #define QTMATERIALBADGE_H 3 | 4 | #include "components/lib/qtmaterialoverlaywidget.h" 5 | 6 | class QtMaterialBadgePrivate; 7 | 8 | class QtMaterialBadge : public QtMaterialOverlayWidget 9 | { 10 | Q_OBJECT 11 | 12 | Q_PROPERTY(QColor textColor WRITE setTextColor READ textColor) 13 | Q_PROPERTY(QColor backgroundColor WRITE setBackgroundColor READ backgroundColor) 14 | Q_PROPERTY(QPointF relativePosition WRITE setRelativePosition READ relativePosition) 15 | 16 | public: 17 | explicit QtMaterialBadge(QWidget *parent = 0); 18 | explicit QtMaterialBadge(const QIcon &icon, QWidget *parent = 0); 19 | explicit QtMaterialBadge(const QString &text, QWidget *parent = 0); 20 | ~QtMaterialBadge(); 21 | 22 | void setUseThemeColors(bool value); 23 | bool useThemeColors() const; 24 | 25 | void setTextColor(const QColor &color); 26 | QColor textColor() const; 27 | 28 | void setBackgroundColor(const QColor &color); 29 | QColor backgroundColor() const; 30 | 31 | void setRelativePosition(const QPointF &pos); 32 | void setRelativePosition(qreal x, qreal y); 33 | QPointF relativePosition() const; 34 | 35 | void setRelativeXPosition(qreal x); 36 | qreal relativeXPosition() const; 37 | 38 | void setRelativeYPosition(qreal y); 39 | qreal relativeYPosition() const; 40 | 41 | QSize sizeHint() const Q_DECL_OVERRIDE; 42 | 43 | void setIcon(const QIcon &icon); 44 | QIcon icon() const; 45 | 46 | void setText(const QString &text); 47 | QString text() const; 48 | 49 | protected: 50 | void paintEvent(QPaintEvent *event) Q_DECL_OVERRIDE; 51 | 52 | int getDiameter() const; 53 | 54 | const QScopedPointer d_ptr; 55 | 56 | private: 57 | Q_DISABLE_COPY(QtMaterialBadge) 58 | Q_DECLARE_PRIVATE(QtMaterialBadge) 59 | }; 60 | 61 | #endif // QTMATERIALBADGE_H 62 | -------------------------------------------------------------------------------- /components/qtmaterialbadge_p.h: -------------------------------------------------------------------------------- 1 | #ifndef QTMATERIALBADGE_P_H 2 | #define QTMATERIALBADGE_P_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | class QtMaterialBadge; 10 | 11 | class QtMaterialBadgePrivate 12 | { 13 | Q_DISABLE_COPY(QtMaterialBadgePrivate) 14 | Q_DECLARE_PUBLIC(QtMaterialBadge) 15 | 16 | public: 17 | QtMaterialBadgePrivate(QtMaterialBadge *q); 18 | ~QtMaterialBadgePrivate(); 19 | 20 | void init(); 21 | 22 | QtMaterialBadge *const q_ptr; 23 | QString text; 24 | QColor textColor; 25 | QColor backgroundColor; 26 | QSize size; 27 | QIcon icon; 28 | qreal x; 29 | qreal y; 30 | int padding; 31 | bool useThemeColors; 32 | }; 33 | 34 | #endif // QTMATERIALBADGE_P_H 35 | -------------------------------------------------------------------------------- /components/qtmaterialcheckbox.cpp: -------------------------------------------------------------------------------- 1 | #include "qtmaterialcheckbox.h" 2 | #include "qtmaterialcheckbox_p.h" 3 | #include 4 | #include 5 | #include 6 | #include "components/lib/qtmaterialcheckable_internal.h" 7 | 8 | /*! 9 | * \class QtMaterialCheckBoxPrivate 10 | * \internal 11 | */ 12 | 13 | /*! 14 | * \internal 15 | */ 16 | QtMaterialCheckBoxPrivate::QtMaterialCheckBoxPrivate(QtMaterialCheckBox *q) 17 | : QtMaterialCheckablePrivate(q) 18 | { 19 | } 20 | 21 | /*! 22 | * \internal 23 | */ 24 | QtMaterialCheckBoxPrivate::~QtMaterialCheckBoxPrivate() 25 | { 26 | } 27 | 28 | /*! 29 | * \internal 30 | */ 31 | void QtMaterialCheckBoxPrivate::init() 32 | { 33 | Q_Q(QtMaterialCheckBox); 34 | 35 | checkedState->assignProperty(checkedIcon, "iconSize", 24); 36 | uncheckedState->assignProperty(checkedIcon, "iconSize", 0); 37 | 38 | QPropertyAnimation *animation; 39 | 40 | animation = new QPropertyAnimation(checkedIcon, "iconSize", q); 41 | animation->setDuration(300); 42 | uncheckedTransition->addAnimation(animation); 43 | 44 | animation = new QPropertyAnimation(checkedIcon, "iconSize", q); 45 | animation->setDuration(1300); 46 | checkedTransition->addAnimation(animation); 47 | 48 | animation = new QPropertyAnimation(checkedIcon, "opacity", q); 49 | animation->setDuration(440); 50 | checkedTransition->addAnimation(animation); 51 | 52 | animation = new QPropertyAnimation(checkedIcon, "opacity", q); 53 | animation->setDuration(440); 54 | uncheckedTransition->addAnimation(animation); 55 | 56 | animation = new QPropertyAnimation(uncheckedIcon, "opacity", q); 57 | animation->setDuration(440); 58 | checkedTransition->addAnimation(animation); 59 | 60 | animation = new QPropertyAnimation(uncheckedIcon, "opacity", q); 61 | animation->setDuration(440); 62 | uncheckedTransition->addAnimation(animation); 63 | 64 | animation = new QPropertyAnimation(uncheckedIcon, "color", q); 65 | animation->setDuration(440); 66 | checkedTransition->addAnimation(animation); 67 | 68 | animation = new QPropertyAnimation(uncheckedIcon, "color", q); 69 | animation->setDuration(440); 70 | uncheckedTransition->addAnimation(animation); 71 | } 72 | 73 | /*! 74 | * \class QtMaterialCheckBox 75 | */ 76 | 77 | QtMaterialCheckBox::QtMaterialCheckBox(QWidget *parent) 78 | : QtMaterialCheckable(*new QtMaterialCheckBoxPrivate(this), parent) 79 | { 80 | d_func()->init(); 81 | } 82 | 83 | QtMaterialCheckBox::~QtMaterialCheckBox() 84 | { 85 | } 86 | -------------------------------------------------------------------------------- /components/qtmaterialcheckbox.h: -------------------------------------------------------------------------------- 1 | #ifndef QTMATERIALCHECKBOX_H 2 | #define QTMATERIALCHECKBOX_H 3 | 4 | #include "components/lib/qtmaterialcheckable.h" 5 | 6 | class QtMaterialCheckBoxPrivate; 7 | 8 | class QtMaterialCheckBox : public QtMaterialCheckable 9 | { 10 | Q_OBJECT 11 | 12 | public: 13 | explicit QtMaterialCheckBox(QWidget *parent = 0); 14 | ~QtMaterialCheckBox(); 15 | 16 | private: 17 | Q_DISABLE_COPY(QtMaterialCheckBox) 18 | Q_DECLARE_PRIVATE(QtMaterialCheckBox) 19 | }; 20 | 21 | #endif // QTMATERIALCHECKBOX_H 22 | -------------------------------------------------------------------------------- /components/qtmaterialcheckbox_p.h: -------------------------------------------------------------------------------- 1 | #ifndef QTMATERIALCHECKBOX_P_H 2 | #define QTMATERIALCHECKBOX_P_H 3 | 4 | #include "components/lib/qtmaterialcheckable_p.h" 5 | 6 | class QtMaterialCheckBox; 7 | 8 | class QtMaterialCheckBoxPrivate : public QtMaterialCheckablePrivate 9 | { 10 | Q_DISABLE_COPY(QtMaterialCheckBoxPrivate) 11 | Q_DECLARE_PUBLIC(QtMaterialCheckBox) 12 | 13 | public: 14 | QtMaterialCheckBoxPrivate(QtMaterialCheckBox *q); 15 | ~QtMaterialCheckBoxPrivate(); 16 | 17 | void init(); 18 | }; 19 | 20 | #endif // QTMATERIALCHECKBOX_P_H 21 | -------------------------------------------------------------------------------- /components/qtmaterialcircularprogress.h: -------------------------------------------------------------------------------- 1 | #ifndef QTMATERIALCIRCULARPROGRESS_H 2 | #define QTMATERIALCIRCULARPROGRESS_H 3 | 4 | #include 5 | #include "components/lib/qtmaterialtheme.h" 6 | 7 | class QtMaterialCircularProgressPrivate; 8 | 9 | class QtMaterialCircularProgress : public QProgressBar 10 | { 11 | Q_OBJECT 12 | 13 | Q_PROPERTY(qreal lineWidth WRITE setLineWidth READ lineWidth) 14 | Q_PROPERTY(qreal size WRITE setSize READ size) 15 | Q_PROPERTY(QColor color WRITE setColor READ color) 16 | 17 | public: 18 | explicit QtMaterialCircularProgress(QWidget *parent = 0); 19 | ~QtMaterialCircularProgress(); 20 | 21 | void setProgressType(Material::ProgressType type); 22 | Material::ProgressType progressType() const; 23 | 24 | void setUseThemeColors(bool value); 25 | bool useThemeColors() const; 26 | 27 | void setLineWidth(qreal width); 28 | qreal lineWidth() const; 29 | 30 | void setSize(int size); 31 | int size() const; 32 | 33 | void setColor(const QColor &color); 34 | QColor color() const; 35 | 36 | QSize sizeHint() const Q_DECL_OVERRIDE; 37 | 38 | protected: 39 | void paintEvent(QPaintEvent *event) Q_DECL_OVERRIDE; 40 | 41 | const QScopedPointer d_ptr; 42 | 43 | private: 44 | Q_DISABLE_COPY(QtMaterialCircularProgress) 45 | Q_DECLARE_PRIVATE(QtMaterialCircularProgress) 46 | }; 47 | 48 | #endif // QTMATERIALCIRCULARPROGRESS_H 49 | -------------------------------------------------------------------------------- /components/qtmaterialcircularprogress_internal.cpp: -------------------------------------------------------------------------------- 1 | #include "qtmaterialcircularprogress_internal.h" 2 | 3 | /*! 4 | * \class QtMaterialCircularProgressDelegate 5 | * \internal 6 | */ 7 | 8 | QtMaterialCircularProgressDelegate::QtMaterialCircularProgressDelegate(QtMaterialCircularProgress *parent) 9 | : QObject(parent), 10 | m_progress(parent), 11 | m_dashOffset(0), 12 | m_dashLength(89), 13 | m_angle(0) 14 | { 15 | Q_ASSERT(parent); 16 | } 17 | 18 | QtMaterialCircularProgressDelegate::~QtMaterialCircularProgressDelegate() 19 | { 20 | } 21 | -------------------------------------------------------------------------------- /components/qtmaterialcircularprogress_internal.h: -------------------------------------------------------------------------------- 1 | #ifndef QTMATERIALCIRCULARPROGRESS_INTERNAL_H 2 | #define QTMATERIALCIRCULARPROGRESS_INTERNAL_H 3 | 4 | #include 5 | #include "qtmaterialcircularprogress.h" 6 | 7 | class QtMaterialCircularProgressDelegate : public QObject 8 | { 9 | Q_OBJECT 10 | 11 | Q_PROPERTY(qreal dashOffset WRITE setDashOffset READ dashOffset) 12 | Q_PROPERTY(qreal dashLength WRITE setDashLength READ dashLength) 13 | Q_PROPERTY(int angle WRITE setAngle READ angle) 14 | 15 | public: 16 | QtMaterialCircularProgressDelegate(QtMaterialCircularProgress *parent); 17 | ~QtMaterialCircularProgressDelegate(); 18 | 19 | inline void setDashOffset(qreal offset); 20 | inline qreal dashOffset() const; 21 | 22 | inline void setDashLength(qreal length); 23 | inline qreal dashLength() const; 24 | 25 | inline void setAngle(int angle); 26 | inline int angle() const; 27 | 28 | private: 29 | Q_DISABLE_COPY(QtMaterialCircularProgressDelegate) 30 | 31 | QtMaterialCircularProgress *const m_progress; 32 | qreal m_dashOffset; 33 | qreal m_dashLength; 34 | int m_angle; 35 | }; 36 | 37 | inline void QtMaterialCircularProgressDelegate::setDashOffset(qreal offset) 38 | { 39 | m_dashOffset = offset; 40 | m_progress->update(); 41 | } 42 | 43 | inline qreal QtMaterialCircularProgressDelegate::dashOffset() const 44 | { 45 | return m_dashOffset; 46 | } 47 | 48 | inline void QtMaterialCircularProgressDelegate::setDashLength(qreal length) 49 | { 50 | m_dashLength = length; 51 | m_progress->update(); 52 | } 53 | 54 | inline qreal QtMaterialCircularProgressDelegate::dashLength() const 55 | { 56 | return m_dashLength; 57 | } 58 | 59 | inline void QtMaterialCircularProgressDelegate::setAngle(int angle) 60 | { 61 | m_angle = angle; 62 | m_progress->update(); 63 | } 64 | 65 | inline int QtMaterialCircularProgressDelegate::angle() const 66 | { 67 | return m_angle; 68 | } 69 | 70 | #endif // QTMATERIALCIRCULARPROGRESS_INTERNAL_H 71 | -------------------------------------------------------------------------------- /components/qtmaterialcircularprogress_p.h: -------------------------------------------------------------------------------- 1 | #ifndef QTMATERIALCIRCULARPROGRESS_P_H 2 | #define QTMATERIALCIRCULARPROGRESS_P_H 3 | 4 | #include 5 | #include "components/lib/qtmaterialtheme.h" 6 | 7 | class QtMaterialCircularProgress; 8 | class QtMaterialCircularProgressDelegate; 9 | 10 | class QtMaterialCircularProgressPrivate 11 | { 12 | Q_DISABLE_COPY(QtMaterialCircularProgressPrivate) 13 | Q_DECLARE_PUBLIC(QtMaterialCircularProgress) 14 | 15 | public: 16 | QtMaterialCircularProgressPrivate(QtMaterialCircularProgress *q); 17 | ~QtMaterialCircularProgressPrivate(); 18 | 19 | void init(); 20 | 21 | QtMaterialCircularProgress *const q_ptr; 22 | QtMaterialCircularProgressDelegate *delegate; 23 | Material::ProgressType progressType; 24 | QColor color; 25 | qreal penWidth; 26 | int size; 27 | bool useThemeColors; 28 | }; 29 | 30 | #endif // QTMATERIALCIRCULARPROGRESS_P_H 31 | -------------------------------------------------------------------------------- /components/qtmaterialdialog.cpp: -------------------------------------------------------------------------------- 1 | #include "qtmaterialdialog.h" 2 | #include "qtmaterialdialog_p.h" 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include "qtmaterialdialog_internal.h" 11 | #include "components/lib/qtmaterialstatetransition.h" 12 | 13 | /*! 14 | * \class QtMaterialDialogPrivate 15 | * \internal 16 | */ 17 | 18 | QtMaterialDialogPrivate::QtMaterialDialogPrivate(QtMaterialDialog *q) 19 | : q_ptr(q) 20 | { 21 | } 22 | 23 | QtMaterialDialogPrivate::~QtMaterialDialogPrivate() 24 | { 25 | } 26 | 27 | void QtMaterialDialogPrivate::init() 28 | { 29 | Q_Q(QtMaterialDialog); 30 | 31 | dialogWindow = new QtMaterialDialogWindow(q); 32 | proxyStack = new QStackedLayout; 33 | stateMachine = new QStateMachine(q); 34 | proxy = new QtMaterialDialogProxy(dialogWindow, proxyStack, q); 35 | 36 | QVBoxLayout *layout = new QVBoxLayout; 37 | q->setLayout(layout); 38 | 39 | QWidget *widget = new QWidget; 40 | widget->setLayout(proxyStack); 41 | widget->setMinimumWidth(400); 42 | 43 | QGraphicsDropShadowEffect *effect = new QGraphicsDropShadowEffect; 44 | effect->setColor(QColor(0, 0, 0, 200)); 45 | effect->setBlurRadius(64); 46 | effect->setOffset(0, 13); 47 | widget->setGraphicsEffect(effect); 48 | 49 | layout->addWidget(widget); 50 | layout->setAlignment(widget, Qt::AlignCenter); 51 | 52 | proxyStack->addWidget(dialogWindow); 53 | proxyStack->addWidget(proxy); 54 | proxyStack->setCurrentIndex(1); 55 | 56 | q->setAttribute(Qt::WA_TransparentForMouseEvents); 57 | 58 | QState *hiddenState = new QState; 59 | QState *visibleState = new QState; 60 | 61 | stateMachine->addState(hiddenState); 62 | stateMachine->addState(visibleState); 63 | stateMachine->setInitialState(hiddenState); 64 | 65 | QtMaterialStateTransition *transition; 66 | 67 | transition = new QtMaterialStateTransition(DialogShowTransition); 68 | transition->setTargetState(visibleState); 69 | hiddenState->addTransition(transition); 70 | 71 | transition = new QtMaterialStateTransition(DialogHideTransition); 72 | transition->setTargetState(hiddenState); 73 | visibleState->addTransition(transition); 74 | 75 | visibleState->assignProperty(proxy, "opacity", 1); 76 | visibleState->assignProperty(effect, "color", QColor(0, 0, 0, 200)); 77 | visibleState->assignProperty(dialogWindow, "offset", 0); 78 | hiddenState->assignProperty(proxy, "opacity", 0); 79 | hiddenState->assignProperty(effect, "color", QColor(0, 0, 0, 0)); 80 | hiddenState->assignProperty(dialogWindow, "offset", 200); 81 | 82 | QPropertyAnimation *animation; 83 | 84 | animation = new QPropertyAnimation(proxy, "opacity", q); 85 | animation->setDuration(280); 86 | stateMachine->addDefaultAnimation(animation); 87 | 88 | animation = new QPropertyAnimation(effect, "color", q); 89 | animation->setDuration(280); 90 | stateMachine->addDefaultAnimation(animation); 91 | 92 | animation = new QPropertyAnimation(dialogWindow, "offset", q); 93 | animation->setDuration(280); 94 | animation->setEasingCurve(QEasingCurve::OutCirc); 95 | stateMachine->addDefaultAnimation(animation); 96 | 97 | QObject::connect(visibleState, SIGNAL(propertiesAssigned()), 98 | proxy, SLOT(makeOpaque())); 99 | QObject::connect(hiddenState, SIGNAL(propertiesAssigned()), 100 | proxy, SLOT(makeTransparent())); 101 | 102 | stateMachine->start(); 103 | QCoreApplication::processEvents(); 104 | } 105 | 106 | /*! 107 | * \class QtMaterialDialog 108 | */ 109 | 110 | QtMaterialDialog::QtMaterialDialog(QWidget *parent) 111 | : QtMaterialOverlayWidget(parent), 112 | d_ptr(new QtMaterialDialogPrivate(this)) 113 | { 114 | d_func()->init(); 115 | } 116 | 117 | QtMaterialDialog::~QtMaterialDialog() 118 | { 119 | } 120 | 121 | QLayout *QtMaterialDialog::windowLayout() const 122 | { 123 | Q_D(const QtMaterialDialog); 124 | 125 | return d->dialogWindow->layout(); 126 | } 127 | 128 | void QtMaterialDialog::setWindowLayout(QLayout *layout) 129 | { 130 | Q_D(QtMaterialDialog); 131 | 132 | d->dialogWindow->setLayout(layout); 133 | } 134 | 135 | void QtMaterialDialog::showDialog() 136 | { 137 | Q_D(QtMaterialDialog); 138 | 139 | d->stateMachine->postEvent(new QtMaterialStateTransitionEvent(DialogShowTransition)); 140 | raise(); 141 | } 142 | 143 | void QtMaterialDialog::hideDialog() 144 | { 145 | Q_D(QtMaterialDialog); 146 | 147 | d->stateMachine->postEvent(new QtMaterialStateTransitionEvent(DialogHideTransition)); 148 | setAttribute(Qt::WA_TransparentForMouseEvents); 149 | d->proxyStack->setCurrentIndex(1); 150 | } 151 | 152 | void QtMaterialDialog::paintEvent(QPaintEvent *event) 153 | { 154 | Q_UNUSED(event) 155 | 156 | Q_D(QtMaterialDialog); 157 | 158 | QPainter painter(this); 159 | 160 | QBrush brush; 161 | brush.setStyle(Qt::SolidPattern); 162 | brush.setColor(Qt::black); 163 | painter.setBrush(brush); 164 | painter.setPen(Qt::NoPen); 165 | painter.setOpacity(d->proxy->opacity()/2.4); 166 | painter.drawRect(rect()); 167 | } 168 | -------------------------------------------------------------------------------- /components/qtmaterialdialog.h: -------------------------------------------------------------------------------- 1 | #ifndef QTMATERIALDIALOG_H 2 | #define QTMATERIALDIALOG_H 3 | 4 | #include 5 | #include "components/lib/qtmaterialoverlaywidget.h" 6 | 7 | class QLayout; 8 | class QtMaterialDialogPrivate; 9 | 10 | class QtMaterialDialog : public QtMaterialOverlayWidget 11 | { 12 | Q_OBJECT 13 | 14 | public: 15 | explicit QtMaterialDialog(QWidget *parent = 0); 16 | ~QtMaterialDialog(); 17 | 18 | QLayout *windowLayout() const; 19 | void setWindowLayout(QLayout *layout); 20 | 21 | public slots: 22 | void showDialog(); 23 | void hideDialog(); 24 | 25 | protected: 26 | void paintEvent(QPaintEvent *event) Q_DECL_OVERRIDE; 27 | 28 | const QScopedPointer d_ptr; 29 | 30 | private: 31 | Q_DISABLE_COPY(QtMaterialDialog) 32 | Q_DECLARE_PRIVATE(QtMaterialDialog) 33 | }; 34 | 35 | #endif // QTMATERIALDIALOG_H 36 | -------------------------------------------------------------------------------- /components/qtmaterialdialog_internal.cpp: -------------------------------------------------------------------------------- 1 | #include "qtmaterialdialog_internal.h" 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include "qtmaterialdialog.h" 7 | 8 | /*! 9 | * \class QtMaterialDialogProxy 10 | * \internal 11 | */ 12 | 13 | QtMaterialDialogProxy::QtMaterialDialogProxy( 14 | QtMaterialDialogWindow *source, 15 | QStackedLayout *layout, 16 | QtMaterialDialog *dialog, 17 | QWidget *parent) 18 | : QWidget(parent), 19 | m_source(source), 20 | m_layout(layout), 21 | m_dialog(dialog), 22 | m_opacity(0), 23 | m_mode(Transparent) 24 | { 25 | } 26 | 27 | QtMaterialDialogProxy::~QtMaterialDialogProxy() 28 | { 29 | } 30 | 31 | void QtMaterialDialogProxy::setOpacity(qreal opacity) 32 | { 33 | m_opacity = opacity; 34 | m_mode = SemiTransparent; 35 | update(); 36 | m_dialog->update(); 37 | } 38 | 39 | 40 | void QtMaterialDialogProxy::makeOpaque() 41 | { 42 | m_dialog->setAttribute(Qt::WA_TransparentForMouseEvents, false); 43 | m_layout->setCurrentIndex(0); 44 | m_opacity = 1.0; 45 | m_mode = Opaque; 46 | update(); 47 | } 48 | 49 | void QtMaterialDialogProxy::makeTransparent() 50 | { 51 | m_opacity = 0.0; 52 | m_mode = Transparent; 53 | update(); 54 | } 55 | 56 | QSize QtMaterialDialogProxy::sizeHint() const 57 | { 58 | return m_source->sizeHint(); 59 | } 60 | 61 | bool QtMaterialDialogProxy::event(QEvent *event) 62 | { 63 | const QEvent::Type type = event->type(); 64 | 65 | if (QEvent::Move == type || QEvent::Resize == type) { 66 | m_source->setGeometry(geometry()); 67 | } 68 | return QWidget::event(event); 69 | } 70 | 71 | void QtMaterialDialogProxy::paintEvent(QPaintEvent *event) 72 | { 73 | Q_UNUSED(event) 74 | 75 | QPainter painter(this); 76 | 77 | if (Transparent == m_mode) { 78 | return; 79 | } else if (Opaque != m_mode) { 80 | painter.setOpacity(m_opacity); 81 | } 82 | QPixmap pm = m_source->grab(m_source->rect()); 83 | painter.drawPixmap(0, 0, pm); 84 | } 85 | 86 | /*! 87 | * \class QtMaterialDialogWindow 88 | * \internal 89 | */ 90 | 91 | QtMaterialDialogWindow::QtMaterialDialogWindow( 92 | QtMaterialDialog *dialog, 93 | QWidget *parent) 94 | : QWidget(parent), 95 | m_dialog(dialog) 96 | { 97 | } 98 | 99 | QtMaterialDialogWindow::~QtMaterialDialogWindow() 100 | { 101 | } 102 | 103 | void QtMaterialDialogWindow::setOffset(int offset) 104 | { 105 | QMargins margins = m_dialog->layout()->contentsMargins(); 106 | margins.setBottom(offset); 107 | m_dialog->layout()->setContentsMargins(margins); 108 | } 109 | 110 | int QtMaterialDialogWindow::offset() const 111 | { 112 | return m_dialog->layout()->contentsMargins().bottom(); 113 | } 114 | 115 | void QtMaterialDialogWindow::paintEvent(QPaintEvent *event) 116 | { 117 | Q_UNUSED(event) 118 | 119 | QPainter painter(this); 120 | 121 | QBrush brush; 122 | brush.setStyle(Qt::SolidPattern); 123 | brush.setColor(Qt::white); 124 | painter.setPen(Qt::NoPen); 125 | painter.setBrush(brush); 126 | painter.drawRect(rect()); 127 | } 128 | -------------------------------------------------------------------------------- /components/qtmaterialdialog_internal.h: -------------------------------------------------------------------------------- 1 | #ifndef QTMATERIALDIALOG_INTERNAL_H 2 | #define QTMATERIALDIALOG_INTERNAL_H 3 | 4 | #include 5 | 6 | class QStackedLayout; 7 | class QtMaterialDialog; 8 | class QtMaterialDialogWindow; 9 | 10 | class QtMaterialDialogProxy : public QWidget 11 | { 12 | Q_OBJECT 13 | 14 | Q_PROPERTY(qreal opacity WRITE setOpacity READ opacity) 15 | 16 | enum TransparencyMode { 17 | Transparent, 18 | SemiTransparent, 19 | Opaque, 20 | }; 21 | 22 | public: 23 | QtMaterialDialogProxy(QtMaterialDialogWindow *source, 24 | QStackedLayout *layout, 25 | QtMaterialDialog *dialog, 26 | QWidget *parent = 0); 27 | ~QtMaterialDialogProxy(); 28 | 29 | void setOpacity(qreal opacity); 30 | inline qreal opacity() const; 31 | 32 | protected slots: 33 | void makeOpaque(); 34 | void makeTransparent(); 35 | 36 | QSize sizeHint() const Q_DECL_OVERRIDE; 37 | 38 | protected: 39 | bool event(QEvent *event) Q_DECL_OVERRIDE; 40 | void paintEvent(QPaintEvent *event) Q_DECL_OVERRIDE; 41 | 42 | private: 43 | Q_DISABLE_COPY(QtMaterialDialogProxy) 44 | 45 | QtMaterialDialogWindow *const m_source; 46 | QStackedLayout *const m_layout; 47 | QtMaterialDialog *const m_dialog; 48 | qreal m_opacity; 49 | TransparencyMode m_mode; 50 | }; 51 | 52 | inline qreal QtMaterialDialogProxy::opacity() const 53 | { 54 | return m_opacity; 55 | } 56 | 57 | class QtMaterialDialogWindow : public QWidget 58 | { 59 | Q_OBJECT 60 | 61 | Q_PROPERTY(int offset WRITE setOffset READ offset) 62 | 63 | public: 64 | explicit QtMaterialDialogWindow(QtMaterialDialog *dialog, QWidget *parent = 0); 65 | ~QtMaterialDialogWindow(); 66 | 67 | void setOffset(int offset); 68 | int offset() const; 69 | 70 | protected: 71 | void paintEvent(QPaintEvent *event) Q_DECL_OVERRIDE; 72 | 73 | private: 74 | Q_DISABLE_COPY(QtMaterialDialogWindow) 75 | 76 | QtMaterialDialog *const m_dialog; 77 | }; 78 | 79 | #endif // QTMATERIALDIALOG_INTERNAL_H 80 | -------------------------------------------------------------------------------- /components/qtmaterialdialog_p.h: -------------------------------------------------------------------------------- 1 | #ifndef QTMATERIALDIALOG_P_H 2 | #define QTMATERIALDIALOG_P_H 3 | 4 | #include 5 | 6 | class QStateMachine; 7 | class QtMaterialDialog; 8 | class QStackedLayout; 9 | class QtMaterialDialogWindow; 10 | class QtMaterialDialogProxy; 11 | 12 | class QtMaterialDialogPrivate 13 | { 14 | Q_DISABLE_COPY(QtMaterialDialogPrivate) 15 | Q_DECLARE_PUBLIC(QtMaterialDialog) 16 | 17 | public: 18 | QtMaterialDialogPrivate(QtMaterialDialog *q); 19 | ~QtMaterialDialogPrivate(); 20 | 21 | void init(); 22 | 23 | QtMaterialDialog *const q_ptr; 24 | QtMaterialDialogWindow *dialogWindow; 25 | QStackedLayout *proxyStack; 26 | QStateMachine *stateMachine; 27 | QtMaterialDialogProxy *proxy; 28 | }; 29 | 30 | #endif // QTMATERIALDIALOG_P_H 31 | -------------------------------------------------------------------------------- /components/qtmaterialdrawer.cpp: -------------------------------------------------------------------------------- 1 | #include "qtmaterialdrawer.h" 2 | #include "qtmaterialdrawer_p.h" 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include "qtmaterialdrawer_internal.h" 12 | 13 | /*! 14 | * \class QtMaterialDrawerPrivate 15 | * \internal 16 | */ 17 | 18 | /*! 19 | * \internal 20 | */ 21 | QtMaterialDrawerPrivate::QtMaterialDrawerPrivate(QtMaterialDrawer *q) 22 | : q_ptr(q) 23 | { 24 | } 25 | 26 | /*! 27 | * \internal 28 | */ 29 | QtMaterialDrawerPrivate::~QtMaterialDrawerPrivate() 30 | { 31 | } 32 | 33 | /*! 34 | * \internal 35 | */ 36 | void QtMaterialDrawerPrivate::init() 37 | { 38 | Q_Q(QtMaterialDrawer); 39 | 40 | widget = new QtMaterialDrawerWidget; 41 | stateMachine = new QtMaterialDrawerStateMachine(widget, q); 42 | window = new QWidget; 43 | width = 250; 44 | clickToClose = false; 45 | autoRaise = true; 46 | closed = true; 47 | overlay = false; 48 | 49 | QVBoxLayout *layout = new QVBoxLayout; 50 | layout->addWidget(window); 51 | 52 | widget->setLayout(layout); 53 | widget->setFixedWidth(width+16); 54 | 55 | widget->setParent(q); 56 | 57 | stateMachine->start(); 58 | QCoreApplication::processEvents(); 59 | } 60 | 61 | /*! 62 | * \class QtMaterialDrawer 63 | */ 64 | 65 | QtMaterialDrawer::QtMaterialDrawer(QWidget *parent) 66 | : QtMaterialOverlayWidget(parent), 67 | d_ptr(new QtMaterialDrawerPrivate(this)) 68 | { 69 | d_func()->init(); 70 | } 71 | 72 | QtMaterialDrawer::~QtMaterialDrawer() 73 | { 74 | } 75 | 76 | void QtMaterialDrawer::setDrawerWidth(int width) 77 | { 78 | Q_D(QtMaterialDrawer); 79 | 80 | d->width = width; 81 | d->stateMachine->updatePropertyAssignments(); 82 | d->widget->setFixedWidth(width+16); 83 | } 84 | 85 | int QtMaterialDrawer::drawerWidth() const 86 | { 87 | Q_D(const QtMaterialDrawer); 88 | 89 | return d->width; 90 | } 91 | 92 | void QtMaterialDrawer::setDrawerLayout(QLayout *layout) 93 | { 94 | Q_D(QtMaterialDrawer); 95 | 96 | d->window->setLayout(layout); 97 | } 98 | 99 | QLayout *QtMaterialDrawer::drawerLayout() const 100 | { 101 | Q_D(const QtMaterialDrawer); 102 | 103 | return d->window->layout(); 104 | } 105 | 106 | void QtMaterialDrawer::setClickOutsideToClose(bool state) 107 | { 108 | Q_D(QtMaterialDrawer); 109 | 110 | d->clickToClose = state; 111 | } 112 | 113 | bool QtMaterialDrawer::clickOutsideToClose() const 114 | { 115 | Q_D(const QtMaterialDrawer); 116 | 117 | return d->clickToClose; 118 | } 119 | 120 | void QtMaterialDrawer::setAutoRaise(bool state) 121 | { 122 | Q_D(QtMaterialDrawer); 123 | 124 | d->autoRaise = state; 125 | } 126 | 127 | bool QtMaterialDrawer::autoRaise() const 128 | { 129 | Q_D(const QtMaterialDrawer); 130 | 131 | return d->autoRaise; 132 | } 133 | 134 | void QtMaterialDrawer::setOverlayMode(bool value) 135 | { 136 | Q_D(QtMaterialDrawer); 137 | 138 | d->overlay = value; 139 | update(); 140 | } 141 | 142 | bool QtMaterialDrawer::overlayMode() const 143 | { 144 | Q_D(const QtMaterialDrawer); 145 | 146 | return d->overlay; 147 | } 148 | 149 | void QtMaterialDrawer::openDrawer() 150 | { 151 | Q_D(QtMaterialDrawer); 152 | 153 | emit d->stateMachine->signalOpen(); 154 | 155 | if (d->autoRaise) { 156 | raise(); 157 | } 158 | setAttribute(Qt::WA_TransparentForMouseEvents, false); 159 | setAttribute(Qt::WA_NoSystemBackground, false); 160 | } 161 | 162 | void QtMaterialDrawer::closeDrawer() 163 | { 164 | Q_D(QtMaterialDrawer); 165 | 166 | emit d->stateMachine->signalClose(); 167 | 168 | if (d->overlay) { 169 | setAttribute(Qt::WA_TransparentForMouseEvents); 170 | setAttribute(Qt::WA_NoSystemBackground); 171 | } 172 | } 173 | 174 | bool QtMaterialDrawer::event(QEvent *event) 175 | { 176 | Q_D(QtMaterialDrawer); 177 | 178 | switch (event->type()) 179 | { 180 | case QEvent::Move: 181 | case QEvent::Resize: 182 | if (!d->overlay) { 183 | setMask(QRegion(d->widget->rect())); 184 | } 185 | break; 186 | default: 187 | break; 188 | } 189 | return QtMaterialOverlayWidget::event(event); 190 | } 191 | 192 | bool QtMaterialDrawer::eventFilter(QObject *obj, QEvent *event) 193 | { 194 | Q_D(QtMaterialDrawer); 195 | 196 | switch (event->type()) 197 | { 198 | case QEvent::MouseButtonPress: { 199 | QMouseEvent *mouseEvent; 200 | if ((mouseEvent = static_cast(event))) { 201 | const bool canClose = d->clickToClose || d->overlay; 202 | if (!d->widget->geometry().contains(mouseEvent->pos()) && canClose) { 203 | closeDrawer(); 204 | } 205 | } 206 | break; 207 | } 208 | case QEvent::Move: 209 | case QEvent::Resize: { 210 | QLayout *lw = d->widget->layout(); 211 | if (lw && 16 != lw->contentsMargins().right()) { 212 | lw->setContentsMargins(0, 0, 16, 0); 213 | } 214 | break; 215 | } 216 | default: 217 | break; 218 | } 219 | return QtMaterialOverlayWidget::eventFilter(obj, event); 220 | } 221 | 222 | void QtMaterialDrawer::paintEvent(QPaintEvent *event) 223 | { 224 | Q_UNUSED(event) 225 | 226 | Q_D(QtMaterialDrawer); 227 | 228 | if (!d->overlay || d->stateMachine->isInClosedState()) { 229 | return; 230 | } 231 | QPainter painter(this); 232 | painter.setOpacity(d->stateMachine->opacity()); 233 | painter.fillRect(rect(), Qt::SolidPattern); 234 | } 235 | -------------------------------------------------------------------------------- /components/qtmaterialdrawer.h: -------------------------------------------------------------------------------- 1 | #ifndef QTMATERIALDRAWER_H 2 | #define QTMATERIALDRAWER_H 3 | 4 | #include "components/lib/qtmaterialoverlaywidget.h" 5 | 6 | class QtMaterialDrawerPrivate; 7 | class QtMaterialDrawerStateMachine; 8 | 9 | class QtMaterialDrawer : public QtMaterialOverlayWidget 10 | { 11 | Q_OBJECT 12 | 13 | public: 14 | explicit QtMaterialDrawer(QWidget *parent = 0); 15 | ~QtMaterialDrawer(); 16 | 17 | void setDrawerWidth(int width); 18 | int drawerWidth() const; 19 | 20 | void setDrawerLayout(QLayout *layout); 21 | QLayout *drawerLayout() const; 22 | 23 | void setClickOutsideToClose(bool state); 24 | bool clickOutsideToClose() const; 25 | 26 | void setAutoRaise(bool state); 27 | bool autoRaise() const; 28 | 29 | void setOverlayMode(bool value); 30 | bool overlayMode() const; 31 | 32 | public slots: 33 | void openDrawer(); 34 | void closeDrawer(); 35 | 36 | protected: 37 | bool event(QEvent *event) Q_DECL_OVERRIDE; 38 | bool eventFilter(QObject *obj, QEvent *event) Q_DECL_OVERRIDE; 39 | void paintEvent(QPaintEvent *event) Q_DECL_OVERRIDE; 40 | 41 | const QScopedPointer d_ptr; 42 | 43 | private: 44 | Q_DISABLE_COPY(QtMaterialDrawer) 45 | Q_DECLARE_PRIVATE(QtMaterialDrawer) 46 | }; 47 | 48 | #endif // QTMATERIALDRAWER_H 49 | -------------------------------------------------------------------------------- /components/qtmaterialdrawer_internal.cpp: -------------------------------------------------------------------------------- 1 | #include "qtmaterialdrawer_internal.h" 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include "qtmaterialdrawer.h" 8 | 9 | /*! 10 | * \class QtMaterialDrawerStateMachine 11 | * \internal 12 | */ 13 | 14 | QtMaterialDrawerStateMachine::QtMaterialDrawerStateMachine(QtMaterialDrawerWidget *drawer, QtMaterialDrawer *parent) 15 | : QStateMachine(parent), 16 | m_drawer(drawer), 17 | m_main(parent), 18 | m_openingState(new QState), 19 | m_openedState(new QState), 20 | m_closingState(new QState), 21 | m_closedState(new QState), 22 | m_opacity(0) 23 | { 24 | addState(m_openingState); 25 | addState(m_openedState); 26 | addState(m_closingState); 27 | addState(m_closedState); 28 | 29 | setInitialState(m_closedState); 30 | 31 | QSignalTransition *transition; 32 | QPropertyAnimation *animation; 33 | 34 | transition = new QSignalTransition(this, SIGNAL(signalOpen())); 35 | transition->setTargetState(m_openingState); 36 | m_closedState->addTransition(transition); 37 | 38 | animation = new QPropertyAnimation(drawer, "offset", this); 39 | animation->setDuration(220); 40 | animation->setEasingCurve(QEasingCurve::OutCirc); 41 | transition->addAnimation(animation); 42 | 43 | animation = new QPropertyAnimation(this, "opacity", this); 44 | animation->setDuration(220); 45 | transition->addAnimation(animation); 46 | 47 | transition = new QSignalTransition(animation, SIGNAL(finished())); 48 | transition->setTargetState(m_openedState); 49 | m_openingState->addTransition(transition); 50 | 51 | transition = new QSignalTransition(this, SIGNAL(signalClose())); 52 | transition->setTargetState(m_closingState); 53 | m_openingState->addTransition(transition); 54 | 55 | animation = new QPropertyAnimation(this, "opacity", this); 56 | animation->setDuration(220); 57 | transition->addAnimation(animation); 58 | 59 | animation = new QPropertyAnimation(drawer, "offset", this); 60 | animation->setDuration(220); 61 | animation->setEasingCurve(QEasingCurve::InCirc); 62 | transition->addAnimation(animation); 63 | 64 | transition = new QSignalTransition(animation, SIGNAL(finished())); 65 | transition->setTargetState(m_closedState); 66 | m_closingState->addTransition(transition); 67 | 68 | transition = new QSignalTransition(this, SIGNAL(signalClose())); 69 | transition->setTargetState(m_closingState); 70 | m_openedState->addTransition(transition); 71 | 72 | animation = new QPropertyAnimation(drawer, "offset", this); 73 | animation->setDuration(220); 74 | animation->setEasingCurve(QEasingCurve::InCirc); 75 | transition->addAnimation(animation); 76 | 77 | animation = new QPropertyAnimation(this, "opacity", this); 78 | animation->setDuration(220); 79 | transition->addAnimation(animation); 80 | 81 | transition = new QSignalTransition(animation, SIGNAL(finished())); 82 | transition->setTargetState(m_closedState); 83 | m_closingState->addTransition(transition); 84 | 85 | updatePropertyAssignments(); 86 | } 87 | 88 | QtMaterialDrawerStateMachine::~QtMaterialDrawerStateMachine() 89 | { 90 | } 91 | 92 | void QtMaterialDrawerStateMachine::setOpacity(qreal opacity) 93 | { 94 | m_opacity = opacity; 95 | m_main->update(); 96 | } 97 | 98 | bool QtMaterialDrawerStateMachine::isInClosedState() const 99 | { 100 | return m_closedState->active(); 101 | } 102 | 103 | void QtMaterialDrawerStateMachine::updatePropertyAssignments() 104 | { 105 | const qreal closedOffset = -(m_drawer->width()+32); 106 | 107 | m_closingState->assignProperty(m_drawer, "offset", closedOffset); 108 | m_closedState->assignProperty(m_drawer, "offset", closedOffset); 109 | 110 | m_closingState->assignProperty(this, "opacity", 0); 111 | m_closedState->assignProperty(this, "opacity", 0); 112 | 113 | m_openingState->assignProperty(m_drawer, "offset", 0); 114 | m_openingState->assignProperty(this, "opacity", 0.4); 115 | } 116 | 117 | /*! 118 | * \class QtMaterialDrawerWidget 119 | * \internal 120 | */ 121 | 122 | QtMaterialDrawerWidget::QtMaterialDrawerWidget(QWidget *parent) 123 | : QtMaterialOverlayWidget(parent), 124 | m_offset(0) 125 | { 126 | } 127 | 128 | QtMaterialDrawerWidget::~QtMaterialDrawerWidget() 129 | { 130 | } 131 | 132 | void QtMaterialDrawerWidget::setOffset(int offset) 133 | { 134 | m_offset = offset; 135 | 136 | QWidget *widget = parentWidget(); 137 | if (widget) { 138 | setGeometry(widget->rect().translated(offset, 0)); 139 | } 140 | update(); 141 | } 142 | 143 | void QtMaterialDrawerWidget::paintEvent(QPaintEvent *event) 144 | { 145 | Q_UNUSED(event) 146 | 147 | QPainter painter(this); 148 | 149 | QBrush brush; 150 | brush.setStyle(Qt::SolidPattern); 151 | brush.setColor(Qt::white); 152 | painter.setBrush(brush); 153 | painter.setPen(Qt::NoPen); 154 | 155 | painter.drawRect(rect().adjusted(0, 0, -16, 0)); 156 | 157 | QLinearGradient gradient(QPointF(width()-16, 0), QPointF(width(), 0)); 158 | gradient.setColorAt(0, QColor(0, 0, 0, 80)); 159 | gradient.setColorAt(0.5, QColor(0, 0, 0, 20)); 160 | gradient.setColorAt(1, QColor(0, 0, 0, 0)); 161 | painter.setBrush(QBrush(gradient)); 162 | 163 | painter.drawRect(width()-16, 0, 16, height()); 164 | } 165 | 166 | QRect QtMaterialDrawerWidget::overlayGeometry() const 167 | { 168 | return QtMaterialOverlayWidget::overlayGeometry().translated(m_offset, 0); 169 | } 170 | -------------------------------------------------------------------------------- /components/qtmaterialdrawer_internal.h: -------------------------------------------------------------------------------- 1 | #ifndef DRAWER_INTERNAL_H 2 | #define DRAWER_INTERNAL_H 3 | 4 | #include 5 | #include "components/lib/qtmaterialoverlaywidget.h" 6 | 7 | class QtMaterialDrawer; 8 | class QtMaterialDrawerWidget; 9 | 10 | class QtMaterialDrawerStateMachine : public QStateMachine 11 | { 12 | Q_OBJECT 13 | 14 | Q_PROPERTY(qreal opacity WRITE setOpacity READ opacity) 15 | 16 | public: 17 | explicit QtMaterialDrawerStateMachine(QtMaterialDrawerWidget *drawer, 18 | QtMaterialDrawer *parent); 19 | ~QtMaterialDrawerStateMachine(); 20 | 21 | void setOpacity(qreal opacity); 22 | inline qreal opacity() const; 23 | 24 | bool isInClosedState() const; 25 | 26 | void updatePropertyAssignments(); 27 | 28 | signals: 29 | void signalOpen(); 30 | void signalClose(); 31 | 32 | private: 33 | Q_DISABLE_COPY(QtMaterialDrawerStateMachine) 34 | 35 | QtMaterialDrawerWidget *const m_drawer; 36 | QtMaterialDrawer *const m_main; 37 | QState *const m_openingState; 38 | QState *const m_openedState; 39 | QState *const m_closingState; 40 | QState *const m_closedState; 41 | qreal m_opacity; 42 | }; 43 | 44 | inline qreal QtMaterialDrawerStateMachine::opacity() const 45 | { 46 | return m_opacity; 47 | } 48 | 49 | class QtMaterialDrawerWidget : public QtMaterialOverlayWidget 50 | { 51 | Q_OBJECT 52 | 53 | Q_PROPERTY(int offset WRITE setOffset READ offset) 54 | 55 | public: 56 | explicit QtMaterialDrawerWidget(QWidget *parent = 0); 57 | ~QtMaterialDrawerWidget(); 58 | 59 | void setOffset(int offset); 60 | inline int offset() const; 61 | 62 | protected: 63 | void paintEvent(QPaintEvent *event) Q_DECL_OVERRIDE; 64 | 65 | QRect overlayGeometry() const Q_DECL_OVERRIDE; 66 | 67 | private: 68 | int m_offset; 69 | }; 70 | 71 | inline int QtMaterialDrawerWidget::offset() const 72 | { 73 | return m_offset; 74 | } 75 | 76 | #endif // DRAWER_INTERNAL_H 77 | -------------------------------------------------------------------------------- /components/qtmaterialdrawer_p.h: -------------------------------------------------------------------------------- 1 | #ifndef DRAWER_P_H 2 | #define DRAWER_P_H 3 | 4 | #include 5 | 6 | class QtMaterialDrawer; 7 | class QtMaterialDrawerWidget; 8 | class QtMaterialDrawerStateMachine; 9 | 10 | class QtMaterialDrawerPrivate 11 | { 12 | Q_DISABLE_COPY(QtMaterialDrawerPrivate) 13 | Q_DECLARE_PUBLIC(QtMaterialDrawer) 14 | 15 | public: 16 | QtMaterialDrawerPrivate(QtMaterialDrawer *q); 17 | ~QtMaterialDrawerPrivate(); 18 | 19 | void init(); 20 | void setClosed(bool value = true); 21 | 22 | QtMaterialDrawer *const q_ptr; 23 | QtMaterialDrawerWidget *widget; 24 | QtMaterialDrawerStateMachine *stateMachine; 25 | QWidget *window; 26 | int width; 27 | bool clickToClose; 28 | bool autoRaise; 29 | bool closed; 30 | bool overlay; 31 | }; 32 | 33 | #endif // DRAWER_P_H 34 | -------------------------------------------------------------------------------- /components/qtmaterialfab.h: -------------------------------------------------------------------------------- 1 | #ifndef QTMATERIALFAB_H 2 | #define QTMATERIALFAB_H 3 | 4 | #include "qtmaterialraisedbutton.h" 5 | 6 | class QtMaterialFloatingActionButtonPrivate; 7 | 8 | class QtMaterialFloatingActionButton : public QtMaterialRaisedButton 9 | { 10 | Q_OBJECT 11 | 12 | public: 13 | explicit QtMaterialFloatingActionButton(const QIcon &icon, QWidget *parent = 0); 14 | ~QtMaterialFloatingActionButton(); 15 | 16 | QSize sizeHint() const Q_DECL_OVERRIDE; 17 | 18 | void setMini(bool state); 19 | bool isMini() const; 20 | 21 | void setCorner(Qt::Corner corner); 22 | Qt::Corner corner() const; 23 | 24 | void setOffset(int x, int y); 25 | QSize offset() const; 26 | 27 | void setXOffset(int x); 28 | int xOffset() const; 29 | 30 | void setYOffset(int y); 31 | int yOffset() const; 32 | 33 | protected: 34 | bool event(QEvent *event) Q_DECL_OVERRIDE; 35 | bool eventFilter(QObject *obj, QEvent *event) Q_DECL_OVERRIDE; 36 | void paintEvent(QPaintEvent *event) Q_DECL_OVERRIDE; 37 | 38 | void updateClipPath() Q_DECL_OVERRIDE; 39 | 40 | private: 41 | Q_DISABLE_COPY(QtMaterialFloatingActionButton) 42 | Q_DECLARE_PRIVATE(QtMaterialFloatingActionButton) 43 | 44 | }; 45 | 46 | #endif // QTMATERIALFAB_H 47 | -------------------------------------------------------------------------------- /components/qtmaterialfab_p.h: -------------------------------------------------------------------------------- 1 | #ifndef QTMATERIALFAB_P_H 2 | #define QTMATERIALFAB_P_H 3 | 4 | #include "qtmaterialraisedbutton_p.h" 5 | 6 | class QtMaterialFloatingActionButton; 7 | 8 | class QtMaterialFloatingActionButtonPrivate : public QtMaterialRaisedButtonPrivate 9 | { 10 | Q_DISABLE_COPY(QtMaterialFloatingActionButtonPrivate) 11 | Q_DECLARE_PUBLIC(QtMaterialFloatingActionButton) 12 | 13 | public: 14 | enum { 15 | DefaultDiameter = 56, 16 | MiniDiameter = 40 17 | }; 18 | 19 | enum { 20 | DefaultIconSize = 24, 21 | MiniIconSize = 18 22 | }; 23 | 24 | QtMaterialFloatingActionButtonPrivate(QtMaterialFloatingActionButton *q); 25 | ~QtMaterialFloatingActionButtonPrivate(); 26 | 27 | void init(); 28 | QRect fabGeometry() const; 29 | void setupProperties(); 30 | 31 | inline int diameter() const; 32 | inline int iconSize() const; 33 | 34 | Qt::Corner corner; 35 | bool mini; 36 | int offsX; 37 | int offsY; 38 | }; 39 | 40 | inline int QtMaterialFloatingActionButtonPrivate::diameter() const 41 | { 42 | return mini ? MiniDiameter : DefaultDiameter; 43 | } 44 | 45 | inline int QtMaterialFloatingActionButtonPrivate::iconSize() const 46 | { 47 | return mini ? MiniIconSize : DefaultIconSize; 48 | } 49 | 50 | #endif // QTMATERIALFAB_P_H 51 | -------------------------------------------------------------------------------- /components/qtmaterialflatbutton.h: -------------------------------------------------------------------------------- 1 | #ifndef QTMATERIALFLATBUTTON_H 2 | #define QTMATERIALFLATBUTTON_H 3 | 4 | #include 5 | #include 6 | #include "components/lib/qtmaterialtheme.h" 7 | 8 | class QtMaterialFlatButtonPrivate; 9 | 10 | class QtMaterialFlatButton : public QPushButton 11 | { 12 | Q_OBJECT 13 | 14 | Q_PROPERTY(QColor foregroundColor WRITE setForegroundColor READ foregroundColor) 15 | Q_PROPERTY(QColor backgroundColor WRITE setBackgroundColor READ backgroundColor) 16 | Q_PROPERTY(QColor overlayColor WRITE setOverlayColor READ overlayColor) 17 | Q_PROPERTY(QColor disabledForegroundColor WRITE setDisabledForegroundColor READ disabledForegroundColor) 18 | Q_PROPERTY(QColor disabledBackgroundColor WRITE setDisabledBackgroundColor READ disabledBackgroundColor) 19 | Q_PROPERTY(qreal fontSize WRITE setFontSize READ fontSize) 20 | 21 | public: 22 | explicit QtMaterialFlatButton(QWidget *parent = 0, Material::ButtonPreset preset = Material::FlatPreset); 23 | explicit QtMaterialFlatButton(const QString &text, QWidget *parent = 0, Material::ButtonPreset preset = Material::FlatPreset); 24 | QtMaterialFlatButton(const QString &text, Material::Role role, QWidget *parent = 0, Material::ButtonPreset preset = Material::FlatPreset); 25 | ~QtMaterialFlatButton(); 26 | 27 | void applyPreset(Material::ButtonPreset preset); 28 | 29 | void setUseThemeColors(bool value); 30 | bool useThemeColors() const; 31 | 32 | void setRole(Material::Role role); 33 | Material::Role role() const; 34 | 35 | void setForegroundColor(const QColor &color); 36 | QColor foregroundColor() const; 37 | 38 | void setBackgroundColor(const QColor &color); 39 | QColor backgroundColor() const; 40 | 41 | void setOverlayColor(const QColor &color); 42 | QColor overlayColor() const; 43 | 44 | void setDisabledForegroundColor(const QColor &color); 45 | QColor disabledForegroundColor() const; 46 | 47 | void setDisabledBackgroundColor(const QColor &color); 48 | QColor disabledBackgroundColor() const; 49 | 50 | void setFontSize(qreal size); 51 | qreal fontSize() const; 52 | 53 | void setHaloVisible(bool visible); 54 | bool isHaloVisible() const; 55 | 56 | void setOverlayStyle(Material::OverlayStyle style); 57 | Material::OverlayStyle overlayStyle() const; 58 | 59 | void setRippleStyle(Material::RippleStyle style); 60 | Material::RippleStyle rippleStyle() const; 61 | 62 | void setIconPlacement(Material::ButtonIconPlacement placement); 63 | Material::ButtonIconPlacement iconPlacement() const; 64 | 65 | void setCornerRadius(qreal radius); 66 | qreal cornerRadius() const; 67 | 68 | void setBackgroundMode(Qt::BGMode mode); 69 | Qt::BGMode backgroundMode() const; 70 | 71 | void setBaseOpacity(qreal opacity); 72 | qreal baseOpacity() const; 73 | 74 | void setCheckable(bool value); 75 | 76 | void setHasFixedRippleRadius(bool value); 77 | bool hasFixedRippleRadius() const; 78 | 79 | void setFixedRippleRadius(qreal radius); 80 | 81 | void setTextAlignment(Qt::Alignment alignment); 82 | Qt::Alignment textAlignment() const; 83 | 84 | QSize sizeHint() const Q_DECL_OVERRIDE; 85 | 86 | protected: 87 | enum { 88 | IconPadding = 12 89 | }; 90 | 91 | QtMaterialFlatButton(QtMaterialFlatButtonPrivate &d, QWidget *parent = 0, Material::ButtonPreset preset = Material::FlatPreset); 92 | 93 | void checkStateSet() Q_DECL_OVERRIDE; 94 | void mousePressEvent(QMouseEvent *event) Q_DECL_OVERRIDE; 95 | void mouseReleaseEvent(QMouseEvent *event) Q_DECL_OVERRIDE; 96 | void resizeEvent(QResizeEvent *event) Q_DECL_OVERRIDE; 97 | void paintEvent(QPaintEvent *event) Q_DECL_OVERRIDE; 98 | 99 | virtual void paintBackground(QPainter *painter); 100 | virtual void paintHalo(QPainter *painter); 101 | virtual void paintForeground(QPainter *painter); 102 | 103 | virtual void updateClipPath(); 104 | 105 | const QScopedPointer d_ptr; 106 | 107 | private: 108 | Q_DISABLE_COPY(QtMaterialFlatButton) 109 | Q_DECLARE_PRIVATE(QtMaterialFlatButton) 110 | }; 111 | 112 | #endif // QTMATERIALFLATBUTTON_H 113 | -------------------------------------------------------------------------------- /components/qtmaterialflatbutton_internal.h: -------------------------------------------------------------------------------- 1 | #ifndef QTMATERIALFLATBUTTON_INTERNAL_H 2 | #define QTMATERIALFLATBUTTON_INTERNAL_H 3 | 4 | #include 5 | #include 6 | 7 | class QtMaterialFlatButton; 8 | class QSequentialAnimationGroup; 9 | 10 | class QtMaterialFlatButtonStateMachine : public QStateMachine 11 | { 12 | Q_OBJECT 13 | 14 | Q_PROPERTY(qreal overlayOpacity WRITE setOverlayOpacity READ overlayOpacity) 15 | Q_PROPERTY(qreal checkedOverlayProgress WRITE setCheckedOverlayProgress READ checkedOverlayProgress) 16 | Q_PROPERTY(qreal haloOpacity WRITE setHaloOpacity READ haloOpacity) 17 | Q_PROPERTY(qreal haloSize WRITE setHaloSize READ haloSize) 18 | Q_PROPERTY(qreal haloScaleFactor WRITE setHaloScaleFactor READ haloScaleFactor) 19 | 20 | public: 21 | explicit QtMaterialFlatButtonStateMachine(QtMaterialFlatButton *parent); 22 | ~QtMaterialFlatButtonStateMachine(); 23 | 24 | void setOverlayOpacity(qreal opacity); 25 | inline qreal overlayOpacity() const; 26 | 27 | void setCheckedOverlayProgress(qreal progress); 28 | inline qreal checkedOverlayProgress() const; 29 | 30 | void setHaloOpacity(qreal opacity); 31 | inline qreal haloOpacity() const; 32 | 33 | void setHaloSize(qreal size); 34 | inline qreal haloSize() const; 35 | 36 | void setHaloScaleFactor(qreal factor); 37 | inline qreal haloScaleFactor() const; 38 | 39 | void startHaloAnimations(); 40 | void setupProperties(); 41 | void updateCheckedStatus(); 42 | 43 | signals: 44 | void buttonPressed(); 45 | void buttonChecked(); 46 | void buttonUnchecked(); 47 | 48 | protected: 49 | bool eventFilter(QObject *watched, QEvent *event) Q_DECL_OVERRIDE; 50 | 51 | private: 52 | Q_DISABLE_COPY(QtMaterialFlatButtonStateMachine) 53 | 54 | void addTransition(QObject *object, QEvent::Type eventType, QState *fromState, QState *toState); 55 | void addTransition(QAbstractTransition *transition, QState *fromState, QState *toState); 56 | 57 | QtMaterialFlatButton *const m_button; 58 | QState *const m_topLevelState; 59 | QState *const m_configState; 60 | QState *const m_checkableState; 61 | QState *const m_checkedState; 62 | QState *const m_uncheckedState; 63 | QState *const m_neutralState; 64 | QState *const m_neutralFocusedState; 65 | QState *const m_hoveredState; 66 | QState *const m_hoveredFocusedState; 67 | QState *const m_pressedState; 68 | QSequentialAnimationGroup 69 | *const m_haloAnimation; 70 | qreal m_overlayOpacity; 71 | qreal m_checkedOverlayProgress; 72 | qreal m_haloOpacity; 73 | qreal m_haloSize; 74 | qreal m_haloScaleFactor; 75 | bool m_wasChecked; 76 | }; 77 | 78 | inline qreal QtMaterialFlatButtonStateMachine::overlayOpacity() const 79 | { 80 | return m_overlayOpacity; 81 | } 82 | 83 | inline qreal QtMaterialFlatButtonStateMachine::checkedOverlayProgress() const 84 | { 85 | return m_checkedOverlayProgress; 86 | } 87 | 88 | inline qreal QtMaterialFlatButtonStateMachine::haloOpacity() const 89 | { 90 | return m_haloOpacity; 91 | } 92 | 93 | inline qreal QtMaterialFlatButtonStateMachine::haloSize() const 94 | { 95 | return m_haloSize; 96 | } 97 | 98 | inline qreal QtMaterialFlatButtonStateMachine::haloScaleFactor() const 99 | { 100 | return m_haloScaleFactor; 101 | } 102 | 103 | #endif // QTMATERIALFLATBUTTON_INTERNAL_H 104 | -------------------------------------------------------------------------------- /components/qtmaterialflatbutton_p.h: -------------------------------------------------------------------------------- 1 | #ifndef QTMATERIALFLATBUTTON_P_H 2 | #define QTMATERIALFLATBUTTON_P_H 3 | 4 | #include 5 | #include 6 | #include "components/lib/qtmaterialtheme.h" 7 | 8 | class QtMaterialFlatButton; 9 | class QtMaterialRippleOverlay; 10 | class QtMaterialFlatButtonStateMachine; 11 | 12 | class QtMaterialFlatButtonPrivate 13 | { 14 | Q_DISABLE_COPY(QtMaterialFlatButtonPrivate) 15 | Q_DECLARE_PUBLIC(QtMaterialFlatButton) 16 | 17 | public: 18 | QtMaterialFlatButtonPrivate(QtMaterialFlatButton *q); 19 | virtual ~QtMaterialFlatButtonPrivate(); 20 | 21 | void init(); 22 | 23 | QtMaterialFlatButton *const q_ptr; 24 | QtMaterialRippleOverlay *rippleOverlay; 25 | QtMaterialFlatButtonStateMachine *stateMachine; 26 | Material::Role role; 27 | Material::RippleStyle rippleStyle; 28 | Material::ButtonIconPlacement iconPlacement; 29 | Material::OverlayStyle overlayStyle; 30 | Qt::BGMode bgMode; 31 | Qt::Alignment textAlignment; 32 | QColor backgroundColor; 33 | QColor foregroundColor; 34 | QColor overlayColor; 35 | QColor disabledColor; 36 | QColor disabledBackgroundColor; 37 | qreal fixedRippleRadius; 38 | qreal cornerRadius; 39 | qreal baseOpacity; 40 | qreal fontSize; 41 | bool useThemeColors; 42 | bool useFixedRippleRadius; 43 | bool haloVisible; 44 | }; 45 | 46 | #endif // QTMATERIALFLATBUTTON_P_H 47 | -------------------------------------------------------------------------------- /components/qtmaterialiconbutton.h: -------------------------------------------------------------------------------- 1 | #ifndef QTMATERIALICONBUTTON_H 2 | #define QTMATERIALICONBUTTON_H 3 | 4 | #include 5 | 6 | #include 7 | #include "components/lib/qtmaterialtheme.h" 8 | 9 | class QtMaterialIconButtonPrivate; 10 | 11 | class QtMaterialIconButton : public QAbstractButton 12 | { 13 | Q_OBJECT 14 | 15 | public: 16 | explicit QtMaterialIconButton(const QIcon &icon=QIcon(), QWidget *parent = 0); 17 | ~QtMaterialIconButton(); 18 | 19 | QSize sizeHint() const Q_DECL_OVERRIDE; 20 | 21 | void setUseThemeColors(bool value); 22 | bool useThemeColors() const; 23 | 24 | void setColor(const QColor &color); 25 | QColor color() const; 26 | 27 | void setDisabledColor(const QColor &color); 28 | QColor disabledColor() const; 29 | 30 | void setBackgroundColor(const QColor &color); 31 | QColor backgroundColor() const; 32 | 33 | void setBackgroundMode(const Qt::BGMode mode); 34 | Qt::BGMode backgroundMode() const; 35 | 36 | void setRole(const Material::Role role); 37 | Material::Role role() const; 38 | 39 | void setOverlayStyle(const Material::OverlayStyle style); 40 | Material::OverlayStyle overlayStyle() const; 41 | 42 | void setOverlayShape(const Material::OverlayShape shape); 43 | Material::OverlayShape overlayShape() const; 44 | 45 | void setHasRipple(const bool hasRipple); 46 | bool hasRipple() const; 47 | 48 | 49 | protected: 50 | QtMaterialIconButton(QtMaterialIconButtonPrivate &d, QWidget *parent = 0); 51 | 52 | bool event(QEvent *event) Q_DECL_OVERRIDE; 53 | bool eventFilter(QObject *obj, QEvent *event) Q_DECL_OVERRIDE; 54 | void mousePressEvent(QMouseEvent *event) Q_DECL_OVERRIDE; 55 | void paintEvent(QPaintEvent *event) Q_DECL_OVERRIDE; 56 | void enterEvent(QEvent *event)Q_DECL_OVERRIDE; 57 | 58 | const QScopedPointer d_ptr; 59 | 60 | private: 61 | Q_DISABLE_COPY(QtMaterialIconButton) 62 | Q_DECLARE_PRIVATE(QtMaterialIconButton) 63 | 64 | signals: 65 | void mouseEntered(); 66 | }; 67 | 68 | #endif // QTMATERIALICONBUTTON_H 69 | -------------------------------------------------------------------------------- /components/qtmaterialiconbutton_internal.cpp: -------------------------------------------------------------------------------- 1 | #include "qtmaterialiconbutton_internal.h" 2 | #include 3 | #include 4 | #include 5 | #include "qtmaterialiconbutton.h" 6 | #include "components/lib/qtmaterialstatetransition.h" 7 | #include 8 | 9 | /*! 10 | * \class QtMateriaIconButtonStateMachine 11 | * \internal 12 | */ 13 | 14 | QtMaterialIconButtonStateMachine::QtMaterialIconButtonStateMachine(QtMaterialIconButton *parent) 15 | : QStateMachine(parent), 16 | m_button(parent), 17 | m_hoveredState(new QState(ExclusiveStates)), 18 | m_neutralState(new QState(ExclusiveStates)), 19 | m_overlayOpacity(0) 20 | { 21 | Q_ASSERT(parent); 22 | 23 | parent->installEventFilter(this); 24 | 25 | addState(m_neutralState); 26 | addState(m_hoveredState); 27 | setInitialState(m_neutralState); 28 | 29 | addTransition(m_button, QEvent::Enter, m_neutralState, m_hoveredState); 30 | addTransition(m_button, QEvent::Leave, m_hoveredState, m_neutralState); 31 | } 32 | 33 | QtMaterialIconButtonStateMachine::~QtMaterialIconButtonStateMachine() 34 | { 35 | 36 | } 37 | 38 | void QtMaterialIconButtonStateMachine::setOverlayOpacity(qreal opacity) 39 | { 40 | m_overlayOpacity = opacity; 41 | m_button->update(); 42 | } 43 | 44 | void QtMaterialIconButtonStateMachine::addTransition(QObject *object, 45 | QEvent::Type eventType, 46 | QState *fromState, 47 | QState *toState) 48 | { 49 | addTransition(new QEventTransition(object, eventType), fromState, toState); 50 | } 51 | 52 | void QtMaterialIconButtonStateMachine::addTransition(QAbstractTransition *transition, 53 | QState *fromState, 54 | QState *toState) 55 | { 56 | transition->setTargetState(toState); 57 | 58 | QPropertyAnimation *animation; 59 | 60 | animation = new QPropertyAnimation(this, "overlayOpacity", this); 61 | animation->setDuration(150); 62 | transition->addAnimation(animation); 63 | 64 | fromState->addTransition(transition); 65 | } 66 | 67 | void QtMaterialIconButtonStateMachine::setupProperties() 68 | { 69 | const qreal baseOpacity = 0.2; 70 | 71 | m_neutralState->assignProperty(this, "overlayOpacity", 0); 72 | m_hoveredState->assignProperty(this, "overlayOpacity", baseOpacity); 73 | 74 | m_button->update(); 75 | } 76 | -------------------------------------------------------------------------------- /components/qtmaterialiconbutton_internal.h: -------------------------------------------------------------------------------- 1 | #ifndef QTMATERIALICONBUTTON_INTERNAL_H 2 | #define QTMATERIALICONBUTTON_INTERNAL_H 3 | 4 | #include 5 | #include 6 | #include "components/lib/qtmaterialtheme.h" 7 | 8 | class QtMaterialIconButton; 9 | class QSequentialAnimationGroup; 10 | 11 | class QtMaterialIconButtonStateMachine : public QStateMachine 12 | { 13 | Q_OBJECT 14 | 15 | Q_PROPERTY(qreal overlayOpacity WRITE setOverlayOpacity READ overlayOpacity) 16 | 17 | public: 18 | explicit QtMaterialIconButtonStateMachine(QtMaterialIconButton *parent); 19 | ~QtMaterialIconButtonStateMachine(); 20 | 21 | void setOverlayOpacity(qreal opacity); 22 | inline qreal overlayOpacity() const; 23 | 24 | void setupProperties(); 25 | 26 | private: 27 | Q_DISABLE_COPY(QtMaterialIconButtonStateMachine) 28 | 29 | void addTransition(QObject *object, QEvent::Type eventType, QState *fromState, QState *toState); 30 | void addTransition(QAbstractTransition *transition, QState *fromState, QState *toState); 31 | 32 | QtMaterialIconButton *const m_button; 33 | QState *const m_hoveredState; 34 | QState *const m_neutralState; 35 | qreal m_overlayOpacity; 36 | }; 37 | 38 | inline qreal QtMaterialIconButtonStateMachine::overlayOpacity() const 39 | { 40 | return m_overlayOpacity; 41 | } 42 | 43 | #endif // QTMATERIALICONBUTTON_INTERNAL_H 44 | -------------------------------------------------------------------------------- /components/qtmaterialiconbutton_p.h: -------------------------------------------------------------------------------- 1 | #ifndef QTMATERIALICONBUTTON_P_H 2 | #define QTMATERIALICONBUTTON_P_H 3 | 4 | #include 5 | #include 6 | #include "components/lib/qtmaterialtheme.h" 7 | 8 | class QtMaterialIconButton; 9 | class QtMaterialRippleOverlay; 10 | class QtMaterialIconButtonStateMachine; 11 | 12 | class QtMaterialIconButtonPrivate 13 | { 14 | Q_DISABLE_COPY(QtMaterialIconButtonPrivate) 15 | Q_DECLARE_PUBLIC(QtMaterialIconButton) 16 | 17 | public: 18 | QtMaterialIconButtonPrivate(QtMaterialIconButton *q); 19 | virtual ~QtMaterialIconButtonPrivate(); 20 | 21 | void init(); 22 | void updateRipple(); 23 | 24 | QtMaterialIconButton *const q_ptr; 25 | QtMaterialRippleOverlay *rippleOverlay; 26 | bool hasRipple; 27 | QtMaterialIconButtonStateMachine *stateMachine; 28 | Material::OverlayStyle overlayStyle; 29 | Material::OverlayShape overlayShape; 30 | QColor color; 31 | Material::Role role; 32 | QColor disabledColor; 33 | QColor backgroundColor; 34 | bool useThemeColors; 35 | Qt::BGMode backgroundMode; 36 | 37 | 38 | }; 39 | 40 | #endif // QTMATERIALICONBUTTON_P_H 41 | -------------------------------------------------------------------------------- /components/qtmateriallist.cpp: -------------------------------------------------------------------------------- 1 | #include "qtmateriallist.h" 2 | #include "qtmateriallist_p.h" 3 | -------------------------------------------------------------------------------- /components/qtmateriallist.h: -------------------------------------------------------------------------------- 1 | #ifndef QTMATERIALLIST_H 2 | #define QTMATERIALLIST_H 3 | 4 | #endif // QTMATERIALLIST_H 5 | -------------------------------------------------------------------------------- /components/qtmateriallist_p.h: -------------------------------------------------------------------------------- 1 | #ifndef QTMATERIALLIST_P_H 2 | #define QTMATERIALLIST_P_H 3 | 4 | #endif // QTMATERIALLIST_P_H 5 | -------------------------------------------------------------------------------- /components/qtmateriallistitem.cpp: -------------------------------------------------------------------------------- 1 | #include "qtmateriallistitem.h" 2 | #include "qtmateriallistitem_p.h" 3 | -------------------------------------------------------------------------------- /components/qtmateriallistitem.h: -------------------------------------------------------------------------------- 1 | #ifndef QTMATERIALLISTITEM_H 2 | #define QTMATERIALLISTITEM_H 3 | 4 | #endif // QTMATERIALLISTITEM_H 5 | -------------------------------------------------------------------------------- /components/qtmateriallistitem_p.h: -------------------------------------------------------------------------------- 1 | #ifndef QTMATERIALLISTITEM_P_H 2 | #define QTMATERIALLISTITEM_P_H 3 | 4 | #endif // QTMATERIALLISTITEM_P_H 5 | -------------------------------------------------------------------------------- /components/qtmaterialmenu.cpp: -------------------------------------------------------------------------------- 1 | #include "qtmaterialmenu.h" 2 | #include "qtmaterialmenu_p.h" 3 | 4 | QtMaterialMenu::QtMaterialMenu(QWidget *parent) 5 | : QWidget(parent) 6 | { 7 | } 8 | 9 | QtMaterialMenu::~QtMaterialMenu() 10 | { 11 | } 12 | -------------------------------------------------------------------------------- /components/qtmaterialmenu.h: -------------------------------------------------------------------------------- 1 | #ifndef QTMATERIALMENU_H 2 | #define QTMATERIALMENU_H 3 | 4 | #include 5 | 6 | class QtMaterialMenu : public QWidget 7 | { 8 | Q_OBJECT 9 | 10 | public: 11 | explicit QtMaterialMenu(QWidget *parent = 0); 12 | ~QtMaterialMenu(); 13 | }; 14 | 15 | #endif // QTMATERIALMENU_H 16 | -------------------------------------------------------------------------------- /components/qtmaterialmenu_internal.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/miangoleh/QtMaterial/8ceb913a9eee9cb0f40b00348c7b9423e37e4cb2/components/qtmaterialmenu_internal.cpp -------------------------------------------------------------------------------- /components/qtmaterialmenu_internal.h: -------------------------------------------------------------------------------- 1 | #ifndef QTMATERIALMENU_INTERNAL_H 2 | #define QTMATERIALMENU_INTERNAL_H 3 | 4 | #endif // QTMATERIALMENU_INTERNAL_H 5 | -------------------------------------------------------------------------------- /components/qtmaterialmenu_p.h: -------------------------------------------------------------------------------- 1 | #ifndef QTMATERIALMENU_P_H 2 | #define QTMATERIALMENU_P_H 3 | 4 | #endif // QTMATERIALMENU_P_H 5 | -------------------------------------------------------------------------------- /components/qtmaterialpaper.cpp: -------------------------------------------------------------------------------- 1 | #include "qtmaterialpaper.h" 2 | #include "qtmaterialpaper_p.h" 3 | -------------------------------------------------------------------------------- /components/qtmaterialpaper.h: -------------------------------------------------------------------------------- 1 | #ifndef QTMATERIALPAPER_H 2 | #define QTMATERIALPAPER_H 3 | 4 | #endif // QTMATERIALPAPER_H 5 | -------------------------------------------------------------------------------- /components/qtmaterialpaper_p.h: -------------------------------------------------------------------------------- 1 | #ifndef QTMATERIALPAPER_P_H 2 | #define QTMATERIALPAPER_P_H 3 | 4 | #endif // QTMATERIALPAPER_P_H 5 | -------------------------------------------------------------------------------- /components/qtmaterialprogress.cpp: -------------------------------------------------------------------------------- 1 | #include "qtmaterialprogress.h" 2 | #include "qtmaterialprogress_p.h" 3 | #include 4 | #include 5 | #include "qtmaterialprogress_internal.h" 6 | #include "components/lib/qtmaterialstyle.h" 7 | 8 | /*! 9 | * \class QtMaterialProgressPrivate 10 | * \internal 11 | */ 12 | 13 | QtMaterialProgressPrivate::QtMaterialProgressPrivate(QtMaterialProgress *q) 14 | : q_ptr(q) 15 | { 16 | } 17 | 18 | QtMaterialProgressPrivate::~QtMaterialProgressPrivate() 19 | { 20 | } 21 | 22 | void QtMaterialProgressPrivate::init() 23 | { 24 | Q_Q(QtMaterialProgress); 25 | 26 | delegate = new QtMaterialProgressDelegate(q); 27 | progressType = Material::IndeterminateProgress; 28 | useThemeColors = true; 29 | 30 | QPropertyAnimation *animation; 31 | 32 | animation = new QPropertyAnimation(q); 33 | animation->setPropertyName("offset"); 34 | animation->setTargetObject(delegate); 35 | animation->setStartValue(0); 36 | animation->setEndValue(1); 37 | animation->setDuration(1000); 38 | 39 | animation->setLoopCount(-1); 40 | 41 | animation->start(); 42 | } 43 | 44 | /*! 45 | * \class QtMaterialProgress 46 | */ 47 | 48 | QtMaterialProgress::QtMaterialProgress(QWidget *parent) 49 | : QProgressBar(parent), 50 | d_ptr(new QtMaterialProgressPrivate(this)) 51 | { 52 | d_func()->init(); 53 | } 54 | 55 | QtMaterialProgress::~QtMaterialProgress() 56 | { 57 | } 58 | 59 | void QtMaterialProgress::setProgressType(Material::ProgressType type) 60 | { 61 | Q_D(QtMaterialProgress); 62 | 63 | d->progressType = type; 64 | update(); 65 | } 66 | 67 | Material::ProgressType QtMaterialProgress::progressType() const 68 | { 69 | Q_D(const QtMaterialProgress); 70 | 71 | return d->progressType; 72 | } 73 | 74 | void QtMaterialProgress::setUseThemeColors(bool state) 75 | { 76 | Q_D(QtMaterialProgress); 77 | 78 | if (d->useThemeColors == state) { 79 | return; 80 | } 81 | 82 | d->useThemeColors = state; 83 | update(); 84 | } 85 | 86 | bool QtMaterialProgress::useThemeColors() const 87 | { 88 | Q_D(const QtMaterialProgress); 89 | 90 | return d->useThemeColors; 91 | } 92 | 93 | void QtMaterialProgress::setProgressColor(const QColor &color) 94 | { 95 | Q_D(QtMaterialProgress); 96 | 97 | d->progressColor = color; 98 | 99 | MATERIAL_DISABLE_THEME_COLORS 100 | update(); 101 | } 102 | 103 | QColor QtMaterialProgress::progressColor() const 104 | { 105 | Q_D(const QtMaterialProgress); 106 | 107 | if (d->useThemeColors || !d->progressColor.isValid()) { 108 | return QtMaterialStyle::instance().themeColor("primary1"); 109 | } else { 110 | return d->progressColor; 111 | } 112 | } 113 | 114 | void QtMaterialProgress::setBackgroundColor(const QColor &color) 115 | { 116 | Q_D(QtMaterialProgress); 117 | 118 | d->backgroundColor = color; 119 | 120 | MATERIAL_DISABLE_THEME_COLORS 121 | update(); 122 | } 123 | 124 | QColor QtMaterialProgress::backgroundColor() const 125 | { 126 | Q_D(const QtMaterialProgress); 127 | 128 | if (d->useThemeColors || !d->backgroundColor.isValid()) { 129 | return QtMaterialStyle::instance().themeColor("border"); 130 | } else { 131 | return d->backgroundColor; 132 | } 133 | } 134 | 135 | /*! 136 | * \reimp 137 | */ 138 | void QtMaterialProgress::paintEvent(QPaintEvent *event) 139 | { 140 | Q_UNUSED(event) 141 | 142 | Q_D(QtMaterialProgress); 143 | 144 | QPainter painter(this); 145 | painter.setRenderHint(QPainter::Antialiasing); 146 | 147 | QBrush brush; 148 | brush.setStyle(Qt::SolidPattern); 149 | brush.setColor(isEnabled() ? backgroundColor() 150 | : QtMaterialStyle::instance().themeColor("disabled")); 151 | painter.setBrush(brush); 152 | painter.setPen(Qt::NoPen); 153 | 154 | QPainterPath path; 155 | path.addRoundedRect(0, height()/2-3, width(), 6, 3, 3); 156 | painter.setClipPath(path); 157 | 158 | painter.drawRect(0, 0, width(), height()); 159 | 160 | if (isEnabled()) 161 | { 162 | brush.setColor(progressColor()); 163 | painter.setBrush(brush); 164 | 165 | if (Material::IndeterminateProgress == d->progressType) { 166 | painter.drawRect(d->delegate->offset()*width()*2-width(), 0, width(), height()); 167 | } else { 168 | qreal p = static_cast(width())*(value()-minimum())/(maximum()-minimum()); 169 | painter.drawRect(0, 0, p, height()); 170 | } 171 | } 172 | } 173 | -------------------------------------------------------------------------------- /components/qtmaterialprogress.h: -------------------------------------------------------------------------------- 1 | #ifndef QTMATERIALPROGRESS_H 2 | #define QTMATERIALPROGRESS_H 3 | 4 | #include 5 | #include "components/lib/qtmaterialtheme.h" 6 | 7 | class QtMaterialProgressPrivate; 8 | 9 | class QtMaterialProgress : public QProgressBar 10 | { 11 | Q_OBJECT 12 | 13 | Q_PROPERTY(QColor progressColor WRITE setProgressColor READ progressColor) 14 | Q_PROPERTY(QColor backgroundColor WRITE setProgressColor READ backgroundColor) 15 | 16 | public: 17 | explicit QtMaterialProgress(QWidget *parent = 0); 18 | ~QtMaterialProgress(); 19 | 20 | void setProgressType(Material::ProgressType type); 21 | Material::ProgressType progressType() const; 22 | 23 | void setUseThemeColors(bool state); 24 | bool useThemeColors() const; 25 | 26 | void setProgressColor(const QColor &color); 27 | QColor progressColor() const; 28 | 29 | void setBackgroundColor(const QColor &color); 30 | QColor backgroundColor() const; 31 | 32 | protected: 33 | void paintEvent(QPaintEvent *event) Q_DECL_OVERRIDE; 34 | 35 | const QScopedPointer d_ptr; 36 | 37 | private: 38 | Q_DISABLE_COPY(QtMaterialProgress) 39 | Q_DECLARE_PRIVATE(QtMaterialProgress) 40 | }; 41 | 42 | #endif // QTMATERIALPROGRESS_H 43 | -------------------------------------------------------------------------------- /components/qtmaterialprogress_internal.cpp: -------------------------------------------------------------------------------- 1 | #include "qtmaterialprogress_internal.h" 2 | 3 | /*! 4 | * \class QtMaterialProgressDelegate 5 | * \internal 6 | */ 7 | 8 | QtMaterialProgressDelegate::QtMaterialProgressDelegate(QtMaterialProgress *parent) 9 | : QObject(parent), 10 | m_progress(parent), 11 | m_offset(0) 12 | { 13 | Q_ASSERT(parent); 14 | } 15 | 16 | QtMaterialProgressDelegate::~QtMaterialProgressDelegate() 17 | { 18 | } 19 | -------------------------------------------------------------------------------- /components/qtmaterialprogress_internal.h: -------------------------------------------------------------------------------- 1 | #ifndef QTMATERIALPROGRESS_INTERNAL_H 2 | #define QTMATERIALPROGRESS_INTERNAL_H 3 | 4 | #include 5 | #include "qtmaterialprogress.h" 6 | 7 | class QtMaterialProgressDelegate : public QObject 8 | { 9 | Q_OBJECT 10 | 11 | Q_PROPERTY(qreal offset WRITE setOffset READ offset) 12 | 13 | public: 14 | QtMaterialProgressDelegate(QtMaterialProgress *parent); 15 | ~QtMaterialProgressDelegate(); 16 | 17 | inline void setOffset(qreal offset); 18 | inline qreal offset() const; 19 | 20 | private: 21 | Q_DISABLE_COPY(QtMaterialProgressDelegate) 22 | 23 | QtMaterialProgress *const m_progress; 24 | qreal m_offset; 25 | }; 26 | 27 | inline void QtMaterialProgressDelegate::setOffset(qreal offset) 28 | { 29 | m_offset = offset; 30 | m_progress->update(); 31 | } 32 | 33 | inline qreal QtMaterialProgressDelegate::offset() const 34 | { 35 | return m_offset; 36 | } 37 | 38 | #endif // QTMATERIALPROGRESS_INTERNAL_H 39 | -------------------------------------------------------------------------------- /components/qtmaterialprogress_p.h: -------------------------------------------------------------------------------- 1 | #ifndef QTMATERIALPROGRESS_P_H 2 | #define QTMATERIALPROGRESS_P_H 3 | 4 | #include 5 | #include 6 | #include "components/lib/qtmaterialtheme.h" 7 | 8 | class QtMaterialProgress; 9 | class QtMaterialProgressDelegate; 10 | 11 | class QtMaterialProgressPrivate 12 | { 13 | Q_DISABLE_COPY(QtMaterialProgressPrivate) 14 | Q_DECLARE_PUBLIC(QtMaterialProgress) 15 | 16 | public: 17 | QtMaterialProgressPrivate(QtMaterialProgress *q); 18 | ~QtMaterialProgressPrivate(); 19 | 20 | void init(); 21 | 22 | QtMaterialProgress *const q_ptr; 23 | QtMaterialProgressDelegate *delegate; 24 | Material::ProgressType progressType; 25 | QColor progressColor; 26 | QColor backgroundColor; 27 | bool useThemeColors; 28 | }; 29 | 30 | #endif // QTMATERIALPROGRESS_P_H 31 | -------------------------------------------------------------------------------- /components/qtmaterialradiobutton.cpp: -------------------------------------------------------------------------------- 1 | #include "qtmaterialradiobutton.h" 2 | #include "qtmaterialradiobutton_p.h" 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include "components/lib/qtmaterialcheckable_internal.h" 8 | 9 | /*! 10 | * \class QtMaterialRadioButtonPrivate 11 | * \internal 12 | */ 13 | 14 | QtMaterialRadioButtonPrivate::QtMaterialRadioButtonPrivate(QtMaterialRadioButton *q) 15 | : QtMaterialCheckablePrivate(q) 16 | { 17 | } 18 | 19 | QtMaterialRadioButtonPrivate::~QtMaterialRadioButtonPrivate() 20 | { 21 | } 22 | 23 | void QtMaterialRadioButtonPrivate::init() 24 | { 25 | Q_Q(QtMaterialRadioButton); 26 | 27 | q->setAutoExclusive(true); 28 | 29 | q->setCheckedIcon(QIcon(":/Images/radioBtn_selected.png")); 30 | q->setUncheckedIcon(QIcon(":/Images/radioBtn_deselect.png")); 31 | 32 | uncheckedState->assignProperty(checkedIcon, "iconSize", 0); 33 | uncheckedState->assignProperty(uncheckedIcon, "iconSize", 24); 34 | 35 | disabledUncheckedState->assignProperty(checkedIcon, "iconSize", 0); 36 | disabledUncheckedState->assignProperty(uncheckedIcon, "iconSize", 24); 37 | 38 | checkedState->assignProperty(uncheckedIcon, "iconSize", 0); 39 | checkedState->assignProperty(checkedIcon, "iconSize", 24); 40 | 41 | disabledCheckedState->assignProperty(uncheckedIcon, "iconSize", 0); 42 | disabledCheckedState->assignProperty(checkedIcon, "iconSize", 24); 43 | 44 | uncheckedState->assignProperty(checkedIcon, "opacity", 0); 45 | uncheckedState->assignProperty(uncheckedIcon, "opacity", 1); 46 | 47 | checkedState->assignProperty(uncheckedIcon, "opacity", 0); 48 | checkedState->assignProperty(checkedIcon, "opacity", 1); 49 | 50 | checkedIcon->setIconSize(0); 51 | 52 | // 53 | 54 | checkedState->assignProperty(checkedIcon, "color", q->checkedColor()); 55 | checkedState->assignProperty(uncheckedIcon, "color", q->uncheckedColor()); 56 | uncheckedState->assignProperty(uncheckedIcon, "color", q->uncheckedColor()); 57 | 58 | QPropertyAnimation *animation; 59 | 60 | animation = new QPropertyAnimation(checkedIcon, "iconSize", q); 61 | animation->setDuration(250); 62 | stateMachine->addDefaultAnimation(animation); 63 | 64 | animation = new QPropertyAnimation(uncheckedIcon, "iconSize", q); 65 | animation->setDuration(250); 66 | stateMachine->addDefaultAnimation(animation); 67 | 68 | animation = new QPropertyAnimation(uncheckedIcon, "opacity", q); 69 | animation->setDuration(250); 70 | stateMachine->addDefaultAnimation(animation); 71 | 72 | animation = new QPropertyAnimation(checkedIcon, "opacity", q); 73 | animation->setDuration(250); 74 | stateMachine->addDefaultAnimation(animation); 75 | } 76 | 77 | /*! 78 | * \class QtMaterialRadioButton 79 | */ 80 | 81 | QtMaterialRadioButton::QtMaterialRadioButton(QWidget *parent) 82 | : QtMaterialCheckable(*new QtMaterialRadioButtonPrivate(this), parent) 83 | { 84 | d_func()->init(); 85 | } 86 | 87 | QtMaterialRadioButton::~QtMaterialRadioButton() 88 | { 89 | } 90 | 91 | void QtMaterialRadioButton::setupProperties() 92 | { 93 | QtMaterialCheckable::setupProperties(); 94 | 95 | Q_D(QtMaterialRadioButton); 96 | 97 | d->checkedState->assignProperty(d->checkedIcon, "color", checkedColor()); 98 | d->checkedState->assignProperty(d->uncheckedIcon, "color", uncheckedColor()); 99 | d->uncheckedState->assignProperty(d->uncheckedIcon, "color", uncheckedColor()); 100 | } 101 | -------------------------------------------------------------------------------- /components/qtmaterialradiobutton.h: -------------------------------------------------------------------------------- 1 | #ifndef QTMATERIALRADIOBUTTON_H 2 | #define QTMATERIALRADIOBUTTON_H 3 | 4 | #include "components/lib/qtmaterialcheckable.h" 5 | 6 | class QtMaterialRadioButtonPrivate; 7 | 8 | class QtMaterialRadioButton : public QtMaterialCheckable 9 | { 10 | Q_OBJECT 11 | 12 | public: 13 | explicit QtMaterialRadioButton(QWidget *parent = 0); 14 | ~QtMaterialRadioButton(); 15 | 16 | protected: 17 | void setupProperties(); 18 | 19 | private: 20 | Q_DISABLE_COPY(QtMaterialRadioButton) 21 | Q_DECLARE_PRIVATE(QtMaterialRadioButton) 22 | }; 23 | 24 | #endif // QTMATERIALRADIOBUTTON_H 25 | -------------------------------------------------------------------------------- /components/qtmaterialradiobutton_p.h: -------------------------------------------------------------------------------- 1 | #ifndef QTMATERIALRADIOBUTTON_P_H 2 | #define QTMATERIALRADIOBUTTON_P_H 3 | 4 | #include "components/lib/qtmaterialcheckable_p.h" 5 | 6 | class QtMaterialRadioButton; 7 | 8 | class QtMaterialRadioButtonPrivate : public QtMaterialCheckablePrivate 9 | { 10 | Q_DISABLE_COPY(QtMaterialRadioButtonPrivate) 11 | Q_DECLARE_PUBLIC(QtMaterialRadioButton) 12 | 13 | public: 14 | QtMaterialRadioButtonPrivate(QtMaterialRadioButton *q); 15 | ~QtMaterialRadioButtonPrivate(); 16 | 17 | void init(); 18 | }; 19 | 20 | #endif // QTMATERIALRADIOBUTTON_P_H 21 | -------------------------------------------------------------------------------- /components/qtmaterialraisedbutton.cpp: -------------------------------------------------------------------------------- 1 | #include "qtmaterialraisedbutton.h" 2 | #include "qtmaterialraisedbutton_p.h" 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | /*! 9 | * \class QtMaterialRaisedButtonPrivate 10 | * \internal 11 | */ 12 | 13 | /*! 14 | * \internal 15 | */ 16 | QtMaterialRaisedButtonPrivate::QtMaterialRaisedButtonPrivate(QtMaterialRaisedButton *q) 17 | : QtMaterialFlatButtonPrivate(q) 18 | { 19 | } 20 | 21 | /*! 22 | * \internal 23 | */ 24 | QtMaterialRaisedButtonPrivate::~QtMaterialRaisedButtonPrivate() 25 | { 26 | } 27 | 28 | /*! 29 | * \internal 30 | */ 31 | void QtMaterialRaisedButtonPrivate::init() 32 | { 33 | Q_Q(QtMaterialRaisedButton); 34 | 35 | shadowStateMachine = new QStateMachine(q); 36 | normalState = new QState; 37 | pressedState = new QState; 38 | effect = new QGraphicsDropShadowEffect; 39 | 40 | effect->setBlurRadius(7); 41 | effect->setOffset(QPointF(0, 2)); 42 | effect->setColor(QColor(0, 0, 0, 75)); 43 | 44 | q->setBackgroundMode(Qt::OpaqueMode); 45 | q->setMinimumHeight(42); 46 | q->setGraphicsEffect(effect); 47 | q->setBaseOpacity(0.3); 48 | 49 | shadowStateMachine->addState(normalState); 50 | shadowStateMachine->addState(pressedState); 51 | 52 | normalState->assignProperty(effect, "offset", QPointF(0, 2)); 53 | normalState->assignProperty(effect, "blurRadius", 7); 54 | 55 | pressedState->assignProperty(effect, "offset", QPointF(0, 5)); 56 | pressedState->assignProperty(effect, "blurRadius", 29); 57 | 58 | QAbstractTransition *transition; 59 | 60 | transition = new QEventTransition(q, QEvent::MouseButtonPress); 61 | transition->setTargetState(pressedState); 62 | normalState->addTransition(transition); 63 | 64 | transition = new QEventTransition(q, QEvent::MouseButtonDblClick); 65 | transition->setTargetState(pressedState); 66 | normalState->addTransition(transition); 67 | 68 | transition = new QEventTransition(q, QEvent::MouseButtonRelease); 69 | transition->setTargetState(normalState); 70 | pressedState->addTransition(transition); 71 | 72 | QPropertyAnimation *animation; 73 | 74 | animation = new QPropertyAnimation(effect, "offset", q); 75 | animation->setDuration(100); 76 | shadowStateMachine->addDefaultAnimation(animation); 77 | 78 | animation = new QPropertyAnimation(effect, "blurRadius", q); 79 | animation->setDuration(100); 80 | shadowStateMachine->addDefaultAnimation(animation); 81 | 82 | shadowStateMachine->setInitialState(normalState); 83 | shadowStateMachine->start(); 84 | } 85 | 86 | /*! 87 | * \class QtMaterialRaisedButton 88 | */ 89 | 90 | QtMaterialRaisedButton::QtMaterialRaisedButton(QWidget *parent) 91 | : QtMaterialFlatButton(*new QtMaterialRaisedButtonPrivate(this), parent) 92 | { 93 | d_func()->init(); 94 | } 95 | 96 | QtMaterialRaisedButton::QtMaterialRaisedButton(const QString &text, QWidget *parent) 97 | : QtMaterialFlatButton(*new QtMaterialRaisedButtonPrivate(this), parent) 98 | { 99 | d_func()->init(); 100 | 101 | setText(text); 102 | } 103 | 104 | QtMaterialRaisedButton::~QtMaterialRaisedButton() 105 | { 106 | } 107 | 108 | QtMaterialRaisedButton::QtMaterialRaisedButton(QtMaterialRaisedButtonPrivate &d, QWidget *parent) 109 | : QtMaterialFlatButton(d, parent) 110 | { 111 | d_func()->init(); 112 | } 113 | 114 | bool QtMaterialRaisedButton::event(QEvent *event) 115 | { 116 | Q_D(QtMaterialRaisedButton); 117 | 118 | if (QEvent::EnabledChange == event->type()) { 119 | if (isEnabled()) { 120 | d->shadowStateMachine->start(); 121 | d->effect->setEnabled(true); 122 | } else { 123 | d->shadowStateMachine->stop(); 124 | d->effect->setEnabled(false); 125 | } 126 | } 127 | return QtMaterialFlatButton::event(event); 128 | } 129 | -------------------------------------------------------------------------------- /components/qtmaterialraisedbutton.h: -------------------------------------------------------------------------------- 1 | #ifndef QTMATERIALRAISEDBUTTON_H 2 | #define QTMATERIALRAISEDBUTTON_H 3 | 4 | #include "qtmaterialflatbutton.h" 5 | 6 | class QtMaterialRaisedButtonPrivate; 7 | 8 | class QtMaterialRaisedButton : public QtMaterialFlatButton 9 | { 10 | Q_OBJECT 11 | 12 | public: 13 | explicit QtMaterialRaisedButton(QWidget *parent = 0); 14 | explicit QtMaterialRaisedButton(const QString &text, QWidget *parent = 0); 15 | ~QtMaterialRaisedButton(); 16 | 17 | protected: 18 | QtMaterialRaisedButton(QtMaterialRaisedButtonPrivate &d, QWidget *parent = 0); 19 | 20 | bool event(QEvent *event) Q_DECL_OVERRIDE; 21 | 22 | private: 23 | Q_DISABLE_COPY(QtMaterialRaisedButton) 24 | Q_DECLARE_PRIVATE(QtMaterialRaisedButton) 25 | }; 26 | 27 | #endif // QTMATERIALRAISEDBUTTON_H 28 | -------------------------------------------------------------------------------- /components/qtmaterialraisedbutton_p.h: -------------------------------------------------------------------------------- 1 | #ifndef QTMATERIALRAISEDBUTTON_P_H 2 | #define QTMATERIALRAISEDBUTTON_P_H 3 | 4 | #include "qtmaterialflatbutton_p.h" 5 | 6 | class QStateMachine; 7 | class QState; 8 | class QGraphicsDropShadowEffect; 9 | class QtMaterialRaisedButton; 10 | 11 | class QtMaterialRaisedButtonPrivate : public QtMaterialFlatButtonPrivate 12 | { 13 | Q_DISABLE_COPY(QtMaterialRaisedButtonPrivate) 14 | Q_DECLARE_PUBLIC(QtMaterialRaisedButton) 15 | 16 | public: 17 | QtMaterialRaisedButtonPrivate(QtMaterialRaisedButton *q); 18 | ~QtMaterialRaisedButtonPrivate(); 19 | 20 | void init(); 21 | 22 | QStateMachine *shadowStateMachine; 23 | QState *normalState; 24 | QState *pressedState; 25 | QGraphicsDropShadowEffect *effect; 26 | }; 27 | 28 | #endif // QTMATERIALRAISEDBUTTON_P_H 29 | -------------------------------------------------------------------------------- /components/qtmaterialscrollbar.cpp: -------------------------------------------------------------------------------- 1 | #include "qtmaterialscrollbar.h" 2 | #include "qtmaterialscrollbar_p.h" 3 | #include 4 | #include 5 | #include "qtmaterialscrollbar_internal.h" 6 | #include "components/lib/qtmaterialstyle.h" 7 | 8 | /*! 9 | * \class QtMaterialScrollBarPrivate 10 | * \internal 11 | */ 12 | 13 | QtMaterialScrollBarPrivate::QtMaterialScrollBarPrivate(QtMaterialScrollBar *q) 14 | : q_ptr(q) 15 | { 16 | } 17 | 18 | QtMaterialScrollBarPrivate::~QtMaterialScrollBarPrivate() 19 | { 20 | } 21 | 22 | void QtMaterialScrollBarPrivate::init() 23 | { 24 | Q_Q(QtMaterialScrollBar); 25 | 26 | stateMachine = new QtMaterialScrollBarStateMachine(q); 27 | hideOnMouseOut = true; 28 | useThemeColors = true; 29 | 30 | q->setMouseTracking(true); 31 | q->setStyle(&QtMaterialStyle::instance()); 32 | // q->setStyleSheet("QScrollBar:vertical { margin: 0; }" 33 | // "QScrollBar::add-line:vertical { height: 0; margin: 0; }" 34 | // "QScrollBar::sub-line:vertical { height: 0; margin: 0; }"); 35 | 36 | stateMachine->start(); 37 | } 38 | 39 | /*! 40 | * \class QtMaterialScrollBar 41 | */ 42 | 43 | QtMaterialScrollBar::QtMaterialScrollBar(QWidget *parent) 44 | : QScrollBar(parent), 45 | d_ptr(new QtMaterialScrollBarPrivate(this)) 46 | { 47 | d_func()->init(); 48 | } 49 | 50 | QtMaterialScrollBar::~QtMaterialScrollBar() 51 | { 52 | } 53 | 54 | /*! 55 | * \reimp 56 | */ 57 | QSize QtMaterialScrollBar::sizeHint() const 58 | { 59 | if (Qt::Horizontal == orientation()) { 60 | return QSize(1, 10); 61 | } else { 62 | return QSize(10, 1); 63 | } 64 | } 65 | 66 | void QtMaterialScrollBar::setUseThemeColors(bool value) 67 | { 68 | Q_D(QtMaterialScrollBar); 69 | 70 | if (d->useThemeColors == value) { 71 | return; 72 | } 73 | 74 | d->useThemeColors = value; 75 | update(); 76 | } 77 | 78 | bool QtMaterialScrollBar::useThemeColors() const 79 | { 80 | Q_D(const QtMaterialScrollBar); 81 | 82 | return d->useThemeColors; 83 | } 84 | 85 | void QtMaterialScrollBar::setCanvasColor(const QColor &color) 86 | { 87 | Q_D(QtMaterialScrollBar); 88 | 89 | d->canvasColor = color; 90 | 91 | MATERIAL_DISABLE_THEME_COLORS 92 | update(); 93 | } 94 | 95 | QColor QtMaterialScrollBar::canvasColor() const 96 | { 97 | Q_D(const QtMaterialScrollBar); 98 | 99 | if (d->useThemeColors || !d->canvasColor.isValid()) { 100 | return parentWidget()->palette().color(backgroundRole()); 101 | } else { 102 | return d->canvasColor; 103 | } 104 | } 105 | 106 | void QtMaterialScrollBar::setBackgroundColor(const QColor &color) 107 | { 108 | Q_D(QtMaterialScrollBar); 109 | 110 | d->backgroundColor = color; 111 | 112 | MATERIAL_DISABLE_THEME_COLORS 113 | update(); 114 | } 115 | 116 | QColor QtMaterialScrollBar::backgroundColor() const 117 | { 118 | Q_D(const QtMaterialScrollBar); 119 | 120 | if (d->useThemeColors || !d->backgroundColor.isValid()) { 121 | return QtMaterialStyle::instance().themeColor("border"); 122 | } else { 123 | return d->backgroundColor; 124 | } 125 | } 126 | 127 | void QtMaterialScrollBar::setSliderColor(const QColor &color) 128 | { 129 | Q_D(QtMaterialScrollBar); 130 | 131 | d->sliderColor = color; 132 | 133 | MATERIAL_DISABLE_THEME_COLORS 134 | update(); 135 | } 136 | 137 | QColor QtMaterialScrollBar::sliderColor() const 138 | { 139 | Q_D(const QtMaterialScrollBar); 140 | 141 | if (d->useThemeColors || !d->sliderColor.isValid()) { 142 | return QtMaterialStyle::instance().themeColor("primary1"); 143 | } else { 144 | return d->sliderColor; 145 | } 146 | } 147 | 148 | void QtMaterialScrollBar::setHideOnMouseOut(bool value) 149 | { 150 | Q_D(QtMaterialScrollBar); 151 | 152 | d->hideOnMouseOut = value; 153 | update(); 154 | } 155 | 156 | bool QtMaterialScrollBar::hideOnMouseOut() const 157 | { 158 | Q_D(const QtMaterialScrollBar); 159 | 160 | return d->hideOnMouseOut; 161 | } 162 | 163 | /*! 164 | * \reimp 165 | */ 166 | void QtMaterialScrollBar::paintEvent(QPaintEvent *event) 167 | { 168 | Q_UNUSED(event) 169 | 170 | Q_D(QtMaterialScrollBar); 171 | 172 | QPainter painter(this); 173 | painter.setRenderHint(QPainter::Antialiasing); 174 | 175 | painter.fillRect(rect(), canvasColor()); 176 | 177 | int x, y, w, h; 178 | rect().getRect(&x, &y, &w, &h); 179 | 180 | QMargins margins(2, 2, 2, 2); 181 | 182 | QBrush brush; 183 | brush.setStyle(Qt::SolidPattern); 184 | brush.setColor(backgroundColor()); 185 | painter.setBrush(brush); 186 | painter.setPen(Qt::NoPen); 187 | 188 | if (d->hideOnMouseOut) { 189 | painter.setOpacity(d->stateMachine->opacity()); 190 | } 191 | 192 | QRect trimmed(rect().marginsRemoved(margins)); 193 | 194 | QPainterPath path; 195 | path.addRoundedRect(trimmed, 3, 3); 196 | painter.setClipPath(path); 197 | 198 | painter.drawRect(trimmed); 199 | 200 | const qreal q = (Qt::Horizontal == orientation() ? w : h) / 201 | static_cast(maximum()-minimum()+pageStep()-1); 202 | 203 | QRect handle = Qt::Horizontal == orientation() 204 | ? QRect(sliderPosition()*q, y, pageStep()*q, h) 205 | : QRect(x, sliderPosition()*q, w, pageStep()*q); 206 | 207 | brush.setColor(sliderColor()); 208 | painter.setBrush(brush); 209 | 210 | painter.drawRoundedRect(handle, 9, 9); 211 | } 212 | -------------------------------------------------------------------------------- /components/qtmaterialscrollbar.h: -------------------------------------------------------------------------------- 1 | #ifndef QTMATERIALSCROLLBAR_H 2 | #define QTMATERIALSCROLLBAR_H 3 | 4 | #include 5 | 6 | class QtMaterialScrollBarPrivate; 7 | 8 | class QtMaterialScrollBar : public QScrollBar 9 | { 10 | Q_OBJECT 11 | 12 | Q_PROPERTY(QColor canvasColor WRITE setCanvasColor READ canvasColor) 13 | Q_PROPERTY(QColor backgroundColor WRITE setBackgroundColor READ backgroundColor) 14 | Q_PROPERTY(QColor sliderColor WRITE setSliderColor READ sliderColor) 15 | 16 | public: 17 | explicit QtMaterialScrollBar(QWidget *parent = 0); 18 | ~QtMaterialScrollBar(); 19 | 20 | QSize sizeHint() const Q_DECL_OVERRIDE; 21 | 22 | void setUseThemeColors(bool value); 23 | bool useThemeColors() const; 24 | 25 | void setCanvasColor(const QColor &color); 26 | QColor canvasColor() const; 27 | 28 | void setBackgroundColor(const QColor &color); 29 | QColor backgroundColor() const; 30 | 31 | void setSliderColor(const QColor &color); 32 | QColor sliderColor() const; 33 | 34 | void setHideOnMouseOut(bool value); 35 | bool hideOnMouseOut() const; 36 | 37 | protected: 38 | void paintEvent(QPaintEvent *event) Q_DECL_OVERRIDE; 39 | 40 | const QScopedPointer d_ptr; 41 | 42 | private: 43 | Q_DISABLE_COPY(QtMaterialScrollBar) 44 | Q_DECLARE_PRIVATE(QtMaterialScrollBar) 45 | }; 46 | 47 | #endif // QTMATERIALSCROLLBAR_H 48 | -------------------------------------------------------------------------------- /components/qtmaterialscrollbar_internal.cpp: -------------------------------------------------------------------------------- 1 | #include "qtmaterialscrollbar_internal.h" 2 | #include 3 | #include 4 | 5 | /*! 6 | * \class QtMaterialScrollBarStateMachine 7 | * \internal 8 | */ 9 | 10 | /*! 11 | * \internal 12 | */ 13 | QtMaterialScrollBarStateMachine::QtMaterialScrollBarStateMachine(QtMaterialScrollBar *parent) 14 | : QStateMachine(parent), 15 | m_scrollBar(parent), 16 | m_focusState(new QState), 17 | m_blurState(new QState), 18 | m_opacity(0) 19 | { 20 | Q_ASSERT(parent); 21 | 22 | addState(m_focusState); 23 | addState(m_blurState); 24 | setInitialState(m_blurState); 25 | 26 | QEventTransition *transition; 27 | 28 | transition = new QEventTransition(parent, QEvent::Enter); 29 | transition->setTargetState(m_focusState); 30 | m_blurState->addTransition(transition); 31 | 32 | transition = new QEventTransition(parent, QEvent::Leave); 33 | transition->setTargetState(m_blurState); 34 | m_focusState->addTransition(transition); 35 | 36 | m_focusState->assignProperty(this, "opacity", 1); 37 | m_blurState->assignProperty(this, "opacity", 0); 38 | 39 | QPropertyAnimation *animation; 40 | 41 | animation = new QPropertyAnimation(this, "opacity", this); 42 | animation->setDuration(340); 43 | addDefaultAnimation(animation); 44 | } 45 | 46 | /*! 47 | * \internal 48 | */ 49 | QtMaterialScrollBarStateMachine::~QtMaterialScrollBarStateMachine() 50 | { 51 | } 52 | -------------------------------------------------------------------------------- /components/qtmaterialscrollbar_internal.h: -------------------------------------------------------------------------------- 1 | #ifndef QTMATERIALSCROLLBAR_INTERNAL_H 2 | #define QTMATERIALSCROLLBAR_INTERNAL_H 3 | 4 | #include 5 | #include "qtmaterialscrollbar.h" 6 | 7 | class QtMaterialScrollBarStateMachine : public QStateMachine 8 | { 9 | Q_OBJECT 10 | 11 | Q_PROPERTY(qreal opacity WRITE setOpacity READ opacity) 12 | 13 | public: 14 | QtMaterialScrollBarStateMachine(QtMaterialScrollBar *parent); 15 | ~QtMaterialScrollBarStateMachine(); 16 | 17 | inline void setOpacity(qreal opacity); 18 | inline qreal opacity() const; 19 | 20 | private: 21 | Q_DISABLE_COPY(QtMaterialScrollBarStateMachine) 22 | 23 | QtMaterialScrollBar *const m_scrollBar; 24 | QState *const m_focusState; 25 | QState *const m_blurState; 26 | qreal m_opacity; 27 | }; 28 | 29 | inline void QtMaterialScrollBarStateMachine::setOpacity(qreal opacity) 30 | { 31 | m_opacity = opacity; 32 | m_scrollBar->update(); 33 | } 34 | 35 | inline qreal QtMaterialScrollBarStateMachine::opacity() const 36 | { 37 | return m_opacity; 38 | } 39 | 40 | #endif // QTMATERIALSCROLLBAR_INTERNAL_H 41 | -------------------------------------------------------------------------------- /components/qtmaterialscrollbar_p.h: -------------------------------------------------------------------------------- 1 | #ifndef QTMATERIALSCROLLBAR_P_H 2 | #define QTMATERIALSCROLLBAR_P_H 3 | 4 | #include 5 | #include 6 | 7 | class QtMaterialScrollBar; 8 | class QtMaterialScrollBarStateMachine; 9 | 10 | class QtMaterialScrollBarPrivate 11 | { 12 | Q_DISABLE_COPY(QtMaterialScrollBarPrivate) 13 | Q_DECLARE_PUBLIC(QtMaterialScrollBar) 14 | 15 | public: 16 | QtMaterialScrollBarPrivate(QtMaterialScrollBar *q); 17 | ~QtMaterialScrollBarPrivate(); 18 | 19 | void init(); 20 | 21 | QtMaterialScrollBar *const q_ptr; 22 | QtMaterialScrollBarStateMachine *stateMachine; 23 | QColor backgroundColor; 24 | QColor sliderColor; 25 | QColor canvasColor; 26 | bool hideOnMouseOut; 27 | bool useThemeColors; 28 | }; 29 | 30 | #endif // QTMATERIALSCROLLBAR_P_H 31 | -------------------------------------------------------------------------------- /components/qtmaterialslider.h: -------------------------------------------------------------------------------- 1 | #ifndef QTMATERIALSLIDER_H 2 | #define QTMATERIALSLIDER_H 3 | 4 | #include 5 | #include 6 | 7 | #define QT_MATERIAL_SLIDER_MARGIN 30 8 | 9 | class QtMaterialSliderPrivate; 10 | 11 | class QtMaterialSlider : public QAbstractSlider 12 | { 13 | Q_OBJECT 14 | 15 | Q_PROPERTY(QColor thumbColor WRITE setThumbColor READ thumbColor) 16 | Q_PROPERTY(QColor trackColor WRITE setTrackColor READ trackColor) 17 | Q_PROPERTY(QColor disabledColor WRITE setDisabledColor READ disabledColor) 18 | 19 | public: 20 | explicit QtMaterialSlider(QWidget *parent = 0); 21 | ~QtMaterialSlider(); 22 | 23 | void setUseThemeColors(bool value); 24 | bool useThemeColors() const; 25 | 26 | void setThumbColor(const QColor &color); 27 | QColor thumbColor() const; 28 | 29 | void setTrackColor(const QColor &color); 30 | QColor trackColor() const; 31 | 32 | void setDisabledColor(const QColor &color); 33 | QColor disabledColor() const; 34 | 35 | void setPageStepMode(bool pageStep); 36 | bool pageStepMode() const; 37 | 38 | QSize minimumSizeHint() const Q_DECL_OVERRIDE; 39 | 40 | void setInvertedAppearance(bool value); 41 | 42 | protected: 43 | void sliderChange(SliderChange change) Q_DECL_OVERRIDE; 44 | void mouseMoveEvent(QMouseEvent *event) Q_DECL_OVERRIDE; 45 | void mousePressEvent(QMouseEvent *event) Q_DECL_OVERRIDE; 46 | void mouseReleaseEvent(QMouseEvent *event) Q_DECL_OVERRIDE; 47 | void leaveEvent(QEvent *event) Q_DECL_OVERRIDE; 48 | 49 | void updateThumbOffset(); 50 | 51 | const QScopedPointer d_ptr; 52 | 53 | private: 54 | Q_DISABLE_COPY(QtMaterialSlider) 55 | Q_DECLARE_PRIVATE(QtMaterialSlider) 56 | }; 57 | 58 | #endif // QTMATERIALSLIDER_H 59 | -------------------------------------------------------------------------------- /components/qtmaterialslider_internal.h: -------------------------------------------------------------------------------- 1 | #ifndef QTMATERIALSLIDER_INTERNAL_H 2 | #define QTMATERIALSLIDER_INTERNAL_H 3 | 4 | #include 5 | #include "components/lib/qtmaterialoverlaywidget.h" 6 | 7 | class QtMaterialSlider; 8 | class QtMaterialSliderThumb; 9 | class QtMaterialSliderTrack; 10 | 11 | class QtMaterialSliderStateMachine : public QStateMachine 12 | { 13 | Q_OBJECT 14 | 15 | public: 16 | QtMaterialSliderStateMachine(QtMaterialSlider *slider, 17 | QtMaterialSliderThumb *thumb, 18 | QtMaterialSliderTrack *track); 19 | ~QtMaterialSliderStateMachine(); 20 | 21 | void setupProperties(); 22 | 23 | private: 24 | Q_DISABLE_COPY(QtMaterialSliderStateMachine) 25 | 26 | QtMaterialSlider *const m_slider; 27 | QtMaterialSliderThumb *const m_thumb; 28 | QtMaterialSliderTrack *const m_track; 29 | QState *const m_topState; 30 | QState *const m_fstState; 31 | QState *const m_sndState; 32 | QState *const m_inactiveState; 33 | QState *const m_focusState; 34 | QState *const m_slidingState; 35 | QState *const m_pulseOutState; 36 | QState *const m_pulseInState; 37 | QState *const m_minState; 38 | QState *const m_normalState; 39 | }; 40 | 41 | class QtMaterialSliderThumb : public QtMaterialOverlayWidget 42 | { 43 | Q_OBJECT 44 | 45 | Q_PROPERTY(qreal diameter WRITE setDiameter READ diameter) 46 | Q_PROPERTY(qreal borderWidth WRITE setBorderWidth READ borderWidth) 47 | Q_PROPERTY(QColor borderColor WRITE setBorderColor READ borderColor) 48 | Q_PROPERTY(QColor fillColor WRITE setFillColor READ fillColor) 49 | Q_PROPERTY(qreal haloSize WRITE setHaloSize READ haloSize) 50 | Q_PROPERTY(QColor haloColor WRITE setHaloColor READ haloColor) 51 | 52 | public: 53 | explicit QtMaterialSliderThumb(QtMaterialSlider *slider); 54 | ~QtMaterialSliderThumb(); 55 | 56 | inline void setDiameter(qreal diameter); 57 | inline qreal diameter() const; 58 | 59 | inline void setBorderWidth(qreal width); 60 | inline qreal borderWidth() const; 61 | 62 | inline void setBorderColor(const QColor &color); 63 | inline QColor borderColor() const; 64 | 65 | inline void setFillColor(const QColor &color); 66 | inline QColor fillColor() const; 67 | 68 | inline void setHaloSize(qreal size); 69 | inline qreal haloSize() const; 70 | 71 | inline void setHaloColor(const QColor &color); 72 | inline QColor haloColor() const; 73 | 74 | inline void setOffset(int offset); 75 | inline int offset() const; 76 | 77 | protected: 78 | bool eventFilter(QObject *obj, QEvent *event) Q_DECL_OVERRIDE; 79 | void paintEvent(QPaintEvent *event) Q_DECL_OVERRIDE; 80 | 81 | private: 82 | Q_DISABLE_COPY(QtMaterialSliderThumb) 83 | 84 | const QtMaterialSlider *const m_slider; 85 | QColor m_borderColor; 86 | QColor m_fillColor; 87 | QColor m_haloColor; 88 | qreal m_diameter; 89 | qreal m_borderWidth; 90 | qreal m_haloSize; 91 | int m_offset; 92 | }; 93 | 94 | inline void QtMaterialSliderThumb::setDiameter(qreal diameter) 95 | { 96 | m_diameter = diameter; 97 | update(); 98 | } 99 | 100 | inline qreal QtMaterialSliderThumb::diameter() const 101 | { 102 | return m_diameter; 103 | } 104 | 105 | inline void QtMaterialSliderThumb::setBorderWidth(qreal width) 106 | { 107 | m_borderWidth = width; 108 | update(); 109 | } 110 | 111 | inline qreal QtMaterialSliderThumb::borderWidth() const 112 | { 113 | return m_borderWidth; 114 | } 115 | 116 | inline void QtMaterialSliderThumb::setBorderColor(const QColor &color) 117 | { 118 | m_borderColor = color; 119 | update(); 120 | } 121 | 122 | inline QColor QtMaterialSliderThumb::borderColor() const 123 | { 124 | return m_borderColor; 125 | } 126 | 127 | inline void QtMaterialSliderThumb::setFillColor(const QColor &color) 128 | { 129 | m_fillColor = color; 130 | update(); 131 | } 132 | 133 | inline QColor QtMaterialSliderThumb::fillColor() const 134 | { 135 | return m_fillColor; 136 | } 137 | 138 | inline void QtMaterialSliderThumb::setHaloSize(qreal size) 139 | { 140 | m_haloSize = size; 141 | update(); 142 | } 143 | 144 | inline qreal QtMaterialSliderThumb::haloSize() const 145 | { 146 | return m_haloSize; 147 | } 148 | 149 | inline void QtMaterialSliderThumb::setHaloColor(const QColor &color) 150 | { 151 | m_haloColor = color; 152 | update(); 153 | } 154 | 155 | inline QColor QtMaterialSliderThumb::haloColor() const 156 | { 157 | return m_haloColor; 158 | } 159 | 160 | inline void QtMaterialSliderThumb::setOffset(int offset) 161 | { 162 | m_offset = offset; 163 | update(); 164 | } 165 | 166 | inline int QtMaterialSliderThumb::offset() const 167 | { 168 | return m_offset; 169 | } 170 | 171 | class QtMaterialSliderTrack : public QtMaterialOverlayWidget 172 | { 173 | Q_OBJECT 174 | 175 | Q_PROPERTY(QColor fillColor WRITE setFillColor READ fillColor) 176 | 177 | public: 178 | explicit QtMaterialSliderTrack(QtMaterialSliderThumb *thumb, QtMaterialSlider *slider); 179 | ~QtMaterialSliderTrack(); 180 | 181 | inline void setFillColor(const QColor &color); 182 | inline QColor fillColor() const; 183 | 184 | inline void setTrackWidth(int width); 185 | inline int trackWidth() const; 186 | 187 | protected: 188 | bool eventFilter(QObject *obj, QEvent *event) Q_DECL_OVERRIDE; 189 | void paintEvent(QPaintEvent *event) Q_DECL_OVERRIDE; 190 | 191 | private: 192 | Q_DISABLE_COPY(QtMaterialSliderTrack) 193 | 194 | const QtMaterialSlider *const m_slider; 195 | QtMaterialSliderThumb *const m_thumb; 196 | QColor m_fillColor; 197 | int m_trackWidth; 198 | }; 199 | 200 | inline void QtMaterialSliderTrack::setFillColor(const QColor &color) 201 | { 202 | m_fillColor = color; 203 | update(); 204 | } 205 | 206 | inline QColor QtMaterialSliderTrack::fillColor() const 207 | { 208 | return m_fillColor; 209 | } 210 | 211 | void QtMaterialSliderTrack::setTrackWidth(int width) 212 | { 213 | m_trackWidth = width; 214 | update(); 215 | } 216 | 217 | int QtMaterialSliderTrack::trackWidth() const 218 | { 219 | return m_trackWidth; 220 | } 221 | 222 | #endif // QTMATERIALSLIDER_INTERNAL_H 223 | -------------------------------------------------------------------------------- /components/qtmaterialslider_p.h: -------------------------------------------------------------------------------- 1 | #ifndef QTMATERIALSLIDER_P_H 2 | #define QTMATERIALSLIDER_P_H 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | class QtMaterialSlider; 9 | class QtMaterialSliderThumb; 10 | class QtMaterialSliderTrack; 11 | class QtMaterialSliderStateMachine; 12 | 13 | class QtMaterialSliderPrivate 14 | { 15 | Q_DISABLE_COPY(QtMaterialSliderPrivate) 16 | Q_DECLARE_PUBLIC(QtMaterialSlider) 17 | 18 | public: 19 | QtMaterialSliderPrivate(QtMaterialSlider *q); 20 | ~QtMaterialSliderPrivate(); 21 | 22 | void init(); 23 | 24 | QRectF trackBoundingRect() const; 25 | QRectF thumbBoundingRect() const; 26 | 27 | int valueFromPosition(const QPoint &pos) const; 28 | 29 | void setHovered(bool status); 30 | 31 | QtMaterialSlider *const q_ptr; 32 | QtMaterialSliderThumb *thumb; 33 | QtMaterialSliderTrack *track; 34 | QtMaterialSliderStateMachine *stateMachine; 35 | QColor thumbColor; 36 | QColor trackColor; 37 | QColor disabledColor; 38 | int stepTo; 39 | int oldValue; 40 | int trackWidth; 41 | bool hoverTrack; 42 | bool hoverThumb; 43 | bool hover; 44 | bool step; 45 | bool pageStepMode; 46 | bool useThemeColors; 47 | }; 48 | 49 | #endif // QTMATERIALSLIDER_P_H 50 | -------------------------------------------------------------------------------- /components/qtmaterialsnackbar.h: -------------------------------------------------------------------------------- 1 | #ifndef QTMATERIALSNACKBAR_H 2 | #define QTMATERIALSNACKBAR_H 3 | 4 | #include "components/lib/qtmaterialoverlaywidget.h" 5 | 6 | class QtMaterialSnackbarPrivate; 7 | 8 | class QtMaterialSnackbar : public QtMaterialOverlayWidget 9 | { 10 | Q_OBJECT 11 | 12 | public: 13 | explicit QtMaterialSnackbar(QWidget *parent = 0); 14 | ~QtMaterialSnackbar(); 15 | 16 | void setAutoHideDuration(int duration); 17 | int autoHideDuration() const; 18 | 19 | void setUseThemeColors(bool value); 20 | bool useThemeColors() const; 21 | 22 | void setBackgroundColor(const QColor &color); 23 | QColor backgroundColor() const; 24 | 25 | void setBackgroundOpacity(qreal opacity); 26 | qreal backgroundOpacity() const; 27 | 28 | void setTextColor(const QColor &color); 29 | QColor textColor() const; 30 | 31 | void setFontSize(qreal size); 32 | qreal fontSize() const; 33 | 34 | void setBoxWidth(int width); 35 | int boxWidth() const; 36 | 37 | void setClickToDismissMode(bool value); 38 | bool clickToDismissMode() const; 39 | 40 | public slots: 41 | void addMessage(const QString &message); 42 | void addInstantMessage(const QString &message); 43 | 44 | protected slots: 45 | void dequeue(); 46 | 47 | protected: 48 | void paintEvent(QPaintEvent *event) Q_DECL_OVERRIDE; 49 | 50 | const QScopedPointer d_ptr; 51 | 52 | private: 53 | Q_DISABLE_COPY(QtMaterialSnackbar) 54 | Q_DECLARE_PRIVATE(QtMaterialSnackbar) 55 | }; 56 | 57 | #endif // QTMATERIALSNACKBAR_H 58 | -------------------------------------------------------------------------------- /components/qtmaterialsnackbar_internal.cpp: -------------------------------------------------------------------------------- 1 | #include "qtmaterialsnackbar_internal.h" 2 | #include 3 | #include "qtmaterialsnackbar.h" 4 | #include "components/lib/qtmaterialstatetransition.h" 5 | #include 6 | 7 | QtMaterialSnackbarStateMachine::QtMaterialSnackbarStateMachine(QtMaterialSnackbar *parent) 8 | : QStateMachine(parent), 9 | m_snackbar(parent) 10 | { 11 | m_timer.setSingleShot(true); 12 | 13 | QState *hiddenState = new QState; 14 | QState *visibleState = new QState; 15 | QState *finalState = new QState; 16 | 17 | addState(hiddenState); 18 | addState(visibleState); 19 | addState(finalState); 20 | 21 | setInitialState(hiddenState); 22 | 23 | QtMaterialStateTransition *transition; 24 | 25 | transition = new QtMaterialStateTransition(SnackbarShowTransition); 26 | transition->setTargetState(visibleState); 27 | hiddenState->addTransition(transition); 28 | 29 | transition = new QtMaterialStateTransition(SnackbarHideTransition); 30 | transition->setTargetState(visibleState); 31 | hiddenState->addTransition(transition); 32 | 33 | transition = new QtMaterialStateTransition(SnackbarHideTransition); 34 | transition->setTargetState(finalState); 35 | visibleState->addTransition(transition); 36 | 37 | transition = new QtMaterialStateTransition(SnackbarWaitTransition); 38 | transition->setTargetState(hiddenState); 39 | finalState->addTransition(transition); 40 | 41 | transition = new QtMaterialStateTransition(SnackbarNextTransition); 42 | transition->setTargetState(visibleState); 43 | finalState->addTransition(transition); 44 | 45 | connect(visibleState, SIGNAL(propertiesAssigned()), 46 | this, SLOT(snackbarShown())); 47 | connect(finalState, SIGNAL(propertiesAssigned()), 48 | m_snackbar, SLOT(dequeue())); 49 | 50 | QPropertyAnimation *animation; 51 | 52 | animation = new QPropertyAnimation(this, "offset", this); 53 | animation->setEasingCurve(QEasingCurve::OutCubic); 54 | animation->setDuration(300); 55 | addDefaultAnimation(animation); 56 | 57 | hiddenState->assignProperty(this, "offset", 1); 58 | visibleState->assignProperty(this, "offset", 0); 59 | finalState->assignProperty(this, "offset", 1); 60 | 61 | connect(&m_timer, SIGNAL(timeout()), this, SLOT(progress())); 62 | 63 | m_snackbar->installEventFilter(this); 64 | } 65 | 66 | QtMaterialSnackbarStateMachine::~QtMaterialSnackbarStateMachine() 67 | { 68 | } 69 | 70 | bool QtMaterialSnackbarStateMachine::eventFilter(QObject *watched, QEvent *event) 71 | { 72 | if (QEvent::MouseButtonPress == event->type() && m_snackbar->clickToDismissMode()) { 73 | progress(); 74 | } 75 | return QStateMachine::eventFilter(watched, event); 76 | } 77 | 78 | void QtMaterialSnackbarStateMachine::setOffset(qreal offset) 79 | { 80 | m_offset = offset; 81 | m_snackbar->update(); 82 | } 83 | 84 | void QtMaterialSnackbarStateMachine::progress() 85 | { 86 | m_timer.stop(); 87 | postEvent(new QtMaterialStateTransitionEvent(SnackbarHideTransition)); 88 | if (m_snackbar->clickToDismissMode()) { 89 | m_snackbar->setAttribute(Qt::WA_TransparentForMouseEvents, true); 90 | } 91 | } 92 | 93 | void QtMaterialSnackbarStateMachine::snackbarShown() 94 | { 95 | m_timer.start(m_snackbar->autoHideDuration()); 96 | if (m_snackbar->clickToDismissMode()) { 97 | m_snackbar->setAttribute(Qt::WA_TransparentForMouseEvents, false); 98 | } 99 | } 100 | -------------------------------------------------------------------------------- /components/qtmaterialsnackbar_internal.h: -------------------------------------------------------------------------------- 1 | #ifndef QTMATERIALSNACKBAR_INTERNAL_H 2 | #define QTMATERIALSNACKBAR_INTERNAL_H 3 | 4 | #include 5 | #include 6 | 7 | class QtMaterialSnackbar; 8 | 9 | class QtMaterialSnackbarStateMachine : public QStateMachine 10 | { 11 | Q_OBJECT 12 | 13 | Q_PROPERTY(qreal offset WRITE setOffset READ offset) 14 | 15 | public: 16 | QtMaterialSnackbarStateMachine(QtMaterialSnackbar *parent); 17 | ~QtMaterialSnackbarStateMachine(); 18 | 19 | void setOffset(qreal offset); 20 | inline qreal offset() const; 21 | 22 | public slots: 23 | void progress(); 24 | 25 | protected slots: 26 | void snackbarShown(); 27 | 28 | protected: 29 | bool eventFilter(QObject *watched, QEvent *event) Q_DECL_OVERRIDE; 30 | 31 | private: 32 | Q_DISABLE_COPY(QtMaterialSnackbarStateMachine) 33 | 34 | QtMaterialSnackbar *const m_snackbar; 35 | QTimer m_timer; 36 | qreal m_offset; 37 | }; 38 | 39 | inline qreal QtMaterialSnackbarStateMachine::offset() const 40 | { 41 | return m_offset; 42 | } 43 | 44 | #endif // QTMATERIALSNACKBAR_INTERNAL_H 45 | -------------------------------------------------------------------------------- /components/qtmaterialsnackbar_p.h: -------------------------------------------------------------------------------- 1 | #ifndef QTMATERIALSNACKBAR_P_H 2 | #define QTMATERIALSNACKBAR_P_H 3 | 4 | #include 5 | #include 6 | 7 | class QtMaterialSnackbar; 8 | class QtMaterialSnackbarStateMachine; 9 | 10 | class QtMaterialSnackbarPrivate 11 | { 12 | Q_DISABLE_COPY(QtMaterialSnackbarPrivate) 13 | Q_DECLARE_PUBLIC(QtMaterialSnackbar) 14 | 15 | public: 16 | QtMaterialSnackbarPrivate(QtMaterialSnackbar *q); 17 | ~QtMaterialSnackbarPrivate(); 18 | 19 | void init(); 20 | 21 | QtMaterialSnackbar *const q_ptr; 22 | QtMaterialSnackbarStateMachine *stateMachine; 23 | QColor backgroundColor; 24 | QColor textColor; 25 | qreal bgOpacity; 26 | QList messages; 27 | int duration; 28 | int boxWidth; 29 | bool clickDismiss; 30 | bool useThemeColors; 31 | }; 32 | 33 | #endif // QTMATERIALSNACKBAR_P_H 34 | -------------------------------------------------------------------------------- /components/qtmaterialtable.cpp: -------------------------------------------------------------------------------- 1 | #include "qtmaterialtable.h" 2 | #include "qtmaterialtable_p.h" 3 | -------------------------------------------------------------------------------- /components/qtmaterialtable.h: -------------------------------------------------------------------------------- 1 | #ifndef QTMATERIALTABLE_H 2 | #define QTMATERIALTABLE_H 3 | 4 | #endif // QTMATERIALTABLE_H 5 | -------------------------------------------------------------------------------- /components/qtmaterialtable_p.h: -------------------------------------------------------------------------------- 1 | #ifndef QTMATERIALTABLE_P_H 2 | #define QTMATERIALTABLE_P_H 3 | 4 | #endif // QTMATERIALTABLE_P_H 5 | -------------------------------------------------------------------------------- /components/qtmaterialtabs.cpp: -------------------------------------------------------------------------------- 1 | #include "qtmaterialtabs.h" 2 | #include "qtmaterialtabs_p.h" 3 | #include 4 | #include "qtmaterialtabs_internal.h" 5 | #include "components/lib/qtmaterialstyle.h" 6 | 7 | /*! 8 | * \QtMaterialTabsPrivate 9 | * \internal 10 | */ 11 | 12 | QtMaterialTabsPrivate::QtMaterialTabsPrivate(QtMaterialTabs *q) 13 | : q_ptr(q) 14 | { 15 | } 16 | 17 | QtMaterialTabsPrivate::~QtMaterialTabsPrivate() 18 | { 19 | } 20 | 21 | void QtMaterialTabsPrivate::QtMaterialTabsPrivate::init() 22 | { 23 | Q_Q(QtMaterialTabs); 24 | 25 | inkBar = new QtMaterialTabsInkBar(q); 26 | tabLayout = new QHBoxLayout; 27 | rippleStyle = Material::CenteredRipple; 28 | tab = -1; 29 | showHalo = true; 30 | useThemeColors = true; 31 | 32 | q->setLayout(tabLayout); 33 | q->setStyle(&QtMaterialStyle::instance()); 34 | 35 | tabLayout->setSpacing(0); 36 | tabLayout->setMargin(0); 37 | } 38 | 39 | /*! 40 | * \QtMaterialTabs 41 | */ 42 | 43 | QtMaterialTabs::QtMaterialTabs(QWidget *parent) 44 | : QWidget(parent), 45 | d_ptr(new QtMaterialTabsPrivate(this)) 46 | { 47 | d_func()->init(); 48 | } 49 | 50 | QtMaterialTabs::~QtMaterialTabs() 51 | { 52 | } 53 | 54 | void QtMaterialTabs::setUseThemeColors(bool value) 55 | { 56 | Q_D(QtMaterialTabs); 57 | 58 | d->useThemeColors = value; 59 | } 60 | 61 | bool QtMaterialTabs::useThemeColors() const 62 | { 63 | Q_D(const QtMaterialTabs); 64 | 65 | return d->useThemeColors; 66 | } 67 | 68 | void QtMaterialTabs::setHaloVisible(bool value) 69 | { 70 | Q_D(QtMaterialTabs); 71 | 72 | d->showHalo = value; 73 | updateTabs(); 74 | } 75 | 76 | bool QtMaterialTabs::isHaloVisible() const 77 | { 78 | Q_D(const QtMaterialTabs); 79 | 80 | return d->showHalo; 81 | } 82 | 83 | void QtMaterialTabs::setRippleStyle(Material::RippleStyle style) 84 | { 85 | Q_D(QtMaterialTabs); 86 | 87 | d->rippleStyle = style; 88 | updateTabs(); 89 | } 90 | 91 | Material::RippleStyle QtMaterialTabs::rippleStyle() const 92 | { 93 | Q_D(const QtMaterialTabs); 94 | 95 | return d->rippleStyle; 96 | } 97 | 98 | void QtMaterialTabs::setInkColor(const QColor &color) 99 | { 100 | Q_D(QtMaterialTabs); 101 | 102 | d->inkColor = color; 103 | 104 | MATERIAL_DISABLE_THEME_COLORS 105 | d->inkBar->update(); 106 | update(); 107 | } 108 | 109 | QColor QtMaterialTabs::inkColor() const 110 | { 111 | Q_D(const QtMaterialTabs); 112 | 113 | if (d->useThemeColors || !d->inkColor.isValid()) { 114 | return QtMaterialStyle::instance().themeColor("accent1"); 115 | } else { 116 | return d->inkColor; 117 | } 118 | } 119 | 120 | void QtMaterialTabs::setBackgroundColor(const QColor &color) 121 | { 122 | Q_D(QtMaterialTabs); 123 | 124 | d->backgroundColor = color; 125 | 126 | MATERIAL_DISABLE_THEME_COLORS 127 | updateTabs(); 128 | update(); 129 | } 130 | 131 | QColor QtMaterialTabs::backgroundColor() const 132 | { 133 | Q_D(const QtMaterialTabs); 134 | 135 | if (d->useThemeColors || !d->backgroundColor.isValid()) { 136 | return QtMaterialStyle::instance().themeColor("primary1"); 137 | } else { 138 | return d->backgroundColor; 139 | } 140 | } 141 | 142 | void QtMaterialTabs::setTextColor(const QColor &color) 143 | { 144 | Q_D(QtMaterialTabs); 145 | 146 | d->textColor = color; 147 | 148 | MATERIAL_DISABLE_THEME_COLORS 149 | updateTabs(); 150 | update(); 151 | } 152 | 153 | QColor QtMaterialTabs::textColor() const 154 | { 155 | Q_D(const QtMaterialTabs); 156 | 157 | if (d->useThemeColors || !d->textColor.isValid()) { 158 | return QtMaterialStyle::instance().themeColor("canvas"); 159 | } else { 160 | return d->textColor; 161 | } 162 | } 163 | 164 | void QtMaterialTabs::setCurrentTab(QtMaterialTab *tab) 165 | { 166 | Q_D(QtMaterialTabs); 167 | 168 | setCurrentTab(d->tabLayout->indexOf(tab)); 169 | } 170 | 171 | void QtMaterialTabs::setCurrentTab(int index) 172 | { 173 | Q_D(QtMaterialTabs); 174 | 175 | setTabActive(d->tab, false); 176 | d->tab = index; 177 | setTabActive(index, true); 178 | d->inkBar->animate(); 179 | 180 | emit currentChanged(index); 181 | } 182 | 183 | void QtMaterialTabs::addTab(const QString &text, const QIcon &icon) 184 | { 185 | Q_D(QtMaterialTabs); 186 | 187 | QtMaterialTab *tab = new QtMaterialTab(this); 188 | tab->setText(text); 189 | tab->setHaloVisible(isHaloVisible()); 190 | tab->setRippleStyle(rippleStyle()); 191 | 192 | if (!icon.isNull()) { 193 | tab->setIcon(icon); 194 | tab->setIconSize(QSize(22, 22)); 195 | } 196 | 197 | d->tabLayout->addWidget(tab); 198 | 199 | if (-1 == d->tab) { 200 | d->tab = 0; 201 | d->inkBar->refreshGeometry(); 202 | d->inkBar->raise(); 203 | tab->setActive(true); 204 | } 205 | } 206 | 207 | int QtMaterialTabs::currentIndex() const 208 | { 209 | Q_D(const QtMaterialTabs); 210 | 211 | return d->tab; 212 | } 213 | 214 | void QtMaterialTabs::setTabActive(int index, bool active) 215 | { 216 | Q_D(QtMaterialTabs); 217 | 218 | QtMaterialTab *tab; 219 | 220 | if (index > -1) { 221 | tab = static_cast(d->tabLayout->itemAt(index)->widget()); 222 | if (tab) { 223 | tab->setActive(active); 224 | } 225 | } 226 | } 227 | 228 | void QtMaterialTabs::updateTabs() 229 | { 230 | Q_D(QtMaterialTabs); 231 | 232 | QtMaterialTab *tab; 233 | for (int i = 0; i < d->tabLayout->count(); ++i) { 234 | QLayoutItem *item = d->tabLayout->itemAt(i); 235 | if ((tab = static_cast(item->widget()))) { 236 | tab->setRippleStyle(d->rippleStyle); 237 | tab->setHaloVisible(d->showHalo); 238 | tab->setBackgroundColor(backgroundColor()); 239 | tab->setForegroundColor(textColor()); 240 | } 241 | } 242 | } 243 | -------------------------------------------------------------------------------- /components/qtmaterialtabs.h: -------------------------------------------------------------------------------- 1 | #ifndef QTMATERIALTABS_H 2 | #define QTMATERIALTABS_H 3 | 4 | #include 5 | #include 6 | #include "components/lib/qtmaterialtheme.h" 7 | 8 | class QtMaterialTabsPrivate; 9 | class QtMaterialTab; 10 | 11 | class QtMaterialTabs : public QWidget 12 | { 13 | Q_OBJECT 14 | 15 | public: 16 | explicit QtMaterialTabs(QWidget *parent = 0); 17 | ~QtMaterialTabs(); 18 | 19 | void setUseThemeColors(bool value); 20 | bool useThemeColors() const; 21 | 22 | void setHaloVisible(bool value); 23 | bool isHaloVisible() const; 24 | 25 | void setRippleStyle(Material::RippleStyle style); 26 | Material::RippleStyle rippleStyle() const; 27 | 28 | void setInkColor(const QColor &color); 29 | QColor inkColor() const; 30 | 31 | void setBackgroundColor(const QColor &color); 32 | QColor backgroundColor() const; 33 | 34 | void setTextColor(const QColor &color); 35 | QColor textColor() const; 36 | 37 | void addTab(const QString &text, const QIcon &icon = QIcon()); 38 | 39 | void setCurrentTab(QtMaterialTab *tab); 40 | void setCurrentTab(int index); 41 | 42 | int currentIndex() const; 43 | 44 | signals: 45 | void currentChanged(int); 46 | 47 | protected: 48 | void setTabActive(int index, bool active = true); 49 | void updateTabs(); 50 | 51 | const QScopedPointer d_ptr; 52 | 53 | private: 54 | Q_DISABLE_COPY(QtMaterialTabs) 55 | Q_DECLARE_PRIVATE(QtMaterialTabs) 56 | }; 57 | 58 | #endif // QTMATERIALTABS_H 59 | -------------------------------------------------------------------------------- /components/qtmaterialtabs_internal.cpp: -------------------------------------------------------------------------------- 1 | #include "qtmaterialtabs_internal.h" 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include "qtmaterialtabs.h" 8 | #include 9 | 10 | /*! 11 | * \class QtMaterialTabsInkBar 12 | * \internal 13 | */ 14 | 15 | QtMaterialTabsInkBar::QtMaterialTabsInkBar(QtMaterialTabs *parent) 16 | : QtMaterialOverlayWidget(parent), 17 | m_tabs(parent), 18 | m_animation(new QPropertyAnimation(parent)), 19 | m_tween(0) 20 | { 21 | Q_ASSERT(parent); 22 | 23 | m_animation->setPropertyName("tweenValue"); 24 | m_animation->setEasingCurve(QEasingCurve::OutCirc); 25 | m_animation->setTargetObject(this); 26 | m_animation->setDuration(700); 27 | 28 | m_tabs->installEventFilter(this); 29 | 30 | setAttribute(Qt::WA_TransparentForMouseEvents); 31 | setAttribute(Qt::WA_NoSystemBackground); 32 | } 33 | 34 | QtMaterialTabsInkBar::~QtMaterialTabsInkBar() 35 | { 36 | } 37 | 38 | void QtMaterialTabsInkBar::refreshGeometry() 39 | { 40 | QLayoutItem *item = m_tabs->layout()->itemAt(m_tabs->currentIndex()); 41 | 42 | if (item) 43 | { 44 | const QRect r(item->geometry()); 45 | const qreal s = 1-m_tween; 46 | 47 | if (QAbstractAnimation::Running != m_animation->state()) { 48 | m_geometry = QRect(r.left(), r.bottom()-1, r.width(), 2); 49 | } else { 50 | const qreal left = m_previousGeometry.left()*s + r.left()*m_tween; 51 | const qreal width = m_previousGeometry.width()*s + r.width()*m_tween; 52 | m_geometry = QRect(left, r.bottom()-1, width, 2); 53 | } 54 | m_tabs->update(); 55 | } 56 | } 57 | 58 | void QtMaterialTabsInkBar::animate() 59 | { 60 | raise(); 61 | 62 | m_previousGeometry = m_geometry; 63 | 64 | m_animation->stop(); 65 | m_animation->setStartValue(0); 66 | m_animation->setEndValue(1); 67 | m_animation->start(); 68 | } 69 | 70 | bool QtMaterialTabsInkBar::eventFilter(QObject *obj, QEvent *event) 71 | { 72 | switch (event->type()) 73 | { 74 | case QEvent::Move: 75 | case QEvent::Resize: 76 | { 77 | refreshGeometry(); 78 | break; 79 | } 80 | default: 81 | break; 82 | } 83 | return QtMaterialOverlayWidget::eventFilter(obj, event); 84 | } 85 | 86 | void QtMaterialTabsInkBar::paintEvent(QPaintEvent *event) 87 | { 88 | Q_UNUSED(event) 89 | 90 | QPainter painter(this); 91 | 92 | painter.setOpacity(1); 93 | painter.fillRect(m_geometry, m_tabs->inkColor()); 94 | } 95 | 96 | /*! 97 | * \class QtMaterialTab 98 | * \internal 99 | */ 100 | 101 | QtMaterialTab::QtMaterialTab(QtMaterialTabs *parent) 102 | : QtMaterialFlatButton(parent), 103 | m_tabs(parent), 104 | m_active(false) 105 | { 106 | Q_ASSERT(parent); 107 | 108 | setMinimumHeight(50); 109 | 110 | QFont f(font()); 111 | f.setStyleName("Normal"); 112 | setFont(f); 113 | 114 | setCornerRadius(0); 115 | setRole(Material::Primary); 116 | setBackgroundMode(Qt::OpaqueMode); 117 | setBaseOpacity(0.25); 118 | 119 | connect(this, SIGNAL(clicked(bool)), this, SLOT(activateTab())); 120 | } 121 | 122 | QtMaterialTab::~QtMaterialTab() 123 | { 124 | } 125 | 126 | QSize QtMaterialTab::sizeHint() const 127 | { 128 | if (icon().isNull()) { 129 | return QtMaterialFlatButton::sizeHint(); 130 | } else { 131 | return QSize(40, iconSize().height()+46); 132 | } 133 | } 134 | 135 | void QtMaterialTab::activateTab() 136 | { 137 | m_tabs->setCurrentTab(this); 138 | } 139 | 140 | void QtMaterialTab::paintForeground(QPainter *painter) 141 | { 142 | painter->setPen(foregroundColor()); 143 | 144 | if (!icon().isNull()) { 145 | painter->translate(0, 12); 146 | } 147 | 148 | QSize textSize(fontMetrics().size(Qt::TextSingleLine, text())); 149 | QSize base(size()-textSize); 150 | 151 | QRect textGeometry(QPoint(base.width(), base.height())/2, textSize); 152 | 153 | painter->drawText(textGeometry, Qt::AlignCenter, text()); 154 | 155 | if (!icon().isNull()) 156 | { 157 | const QSize &size = iconSize(); 158 | QRect iconRect(QPoint((width()-size.width())/2, 0), size); 159 | 160 | QPixmap pixmap = icon().pixmap(iconSize()); 161 | QPainter icon(&pixmap); 162 | icon.setCompositionMode(QPainter::CompositionMode_SourceIn); 163 | icon.fillRect(pixmap.rect(), painter->pen().color()); 164 | painter->drawPixmap(iconRect, pixmap); 165 | } 166 | 167 | if (!m_active) 168 | { 169 | if (!icon().isNull()) { 170 | painter->translate(0, -12); 171 | } 172 | QBrush overlay; 173 | overlay.setStyle(Qt::SolidPattern); 174 | overlay.setColor(backgroundColor()); 175 | painter->setOpacity(0.36); 176 | painter->fillRect(rect(), overlay); 177 | } 178 | } 179 | -------------------------------------------------------------------------------- /components/qtmaterialtabs_internal.h: -------------------------------------------------------------------------------- 1 | #ifndef QTMATERIALTABS_INTERNAL_H 2 | #define QTMATERIALTABS_INTERNAL_H 3 | 4 | #include "components/lib/qtmaterialoverlaywidget.h" 5 | #include "qtmaterialflatbutton.h" 6 | 7 | class QPropertyAnimation; 8 | class QtMaterialTabs; 9 | 10 | class QtMaterialTabsInkBar : public QtMaterialOverlayWidget 11 | { 12 | Q_OBJECT 13 | 14 | Q_PROPERTY(qreal tweenValue WRITE setTweenValue READ tweenValue) 15 | 16 | public: 17 | QtMaterialTabsInkBar(QtMaterialTabs *parent); 18 | ~QtMaterialTabsInkBar(); 19 | 20 | inline void setTweenValue(qreal value); 21 | inline qreal tweenValue() const; 22 | 23 | void refreshGeometry(); 24 | void animate(); 25 | 26 | protected: 27 | bool eventFilter(QObject *obj, QEvent *event) Q_DECL_OVERRIDE; 28 | void paintEvent(QPaintEvent *event) Q_DECL_OVERRIDE; 29 | 30 | private: 31 | Q_DISABLE_COPY(QtMaterialTabsInkBar) 32 | 33 | QtMaterialTabs *const m_tabs; 34 | QPropertyAnimation *const m_animation; 35 | QRect m_geometry; 36 | QRect m_previousGeometry; 37 | qreal m_tween; 38 | }; 39 | 40 | inline void QtMaterialTabsInkBar::setTweenValue(qreal value) 41 | { 42 | m_tween = value; 43 | refreshGeometry(); 44 | } 45 | 46 | inline qreal QtMaterialTabsInkBar::tweenValue() const 47 | { 48 | return m_tween; 49 | } 50 | 51 | class QtMaterialTab : public QtMaterialFlatButton 52 | { 53 | Q_OBJECT 54 | 55 | public: 56 | explicit QtMaterialTab(QtMaterialTabs *parent); 57 | ~QtMaterialTab(); 58 | 59 | inline void setActive(bool state); 60 | inline bool isActive() const; 61 | 62 | QSize sizeHint() const Q_DECL_OVERRIDE; 63 | 64 | protected slots: 65 | void activateTab(); 66 | 67 | protected: 68 | void paintForeground(QPainter *painter) Q_DECL_OVERRIDE; 69 | 70 | private: 71 | Q_DISABLE_COPY(QtMaterialTab) 72 | 73 | QtMaterialTabs *const m_tabs; 74 | bool m_active; 75 | }; 76 | 77 | inline void QtMaterialTab::setActive(bool state) 78 | { 79 | m_active = state; 80 | update(); 81 | } 82 | 83 | inline bool QtMaterialTab::isActive() const 84 | { 85 | return m_active; 86 | } 87 | 88 | #endif // QTMATERIALTABS_INTERNAL_H 89 | -------------------------------------------------------------------------------- /components/qtmaterialtabs_p.h: -------------------------------------------------------------------------------- 1 | #ifndef QTMATERIALTABS_P_H 2 | #define QTMATERIALTABS_P_H 3 | 4 | #include 5 | #include "components/lib/qtmaterialtheme.h" 6 | 7 | class QHBoxLayout; 8 | class QtMaterialTabs; 9 | class QtMaterialTabsInkBar; 10 | 11 | class QtMaterialTabsPrivate 12 | { 13 | Q_DISABLE_COPY(QtMaterialTabsPrivate) 14 | Q_DECLARE_PUBLIC(QtMaterialTabs) 15 | 16 | public: 17 | QtMaterialTabsPrivate(QtMaterialTabs *q); 18 | ~QtMaterialTabsPrivate(); 19 | 20 | void init(); 21 | 22 | QtMaterialTabs *const q_ptr; 23 | QtMaterialTabsInkBar *inkBar; 24 | QHBoxLayout *tabLayout; 25 | Material::RippleStyle rippleStyle; 26 | QColor inkColor; 27 | QColor backgroundColor; 28 | QColor textColor; 29 | int tab; 30 | bool showHalo; 31 | bool useThemeColors; 32 | }; 33 | 34 | #endif // QTMATERIALTABS_P_H 35 | -------------------------------------------------------------------------------- /components/qtmaterialtextfield.h: -------------------------------------------------------------------------------- 1 | #ifndef QTMATERIALTEXTFIELD_H 2 | #define QTMATERIALTEXTFIELD_H 3 | 4 | #include 5 | #include 6 | 7 | class QtMaterialTextFieldPrivate; 8 | 9 | class QtMaterialTextField : public QLineEdit 10 | { 11 | Q_OBJECT 12 | 13 | Q_PROPERTY(QColor textColor WRITE setTextColor READ textColor) 14 | Q_PROPERTY(QColor inkColor WRITE setInkColor READ inkColor) 15 | Q_PROPERTY(QColor inputLineColor WRITE setInputLineColor READ inputLineColor) 16 | 17 | public: 18 | explicit QtMaterialTextField(QWidget *parent = 0); 19 | ~QtMaterialTextField(); 20 | 21 | void setUseThemeColors(bool value); 22 | bool useThemeColors() const; 23 | 24 | void setShowLabel(bool value); 25 | bool hasLabel() const; 26 | 27 | void setLabelFontSize(qreal size); 28 | qreal labelFontSize() const; 29 | 30 | void setLabel(const QString &label); 31 | QString label() const; 32 | 33 | void setTextColor(const QColor &color); 34 | QColor textColor() const; 35 | 36 | void setLabelColor(const QColor &color); 37 | QColor labelColor() const; 38 | 39 | void setInkColor(const QColor &color); 40 | QColor inkColor() const; 41 | 42 | void setInputLineColor(const QColor &color); 43 | QColor inputLineColor() const; 44 | 45 | void setShowInputLine(bool value); 46 | bool hasInputLine() const; 47 | 48 | protected: 49 | QtMaterialTextField(QtMaterialTextFieldPrivate &d, QWidget *parent = 0); 50 | 51 | bool event(QEvent *event) Q_DECL_OVERRIDE; 52 | void paintEvent(QPaintEvent *event) Q_DECL_OVERRIDE; 53 | 54 | const QScopedPointer d_ptr; 55 | 56 | private: 57 | Q_DISABLE_COPY(QtMaterialTextField) 58 | Q_DECLARE_PRIVATE(QtMaterialTextField) 59 | }; 60 | 61 | #endif // QTMATERIALTEXTFIELD_H 62 | -------------------------------------------------------------------------------- /components/qtmaterialtextfield_internal.cpp: -------------------------------------------------------------------------------- 1 | #include "qtmaterialtextfield_internal.h" 2 | #include 3 | #include 4 | #include 5 | #include "qtmaterialtextfield.h" 6 | 7 | /*! 8 | * \class QtMaterialTextFieldStateMachine 9 | * \internal 10 | */ 11 | 12 | QtMaterialTextFieldStateMachine::QtMaterialTextFieldStateMachine(QtMaterialTextField *parent) 13 | : QStateMachine(parent), 14 | m_textField(parent), 15 | m_normalState(new QState), 16 | m_focusedState(new QState), 17 | m_label(0), 18 | m_offsetAnimation(0), 19 | m_colorAnimation(0), 20 | m_progress(0.0) 21 | { 22 | Q_ASSERT(parent); 23 | 24 | addState(m_normalState); 25 | addState(m_focusedState); 26 | 27 | setInitialState(m_normalState); 28 | 29 | QEventTransition *transition; 30 | QPropertyAnimation *animation; 31 | 32 | transition = new QEventTransition(parent, QEvent::FocusIn); 33 | transition->setTargetState(m_focusedState); 34 | m_normalState->addTransition(transition); 35 | 36 | animation = new QPropertyAnimation(this, "progress", this); 37 | animation->setEasingCurve(QEasingCurve::InCubic); 38 | animation->setDuration(310); 39 | transition->addAnimation(animation); 40 | 41 | transition = new QEventTransition(parent, QEvent::FocusOut); 42 | transition->setTargetState(m_normalState); 43 | m_focusedState->addTransition(transition); 44 | 45 | animation = new QPropertyAnimation(this, "progress", this); 46 | animation->setEasingCurve(QEasingCurve::OutCubic); 47 | animation->setDuration(310); 48 | transition->addAnimation(animation); 49 | 50 | m_normalState->assignProperty(this, "progress", 0); 51 | m_focusedState->assignProperty(this, "progress", 1); 52 | 53 | setupProperties(); 54 | 55 | connect(m_textField, SIGNAL(textChanged(QString)), this, SLOT(setupProperties())); 56 | } 57 | 58 | QtMaterialTextFieldStateMachine::~QtMaterialTextFieldStateMachine() 59 | { 60 | } 61 | 62 | void QtMaterialTextFieldStateMachine::setLabel(QtMaterialTextFieldLabel *label) 63 | { 64 | if (m_label) { 65 | delete m_label; 66 | } 67 | 68 | if (m_offsetAnimation) { 69 | removeDefaultAnimation(m_offsetAnimation); 70 | delete m_offsetAnimation; 71 | } 72 | 73 | if (m_colorAnimation) { 74 | removeDefaultAnimation(m_colorAnimation); 75 | delete m_colorAnimation; 76 | } 77 | 78 | m_label = label; 79 | 80 | if (m_label) 81 | { 82 | m_offsetAnimation = new QPropertyAnimation(m_label, "offset", this); 83 | m_offsetAnimation->setDuration(210); 84 | m_offsetAnimation->setEasingCurve(QEasingCurve::OutCubic); 85 | addDefaultAnimation(m_offsetAnimation); 86 | 87 | m_colorAnimation = new QPropertyAnimation(m_label, "color", this); 88 | m_colorAnimation->setDuration(210); 89 | addDefaultAnimation(m_colorAnimation); 90 | } 91 | 92 | setupProperties(); 93 | } 94 | 95 | void QtMaterialTextFieldStateMachine::setupProperties() 96 | { 97 | if (m_label) 98 | { 99 | const int m = m_textField->textMargins().top(); 100 | 101 | if (m_textField->text().isEmpty()) { 102 | m_normalState->assignProperty(m_label, "offset", QPointF(0, 26)); 103 | } else { 104 | m_normalState->assignProperty(m_label, "offset", QPointF(0, 0-m)); 105 | } 106 | 107 | m_focusedState->assignProperty(m_label, "offset", QPointF(0, 0-m)); 108 | m_focusedState->assignProperty(m_label, "color", m_textField->inkColor()); 109 | m_normalState->assignProperty(m_label, "color", m_textField->labelColor()); 110 | 111 | if (0 != m_label->offset().y() && !m_textField->text().isEmpty()) { 112 | m_label->setOffset(QPointF(0, 0-m)); 113 | } else if (!m_textField->hasFocus() && m_label->offset().y() <= 0 && m_textField->text().isEmpty()) { 114 | m_label->setOffset(QPointF(0, 26)); 115 | } 116 | } 117 | 118 | m_textField->update(); 119 | } 120 | 121 | /*! 122 | * \class QtMaterialTextFieldLabel 123 | * \internal 124 | */ 125 | 126 | QtMaterialTextFieldLabel::QtMaterialTextFieldLabel(QtMaterialTextField *parent) 127 | : QWidget(parent), 128 | m_textField(parent), 129 | m_scale(1), 130 | m_posX(0), 131 | m_posY(26), 132 | m_color(parent->labelColor()) 133 | { 134 | Q_ASSERT(parent); 135 | 136 | QFont font("Roboto", parent->labelFontSize(), QFont::Medium); 137 | font.setLetterSpacing(QFont::PercentageSpacing, 102); 138 | setFont(font); 139 | } 140 | 141 | QtMaterialTextFieldLabel::~QtMaterialTextFieldLabel() 142 | { 143 | } 144 | 145 | /*! 146 | * \reimp 147 | */ 148 | void QtMaterialTextFieldLabel::paintEvent(QPaintEvent *event) 149 | { 150 | Q_UNUSED(event) 151 | 152 | if (!m_textField->hasLabel()) { 153 | return; 154 | } 155 | 156 | QPainter painter(this); 157 | painter.setRenderHint(QPainter::Antialiasing); 158 | painter.scale(m_scale, m_scale); 159 | painter.setPen(m_color); 160 | painter.setOpacity(1); 161 | 162 | QPointF pos(2+m_posX, height()-36+m_posY); 163 | painter.drawText(pos.x(), pos.y(), m_textField->label()); 164 | } 165 | -------------------------------------------------------------------------------- /components/qtmaterialtextfield_internal.h: -------------------------------------------------------------------------------- 1 | #ifndef QTMATERIALTEXTFIELD_INTERNAL_H 2 | #define QTMATERIALTEXTFIELD_INTERNAL_H 3 | 4 | #include 5 | #include 6 | #include "qtmaterialtextfield.h" 7 | 8 | class QPropertyAnimation; 9 | class QtMaterialTextFieldLabel; 10 | 11 | class QtMaterialTextFieldStateMachine : public QStateMachine 12 | { 13 | Q_OBJECT 14 | 15 | Q_PROPERTY(qreal progress WRITE setProgress READ progress) 16 | 17 | public: 18 | QtMaterialTextFieldStateMachine(QtMaterialTextField *parent); 19 | ~QtMaterialTextFieldStateMachine(); 20 | 21 | void setLabel(QtMaterialTextFieldLabel *label); 22 | 23 | inline void setProgress(qreal progress); 24 | inline qreal progress() const; 25 | 26 | public slots: 27 | void setupProperties(); 28 | 29 | private: 30 | Q_DISABLE_COPY(QtMaterialTextFieldStateMachine) 31 | 32 | QtMaterialTextField *const m_textField; 33 | QState *const m_normalState; 34 | QState *const m_focusedState; 35 | QtMaterialTextFieldLabel *m_label; 36 | QPropertyAnimation *m_offsetAnimation; 37 | QPropertyAnimation *m_colorAnimation; 38 | qreal m_progress; 39 | }; 40 | 41 | inline void QtMaterialTextFieldStateMachine::setProgress(qreal progress) 42 | { 43 | m_progress = progress; 44 | m_textField->update(); 45 | } 46 | 47 | inline qreal QtMaterialTextFieldStateMachine::progress() const 48 | { 49 | return m_progress; 50 | } 51 | 52 | class QtMaterialTextFieldLabel : public QWidget 53 | { 54 | Q_OBJECT 55 | 56 | Q_PROPERTY(qreal scale WRITE setScale READ scale) 57 | Q_PROPERTY(QPointF offset WRITE setOffset READ offset) 58 | Q_PROPERTY(QColor color WRITE setColor READ color) 59 | 60 | public: 61 | QtMaterialTextFieldLabel(QtMaterialTextField *parent); 62 | ~QtMaterialTextFieldLabel(); 63 | 64 | inline void setScale(qreal scale); 65 | inline qreal scale() const; 66 | 67 | inline void setOffset(const QPointF &pos); 68 | inline QPointF offset() const; 69 | 70 | inline void setColor(const QColor &color); 71 | inline QColor color() const; 72 | 73 | protected: 74 | void paintEvent(QPaintEvent *event) Q_DECL_OVERRIDE; 75 | 76 | private: 77 | Q_DISABLE_COPY(QtMaterialTextFieldLabel) 78 | 79 | QtMaterialTextField *const m_textField; 80 | qreal m_scale; 81 | qreal m_posX; 82 | qreal m_posY; 83 | QColor m_color; 84 | }; 85 | 86 | inline void QtMaterialTextFieldLabel::setScale(qreal scale) 87 | { 88 | m_scale = scale; 89 | update(); 90 | } 91 | 92 | inline qreal QtMaterialTextFieldLabel::scale() const 93 | { 94 | return m_scale; 95 | } 96 | 97 | inline void QtMaterialTextFieldLabel::setOffset(const QPointF &pos) 98 | { 99 | m_posX = pos.x(); 100 | m_posY = pos.y(); 101 | update(); 102 | } 103 | 104 | inline QPointF QtMaterialTextFieldLabel::offset() const 105 | { 106 | return QPointF(m_posX, m_posY); 107 | } 108 | 109 | inline void QtMaterialTextFieldLabel::setColor(const QColor &color) 110 | { 111 | m_color = color; 112 | update(); 113 | } 114 | 115 | inline QColor QtMaterialTextFieldLabel::color() const 116 | { 117 | return m_color; 118 | } 119 | 120 | #endif // QTMATERIALTEXTFIELD_INTERNAL_H 121 | -------------------------------------------------------------------------------- /components/qtmaterialtextfield_p.h: -------------------------------------------------------------------------------- 1 | #ifndef QTMATERIALTEXTFIELD_P_H 2 | #define QTMATERIALTEXTFIELD_P_H 3 | 4 | #include 5 | #include 6 | 7 | class QtMaterialTextField; 8 | class QtMaterialTextFieldStateMachine; 9 | class QtMaterialTextFieldLabel; 10 | 11 | class QtMaterialTextFieldPrivate 12 | { 13 | Q_DISABLE_COPY(QtMaterialTextFieldPrivate) 14 | Q_DECLARE_PUBLIC(QtMaterialTextField) 15 | 16 | public: 17 | QtMaterialTextFieldPrivate(QtMaterialTextField *q); 18 | virtual ~QtMaterialTextFieldPrivate(); 19 | 20 | void init(); 21 | 22 | QtMaterialTextField *const q_ptr; 23 | QtMaterialTextFieldStateMachine *stateMachine; 24 | QtMaterialTextFieldLabel *label; 25 | QColor textColor; 26 | QColor labelColor; 27 | QColor inkColor; 28 | QColor inputLineColor; 29 | QString labelString; 30 | qreal labelFontSize; 31 | bool showLabel; 32 | bool showInputLine; 33 | bool useThemeColors; 34 | }; 35 | 36 | #endif // QTMATERIALTEXTFIELD_P_H 37 | -------------------------------------------------------------------------------- /components/qtmaterialtoggle.h: -------------------------------------------------------------------------------- 1 | #ifndef QTMATERIALTOGGLE_H 2 | #define QTMATERIALTOGGLE_H 3 | 4 | #include 5 | 6 | class QtMaterialTogglePrivate; 7 | 8 | class QtMaterialToggle : public QAbstractButton 9 | { 10 | Q_OBJECT 11 | 12 | Q_PROPERTY(QColor disabledColor WRITE setDisabledColor READ disabledColor) 13 | Q_PROPERTY(QColor activeColor WRITE setActiveColor READ activeColor) 14 | Q_PROPERTY(QColor inactiveColor WRITE setInactiveColor READ inactiveColor) 15 | Q_PROPERTY(QColor trackColor WRITE setTrackColor READ trackColor) 16 | 17 | public: 18 | explicit QtMaterialToggle(QWidget *parent = 0); 19 | ~QtMaterialToggle(); 20 | 21 | void setUseThemeColors(bool value); 22 | bool useThemeColors() const; 23 | 24 | void setDisabledColor(const QColor &color); 25 | QColor disabledColor() const; 26 | 27 | void setActiveColor(const QColor &color); 28 | QColor activeColor() const; 29 | 30 | void setInactiveColor(const QColor &color); 31 | QColor inactiveColor() const; 32 | 33 | void setTrackColor(const QColor &color); 34 | QColor trackColor() const; 35 | 36 | void setOrientation(Qt::Orientation orientation); 37 | Qt::Orientation orientation() const; 38 | 39 | void setSize(const QSize size); 40 | QSize size() const; 41 | 42 | QSize sizeHint() const Q_DECL_OVERRIDE; 43 | 44 | protected: 45 | bool event(QEvent *event) Q_DECL_OVERRIDE; 46 | void paintEvent(QPaintEvent *event) Q_DECL_OVERRIDE; 47 | 48 | const QScopedPointer d_ptr; 49 | 50 | private: 51 | Q_DISABLE_COPY(QtMaterialToggle) 52 | Q_DECLARE_PRIVATE(QtMaterialToggle) 53 | }; 54 | 55 | #endif // QTMATERIALTOGGLE_H 56 | -------------------------------------------------------------------------------- /components/qtmaterialtoggle_internal.cpp: -------------------------------------------------------------------------------- 1 | #include "qtmaterialtoggle_internal.h" 2 | #include 3 | #include 4 | #include 5 | #include "qtmaterialtoggle.h" 6 | #include "components/lib/qtmaterialripple.h" 7 | 8 | /*! 9 | * \class QtMaterialToggleRippleOverlay 10 | * \internal 11 | */ 12 | 13 | QtMaterialToggleRippleOverlay::QtMaterialToggleRippleOverlay( 14 | QtMaterialToggleThumb *thumb, 15 | QtMaterialToggleTrack *track, 16 | QtMaterialToggle *parent) 17 | : QtMaterialRippleOverlay(parent->parentWidget()), 18 | m_toggle(parent), 19 | m_thumb(thumb), 20 | m_track(track) 21 | { 22 | connect(parent, SIGNAL(toggled(bool)), this, SLOT(addToggleRipple())); 23 | 24 | thumb->installEventFilter(this); 25 | } 26 | 27 | QtMaterialToggleRippleOverlay::~QtMaterialToggleRippleOverlay() 28 | { 29 | } 30 | 31 | void QtMaterialToggleRippleOverlay::addToggleRipple() 32 | { 33 | if (!m_toggle->isEnabled()) { 34 | return; 35 | } 36 | 37 | int t, w; 38 | 39 | if (Qt::Horizontal == m_toggle->orientation()) { 40 | t = m_toggle->height()/2; 41 | w = m_thumb->height()/2 + m_thumb->height()*0.15; 42 | } else { 43 | t = m_toggle->width()/2; 44 | w = m_thumb->width()/2; 45 | } 46 | 47 | QtMaterialRipple *ripple = new QtMaterialRipple(QPoint(t,t)); 48 | ripple->setColor(m_track->trackColor()); 49 | ripple->setRadiusEndValue(w); 50 | ripple->setOpacityStartValue(0.8); 51 | 52 | addRipple(ripple); 53 | } 54 | 55 | bool QtMaterialToggleRippleOverlay::eventFilter(QObject *obj, QEvent *event) 56 | { 57 | if (QEvent::Paint == event->type()) { 58 | setGeometry(overlayGeometry()); 59 | QList::const_iterator i; 60 | QList items = ripples(); 61 | QColor color = m_track->trackColor(); 62 | for (i = items.begin(); i != items.end(); ++i) { 63 | (*i)->setColor(color); 64 | } 65 | } 66 | return QtMaterialRippleOverlay::eventFilter(obj, event); 67 | } 68 | 69 | QRect QtMaterialToggleRippleOverlay::overlayGeometry() const 70 | { 71 | const qreal offset = m_thumb->offset(); 72 | if (Qt::Horizontal == m_toggle->orientation()) { 73 | return m_toggle->geometry().adjusted(offset, 0, offset,0); 74 | } else { 75 | return m_toggle->geometry().adjusted(0, offset, 0,offset); 76 | } 77 | } 78 | 79 | /*! 80 | * \class QtMaterialToggleThumb 81 | * \internal 82 | */ 83 | 84 | QtMaterialToggleThumb::QtMaterialToggleThumb(QtMaterialToggle *parent) 85 | : QWidget(parent), 86 | m_toggle(parent), 87 | m_shift(0), 88 | m_offset(0) 89 | { 90 | Q_ASSERT(parent); 91 | 92 | QGraphicsDropShadowEffect *effect = new QGraphicsDropShadowEffect; 93 | effect->setBlurRadius(6); 94 | effect->setColor(QColor(0, 0, 0, 80)); 95 | effect->setOffset(QPointF(0, 1)); 96 | setGraphicsEffect(effect); 97 | 98 | parent->installEventFilter(this); 99 | } 100 | 101 | QtMaterialToggleThumb::~QtMaterialToggleThumb() 102 | { 103 | } 104 | 105 | void QtMaterialToggleThumb::setShift(qreal shift) 106 | { 107 | if (m_shift == shift) { 108 | return; 109 | } 110 | 111 | m_shift = shift; 112 | updateOffset(); 113 | } 114 | 115 | bool QtMaterialToggleThumb::eventFilter(QObject *obj, QEvent *event) 116 | { 117 | const QEvent::Type type = event->type(); 118 | 119 | if (QEvent::Resize == type || QEvent::Move == type) 120 | { 121 | setGeometry(m_toggle->rect()); 122 | updateOffset(); 123 | } 124 | return QWidget::eventFilter(obj, event); 125 | } 126 | 127 | void QtMaterialToggleThumb::paintEvent(QPaintEvent *event) 128 | { 129 | Q_UNUSED(event) 130 | 131 | QPainter painter(this); 132 | painter.setRenderHint(QPainter::Antialiasing); 133 | 134 | QBrush brush; 135 | brush.setStyle(Qt::SolidPattern); 136 | brush.setColor(m_toggle->isEnabled() ? m_thumbColor : Qt::white); 137 | 138 | painter.setBrush(brush); 139 | painter.setPen(Qt::NoPen); 140 | 141 | int s; 142 | QRectF r; 143 | 144 | if (Qt::Horizontal == m_toggle->orientation()) { 145 | s = height()*0.8; 146 | r = QRectF(m_offset,height()*0.1, s, s); 147 | } else { 148 | s = width()*0.8; 149 | r = QRectF(height()*0.1,m_offset, s, s); 150 | } 151 | 152 | painter.drawEllipse(r); 153 | 154 | if (!m_toggle->isEnabled()) { 155 | brush.setColor(m_toggle->disabledColor()); 156 | painter.setBrush(brush); 157 | painter.drawEllipse(r); 158 | } 159 | } 160 | 161 | void QtMaterialToggleThumb::updateOffset() 162 | { 163 | const QSize s(Qt::Horizontal == m_toggle->orientation() 164 | ? size() : size().transposed()); 165 | m_offset = m_shift*static_cast(s.width()-1.1*s.height()); 166 | qDebug() << "QtMaterialToggleThumb::updateOffset" << m_offset; 167 | update(); 168 | } 169 | 170 | /*! 171 | * \class QtMaterialToggleTrack 172 | * \internal 173 | */ 174 | 175 | QtMaterialToggleTrack::QtMaterialToggleTrack(QtMaterialToggle *parent) 176 | : QWidget(parent), 177 | m_toggle(parent) 178 | { 179 | Q_ASSERT(parent); 180 | 181 | parent->installEventFilter(this); 182 | } 183 | 184 | QtMaterialToggleTrack::~QtMaterialToggleTrack() 185 | { 186 | } 187 | 188 | void QtMaterialToggleTrack::setTrackColor(const QColor &color) 189 | { 190 | m_trackColor = color; 191 | update(); 192 | } 193 | 194 | bool QtMaterialToggleTrack::eventFilter(QObject *obj, QEvent *event) 195 | { 196 | const QEvent::Type type = event->type(); 197 | 198 | if (QEvent::Resize == type || QEvent::Move == type) { 199 | setGeometry(m_toggle->rect()); 200 | } 201 | return QWidget::eventFilter(obj, event); 202 | } 203 | 204 | void QtMaterialToggleTrack::paintEvent(QPaintEvent *event) 205 | { 206 | Q_UNUSED(event) 207 | 208 | QPainter painter(this); 209 | painter.setRenderHint(QPainter::Antialiasing); 210 | 211 | QBrush brush; 212 | if (m_toggle->isEnabled()) { 213 | brush.setColor(m_trackColor); 214 | painter.setOpacity(0.8); 215 | } else { 216 | brush.setColor(m_toggle->disabledColor()); 217 | painter.setOpacity(0.6); 218 | } 219 | brush.setStyle(Qt::SolidPattern); 220 | painter.setBrush(brush); 221 | painter.setPen(Qt::NoPen); 222 | 223 | if (Qt::Horizontal == m_toggle->orientation()) { 224 | const int h = height()*0.2; 225 | const QRect r(0, 0, width()*0.8, height()*0.6); 226 | painter.drawRoundedRect(r.adjusted(width()*0.1,h,-width()*0.1,h),height()*0.3, height()*0.3); 227 | } else { 228 | const int w = width()*0.2; 229 | const QRect r(0, 0, w, height()); 230 | painter.drawRoundedRect(r.adjusted(0, w, 0, w), w/2, w/2); 231 | } 232 | } 233 | -------------------------------------------------------------------------------- /components/qtmaterialtoggle_internal.h: -------------------------------------------------------------------------------- 1 | #ifndef QTMATERIALTOGGLE_INTERNAL_H 2 | #define QTMATERIALTOGGLE_INTERNAL_H 3 | 4 | #include 5 | #include 6 | #include "components/lib/qtmaterialrippleoverlay.h" 7 | 8 | class QtMaterialToggle; 9 | class QtMaterialToggleThumb; 10 | class QtMaterialToggleTrack; 11 | 12 | class QtMaterialToggleRippleOverlay : public QtMaterialRippleOverlay 13 | { 14 | Q_OBJECT 15 | 16 | public: 17 | QtMaterialToggleRippleOverlay(QtMaterialToggleThumb *thumb, 18 | QtMaterialToggleTrack *track, 19 | QtMaterialToggle *parent); 20 | ~QtMaterialToggleRippleOverlay(); 21 | 22 | protected slots: 23 | void addToggleRipple(); 24 | 25 | protected: 26 | bool eventFilter(QObject *obj, QEvent *event) Q_DECL_OVERRIDE; 27 | QRect overlayGeometry() const Q_DECL_OVERRIDE; 28 | 29 | private: 30 | Q_DISABLE_COPY(QtMaterialToggleRippleOverlay) 31 | 32 | QtMaterialToggle *const m_toggle; 33 | QtMaterialToggleThumb *const m_thumb; 34 | QtMaterialToggleTrack *const m_track; 35 | }; 36 | 37 | class QtMaterialToggleThumb : public QWidget 38 | { 39 | Q_OBJECT 40 | 41 | Q_PROPERTY(qreal shift WRITE setShift READ shift) 42 | Q_PROPERTY(QColor thumbColor WRITE setThumbColor READ thumbColor) 43 | 44 | public: 45 | QtMaterialToggleThumb(QtMaterialToggle *parent); 46 | ~QtMaterialToggleThumb(); 47 | 48 | void setShift(qreal shift); 49 | inline qreal shift() const; 50 | 51 | inline qreal offset() const; 52 | 53 | inline void setThumbColor(const QColor &color); 54 | inline QColor thumbColor() const; 55 | 56 | protected: 57 | bool eventFilter(QObject *obj, QEvent *event) Q_DECL_OVERRIDE; 58 | void paintEvent(QPaintEvent *event) Q_DECL_OVERRIDE; 59 | 60 | private: 61 | Q_DISABLE_COPY(QtMaterialToggleThumb) 62 | 63 | void updateOffset(); 64 | 65 | QtMaterialToggle *const m_toggle; 66 | QColor m_thumbColor; 67 | qreal m_shift; 68 | qreal m_offset; 69 | }; 70 | 71 | inline qreal QtMaterialToggleThumb::shift() const 72 | { 73 | return m_shift; 74 | } 75 | 76 | inline qreal QtMaterialToggleThumb::offset() const 77 | { 78 | return m_offset; 79 | } 80 | 81 | inline void QtMaterialToggleThumb::setThumbColor(const QColor &color) 82 | { 83 | m_thumbColor = color; 84 | update(); 85 | } 86 | 87 | inline QColor QtMaterialToggleThumb::thumbColor() const 88 | { 89 | return m_thumbColor; 90 | } 91 | 92 | class QtMaterialToggleTrack : public QWidget 93 | { 94 | Q_OBJECT 95 | 96 | Q_PROPERTY(QColor trackColor WRITE setTrackColor READ trackColor) 97 | 98 | public: 99 | QtMaterialToggleTrack(QtMaterialToggle *parent); 100 | ~QtMaterialToggleTrack(); 101 | 102 | void setTrackColor(const QColor &color); 103 | inline QColor trackColor() const; 104 | 105 | protected: 106 | bool eventFilter(QObject *obj, QEvent *event) Q_DECL_OVERRIDE; 107 | void paintEvent(QPaintEvent *event) Q_DECL_OVERRIDE; 108 | 109 | private: 110 | Q_DISABLE_COPY(QtMaterialToggleTrack) 111 | 112 | QtMaterialToggle *const m_toggle; 113 | QColor m_trackColor; 114 | }; 115 | 116 | inline QColor QtMaterialToggleTrack::trackColor() const 117 | { 118 | return m_trackColor; 119 | } 120 | 121 | #endif // QTMATERIALTOGGLE_INTERNAL_H 122 | -------------------------------------------------------------------------------- /components/qtmaterialtoggle_p.h: -------------------------------------------------------------------------------- 1 | #ifndef QTMATERIALTOGGLE_P_H 2 | #define QTMATERIALTOGGLE_P_H 3 | 4 | #include 5 | 6 | class QStateMachine; 7 | class QState; 8 | class QColor; 9 | class QtMaterialToggle; 10 | class QtMaterialToggleTrack; 11 | class QtMaterialToggleThumb; 12 | class QtMaterialToggleRippleOverlay; 13 | 14 | class QtMaterialTogglePrivate 15 | { 16 | Q_DISABLE_COPY(QtMaterialTogglePrivate) 17 | Q_DECLARE_PUBLIC(QtMaterialToggle) 18 | 19 | public: 20 | QtMaterialTogglePrivate(QtMaterialToggle *q); 21 | ~QtMaterialTogglePrivate(); 22 | 23 | void init(); 24 | void setupProperties(); 25 | 26 | QtMaterialToggle *const q_ptr; 27 | QtMaterialToggleTrack *track; 28 | QtMaterialToggleThumb *thumb; 29 | QtMaterialToggleRippleOverlay *rippleOverlay; 30 | QStateMachine *stateMachine; 31 | QState *offState; 32 | QState *onState; 33 | Qt::Orientation orientation; 34 | QColor disabledColor; 35 | QColor activeColor; 36 | QColor inactiveColor; 37 | QColor trackColor; 38 | bool useThemeColors; 39 | QSize size; 40 | }; 41 | 42 | #endif // QTMATERIALTOGGLE_P_H 43 | -------------------------------------------------------------------------------- /resources.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | Images/checkBox_checked.png 4 | Images/checkBox_uncheck.png 5 | Images/radioBtn_deselect.png 6 | Images/radioBtn_selected.png 7 | 8 | 9 | --------------------------------------------------------------------------------