1 // Commit: 7ddec9f3179bfd854ae53e23ab292de1f9a26377
2 /****************************************************************************
4 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
5 ** All rights reserved.
6 ** Contact: Nokia Corporation (qt-info@nokia.com)
8 ** This file is part of the QtDeclarative module of the Qt Toolkit.
10 ** $QT_BEGIN_LICENSE:LGPL$
11 ** No Commercial Usage
12 ** This file contains pre-release code and may not be distributed.
13 ** You may use this file in accordance with the terms and conditions
14 ** contained in the Technology Preview License Agreement accompanying
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.
25 ** In addition, as a special exception, Nokia gives you certain additional
26 ** rights. These rights are described in the Nokia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
29 ** If you have questions regarding the use of this file, please contact
30 ** Nokia at qt-info@nokia.com.
41 ****************************************************************************/
43 #include "qsgscalegrid_p_p.h"
45 #include <QtDeclarative/qdeclarative.h>
52 \brief The QSGScaleGrid class allows you to specify a 3x3 grid to use in scaling an image.
55 QSGScaleGrid::QSGScaleGrid(QObject *parent) : QObject(parent), _left(0), _top(0), _right(0), _bottom(0)
59 QSGScaleGrid::~QSGScaleGrid()
63 bool QSGScaleGrid::isNull() const
65 return !_left && !_top && !_right && !_bottom;
68 void QSGScaleGrid::setLeft(int pos)
76 void QSGScaleGrid::setTop(int pos)
84 void QSGScaleGrid::setRight(int pos)
92 void QSGScaleGrid::setBottom(int pos)
100 QSGGridScaledImage::QSGGridScaledImage()
101 : _l(-1), _r(-1), _t(-1), _b(-1),
102 _h(QSGBorderImage::Stretch), _v(QSGBorderImage::Stretch)
106 QSGGridScaledImage::QSGGridScaledImage(const QSGGridScaledImage &o)
107 : _l(o._l), _r(o._r), _t(o._t), _b(o._b), _h(o._h), _v(o._v), _pix(o._pix)
111 QSGGridScaledImage &QSGGridScaledImage::operator=(const QSGGridScaledImage &o)
123 QSGGridScaledImage::QSGGridScaledImage(QIODevice *data)
124 : _l(-1), _r(-1), _t(-1), _b(-1), _h(QSGBorderImage::Stretch), _v(QSGBorderImage::Stretch)
133 while(raw = data->readLine(), !raw.isEmpty()) {
134 QString line = QString::fromUtf8(raw.trimmed());
135 if (line.isEmpty() || line.startsWith(QLatin1Char('#')))
138 int colonId = line.indexOf(QLatin1Char(':'));
143 list.append(line.left(colonId).trimmed());
144 list.append(line.mid(colonId+1).trimmed());
146 if (list[0] == QLatin1String("border.left"))
148 else if (list[0] == QLatin1String("border.right"))
150 else if (list[0] == QLatin1String("border.top"))
152 else if (list[0] == QLatin1String("border.bottom"))
154 else if (list[0] == QLatin1String("source"))
156 else if (list[0] == QLatin1String("horizontalTileRule"))
157 _h = stringToRule(list[1]);
158 else if (list[0] == QLatin1String("verticalTileRule"))
159 _v = stringToRule(list[1]);
162 if (l < 0 || r < 0 || t < 0 || b < 0 || imgFile.isEmpty())
165 _l = l; _r = r; _t = t; _b = b;
170 QSGBorderImage::TileMode QSGGridScaledImage::stringToRule(const QString &s)
172 if (s == QLatin1String("Stretch"))
173 return QSGBorderImage::Stretch;
174 if (s == QLatin1String("Repeat"))
175 return QSGBorderImage::Repeat;
176 if (s == QLatin1String("Round"))
177 return QSGBorderImage::Round;
179 qWarning("QSGGridScaledImage: Invalid tile rule specified. Using Stretch.");
180 return QSGBorderImage::Stretch;
183 bool QSGGridScaledImage::isValid() const
188 int QSGGridScaledImage::gridLeft() const
193 int QSGGridScaledImage::gridRight() const
198 int QSGGridScaledImage::gridTop() const
203 int QSGGridScaledImage::gridBottom() const
208 QString QSGGridScaledImage::pixmapUrl() const