1 /****************************************************************************
3 ** Copyright (C) 2011 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 ** No Commercial Usage
11 ** This file contains pre-release code and may not be distributed.
12 ** You may use this file in accordance with the terms and conditions
13 ** contained in the Technology Preview License Agreement accompanying
16 ** GNU Lesser General Public License Usage
17 ** Alternatively, this file may be used under the terms of the GNU Lesser
18 ** General Public License version 2.1 as published by the Free Software
19 ** Foundation and appearing in the file LICENSE.LGPL included in the
20 ** packaging of this file. Please review the following information to
21 ** ensure the GNU Lesser General Public License version 2.1 requirements
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 ** In addition, as a special exception, Nokia gives you certain additional
25 ** rights. These rights are described in the Nokia Qt LGPL Exception
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
40 ****************************************************************************/
42 #include "private/qdeclarativescalegrid_p_p.h"
44 #include <qdeclarative.h>
52 \class QDeclarativeScaleGrid
53 \brief The QDeclarativeScaleGrid class allows you to specify a 3x3 grid to use in scaling an image.
56 QDeclarativeScaleGrid::QDeclarativeScaleGrid(QObject *parent) : QObject(parent), _left(0), _top(0), _right(0), _bottom(0)
60 QDeclarativeScaleGrid::~QDeclarativeScaleGrid()
64 bool QDeclarativeScaleGrid::isNull() const
66 return !_left && !_top && !_right && !_bottom;
69 void QDeclarativeScaleGrid::setLeft(int pos)
77 void QDeclarativeScaleGrid::setTop(int pos)
85 void QDeclarativeScaleGrid::setRight(int pos)
93 void QDeclarativeScaleGrid::setBottom(int pos)
101 QDeclarativeGridScaledImage::QDeclarativeGridScaledImage()
102 : _l(-1), _r(-1), _t(-1), _b(-1),
103 _h(QDeclarativeBorderImage::Stretch), _v(QDeclarativeBorderImage::Stretch)
107 QDeclarativeGridScaledImage::QDeclarativeGridScaledImage(const QDeclarativeGridScaledImage &o)
108 : _l(o._l), _r(o._r), _t(o._t), _b(o._b), _h(o._h), _v(o._v), _pix(o._pix)
112 QDeclarativeGridScaledImage &QDeclarativeGridScaledImage::operator=(const QDeclarativeGridScaledImage &o)
124 QDeclarativeGridScaledImage::QDeclarativeGridScaledImage(QIODevice *data)
125 : _l(-1), _r(-1), _t(-1), _b(-1), _h(QDeclarativeBorderImage::Stretch), _v(QDeclarativeBorderImage::Stretch)
134 while(raw = data->readLine(), !raw.isEmpty()) {
135 QString line = QString::fromUtf8(raw.trimmed());
136 if (line.isEmpty() || line.startsWith(QLatin1Char('#')))
139 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 QDeclarativeBorderImage::TileMode QDeclarativeGridScaledImage::stringToRule(const QString &s)
172 if (s == QLatin1String("Stretch"))
173 return QDeclarativeBorderImage::Stretch;
174 if (s == QLatin1String("Repeat"))
175 return QDeclarativeBorderImage::Repeat;
176 if (s == QLatin1String("Round"))
177 return QDeclarativeBorderImage::Round;
179 qWarning("QDeclarativeGridScaledImage: Invalid tile rule specified. Using Stretch.");
180 return QDeclarativeBorderImage::Stretch;
183 bool QDeclarativeGridScaledImage::isValid() const
188 int QDeclarativeGridScaledImage::gridLeft() const
193 int QDeclarativeGridScaledImage::gridRight() const
198 int QDeclarativeGridScaledImage::gridTop() const
203 int QDeclarativeGridScaledImage::gridBottom() const
208 QString QDeclarativeGridScaledImage::pixmapUrl() const