File indexing completed on 2024-09-08 08:00:10
0001 /* 0002 SPDX-FileCopyrightText: 2018 Michail Vourlakos <mvourlakos@gmail.com> 0003 SPDX-License-Identifier: GPL-2.0-or-later 0004 */ 0005 0006 #ifndef EFFECTS_H 0007 #define EFFECTS_H 0008 0009 // local 0010 #include "../plasma/extended/theme.h" 0011 0012 // Qt 0013 #include <QObject> 0014 #include <QPointer> 0015 #include <QQuickView> 0016 #include <QRect> 0017 0018 // Plasma 0019 #include <Plasma/FrameSvg> 0020 #include <Plasma/Theme> 0021 0022 namespace Latte { 0023 class Corona; 0024 class View; 0025 } 0026 0027 namespace Latte { 0028 namespace ViewPart { 0029 0030 class Effects: public QObject 0031 { 0032 Q_OBJECT 0033 Q_PROPERTY(bool animationsBlocked READ animationsBlocked NOTIFY animationsBlockedChanged) 0034 Q_PROPERTY(bool drawShadows READ drawShadows WRITE setDrawShadows NOTIFY drawShadowsChanged) 0035 Q_PROPERTY(bool drawEffects READ drawEffects WRITE setDrawEffects NOTIFY drawEffectsChanged) 0036 0037 //! thickness shadow size when is drawn inside the window from qml 0038 Q_PROPERTY(int editShadow READ editShadow WRITE setEditShadow NOTIFY editShadowChanged) 0039 Q_PROPERTY(int innerShadow READ innerShadow WRITE setInnerShadow NOTIFY innerShadowChanged) 0040 0041 Q_PROPERTY(bool backgroundAllCorners READ backgroundAllCorners WRITE setBackgroundAllCorners NOTIFY backgroundAllCornersChanged) 0042 Q_PROPERTY(bool backgroundRadiusEnabled READ backgroundRadiusEnabled WRITE setBackgroundRadiusEnabled NOTIFY backgroundRadiusEnabledChanged) 0043 Q_PROPERTY(int backgroundRadius READ backgroundRadius WRITE setBackgroundRadius NOTIFY backgroundRadiusChanged) 0044 Q_PROPERTY(float backgroundOpacity READ backgroundOpacity WRITE setBackgroundOpacity NOTIFY backgroundOpacityChanged) 0045 0046 Q_PROPERTY(int popUpMargin READ popUpMargin NOTIFY popUpMarginChanged) 0047 0048 Q_PROPERTY(QRect mask READ mask WRITE setMask NOTIFY maskChanged) 0049 Q_PROPERTY(QRect rect READ rect WRITE setRect NOTIFY rectChanged) 0050 Q_PROPERTY(QRect inputMask READ inputMask WRITE setInputMask NOTIFY inputMaskChanged) 0051 Q_PROPERTY(QRect appletsLayoutGeometry READ appletsLayoutGeometry WRITE setAppletsLayoutGeometry NOTIFY appletsLayoutGeometryChanged) 0052 0053 Q_PROPERTY(Plasma::FrameSvg::EnabledBorders enabledBorders READ enabledBorders NOTIFY enabledBordersChanged) 0054 0055 Q_PROPERTY(QQuickItem *panelBackgroundSvg READ panelBackgroundSvg WRITE setPanelBackgroundSvg NOTIFY panelBackgroundSvgChanged) 0056 0057 public: 0058 Effects(Latte::View *parent); 0059 virtual ~Effects(); 0060 0061 bool animationsBlocked() const; 0062 void setAnimationsBlocked(bool blocked); 0063 0064 bool backgroundAllCorners() const; 0065 void setBackgroundAllCorners(bool allcorners); 0066 0067 bool backgroundRadiusEnabled() const; 0068 void setBackgroundRadiusEnabled(bool enabled); 0069 0070 bool drawShadows() const; 0071 void setDrawShadows(bool draw); 0072 0073 bool drawEffects() const; 0074 void setDrawEffects(bool draw); 0075 0076 void setForceTopBorder(bool draw); 0077 void setForceBottomBorder(bool draw); 0078 0079 int editShadow() const; 0080 void setEditShadow(int shadow); 0081 0082 int innerShadow() const; 0083 void setInnerShadow(int shadow); 0084 0085 int backgroundRadius(); 0086 void setBackgroundRadius(const int &radius); 0087 0088 int popUpMargin() const; 0089 0090 float backgroundOpacity() const; 0091 void setBackgroundOpacity(float opacity); 0092 0093 QRect mask() const; 0094 void setMask(QRect area); 0095 0096 QRect inputMask() const; 0097 void setInputMask(QRect area); 0098 0099 QRect rect() const; 0100 void setRect(QRect area); 0101 0102 QRect appletsLayoutGeometry() const; 0103 void setAppletsLayoutGeometry(const QRect &geom); 0104 0105 Plasma::FrameSvg::EnabledBorders enabledBorders() const; 0106 0107 QQuickItem *panelBackgroundSvg() const; 0108 void setPanelBackgroundSvg(QQuickItem *quickitem); 0109 0110 public slots: 0111 Q_INVOKABLE void forceMaskRedraw(); 0112 Q_INVOKABLE void setSubtractedMaskRegion(const QString ®ionid, const QRegion ®ion); 0113 Q_INVOKABLE void removeSubtractedMaskRegion(const QString ®ionid); 0114 Q_INVOKABLE void setUnitedMaskRegion(const QString ®ionid, const QRegion ®ion); 0115 Q_INVOKABLE void removeUnitedMaskRegion(const QString ®ionid); 0116 0117 void clearShadows(); 0118 void updateShadows(); 0119 void updateEffects(); 0120 void updateEnabledBorders(); 0121 void updateMask(); 0122 0123 signals: 0124 void animationsBlockedChanged(); 0125 void appletsLayoutGeometryChanged(); 0126 void backgroundAllCornersChanged(); 0127 void backgroundCornersMaskChanged(); 0128 void backgroundOpacityChanged(); 0129 void backgroundRadiusEnabledChanged(); 0130 void backgroundRadiusChanged(); 0131 void drawShadowsChanged(); 0132 void drawEffectsChanged(); 0133 void editShadowChanged(); 0134 void enabledBordersChanged(); 0135 void maskChanged(); 0136 void innerShadowChanged(); 0137 void inputMaskChanged(); 0138 void panelBackgroundSvgChanged(); 0139 void popUpMarginChanged(); 0140 void rectChanged(); 0141 0142 void subtractedMaskRegionsChanged(); 0143 void unitedMaskRegionsChanged(); 0144 0145 private slots: 0146 void init(); 0147 0148 void onPopUpMarginChanged(); 0149 0150 void updateBackgroundContrastValues(); 0151 void updateBackgroundCorners(); 0152 0153 private: 0154 bool backgroundRadiusIsEnabled() const; 0155 qreal currentMidValue(const qreal &max, const qreal &factor, const qreal &min) const; 0156 QRegion customMask(const QRect &rect); 0157 QRegion maskCombinedRegion(); 0158 0159 private: 0160 bool m_animationsBlocked{false}; 0161 bool m_backgroundAllCorners{false}; 0162 bool m_backgroundRadiusEnabled{false}; 0163 bool m_drawShadows{true}; 0164 bool m_drawEffects{false}; 0165 bool m_forceTopBorder{false}; 0166 bool m_forceBottomBorder{false}; 0167 0168 bool m_hasTopLeftCorner{false}; 0169 bool m_hasTopRightCorner{false}; 0170 bool m_hasBottomLeftCorner{false}; 0171 bool m_hasBottomRightCorner{false}; 0172 0173 int m_editShadow{0}; 0174 int m_innerShadow{0}; 0175 0176 int m_backgroundRadius{-1}; 0177 float m_backgroundOpacity{1.0}; 0178 0179 qreal m_backEffectContrast{1}; 0180 qreal m_backEffectIntesity{1}; 0181 qreal m_backEffectSaturation{1}; 0182 0183 QRect m_rect; 0184 QRect m_mask; 0185 QRect m_inputMask; 0186 QRect m_appletsLayoutGeometry; 0187 0188 QPointer<Latte::View> m_view; 0189 QPointer<Latte::Corona> m_corona; 0190 0191 PlasmaExtended::CornerRegions m_cornersMaskRegion; 0192 0193 Plasma::Theme m_theme; 0194 0195 //only for the mask, not to actually paint 0196 Plasma::FrameSvg::EnabledBorders m_enabledBorders{Plasma::FrameSvg::AllBorders}; 0197 0198 //assigned from qml side in order to access the official panel background svg 0199 QQuickItem *m_panelBackgroundSvg{nullptr}; 0200 0201 //! Subtracted and United Mask regions 0202 QHash<QString, QRegion> m_subtractedMaskRegions; 0203 QHash<QString, QRegion> m_unitedMaskRegions; 0204 }; 0205 0206 } 0207 } 0208 0209 #endif