MauiKit Controls

linux/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 <KWindowShadow>
25#include <KWindowShadowTile>
26#include <KWindowSystem>
27
28#include <QApplication>
29#include <QMap>
30#include <QObject>
31#include <QPainter>
32#include <QPixmap>
33#include <QQmlEngine>
34#include <QQmlParserStatus>
35#include <QRect>
36#include <QWindow>
37#include <QVector>
38
39struct ShadowParams
40{
41 ShadowParams() = default;
42
43 ShadowParams(const QPoint &offset, int radius, qreal opacity):
44 offset(offset),
45 radius(radius),
46 opacity(opacity)
47 {}
48
49 QPoint offset;
50 int radius = 0;
51 qreal opacity = 0;
52};
53
54struct CompositeShadowParams
55{
56 CompositeShadowParams() = default;
57
58 CompositeShadowParams(
59 const QPoint &offset,
60 const ShadowParams &shadow1,
61 const ShadowParams &shadow2)
62 : offset(offset)
63 , shadow1(shadow1)
64 , shadow2(shadow2) {}
65
66 bool isNone() const
67 { return qMax(shadow1.radius, shadow2.radius) == 0; }
68
69 QPoint offset;
70 ShadowParams shadow1;
71 ShadowParams shadow2;
72};
73
74class WindowShadow : public QObject, public QQmlParserStatus
75{
77 QML_ELEMENT
79 Q_PROPERTY(QWindow *view READ view WRITE setView NOTIFY viewChanged)
80 Q_PROPERTY(QRect geometry READ geometry WRITE setGeometry NOTIFY geometryChanged)
81 Q_PROPERTY(qreal radius READ radius WRITE setRadius NOTIFY radiusChanged)
82 Q_PROPERTY(qreal strength READ strength WRITE setStrength NOTIFY strengthChanged)
83
84public:
85 WindowShadow(QObject *parent = nullptr) noexcept;
86 ~WindowShadow() override;
87
88 static CompositeShadowParams lookupShadowParams(int shadowSizeEnum);
89
90 void classBegin() override;
91 void componentComplete() override;
92
93 void setView(QWindow *view);
94 QWindow *view() const;
95
96 void setGeometry(const QRect &rect);
97 QRect geometry() const;
98
99 void setRadius(qreal value);
100 qreal radius() { return m_radius; }
101
102 qreal strength() const;
103 void setStrength(qreal strength);
104
105private Q_SLOTS:
106 void onViewVisibleChanged(bool);
107
108private:
109 void configureTiles();
110 KWindowShadowTile::Ptr createTile(const QPixmap &);
111 TileSet shadowTiles();
112
113 QMargins shadowMargins(TileSet) const;
114
116 void geometryChanged();
117 void enabledChanged();
118 void viewChanged();
119 void edgesChanged();
120 void radiusChanged();
121 void strengthChanged();
122
123private:
124 QWindow *m_view;
125 QRect m_rect;
126 KWindowShadow *m_shadow;
128 TileSet m_shadowTiles;
129 qreal m_radius = 10;
130 qreal m_strength = 1.2;
131};
132
tilesets are collections of stretchable pixmaps corresponding to a given widget corners,...
Q_INTERFACES(...)
Q_OBJECTQ_OBJECT
Q_PROPERTY(...)
Q_SIGNALSQ_SIGNALS
Q_SLOTSQ_SLOTS
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.