File indexing completed on 2024-05-19 05:28:49
0001 /* 0002 * SPDX-FileCopyrightText: 2014 Hugo Pereira Da Costa <hugo.pereira@free.fr> 0003 * 0004 * SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #pragma once 0008 0009 #include "breezewidgetstatedata.h" 0010 0011 #include <QStyle> 0012 0013 namespace Breeze 0014 { 0015 //* scrollbar data 0016 class ScrollBarData : public WidgetStateData 0017 { 0018 Q_OBJECT 0019 Q_PROPERTY(qreal addLineOpacity READ addLineOpacity WRITE setAddLineOpacity) 0020 Q_PROPERTY(qreal subLineOpacity READ subLineOpacity WRITE setSubLineOpacity) 0021 Q_PROPERTY(qreal grooveOpacity READ grooveOpacity WRITE setGrooveOpacity) 0022 0023 public: 0024 //* constructor 0025 ScrollBarData(QObject *parent, QObject *target, int duration); 0026 0027 //* event filter 0028 bool eventFilter(QObject *, QEvent *) override; 0029 0030 //* needed to avoid warning about virtual function being hidden 0031 using WidgetStateData::animation; 0032 using WidgetStateData::opacity; 0033 0034 //* return animation for a given subcontrol 0035 const Animation::Pointer &animation(QStyle::SubControl) const; 0036 0037 //* return default opacity for a given subcontrol 0038 qreal opacity(QStyle::SubControl) const; 0039 0040 //* return default opacity for a given subcontrol 0041 bool isHovered(QStyle::SubControl control) const 0042 { 0043 switch (control) { 0044 case QStyle::SC_ScrollBarAddLine: 0045 return addLineArrowHovered(); 0046 case QStyle::SC_ScrollBarSubLine: 0047 return subLineArrowHovered(); 0048 case QStyle::SC_ScrollBarGroove: 0049 return grooveHovered(); 0050 default: 0051 return false; 0052 } 0053 } 0054 0055 //* subControlRect 0056 QRect subControlRect(QStyle::SubControl control) const 0057 { 0058 switch (control) { 0059 case QStyle::SC_ScrollBarAddLine: 0060 return _addLineData._rect; 0061 case QStyle::SC_ScrollBarSubLine: 0062 return _subLineData._rect; 0063 default: 0064 return QRect(); 0065 } 0066 } 0067 0068 //* subcontrol rect 0069 void setSubControlRect(QStyle::SubControl control, const QRect &rect) 0070 { 0071 switch (control) { 0072 case QStyle::SC_ScrollBarAddLine: 0073 _addLineData._rect = rect; 0074 break; 0075 0076 case QStyle::SC_ScrollBarSubLine: 0077 _subLineData._rect = rect; 0078 break; 0079 0080 default: 0081 break; 0082 } 0083 } 0084 0085 //* duration 0086 void setDuration(int duration) override 0087 { 0088 WidgetStateData::setDuration(duration); 0089 addLineAnimation().data()->setDuration(duration); 0090 subLineAnimation().data()->setDuration(duration); 0091 grooveAnimation().data()->setDuration(duration); 0092 } 0093 0094 //* addLine opacity 0095 void setAddLineOpacity(qreal value) 0096 { 0097 value = digitize(value); 0098 if (_addLineData._opacity == value) { 0099 return; 0100 } 0101 _addLineData._opacity = value; 0102 setDirty(); 0103 } 0104 0105 //* addLine opacity 0106 qreal addLineOpacity() const 0107 { 0108 return _addLineData._opacity; 0109 } 0110 0111 //* subLine opacity 0112 void setSubLineOpacity(qreal value) 0113 { 0114 value = digitize(value); 0115 if (_subLineData._opacity == value) { 0116 return; 0117 } 0118 _subLineData._opacity = value; 0119 setDirty(); 0120 } 0121 0122 //* subLine opacity 0123 qreal subLineOpacity() const 0124 { 0125 return _subLineData._opacity; 0126 } 0127 0128 //* groove opacity 0129 void setGrooveOpacity(qreal value) 0130 { 0131 value = digitize(value); 0132 if (_grooveData._opacity == value) { 0133 return; 0134 } 0135 _grooveData._opacity = value; 0136 setDirty(); 0137 } 0138 0139 //* groove opacity 0140 qreal grooveOpacity() const 0141 { 0142 return _grooveData._opacity; 0143 } 0144 0145 //* mouse position 0146 QPoint position() const 0147 { 0148 return _position; 0149 } 0150 0151 protected Q_SLOTS: 0152 0153 //* clear addLineRect 0154 void clearAddLineRect() 0155 { 0156 if (addLineAnimation().data()->direction() == Animation::Backward) { 0157 _addLineData._rect = QRect(); 0158 } 0159 } 0160 0161 //* clear subLineRect 0162 void clearSubLineRect() 0163 { 0164 if (subLineAnimation().data()->direction() == Animation::Backward) { 0165 _subLineData._rect = QRect(); 0166 } 0167 } 0168 0169 private: 0170 //* hoverMoveEvent 0171 void hoverMoveEvent(QObject *, QEvent *); 0172 0173 //* hoverMoveEvent 0174 void hoverLeaveEvent(QObject *, QEvent *); 0175 0176 //*@name hover flags 0177 //@{ 0178 0179 bool addLineArrowHovered() const 0180 { 0181 return _addLineData._hovered; 0182 } 0183 0184 void setAddLineArrowHovered(bool value) 0185 { 0186 _addLineData._hovered = value; 0187 } 0188 0189 bool subLineArrowHovered() const 0190 { 0191 return _subLineData._hovered; 0192 } 0193 0194 void setSubLineArrowHovered(bool value) 0195 { 0196 _subLineData._hovered = value; 0197 } 0198 0199 bool grooveHovered() const 0200 { 0201 return _grooveData._hovered; 0202 } 0203 0204 void setGrooveHovered(bool value) 0205 { 0206 _grooveData._hovered = value; 0207 } 0208 0209 //@} 0210 0211 //* update add line arrow 0212 void updateAddLineArrow(QStyle::SubControl); 0213 0214 //* update sub line arrow 0215 void updateSubLineArrow(QStyle::SubControl); 0216 0217 //*@name timelines 0218 //@{ 0219 0220 const Animation::Pointer &addLineAnimation() const 0221 { 0222 return _addLineData._animation; 0223 } 0224 0225 const Animation::Pointer &subLineAnimation() const 0226 { 0227 return _subLineData._animation; 0228 } 0229 0230 const Animation::Pointer &grooveAnimation() const 0231 { 0232 return _grooveData._animation; 0233 } 0234 0235 //* stores sub control data 0236 class Data 0237 { 0238 public: 0239 //* constructor 0240 Data() 0241 : _hovered(false) 0242 , _opacity(AnimationData::OpacityInvalid) 0243 { 0244 } 0245 0246 //* true if hovered 0247 bool _hovered; 0248 0249 //* animation 0250 Animation::Pointer _animation; 0251 0252 //* opacity 0253 qreal _opacity; 0254 0255 //* rect 0256 QRect _rect; 0257 }; 0258 0259 //* add line data (down arrow) 0260 Data _addLineData; 0261 0262 //* subtract line data (up arrow) 0263 Data _subLineData; 0264 0265 //* groove data 0266 Data _grooveData; 0267 0268 //* mouse position 0269 QPoint _position; 0270 }; 0271 0272 }