diff options
author | Michael Brasser <michael.brasser@nokia.com> | 2009-08-06 23:06:22 (GMT) |
---|---|---|
committer | Michael Brasser <michael.brasser@nokia.com> | 2009-08-06 23:06:22 (GMT) |
commit | d0ee8e1a7d71d720a1fac789299cf59a58791149 (patch) | |
tree | fcd6185f121e6f5f927e44d81170f270a854e0a3 /src | |
parent | b8868d6622b4381c60cabf458a9b80b1bfb92d61 (diff) | |
parent | e80c63a54fd7f9aa9445ef813cf52300f9204404 (diff) | |
download | Qt-d0ee8e1a7d71d720a1fac789299cf59a58791149.zip Qt-d0ee8e1a7d71d720a1fac789299cf59a58791149.tar.gz Qt-d0ee8e1a7d71d720a1fac789299cf59a58791149.tar.bz2 |
Merge branch 'kinetic-declarativeui' of git@scm.dev.nokia.troll.no:qt/kinetic into kinetic-declarativeui
Diffstat (limited to 'src')
-rw-r--r-- | src/declarative/fx/fx.pri | 2 | ||||
-rw-r--r-- | src/declarative/fx/qfximage.cpp | 60 | ||||
-rw-r--r-- | src/declarative/fx/qfxlayoutitem.cpp | 105 | ||||
-rw-r--r-- | src/declarative/fx/qfxlayoutitem.h | 93 | ||||
-rw-r--r-- | src/declarative/fx/qfxscalegrid.cpp | 43 | ||||
-rw-r--r-- | src/declarative/fx/qfxscalegrid_p.h | 21 |
6 files changed, 263 insertions, 61 deletions
diff --git a/src/declarative/fx/fx.pri b/src/declarative/fx/fx.pri index bbb09fb..a6c5281 100644 --- a/src/declarative/fx/fx.pri +++ b/src/declarative/fx/fx.pri @@ -42,6 +42,7 @@ HEADERS += \ fx/qfxvisualitemmodel.h \ fx/qfxlistview.h \ fx/qfxgraphicsobjectcontainer.h \ + fx/qfxlayoutitem.h \ SOURCES += \ fx/qfxanchors.cpp \ @@ -71,6 +72,7 @@ SOURCES += \ fx/qfxvisualitemmodel.cpp \ fx/qfxlistview.cpp \ fx/qfxgraphicsobjectcontainer.cpp \ + fx/qfxlayoutitem.cpp \ contains(QT_CONFIG, webkit) { QT+=webkit diff --git a/src/declarative/fx/qfximage.cpp b/src/declarative/fx/qfximage.cpp index ec3053c..792b015 100644 --- a/src/declarative/fx/qfximage.cpp +++ b/src/declarative/fx/qfximage.cpp @@ -348,60 +348,10 @@ void QFxImage::paint(QPainter *p, const QStyleOptionGraphicsItem *, QWidget *) p->drawPixmap(0, 0, pix); } } else { - if (d->fillMode != Stretch) - qWarning("Only fillmode:Stretch supported for scale grid images"); - int sgl = d->scaleGrid->left(); - int sgr = d->scaleGrid->right(); - int sgt = d->scaleGrid->top(); - int sgb = d->scaleGrid->bottom(); - - int w = width(); - int h = height(); - if (sgt + sgb > h) - sgt = sgb = h/2; - if (sgl + sgr > w) - sgl = sgr = w/2; - - const int xSide = sgl + sgr; - const int ySide = sgt + sgb; - - // Upper left - if (sgt && sgl) - p->drawPixmap(QRect(0, 0, sgl, sgt), pix, QRect(0, 0, sgl, sgt)); - // Upper middle - if (pix.width() - xSide && sgt) - p->drawPixmap(QRect(sgl, 0, w - xSide, sgt), pix, - QRect(sgl, 0, pix.width() - xSide, sgt)); - // Upper right - if (sgt && pix.width() - sgr) - p->drawPixmap(QPoint(w-sgr, 0), pix, - QRect(pix.width()-sgr, 0, sgr, sgt)); - // Middle left - if (sgl && pix.height() - ySide) - p->drawPixmap(QRect(0, sgt, sgl, h - ySide), pix, - QRect(0, sgt, sgl, pix.height() - ySide)); - - // Middle - if (pix.width() - xSide && pix.height() - ySide) - p->drawPixmap(QRect(sgl, sgt, w - xSide, h - ySide), - pix, - QRect(sgl, sgt, pix.width() - xSide, pix.height() - ySide)); - // Middle right - if (sgr && pix.height() - ySide) - p->drawPixmap(QRect(w-sgr, sgt, sgr, h - ySide), pix, - QRect(pix.width()-sgr, sgt, sgr, pix.height() - ySide)); - // Lower left - if (sgl && sgr) - p->drawPixmap(QPoint(0, h - sgb), pix, - QRect(0, pix.height() - sgb, sgl, sgb)); - // Lower Middle - if (pix.width() - xSide && sgb) - p->drawPixmap(QRect(sgl, h - sgb, w - xSide, sgb), pix, - QRect(sgl, pix.height() - sgb, pix.width() - xSide, sgb)); - // Lower Right - if (sgr && sgb) - p->drawPixmap(QPoint(w-sgr, h - sgb), pix, - QRect(pix.width()-sgr, pix.height() - sgb, sgr, sgb)); + QMargins margins(d->scaleGrid->top(), d->scaleGrid->left(), d->scaleGrid->bottom(), d->scaleGrid->right()); + QTileRules rules((Qt::TileRule)d->scaleGrid->horizontalTileRule(), + (Qt::TileRule)d->scaleGrid->verticalTileRule()); + qDrawBorderPixmap(p, QRect(0, 0, (int)d->width, (int)d->height), margins, pix, pix.rect(), margins, rules); } if (d->smooth) { @@ -612,6 +562,8 @@ void QFxImage::setGridScaledImage(const QFxGridScaledImage& sci) sg->setBottom(sci.gridBottom()); sg->setLeft(sci.gridLeft()); sg->setRight(sci.gridRight()); + sg->setHorizontalTileRule(sci.horizontalTileRule()); + sg->setVerticalTileRule(sci.verticalTileRule()); d->sciurl = d->url.resolved(QUrl(sci.pixmapUrl())); d->reply = QFxPixmap::get(qmlEngine(this), d->sciurl, this, SLOT(requestFinished())); diff --git a/src/declarative/fx/qfxlayoutitem.cpp b/src/declarative/fx/qfxlayoutitem.cpp new file mode 100644 index 0000000..446a8d7 --- /dev/null +++ b/src/declarative/fx/qfxlayoutitem.cpp @@ -0,0 +1,105 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the QtDeclarative module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qfxlayoutitem.h" +#include <QDebug> +#include <limits.h> + +QT_BEGIN_NAMESPACE + +QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,LayoutItem,QFxLayoutItem) + +/*! + \qmlclass LayoutItem QFxLayoutItem + \brief The LayoutItem element allows you to place your Fluid UI elements inside a classical Qt layout. +*/ + +/*! + \internal + \class QFxLayoutItem + \brief The QFxLayoutItem class allows you to place your Fluid UI elements inside a classical Qt layout. +*/ + + +/*! + \qmlproperty QSizeF LayoutItem::maximumSize + + The maximumSize property can be set to specify the maximum desired size of this LayoutItem +*/ + +/*! + \qmlproperty QSizeF LayoutItem::minimumSize + + The minimumSize property can be set to specify the minimum desired size of this LayoutItem +*/ + +/*! + \qmlproperty QSizeF LayoutItem::preferredSize + + The preferredSize property can be set to specify the preferred size of this LayoutItem +*/ + +QFxLayoutItem::QFxLayoutItem(QFxItem* parent) + : QFxItem(parent), m_maximumSize(INT_MAX,INT_MAX), m_preferredSize(100,100), m_minimumSize(0,0) +{ + setGraphicsItem(this); +} + +void QFxLayoutItem::setGeometry(const QRectF & rect) +{ + setX(rect.x()); + setY(rect.y()); + setWidth(rect.width()); + setHeight(rect.height()); +} + +QSizeF QFxLayoutItem::sizeHint(Qt::SizeHint w, const QSizeF &constraint) const +{ + if(w == Qt::MinimumSize){ + return m_minimumSize; + }else if(w == Qt::MaximumSize){ + return m_maximumSize; + }else{ + return m_preferredSize; + } +} + +QT_END_NAMESPACE diff --git a/src/declarative/fx/qfxlayoutitem.h b/src/declarative/fx/qfxlayoutitem.h new file mode 100644 index 0000000..7150554 --- /dev/null +++ b/src/declarative/fx/qfxlayoutitem.h @@ -0,0 +1,93 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the QtDeclarative module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QFXGRAPHICSLAYOUTITEM_H +#define QFXGRAPHICSLAYOUTITEM_H +#include <QGraphicsLayoutItem> +#include <QFxItem> +#include <QSizeF> + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Declarative) + +class QFxLayoutItem : public QFxItem, public QGraphicsLayoutItem +{ + Q_OBJECT + Q_INTERFACES(QGraphicsLayoutItem) + Q_PROPERTY(QSizeF maximumSize READ maximumSize WRITE setMaximumSize NOTIFY maximumSizeChanged) + Q_PROPERTY(QSizeF minimumSize READ minimumSize WRITE setMinimumSize NOTIFY minimumSizeChanged) + Q_PROPERTY(QSizeF preferredSize READ preferredSize WRITE setPreferredSize NOTIFY preferredSizeChanged) +public: + QFxLayoutItem(QFxItem* parent=0); + + QSizeF maximumSize() const { return m_maximumSize; } + void setMaximumSize(const QSizeF &s) { if(s==m_maximumSize) return; m_maximumSize = s; emit maximumSizeChanged(); } + + QSizeF minimumSize() const { return m_minimumSize; } + void setMinimumSize(const QSizeF &s) { if(s==m_minimumSize) return; m_minimumSize = s; emit minimumSizeChanged(); } + + QSizeF preferredSize() const { return m_preferredSize; } + void setPreferredSize(const QSizeF &s) { if(s==m_preferredSize) return; m_preferredSize = s; emit preferredSizeChanged(); } + + virtual void setGeometry(const QRectF & rect); +protected: + virtual QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint = QSizeF()) const; + +Q_SIGNALS: + void maximumSizeChanged(); + void minimumSizeChanged(); + void preferredSizeChanged(); + +private: + QSizeF m_maximumSize; + QSizeF m_minimumSize; + QSizeF m_preferredSize; +}; + +QT_END_NAMESPACE + +QML_DECLARE_TYPE(QFxLayoutItem) + +QT_END_HEADER +#endif diff --git a/src/declarative/fx/qfxscalegrid.cpp b/src/declarative/fx/qfxscalegrid.cpp index 74ef0a1..198ac6d 100644 --- a/src/declarative/fx/qfxscalegrid.cpp +++ b/src/declarative/fx/qfxscalegrid.cpp @@ -73,7 +73,8 @@ QT_BEGIN_NAMESPACE */ QML_DEFINE_NOCREATE_TYPE(QFxScaleGrid) -QFxScaleGrid::QFxScaleGrid() : QObject(), _left(0), _top(0), _right(0), _bottom(0) +QFxScaleGrid::QFxScaleGrid() : QObject(), _left(0), _top(0), _right(0), _bottom(0), + _horizontalTileRule(Stretch), _verticalTileRule(Stretch) { } @@ -122,13 +123,25 @@ void QFxScaleGrid::setBottom(int pos) _bottom = pos; } +void QFxScaleGrid::setHorizontalTileRule(TileRule r) +{ + _horizontalTileRule = r; +} + +void QFxScaleGrid::setVerticalTileRule(TileRule r) +{ + _verticalTileRule = r; +} + + QFxGridScaledImage::QFxGridScaledImage() -: _l(-1), _r(-1), _t(-1), _b(-1) +: _l(-1), _r(-1), _t(-1), _b(-1), + _h(QFxScaleGrid::Stretch), _v(QFxScaleGrid::Stretch) { } QFxGridScaledImage::QFxGridScaledImage(const QFxGridScaledImage &o) -: _l(o._l), _r(o._r), _t(o._t), _b(o._b), _pix(o._pix) +: _l(o._l), _r(o._r), _t(o._t), _b(o._b), _h(o._h), _v(o._v), _pix(o._pix) { } @@ -138,22 +151,24 @@ QFxGridScaledImage &QFxGridScaledImage::operator=(const QFxGridScaledImage &o) _r = o._r; _t = o._t; _b = o._b; + _h = o._h; + _v = o._v; _pix = o._pix; return *this; } QFxGridScaledImage::QFxGridScaledImage(QIODevice *data) -: _l(-1), _r(-1), _t(-1), _b(-1) +: _l(-1), _r(-1), _t(-1), _b(-1), _h(QFxScaleGrid::Stretch), _v(QFxScaleGrid::Stretch) { int l = -1; - int r = -1; - int t = -1; + int r = -1; + int t = -1; int b = -1; QString imgFile; while(!data->atEnd()) { QString line = QString::fromUtf8(data->readLine().trimmed()); - if (line.isEmpty() || line.startsWith(QLatin1String("#"))) + if (line.isEmpty() || line.startsWith(QLatin1String("#"))) continue; QStringList list = line.split(QLatin1Char(':')); @@ -173,6 +188,10 @@ QFxGridScaledImage::QFxGridScaledImage(QIODevice *data) b = list[1].toInt(); else if (list[0] == QLatin1String("imageFile")) imgFile = list[1]; + else if (list[0] == QLatin1String("horizontalTileRule")) + _h = stringToRule(list[1]); + else if (list[0] == QLatin1String("verticalTileRule")) + _v = stringToRule(list[1]); } if (l < 0 || r < 0 || t < 0 || b < 0 || imgFile.isEmpty()) @@ -183,6 +202,16 @@ QFxGridScaledImage::QFxGridScaledImage(QIODevice *data) _pix = imgFile; } +QFxScaleGrid::TileRule QFxGridScaledImage::stringToRule(const QString &s) const +{ + if (s == QLatin1String("Stretch")) + return QFxScaleGrid::Stretch; + if (s == QLatin1String("Repeat")) + return QFxScaleGrid::Repeat; + if (s == QLatin1String("Round")) + return QFxScaleGrid::Round; +} + bool QFxGridScaledImage::isValid() const { return _l >= 0; diff --git a/src/declarative/fx/qfxscalegrid_p.h b/src/declarative/fx/qfxscalegrid_p.h index 986bcda..a8df3c1 100644 --- a/src/declarative/fx/qfxscalegrid_p.h +++ b/src/declarative/fx/qfxscalegrid_p.h @@ -57,11 +57,15 @@ QT_MODULE(Declarative) class Q_DECLARATIVE_EXPORT QFxScaleGrid : public QObject { Q_OBJECT + Q_ENUMS(TileRule) Q_PROPERTY(int left READ left WRITE setLeft) Q_PROPERTY(int top READ top WRITE setTop) Q_PROPERTY(int right READ right WRITE setRight) Q_PROPERTY(int bottom READ bottom WRITE setBottom) + Q_PROPERTY(TileRule horizontalTileRule READ horizontalTileRule WRITE setHorizontalTileRule) + Q_PROPERTY(TileRule verticalTileRule READ verticalTileRule WRITE setVerticalTileRule) + public: QFxScaleGrid(); ~QFxScaleGrid(); @@ -80,11 +84,21 @@ public: int bottom() const { return _bottom; } void setBottom(int); + enum TileRule { Stretch = Qt::Stretch, Repeat = Qt::Repeat, Round = Qt::Round }; + + TileRule horizontalTileRule() const { return _horizontalTileRule; } + void setHorizontalTileRule(TileRule); + + TileRule verticalTileRule() const { return _verticalTileRule; } + void setVerticalTileRule(TileRule); + private: int _left; int _top; int _right; int _bottom; + TileRule _horizontalTileRule; + TileRule _verticalTileRule; }; class Q_DECLARATIVE_EXPORT QFxGridScaledImage @@ -99,14 +113,21 @@ public: int gridRight() const; int gridTop() const; int gridBottom() const; + QFxScaleGrid::TileRule horizontalTileRule() const { return _h; } + QFxScaleGrid::TileRule verticalTileRule() const { return _v; } QString pixmapUrl() const; private: + QFxScaleGrid::TileRule stringToRule(const QString &) const; + +private: int _l; int _r; int _t; int _b; + QFxScaleGrid::TileRule _h; + QFxScaleGrid::TileRule _v; QString _pix; }; |