File indexing completed on 2024-06-16 14:04:37

0001 /*
0002 *  Copyright 2018  Michail Vourlakos <mvourlakos@gmail.com>
0003 *
0004 *  This file is part of Latte-Dock
0005 *
0006 *  Latte-Dock is free software; you can redistribute it and/or
0007 *  modify it under the terms of the GNU General Public License as
0008 *  published by the Free Software Foundation; either version 2 of
0009 *  the License, or (at your option) any later version.
0010 *
0011 *  Latte-Dock is distributed in the hope that it will be useful,
0012 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
0013 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0014 *  GNU General Public License for more details.
0015 *
0016 *  You should have received a copy of the GNU General Public License
0017 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
0018 */
0019 
0020 #ifndef EFFECTS_H
0021 #define EFFECTS_H
0022 
0023 // Qt
0024 #include <QObject>
0025 #include <QPointer>
0026 #include <QQuickView>
0027 #include <QRect>
0028 
0029 // Plasma
0030 #include <Plasma/FrameSvg>
0031 #include <Plasma/Theme>
0032 
0033 namespace Latte {
0034 class View;
0035 }
0036 
0037 namespace Latte {
0038 namespace ViewPart {
0039 
0040 class Effects: public QObject
0041 {
0042     Q_OBJECT
0043     Q_PROPERTY(bool animationsBlocked READ animationsBlocked NOTIFY animationsBlockedChanged)
0044     Q_PROPERTY(bool drawShadows READ drawShadows WRITE setDrawShadows NOTIFY drawShadowsChanged)
0045     Q_PROPERTY(bool drawEffects READ drawEffects WRITE setDrawEffects NOTIFY drawEffectsChanged)
0046     Q_PROPERTY(bool settingsMaskSubtracted READ settingsMaskSubtracted WRITE setSettingsMaskSubtracted NOTIFY settingsMaskSubtractedChanged)
0047 
0048     //! thickness shadow size when is drawn inside the window from qml
0049     Q_PROPERTY(int backgroundOpacity READ backgroundOpacity WRITE setBackgroundOpacity NOTIFY backgroundOpacityChanged)
0050     Q_PROPERTY(int editShadow READ editShadow WRITE setEditShadow NOTIFY editShadowChanged)
0051     Q_PROPERTY(int innerShadow READ innerShadow WRITE setInnerShadow NOTIFY innerShadowChanged)
0052 
0053     Q_PROPERTY(QRect mask READ mask WRITE setMask NOTIFY maskChanged)
0054     Q_PROPERTY(QRect rect READ rect WRITE setRect NOTIFY rectChanged)
0055 
0056     Q_PROPERTY(Plasma::FrameSvg::EnabledBorders enabledBorders READ enabledBorders NOTIFY enabledBordersChanged)
0057 
0058 public:
0059     Effects(Latte::View *parent);
0060     virtual ~Effects();
0061 
0062     bool animationsBlocked() const;
0063     void setAnimationsBlocked(bool blocked);
0064 
0065     bool drawShadows() const;
0066     void setDrawShadows(bool draw);
0067 
0068     bool drawEffects() const;
0069     void setDrawEffects(bool draw);
0070 
0071     bool forceDrawCenteredBorders() const;
0072     void setForceDrawCenteredBorders(bool draw);
0073 
0074     bool settingsMaskSubtracted() const;
0075     void setSettingsMaskSubtracted(bool enabled);
0076 
0077     int backgroundOpacity() const;
0078     void setBackgroundOpacity(int opacity);
0079 
0080     int editShadow() const;
0081     void setEditShadow(int shadow);
0082 
0083     int innerShadow() const;
0084     void setInnerShadow(int shadow);
0085 
0086     QRect mask() const;
0087     void setMask(QRect area);
0088 
0089     QRect rect() const;
0090     void setRect(QRect area);
0091 
0092     Plasma::FrameSvg::EnabledBorders enabledBorders() const;
0093 
0094 public slots:
0095     Q_INVOKABLE void forceMaskRedraw();
0096 
0097     void clearShadows();
0098     void updateShadows();
0099     void updateEffects();
0100     void updateEnabledBorders();
0101     void updateMask();
0102 
0103 signals:
0104     void animationsBlockedChanged();
0105     void backgroundOpacityChanged();
0106     void drawShadowsChanged();
0107     void drawEffectsChanged();
0108     void editShadowChanged();
0109     void enabledBordersChanged();
0110     void maskChanged();
0111     void innerShadowChanged();
0112     void rectChanged();
0113     void settingsMaskSubtractedChanged();
0114 
0115 private slots:
0116     void init();
0117 
0118     void updateBackgroundContrastValues();
0119 
0120 private:
0121     qreal currentMidValue(const qreal &max, const qreal &factor, const qreal &min) const;
0122 
0123     QRegion subtractedMask();
0124     QRegion subtrackedMaskFromWindow(QRegion initialRegion, QQuickView *window);
0125 
0126 private:
0127     bool m_animationsBlocked{false};
0128     bool m_drawShadows{true};
0129     bool m_drawEffects{false};
0130     bool m_forceDrawCenteredBorders{false};
0131     bool m_settingsMaskSubtracted{false};
0132 
0133     int m_backgroundOpacity{100};
0134     int m_editShadow{0};
0135     int m_innerShadow{0};
0136 
0137     qreal m_backEffectContrast{1};
0138     qreal m_backEffectIntesity{1};
0139     qreal m_backEffectSaturation{1};
0140 
0141     QRect m_rect;
0142     QRect m_mask;
0143 
0144     QPointer<Latte::View> m_view;
0145 
0146     Plasma::Theme m_theme;
0147     //only for the mask on disabled compositing, not to actually paint
0148     Plasma::FrameSvg *m_background{nullptr};
0149 
0150     //only for the mask, not to actually paint
0151     Plasma::FrameSvg::EnabledBorders m_enabledBorders{Plasma::FrameSvg::AllBorders};
0152 };
0153 
0154 }
0155 }
0156 
0157 #endif