MauiKit Controls

android/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#pragma once
21
22#include "tileset.h"
23
24#include <QGuiApplication>
25#include <QMap>
26#include <QObject>
27#include <QPainter>
28#include <QPixmap>
29#include <QQmlEngine>
30#include <QQmlParserStatus>
31#include <QRect>
32#include <QWindow>
33#include <QVector>
34
35struct ShadowParams
36{
37 ShadowParams() = default;
38
39 ShadowParams(const QPoint &offset, int radius, qreal opacity):
40 offset(offset),
41 radius(radius),
42 opacity(opacity)
43 {}
44
45 QPoint offset;
46 int radius = 0;
47 qreal opacity = 0;
48};
49
50struct CompositeShadowParams
51{
52 CompositeShadowParams() = default;
53
54 CompositeShadowParams(
55 const QPoint &offset,
56 const ShadowParams &shadow1,
57 const ShadowParams &shadow2)
58 : offset(offset)
59 , shadow1(shadow1)
60 , shadow2(shadow2) {}
61
62 bool isNone() const
63 { return qMax(shadow1.radius, shadow2.radius) == 0; }
64
65 QPoint offset;
66 ShadowParams shadow1;
67 ShadowParams shadow2;
68};
69
70class WindowShadow : public QObject, public QQmlParserStatus
71{
73 QML_ELEMENT
75 Q_PROPERTY(QWindow *view READ view WRITE setView NOTIFY viewChanged)
76 Q_PROPERTY(QRect geometry READ geometry WRITE setGeometry NOTIFY geometryChanged)
77 Q_PROPERTY(qreal radius READ radius WRITE setRadius NOTIFY radiusChanged)
78 Q_PROPERTY(qreal strength READ strength WRITE setStrength NOTIFY strengthChanged)
79
80public:
81 WindowShadow(QObject *parent = nullptr) noexcept;
82 ~WindowShadow() override;
83
84 static CompositeShadowParams lookupShadowParams(int shadowSizeEnum);
85
86 void classBegin() override;
87 void componentComplete() override;
88
89 void setView(QWindow *view);
90 QWindow *view() const;
91
92 void setGeometry(const QRect &rect);
93 QRect geometry() const;
94
95 void setRadius(qreal value);
96 qreal radius() { return m_radius; }
97
98 qreal strength() const;
99 void setStrength(qreal strength);
100
101private slots:
102 void onViewVisibleChanged(bool);
103
104private:
105 void configureTiles();
106 TileSet shadowTiles();
107
108 QMargins shadowMargins(TileSet) const;
109
110signals:
111 void geometryChanged();
112 void enabledChanged();
113 void viewChanged();
114 void edgesChanged();
115 void radiusChanged();
116 void strengthChanged();
117
118private:
119 QWindow *m_view;
120 QRect m_rect;
121 TileSet m_shadowTiles;
122 qreal m_radius = 10;
123 qreal m_strength = 1.2;
124};
125
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 Fri May 17 2024 11:56:16 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.