KSvg

framesvgitem.h
1/*
2 SPDX-FileCopyrightText: 2010 Marco Martin <mart@kde.org>
3 SPDX-FileCopyrightText: 2014 David Edmundson <davidedmundson@kde.org>
4
5 SPDX-License-Identifier: GPL-2.0-or-later
6*/
7#ifndef FRAMESVGITEM_P
8#define FRAMESVGITEM_P
9
10#include <QQmlParserStatus>
11#include <QQuickItem>
12
13#include <KSvg/FrameSvg>
14
15namespace Kirigami
16{
17namespace Platform
18{
19class PlatformTheme;
20}
21};
22
23namespace KSvg
24{
25class FrameSvg;
26
27/**
28 * @class FrameSvgItemMargins
29 *
30 * @short The sizes of a frame's margins.
31 */
33{
35
36 /**
37 * @brief This property holds the left margin's width in pixels.
38 * @property real left
39 */
40 Q_PROPERTY(qreal left READ left NOTIFY marginsChanged)
41
42 /**
43 * @brief This property holds the top margin's width in pixels.
44 * @property real top
45 */
46 Q_PROPERTY(qreal top READ top NOTIFY marginsChanged)
47
48 /**
49 * @brief This property holds the right margin's width in pixels.
50 * @property real right
51 */
52 Q_PROPERTY(qreal right READ right NOTIFY marginsChanged)
53
54 /**
55 * @brief This property holds the bottom margin's width in pixels.
56 * @property real bottom
57 */
58 Q_PROPERTY(qreal bottom READ bottom NOTIFY marginsChanged)
59
60 /**
61 * @brief This property holds the combined width of the left and right margins.
62 * @property real horizontal
63 */
64 Q_PROPERTY(qreal horizontal READ horizontal NOTIFY marginsChanged)
65
66 /**
67 * @brief This property holds the combined width of the top and bottom margins.
68 * @property real vertical
69 */
70 Q_PROPERTY(qreal vertical READ vertical NOTIFY marginsChanged)
71
72public:
73 FrameSvgItemMargins(KSvg::FrameSvg *frameSvg, QObject *parent = nullptr);
74
75 qreal left() const;
76 qreal top() const;
77 qreal right() const;
78 qreal bottom() const;
79 qreal horizontal() const;
80 qreal vertical() const;
81
82 /// returns a vector with left, top, right, bottom
83 QList<qreal> margins() const;
84
85 void setFixed(bool fixed);
86 bool isFixed() const;
87
88 void setInset(bool inset);
89 bool isInset() const;
90
91public Q_SLOTS:
92 void update();
93
95 void marginsChanged();
96
97private:
98 FrameSvg *m_frameSvg;
99 bool m_fixed;
100 bool m_inset;
101};
102
103/**
104 * @class FrameSvgItem
105 * @short An SVG Item with borders.
106 * @import org.kde.ksvg
107 */
109{
112
113 /**
114 * @brief This property specifies the relative path of the SVG in the theme.
115 *
116 * Example: "widgets/background"
117 *
118 * @property QString imagePath
119 */
120 Q_PROPERTY(QString imagePath READ imagePath WRITE setImagePath NOTIFY imagePathChanged)
121
122 /**
123 * This property holds the prefix for the SVG.
124 * prefix for the 9-piece SVG, like "pushed" or "normal" for a button.
125 * see https://techbase.kde.org/Development/Tutorials/Plasma5/ThemeDetails
126 * for a list of paths and prefixes
127 * It can also be an array of strings, specifying a fallback chain in case
128 * the first element isn't found in the theme, eg ["toolbutton-normal", "normal"]
129 * so it's easy to keep backwards compatibility with old themes
130 * (Note: fallback chain is supported only @since 5.32)
131 */
132 Q_PROPERTY(QVariant prefix READ prefix WRITE setPrefix NOTIFY prefixChanged)
133
134 /**
135 * @brief This property holds the actual prefix that was used, if a fallback
136 * chain array was set as "prefix".
137 *
138 * @since 5.34
139 * @property QString usedPrefix
140 */
141 Q_PROPERTY(QString usedPrefix READ usedPrefix NOTIFY usedPrefixChanged)
142
143 /**
144 * @brief This property holds the frame's margins.
145 * @see FrameSvgItemMargins
146 * @property FrameSvgItemMargins margins
147 */
149
150 /**
151 * @brief This property holds the fixed margins of the frame which are used
152 * regardless of any margins being enabled or not.
153 *
154 * @see FrameSvgItemMargins
155 * @property FrameSvgItemMargins margins
156 */
157 Q_PROPERTY(KSvg::FrameSvgItemMargins *fixedMargins READ fixedMargins CONSTANT)
158
159 /**
160 * @brief This property holds the frame's inset.
161 *
162 * @see FrameSvgItemMargins
163 *
164 * @since 5.77
165 * @property FrameSvgItemMargins margins
166 */
167 Q_PROPERTY(KSvg::FrameSvgItemMargins *inset READ inset CONSTANT)
168
169 /**
170 * @brief This property specifies which borders are shown.
171 * @see KSvg::FrameSvg::EnabledBorder
172 * @property flags<KSvg::FrameSvg::EnabledBorder> enabledBorders
173 */
174 Q_PROPERTY(KSvg::FrameSvg::EnabledBorders enabledBorders READ enabledBorders WRITE setEnabledBorders NOTIFY enabledBordersChanged)
175
176 /**
177 * @brief This property holds whether the current SVG is present in
178 * the currently-used theme and no fallback is involved.
179 */
180 Q_PROPERTY(bool fromCurrentImageSet READ fromCurrentImageSet NOTIFY fromCurrentImageSetChanged)
181
182 /**
183 * @brief This property specifies the SVG's status.
184 *
185 * Depending on the specified status, the SVG will use different colors:
186 * * Normal: text's color is textColor, and background color is
187 * backgroundColor.
188 * * Selected: text color becomes highlightedText and background color is
189 * changed to highlightColor.
190 *
191 * @see Kirigami::PlatformTheme
192 * @see KSvg::Svg::status
193 * @since 5.23
194 * @property enum<KSvg::Svg::Status> status
195 */
196 Q_PROPERTY(KSvg::Svg::Status status READ status WRITE setStatus NOTIFY statusChanged)
197
198 /**
199 * @brief This property holds the mask that contains the SVG's painted areas.
200 * @since 5.58
201 * @property QRegion mask
202 */
203 Q_PROPERTY(QRegion mask READ mask NOTIFY maskChanged)
204
205 /**
206 * @brief This property holds the minimum height required to correctly draw
207 * this SVG.
208 *
209 * @since 5.101
210 * @property int minimumDrawingHeight
211 */
212 Q_PROPERTY(int minimumDrawingHeight READ minimumDrawingHeight NOTIFY repaintNeeded)
213
214 /**
215 * @brief This property holds the minimum width required to correctly draw
216 * this SVG.
217 *
218 * @since 5.101
219 * @property int minimumDrawingWidth
220 */
221 Q_PROPERTY(int minimumDrawingWidth READ minimumDrawingWidth NOTIFY repaintNeeded)
222
223public:
224 /**
225 * @return whether the svg has the necessary elements with the given prefix
226 * to draw a frame.
227 *
228 * @param prefix the given prefix we want to check if drawable
229 */
230 Q_INVOKABLE bool hasElementPrefix(const QString &prefix) const;
231
232 /**
233 * @return whether the SVG includes the given element.
234 *
235 * This is a convenience function that forwards to hasElement().
236 *
237 * @see KSvg::Svg::hasElement()
238 */
239 Q_INVOKABLE bool hasElement(const QString &elementName) const;
240
241 /// @cond INTERNAL_DOCS
242 FrameSvgItem(QQuickItem *parent = nullptr);
243 ~FrameSvgItem() override;
244
245 void setImagePath(const QString &path);
246 QString imagePath() const;
247
248 void setPrefix(const QVariant &prefix);
249 QVariant prefix() const;
250
251 QString usedPrefix() const;
252
253 void setEnabledBorders(const KSvg::FrameSvg::EnabledBorders borders);
254 KSvg::FrameSvg::EnabledBorders enabledBorders() const;
255
256 void setColorSet(KSvg::Svg::ColorSet colorSet);
257 KSvg::Svg::ColorSet colorSet() const;
258
260 FrameSvgItemMargins *fixedMargins();
261 FrameSvgItemMargins *inset();
262
263 bool fromCurrentImageSet() const;
264
265 void setStatus(KSvg::Svg::Status status);
266 KSvg::Svg::Status status() const;
267 int minimumDrawingHeight() const;
268 int minimumDrawingWidth() const;
269
270 void geometryChange(const QRectF &newGeometry, const QRectF &oldGeometry) override;
271
272 QRegion mask() const;
273
274 /**
275 * Only to be used from inside this library, is not intended to be invokable
276 */
277 KSvg::FrameSvg *frameSvg() const;
278
279 QSGNode *updatePaintNode(QSGNode *, UpdatePaintNodeData *) override;
280
281 void itemChange(QQuickItem::ItemChange change, const QQuickItem::ItemChangeData &data) override;
282
283protected:
284 void classBegin() override;
285 void componentComplete() override;
286
287 /// @endcond
288
290 void imagePathChanged();
291 void prefixChanged();
292 void enabledBordersChanged();
293 void fromCurrentImageSetChanged();
294 void repaintNeeded();
295 void statusChanged();
296 void usedPrefixChanged();
297 void maskChanged();
298
299private Q_SLOTS:
300 void doUpdate();
301
302private:
303 void updateDevicePixelRatio();
304 void applyPrefixes();
305
306 KSvg::FrameSvg *m_frameSvg;
307 Kirigami::Platform::PlatformTheme *m_kirigamiTheme;
308 FrameSvgItemMargins *m_margins;
309 FrameSvgItemMargins *m_fixedMargins;
310 FrameSvgItemMargins *m_insetMargins;
311 // logged margins to check for changes
312 QList<qreal> m_oldMargins;
313 QList<qreal> m_oldFixedMargins;
314 QList<qreal> m_oldInsetMargins;
315 QStringList m_prefixes;
316 bool m_textureChanged;
317 bool m_sizeChanged;
318 bool m_fastPath;
319};
320
321}
322
323#endif
The sizes of a frame's margins.
qreal horizontal
This property holds the combined width of the left and right margins.
qreal vertical
This property holds the combined width of the top and bottom margins.
QList< qreal > margins() const
returns a vector with left, top, right, bottom
qreal right
This property holds the right margin's width in pixels.
qreal bottom
This property holds the bottom margin's width in pixels.
qreal left
This property holds the left margin's width in pixels.
qreal top
This property holds the top margin's width in pixels.
An SVG Item with borders.
Provides an SVG with borders.
Definition framesvg.h:61
A theme aware image-centric SVG class.
Definition svg.h:46
Q_SCRIPTABLE CaptureState status()
The KSvg namespace.
Q_INTERFACES(...)
Q_INVOKABLEQ_INVOKABLE
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 10 2024 11:47:10 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.