1 /****************************************************************************
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
7 ** This file is part of the QtDeclarative module of the Qt Toolkit.
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** GNU Lesser General Public License Usage
11 ** This file may be used under the terms of the GNU Lesser General Public
12 ** License version 2.1 as published by the Free Software Foundation and
13 ** appearing in the file LICENSE.LGPL included in the packaging of this
14 ** file. Please review the following information to ensure the GNU Lesser
15 ** General Public License version 2.1 requirements will be met:
16 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
18 ** In addition, as a special exception, Nokia gives you certain additional
19 ** rights. These rights are described in the Nokia Qt LGPL Exception
20 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
22 ** GNU General Public License Usage
23 ** Alternatively, this file may be used under the terms of the GNU General
24 ** Public License version 3.0 as published by the Free Software Foundation
25 ** and appearing in the file LICENSE.GPL included in the packaging of this
26 ** file. Please review the following information to ensure the GNU General
27 ** Public License version 3.0 requirements will be met:
28 ** http://www.gnu.org/copyleft/gpl.html.
31 ** Alternatively, this file may be used in accordance with the terms and
32 ** conditions contained in a signed written agreement between you and Nokia.
40 ****************************************************************************/
42 #include "qquickscalegrid_p_p.h"
44 #include <QtDeclarative/qdeclarative.h>
50 \class QQuickScaleGrid
51 \brief The QQuickScaleGrid class allows you to specify a 3x3 grid to use in scaling an image.
54 QQuickScaleGrid::QQuickScaleGrid(QObject *parent) : QObject(parent), _left(0), _top(0), _right(0), _bottom(0)
58 QQuickScaleGrid::~QQuickScaleGrid()
62 bool QQuickScaleGrid::isNull() const
64 return !_left && !_top && !_right && !_bottom;
67 void QQuickScaleGrid::setLeft(int pos)
75 void QQuickScaleGrid::setTop(int pos)
83 void QQuickScaleGrid::setRight(int pos)
91 void QQuickScaleGrid::setBottom(int pos)
99 QQuickGridScaledImage::QQuickGridScaledImage()
100 : _l(-1), _r(-1), _t(-1), _b(-1),
101 _h(QQuickBorderImage::Stretch), _v(QQuickBorderImage::Stretch)
105 QQuickGridScaledImage::QQuickGridScaledImage(const QQuickGridScaledImage &o)
106 : _l(o._l), _r(o._r), _t(o._t), _b(o._b), _h(o._h), _v(o._v), _pix(o._pix)
110 QQuickGridScaledImage &QQuickGridScaledImage::operator=(const QQuickGridScaledImage &o)
122 QQuickGridScaledImage::QQuickGridScaledImage(QIODevice *data)
123 : _l(-1), _r(-1), _t(-1), _b(-1), _h(QQuickBorderImage::Stretch), _v(QQuickBorderImage::Stretch)
132 while (raw = data->readLine(), !raw.isEmpty()) {
133 QString line = QString::fromUtf8(raw.trimmed());
134 if (line.isEmpty() || line.startsWith(QLatin1Char('#')))
137 int colonId = line.indexOf(QLatin1Char(':'));
142 list.append(line.left(colonId).trimmed());
143 list.append(line.mid(colonId+1).trimmed());
145 if (list[0] == QLatin1String("border.left"))
147 else if (list[0] == QLatin1String("border.right"))
149 else if (list[0] == QLatin1String("border.top"))
151 else if (list[0] == QLatin1String("border.bottom"))
153 else if (list[0] == QLatin1String("source"))
155 else if (list[0] == QLatin1String("horizontalTileRule"))
156 _h = stringToRule(list[1]);
157 else if (list[0] == QLatin1String("verticalTileRule"))
158 _v = stringToRule(list[1]);
161 if (l < 0 || r < 0 || t < 0 || b < 0 || imgFile.isEmpty())
164 _l = l; _r = r; _t = t; _b = b;
167 if (_pix.startsWith(QLatin1Char('"')) && _pix.endsWith(QLatin1Char('"')))
168 _pix = _pix.mid(1, _pix.size() - 2); // remove leading/trailing quotes.
171 QQuickBorderImage::TileMode QQuickGridScaledImage::stringToRule(const QString &s)
173 if (s == QLatin1String("Stretch"))
174 return QQuickBorderImage::Stretch;
175 if (s == QLatin1String("Repeat"))
176 return QQuickBorderImage::Repeat;
177 if (s == QLatin1String("Round"))
178 return QQuickBorderImage::Round;
180 qWarning("QQuickGridScaledImage: Invalid tile rule specified. Using Stretch.");
181 return QQuickBorderImage::Stretch;
184 bool QQuickGridScaledImage::isValid() const
189 int QQuickGridScaledImage::gridLeft() const
194 int QQuickGridScaledImage::gridRight() const
199 int QQuickGridScaledImage::gridTop() const
204 int QQuickGridScaledImage::gridBottom() const
209 QString QQuickGridScaledImage::pixmapUrl() const