Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
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
5
6#include <QtQml/qqml.h>
7
9
16QQuickScaleGrid::QQuickScaleGrid(QObject *parent) : QObject(parent), _left(0), _top(0), _right(0), _bottom(0)
17{
18}
19
21{
22 return !_left && !_top && !_right && !_bottom;
23}
24
26{
27 if (_left != pos) {
28 _left = pos;
31 }
32}
33
35{
36 if (_top != pos) {
37 _top = pos;
40 }
41}
42
44{
45 if (_right != pos) {
46 _right = pos;
49 }
50}
51
53{
54 if (_bottom != pos) {
55 _bottom = pos;
58 }
59}
60
62: _l(-1), _r(-1), _t(-1), _b(-1),
63 _h(QQuickBorderImage::Stretch), _v(QQuickBorderImage::Stretch)
64{
65}
66
68: _l(o._l), _r(o._r), _t(o._t), _b(o._b), _h(o._h), _v(o._v), _pix(o._pix)
69{
70}
71
73{
74 _l = o._l;
75 _r = o._r;
76 _t = o._t;
77 _b = o._b;
78 _h = o._h;
79 _v = o._v;
80 _pix = o._pix;
81 return *this;
82}
83
85: _l(-1), _r(-1), _t(-1), _b(-1), _h(QQuickBorderImage::Stretch), _v(QQuickBorderImage::Stretch)
86{
87 int l = -1;
88 int r = -1;
89 int t = -1;
90 int b = -1;
91 QString imgFile;
92
93 QByteArray raw;
94 while (raw = data->readLine(), !raw.isEmpty()) {
95 QString line = QString::fromUtf8(raw.trimmed());
96 if (line.isEmpty() || line.startsWith(QLatin1Char('#')))
97 continue;
98
99 int colonId = line.indexOf(QLatin1Char(':'));
100 if (colonId <= 0)
101 return;
102
103 const QStringView property = QStringView{line}.left(colonId).trimmed();
104 QStringView value = QStringView{line}.mid(colonId + 1).trimmed();
105
106 if (property == QLatin1String("border.left")) {
107 l = value.toInt();
108 } else if (property == QLatin1String("border.right")) {
109 r = value.toInt();
110 } else if (property == QLatin1String("border.top")) {
111 t = value.toInt();
112 } else if (property == QLatin1String("border.bottom")) {
113 b = value.toInt();
114 } else if (property == QLatin1String("source")) {
115 if (value.startsWith(QLatin1Char('"')) && value.endsWith(QLatin1Char('"')))
116 value = value.mid(1, value.size() - 2); // remove leading/trailing quotes.
117 imgFile = value.toString();
118 } else if (property == QLatin1String("horizontalTileRule") || property == QLatin1String("horizontalTileMode")) {
119 _h = stringToRule(value);
120 } else if (property == QLatin1String("verticalTileRule") || property == QLatin1String("verticalTileMode")) {
121 _v = stringToRule(value);
122 }
123 }
124
125 if (l < 0 || r < 0 || t < 0 || b < 0 || imgFile.isEmpty())
126 return;
127
128 _l = l; _r = r; _t = t; _b = b;
129 _pix = imgFile;
130}
131
132QQuickBorderImage::TileMode QQuickGridScaledImage::stringToRule(QStringView s)
133{
134 QStringView string = s;
135 if (string.startsWith(QLatin1Char('"')) && string.endsWith(QLatin1Char('"')))
136 string = string.mid(1, string.size() - 2); // remove leading/trailing quotes.
137
138 if (string == QLatin1String("Stretch") || string == QLatin1String("BorderImage.Stretch"))
140 if (string == QLatin1String("Repeat") || string == QLatin1String("BorderImage.Repeat"))
142 if (string == QLatin1String("Round") || string == QLatin1String("BorderImage.Round"))
144
145 qWarning("QQuickGridScaledImage: Invalid tile rule specified. Using Stretch.");
147}
148
150{
151 return _l >= 0;
152}
153
155{
156 return _l;
157}
158
160{
161 return _r;
162}
163
165{
166 return _t;
167}
168
170{
171 return _b;
172}
173
175{
176 return _pix;
177}
178
180
181#include "moc_qquickscalegrid_p_p.cpp"
\inmodule QtCore
Definition qbytearray.h:57
\inmodule QtCore \reentrant
Definition qiodevice.h:34
\inmodule QtCore
Definition qobject.h:103
QQuickGridScaledImage & operator=(const QQuickGridScaledImage &)
void borderChanged()
QQuickScaleGrid(QObject *parent=nullptr)
void rightBorderChanged()
void leftBorderChanged()
void topBorderChanged()
bool isNull() const
void bottomBorderChanged()
\inmodule QtCore
Definition qstringview.h:78
constexpr QStringView mid(qsizetype pos, qsizetype n=-1) const noexcept
Returns the substring of length length starting at position start in this object.
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
QString left(qsizetype n) const &
Definition qstring.h:363
qsizetype indexOf(QLatin1StringView s, qsizetype from=0, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Definition qstring.cpp:4517
int toInt(bool *ok=nullptr, int base=10) const
Returns the string converted to an int using base base, which is 10 by default and must be between 2 ...
Definition qstring.h:731
bool startsWith(const QString &s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Returns true if the string starts with s; otherwise returns false.
Definition qstring.cpp:5455
QString mid(qsizetype position, qsizetype n=-1) const &
Definition qstring.cpp:5300
bool isEmpty() const noexcept
Returns true if the string has no characters; otherwise returns false.
Definition qstring.h:192
static QString fromUtf8(QByteArrayView utf8)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition qstring.cpp:6018
QString trimmed() const &
Definition qstring.h:447
Combined button and popup list for selecting options.
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
#define qWarning
Definition qlogging.h:166
GLboolean GLboolean GLboolean b
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLboolean r
[2]
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLdouble s
[6]
Definition qopenglext.h:235
GLdouble GLdouble t
Definition qopenglext.h:243
QLatin1StringView QLatin1String
Definition qstringfwd.h:31
#define emit
const char property[13]
Definition qwizard.cpp:101
\inmodule QtCore \reentrant
Definition qchar.h:18