MauiKit Controls

windows/shadowhelper/windowshadow.h
1/*
2 * Copyright (C) 2021 CutefishOS Team.
3 *
4 * Author: revenmartin <revenmartin@gmail.com>
5 *
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#ifndef WINDOWSHADOW_H
21#define WINDOWSHADOW_H
22
23#include "tileset.h"
24
25
26#include <QGuiApplication>
27#include <QMap>
28#include <QObject>
29#include <QPainter>
30#include <QPixmap>
31#include <QQmlEngine>
32#include <QQmlParserStatus>
33#include <QRect>
34#include <QWindow>
35#include <QVector>
36
37struct ShadowParams
38{
39 ShadowParams() = default;
40
41 ShadowParams(const QPoint &offset, int radius, qreal opacity):
42 offset(offset),
43 radius(radius),
44 opacity(opacity)
45 {}
46
47 QPoint offset;
48 int radius = 0;
49 qreal opacity = 0;
50};
51
52struct CompositeShadowParams
53{
54 CompositeShadowParams() = default;
55
56 CompositeShadowParams(
57 const QPoint &offset,
58 const ShadowParams &shadow1,
59 const ShadowParams &shadow2)
60 : offset(offset)
61 , shadow1(shadow1)
62 , shadow2(shadow2) {}
63
64 bool isNone() const
65 { return qMax(shadow1.radius, shadow2.radius) == 0; }
66
67 QPoint offset;
68 ShadowParams shadow1;
69 ShadowParams shadow2;
70};
71
72class WindowShadow : public QObject, public QQmlParserStatus
73{
76 Q_PROPERTY(QWindow *view READ view WRITE setView NOTIFY viewChanged)
77 Q_PROPERTY(QRect geometry READ geometry WRITE setGeometry NOTIFY geometryChanged)
78 Q_PROPERTY(qreal radius READ radius WRITE setRadius NOTIFY radiusChanged)
79 Q_PROPERTY(qreal strength READ strength WRITE setStrength NOTIFY strengthChanged)
80
81public:
82 WindowShadow(QObject *parent = nullptr) noexcept;
83 ~WindowShadow() override;
84
85 static CompositeShadowParams lookupShadowParams(int shadowSizeEnum);
86
87 void classBegin() override;
88 void componentComplete() override;
89
90 void setView(QWindow *view);
91 QWindow *view() const;
92
93 void setGeometry(const QRect &rect);
94 QRect geometry() const;
95
96 void setRadius(qreal value);
97 qreal radius() { return m_radius; }
98
99 qreal strength() const;
100 void setStrength(qreal strength);
101
102private slots:
103 void onViewVisibleChanged(bool);
104
105private:
106 void configureTiles();
107 TileSet shadowTiles();
108
109 QMargins shadowMargins(TileSet) const;
110
111signals:
112 void geometryChanged();
113 void enabledChanged();
114 void viewChanged();
115 void edgesChanged();
116 void radiusChanged();
117 void strengthChanged();
118
119private:
120 QWindow *m_view;
121 QRect m_rect;
122 TileSet m_shadowTiles;
123 qreal m_radius = 10;
124 qreal m_strength = 1.2;
125};
126
127#endif
tilesets are collections of stretchable pixmaps corresponding to a given widget corners,...
Q_INTERFACES(...)
Q_OBJECTQ_OBJECT
Q_PROPERTY(...)
QObject * parent() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 17:04:30 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.