Qt 4.8
qdeclarativescalegrid.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtDeclarative module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
42 #include "private/qdeclarativescalegrid_p_p.h"
43 
44 #include <qdeclarative.h>
45 
46 #include <QBuffer>
47 #include <QDebug>
48 
59 QDeclarativeScaleGrid::QDeclarativeScaleGrid(QObject *parent) : QObject(parent), _left(0), _top(0), _right(0), _bottom(0)
60 {
61 }
62 
64 {
65 }
66 
68 {
69  return !_left && !_top && !_right && !_bottom;
70 }
71 
73 {
74  if (_left != pos) {
75  _left = pos;
77  }
78 }
79 
81 {
82  if (_top != pos) {
83  _top = pos;
85  }
86 }
87 
89 {
90  if (_right != pos) {
91  _right = pos;
93  }
94 }
95 
97 {
98  if (_bottom != pos) {
99  _bottom = pos;
101  }
102 }
103 
105 : _l(-1), _r(-1), _t(-1), _b(-1),
107 {
108 }
109 
111 : _l(o._l), _r(o._r), _t(o._t), _b(o._b), _h(o._h), _v(o._v), _pix(o._pix)
112 {
113 }
114 
116 {
117  _l = o._l;
118  _r = o._r;
119  _t = o._t;
120  _b = o._b;
121  _h = o._h;
122  _v = o._v;
123  _pix = o._pix;
124  return *this;
125 }
126 
129 {
130  int l = -1;
131  int r = -1;
132  int t = -1;
133  int b = -1;
134  QString imgFile;
135 
136  QByteArray raw;
137  while(raw = data->readLine(), !raw.isEmpty()) {
138  QString line = QString::fromUtf8(raw.trimmed());
139  if (line.isEmpty() || line.startsWith(QLatin1Char('#')))
140  continue;
141 
142  int colonId = line.indexOf(QLatin1Char(':'));
143  if (colonId <= 0)
144  return;
145  QStringList list;
146  list.append(line.left(colonId).trimmed());
147  list.append(line.mid(colonId+1).trimmed());
148 
149  if (list[0] == QLatin1String("border.left"))
150  l = list[1].toInt();
151  else if (list[0] == QLatin1String("border.right"))
152  r = list[1].toInt();
153  else if (list[0] == QLatin1String("border.top"))
154  t = list[1].toInt();
155  else if (list[0] == QLatin1String("border.bottom"))
156  b = list[1].toInt();
157  else if (list[0] == QLatin1String("source"))
158  imgFile = list[1];
159  else if (list[0] == QLatin1String("horizontalTileRule"))
160  _h = stringToRule(list[1]);
161  else if (list[0] == QLatin1String("verticalTileRule"))
162  _v = stringToRule(list[1]);
163  }
164 
165  if (l < 0 || r < 0 || t < 0 || b < 0 || imgFile.isEmpty())
166  return;
167 
168  _l = l; _r = r; _t = t; _b = b;
169 
170  _pix = imgFile;
171 }
172 
174 {
175  if (s == QLatin1String("Stretch"))
177  if (s == QLatin1String("Repeat"))
179  if (s == QLatin1String("Round"))
181 
182  qWarning("QDeclarativeGridScaledImage: Invalid tile rule specified. Using Stretch.");
184 }
185 
187 {
188  return _l >= 0;
189 }
190 
192 {
193  return _l;
194 }
195 
197 {
198  return _r;
199 }
200 
202 {
203  return _t;
204 }
205 
207 {
208  return _b;
209 }
210 
212 {
213  return _pix;
214 }
215 
QDeclarativeScaleGrid(QObject *parent=0)
QDeclarativeGridScaledImage & operator=(const QDeclarativeGridScaledImage &)
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
static QDeclarativeBorderImage::TileMode stringToRule(const QString &)
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:3734
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
The QString class provides a Unicode character string.
Definition: qstring.h:83
The QObject class is the base class of all Qt objects.
Definition: qobject.h:111
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
QString left(int n) const Q_REQUIRED_RESULT
Returns a substring that contains the n leftmost characters of the string.
Definition: qstring.cpp:3664
QString trimmed() const Q_REQUIRED_RESULT
Returns a string that has whitespace removed from the start and the end.
Definition: qstring.cpp:4506
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
QByteArray trimmed() const
Returns a byte array that has whitespace removed from the start and the end.
#define emit
Definition: qobjectdefs.h:76
The QStringList class provides a list of strings.
Definition: qstringlist.h:66
static int toInt(const QByteArray &str)
Definition: generator.cpp:167
static QString fromUtf8(const char *, int size=-1)
Returns a QString initialized with the first size bytes of the UTF-8 string str.
Definition: qstring.cpp:4302
Q_CORE_EXPORT void qWarning(const char *,...)
static const char * data(const QByteArray &arr)
int indexOf(QChar c, int from=0, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Definition: qstring.cpp:2838
QString mid(int position, int n=-1) const Q_REQUIRED_RESULT
Returns a string that contains n characters of this string, starting at the specified position index...
Definition: qstring.cpp:3706
QDeclarativeBorderImage::TileMode _v
qint64 readLine(char *data, qint64 maxlen)
This function reads a line of ASCII characters from the device, up to a maximum of maxSize - 1 bytes...
Definition: qiodevice.cpp:1110
QFactoryLoader * l
QDeclarativeBorderImage::TileMode _h
bool isEmpty() const
Returns true if the byte array has size 0; otherwise returns false.
Definition: qbytearray.h:421
The QIODevice class is the base interface class of all I/O devices in Qt.
Definition: qiodevice.h:66
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55