1 /****************************************************************************
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
6 ** This file is part of the QtDeclarative module of the Qt Toolkit.
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** GNU Lesser General Public License Usage
10 ** This file may be used under the terms of the GNU Lesser General Public
11 ** License version 2.1 as published by the Free Software Foundation and
12 ** appearing in the file LICENSE.LGPL included in the packaging of this
13 ** file. Please review the following information to ensure the GNU Lesser
14 ** General Public License version 2.1 requirements will be met:
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
17 ** In addition, as a special exception, Nokia gives you certain additional
18 ** rights. These rights are described in the Nokia Qt LGPL Exception
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
21 ** GNU General Public License Usage
22 ** Alternatively, this file may be used under the terms of the GNU General
23 ** Public License version 3.0 as published by the Free Software Foundation
24 ** and appearing in the file LICENSE.GPL included in the packaging of this
25 ** file. Please review the following information to ensure the GNU General
26 ** Public License version 3.0 requirements will be met:
27 ** http://www.gnu.org/copyleft/gpl.html.
30 ** Alternatively, this file may be used in accordance with the terms and
31 ** conditions contained in a signed written agreement between you and Nokia.
40 ****************************************************************************/
42 #include "QtQuick1/private/qdeclarativescalegrid_p_p.h"
44 #include <QtDeclarative/qdeclarative.h>
54 \class QDeclarative1ScaleGrid
55 \brief The QDeclarative1ScaleGrid class allows you to specify a 3x3 grid to use in scaling an image.
58 QDeclarative1ScaleGrid::QDeclarative1ScaleGrid(QObject *parent) : QObject(parent), _left(0), _top(0), _right(0), _bottom(0)
62 QDeclarative1ScaleGrid::~QDeclarative1ScaleGrid()
66 bool QDeclarative1ScaleGrid::isNull() const
68 return !_left && !_top && !_right && !_bottom;
71 void QDeclarative1ScaleGrid::setLeft(int pos)
79 void QDeclarative1ScaleGrid::setTop(int pos)
87 void QDeclarative1ScaleGrid::setRight(int pos)
95 void QDeclarative1ScaleGrid::setBottom(int pos)
103 QDeclarative1GridScaledImage::QDeclarative1GridScaledImage()
104 : _l(-1), _r(-1), _t(-1), _b(-1),
105 _h(QDeclarative1BorderImage::Stretch), _v(QDeclarative1BorderImage::Stretch)
109 QDeclarative1GridScaledImage::QDeclarative1GridScaledImage(const QDeclarative1GridScaledImage &o)
110 : _l(o._l), _r(o._r), _t(o._t), _b(o._b), _h(o._h), _v(o._v), _pix(o._pix)
114 QDeclarative1GridScaledImage &QDeclarative1GridScaledImage::operator=(const QDeclarative1GridScaledImage &o)
126 QDeclarative1GridScaledImage::QDeclarative1GridScaledImage(QIODevice *data)
127 : _l(-1), _r(-1), _t(-1), _b(-1), _h(QDeclarative1BorderImage::Stretch), _v(QDeclarative1BorderImage::Stretch)
136 while(raw = data->readLine(), !raw.isEmpty()) {
137 QString line = QString::fromUtf8(raw.trimmed());
138 if (line.isEmpty() || line.startsWith(QLatin1Char('#')))
141 int colonId = line.indexOf(QLatin1Char(':'));
145 list.append(line.left(colonId).trimmed());
146 list.append(line.mid(colonId+1).trimmed());
148 if (list[0] == QLatin1String("border.left"))
150 else if (list[0] == QLatin1String("border.right"))
152 else if (list[0] == QLatin1String("border.top"))
154 else if (list[0] == QLatin1String("border.bottom"))
156 else if (list[0] == QLatin1String("source"))
158 else if (list[0] == QLatin1String("horizontalTileRule"))
159 _h = stringToRule(list[1]);
160 else if (list[0] == QLatin1String("verticalTileRule"))
161 _v = stringToRule(list[1]);
164 if (l < 0 || r < 0 || t < 0 || b < 0 || imgFile.isEmpty())
167 _l = l; _r = r; _t = t; _b = b;
170 if (_pix.startsWith(QLatin1Char('"')) && _pix.endsWith(QLatin1Char('"')))
171 _pix = _pix.mid(1, _pix.size() - 2); // remove leading/trailing quotes.
174 QDeclarative1BorderImage::TileMode QDeclarative1GridScaledImage::stringToRule(const QString &s)
176 if (s == QLatin1String("Stretch"))
177 return QDeclarative1BorderImage::Stretch;
178 if (s == QLatin1String("Repeat"))
179 return QDeclarative1BorderImage::Repeat;
180 if (s == QLatin1String("Round"))
181 return QDeclarative1BorderImage::Round;
183 qWarning("QDeclarative1GridScaledImage: Invalid tile rule specified. Using Stretch.");
184 return QDeclarative1BorderImage::Stretch;
187 bool QDeclarative1GridScaledImage::isValid() const
192 int QDeclarative1GridScaledImage::gridLeft() const
197 int QDeclarative1GridScaledImage::gridRight() const
202 int QDeclarative1GridScaledImage::gridTop() const
207 int QDeclarative1GridScaledImage::gridBottom() const
212 QString QDeclarative1GridScaledImage::pixmapUrl() const