Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qquickscalegrid.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3// Qt-Security score:critical reason:data-parser
4
6
7#include <QtQml/qqml.h>
8#include <QtCore/qiodevice.h>
9
11
12/*!
13 \internal
14 \class QQuickScaleGrid
15 \brief The QQuickScaleGrid class allows you to specify a 3x3 grid to use in scaling an image.
16*/
17
18QQuickScaleGrid::QQuickScaleGrid(QObject *parent) : QObject(parent), _left(0), _top(0), _right(0), _bottom(0)
19{
20}
21
22bool QQuickScaleGrid::isNull() const
23{
24 return !_left && !_top && !_right && !_bottom;
25}
26
27void QQuickScaleGrid::setLeft(int pos)
28{
29 if (_left != pos) {
30 _left = pos;
31 emit leftBorderChanged();
32 emit borderChanged();
33 }
34}
35
36void QQuickScaleGrid::setTop(int pos)
37{
38 if (_top != pos) {
39 _top = pos;
40 emit topBorderChanged();
41 emit borderChanged();
42 }
43}
44
45void QQuickScaleGrid::setRight(int pos)
46{
47 if (_right != pos) {
48 _right = pos;
49 emit rightBorderChanged();
50 emit borderChanged();
51 }
52}
53
54void QQuickScaleGrid::setBottom(int pos)
55{
56 if (_bottom != pos) {
57 _bottom = pos;
58 emit bottomBorderChanged();
59 emit borderChanged();
60 }
61}
62
63QQuickGridScaledImage::QQuickGridScaledImage()
64: _l(-1), _r(-1), _t(-1), _b(-1),
65 _h(QQuickBorderImage::Stretch), _v(QQuickBorderImage::Stretch)
66{
67}
68
69QQuickGridScaledImage::QQuickGridScaledImage(const QQuickGridScaledImage &o)
70: _l(o._l), _r(o._r), _t(o._t), _b(o._b), _h(o._h), _v(o._v), _pix(o._pix)
71{
72}
73
74QQuickGridScaledImage &QQuickGridScaledImage::operator=(const QQuickGridScaledImage &o)
75{
76 _l = o._l;
77 _r = o._r;
78 _t = o._t;
79 _b = o._b;
80 _h = o._h;
81 _v = o._v;
82 _pix = o._pix;
83 return *this;
84}
85
86QQuickGridScaledImage::QQuickGridScaledImage(QIODevice *data)
87: _l(-1), _r(-1), _t(-1), _b(-1), _h(QQuickBorderImage::Stretch), _v(QQuickBorderImage::Stretch)
88{
89 int l = -1;
90 int r = -1;
91 int t = -1;
92 int b = -1;
93 QString imgFile;
94
95 QByteArray raw;
96 while (raw = data->readLine(), !raw.isEmpty()) {
97 QString line = QString::fromUtf8(raw.trimmed());
98 if (line.isEmpty() || line.startsWith(QLatin1Char('#')))
99 continue;
100
101 int colonId = line.indexOf(QLatin1Char(':'));
102 if (colonId <= 0)
103 return;
104
105 const QStringView property = QStringView{line}.left(colonId).trimmed();
106 QStringView value = QStringView{line}.mid(colonId + 1).trimmed();
107
108 if (property == QLatin1String("border.left")) {
109 l = value.toInt();
110 } else if (property == QLatin1String("border.right")) {
111 r = value.toInt();
112 } else if (property == QLatin1String("border.top")) {
113 t = value.toInt();
114 } else if (property == QLatin1String("border.bottom")) {
115 b = value.toInt();
116 } else if (property == QLatin1String("source")) {
117 if (value.startsWith(QLatin1Char('"')) && value.endsWith(QLatin1Char('"')))
118 value = value.mid(1, value.size() - 2); // remove leading/trailing quotes.
119 imgFile = value.toString();
120 } else if (property == QLatin1String("horizontalTileRule") || property == QLatin1String("horizontalTileMode")) {
121 _h = stringToRule(value);
122 } else if (property == QLatin1String("verticalTileRule") || property == QLatin1String("verticalTileMode")) {
123 _v = stringToRule(value);
124 }
125 }
126
127 if (l < 0 || r < 0 || t < 0 || b < 0 || imgFile.isEmpty())
128 return;
129
130 _l = l; _r = r; _t = t; _b = b;
131 _pix = imgFile;
132}
133
134QQuickBorderImage::TileMode QQuickGridScaledImage::stringToRule(QStringView s)
135{
136 QStringView string = s;
137 if (string.startsWith(QLatin1Char('"')) && string.endsWith(QLatin1Char('"')))
138 string = string.mid(1, string.size() - 2); // remove leading/trailing quotes.
139
140 if (string == QLatin1String("Stretch") || string == QLatin1String("BorderImage.Stretch"))
141 return QQuickBorderImage::Stretch;
142 if (string == QLatin1String("Repeat") || string == QLatin1String("BorderImage.Repeat"))
143 return QQuickBorderImage::Repeat;
144 if (string == QLatin1String("Round") || string == QLatin1String("BorderImage.Round"))
145 return QQuickBorderImage::Round;
146
147 qWarning("QQuickGridScaledImage: Invalid tile rule specified. Using Stretch.");
148 return QQuickBorderImage::Stretch;
149}
150
151bool QQuickGridScaledImage::isValid() const
152{
153 return _l >= 0;
154}
155
156int QQuickGridScaledImage::gridLeft() const
157{
158 return _l;
159}
160
161int QQuickGridScaledImage::gridRight() const
162{
163 return _r;
164}
165
166int QQuickGridScaledImage::gridTop() const
167{
168 return _t;
169}
170
171int QQuickGridScaledImage::gridBottom() const
172{
173 return _b;
174}
175
176QString QQuickGridScaledImage::pixmapUrl() const
177{
178 return _pix;
179}
180
181QT_END_NAMESPACE
182
183#include "moc_qquickscalegrid_p_p.cpp"