diff options
author | Martin Jones <martin.jones@nokia.com> | 2009-10-05 06:32:26 (GMT) |
---|---|---|
committer | Martin Jones <martin.jones@nokia.com> | 2009-10-05 06:32:26 (GMT) |
commit | 231745acfc4b106d889b139d208563df190db264 (patch) | |
tree | 3677db18f7b2adea9d86168f7a5c8eb047b92b66 /src/declarative | |
parent | 0251974200e4f931c534f120834ab89fe3836405 (diff) | |
parent | 9c80d8284449e8cfc421aa047598020dc4c58772 (diff) | |
download | Qt-231745acfc4b106d889b139d208563df190db264.zip Qt-231745acfc4b106d889b139d208563df190db264.tar.gz Qt-231745acfc4b106d889b139d208563df190db264.tar.bz2 |
Merge branch 'kinetic-declarativeui' of git@scm.dev.nokia.troll.no:qt/kinetic into kinetic-declarativeui
Diffstat (limited to 'src/declarative')
-rw-r--r-- | src/declarative/fx/qfxborderimage.cpp | 23 | ||||
-rw-r--r-- | src/declarative/fx/qfxgraphicsobjectcontainer.cpp | 96 | ||||
-rw-r--r-- | src/declarative/fx/qfxgraphicsobjectcontainer.h | 9 | ||||
-rw-r--r-- | src/declarative/fx/qfxrect.cpp | 2 | ||||
-rw-r--r-- | src/declarative/fx/qfxscalegrid.cpp | 10 |
5 files changed, 119 insertions, 21 deletions
diff --git a/src/declarative/fx/qfxborderimage.cpp b/src/declarative/fx/qfxborderimage.cpp index 3bc76da..6616912 100644 --- a/src/declarative/fx/qfxborderimage.cpp +++ b/src/declarative/fx/qfxborderimage.cpp @@ -124,19 +124,16 @@ QFxBorderImage::~QFxBorderImage() BorderImage can handle any image format supported by Qt, loaded from any URL scheme supported by Qt. It can also handle .sci files, which are a Qml-specific format. A .sci file uses a simple text-based format that specifies - \list - \i the grid lines describing a \l {BorderImage::border.left}{scale grid}. - \i an image file. - \endlist - - The following .sci file sets grid line offsets of 10 on each side for the image \c picture.png: - \code - gridLeft: 10 - gridTop: 10 - gridBottom: 10 - gridRight: 10 - imageFile: picture.png - \endcode + the borders, the image file and the tile rules. + + The following .sci file sets the borders to 10 on each side for the image \c picture.png: + \qml + border.left: 10 + border.top: 10 + border.bottom: 10 + border.right: 10 + source: picture.png + \endqml The URL may be absolute, or relative to the URL of the component. */ diff --git a/src/declarative/fx/qfxgraphicsobjectcontainer.cpp b/src/declarative/fx/qfxgraphicsobjectcontainer.cpp index 08120fc..c0cac6c 100644 --- a/src/declarative/fx/qfxgraphicsobjectcontainer.cpp +++ b/src/declarative/fx/qfxgraphicsobjectcontainer.cpp @@ -41,6 +41,8 @@ #include "qfxgraphicsobjectcontainer.h" #include <QGraphicsObject> +#include <QGraphicsWidget> +#include <QGraphicsSceneResizeEvent> QT_BEGIN_NAMESPACE @@ -59,7 +61,7 @@ QML_DEFINE_NOCREATE_TYPE(QGraphicsObject) QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,GraphicsObjectContainer,QFxGraphicsObjectContainer) QFxGraphicsObjectContainer::QFxGraphicsObjectContainer(QFxItem *parent) -: QFxItem(parent), _graphicsObject(0) +: QFxItem(parent), _graphicsObject(0), _syncedResize(false) { } @@ -81,9 +83,20 @@ void QFxGraphicsObjectContainer::setGraphicsObject(QGraphicsObject *object) if (object == _graphicsObject) return; + //### what should we do with previously set object? + _graphicsObject = object; - _graphicsObject->setParentItem(this); + if (_graphicsObject) { + _graphicsObject->setParentItem(this); + + if (_syncedResize && _graphicsObject->isWidget()) { + _graphicsObject->installEventFilter(this); + QSizeF newSize = static_cast<QGraphicsWidget*>(_graphicsObject)->size(); //### use sizeHint? + setImplicitWidth(newSize.width()); + setImplicitHeight(newSize.height()); + } + } } QVariant QFxGraphicsObjectContainer::itemChange(GraphicsItemChange change, const QVariant &value) @@ -96,4 +109,83 @@ QVariant QFxGraphicsObjectContainer::itemChange(GraphicsItemChange change, const return QFxItem::itemChange(change, value); } +bool QFxGraphicsObjectContainer::eventFilter(QObject *watched, QEvent *e) +{ + if (watched == _graphicsObject && e->type() == QEvent::GraphicsSceneResize) { + if (_graphicsObject && _graphicsObject->isWidget() && _syncedResize) { + QSizeF newSize = static_cast<QGraphicsWidget*>(_graphicsObject)->size(); + setImplicitWidth(newSize.width()); + setImplicitHeight(newSize.height()); + } + } + return QFxItem::eventFilter(watched, e); +} + +/*! + \qmlproperty bool GraphicsObjectContainer::synchronizedResizing + + This property determines whether or not the container and graphics object will synchronize their + sizes. + + \note This property only applies when wrapping a QGraphicsWidget. + + If synchronizedResizing is enabled, the container and widget will + synchronize their sizes as follows. + \list + \o If a size has been set on the container, the widget will be resized to the container. + Any changes in the container's size will be reflected in the widget. + + \o \e Otherwise, the container will initially be sized to the preferred size of the widget. + Any changes to the container's size will be reflected in the widget, and any changes to the + widget's size will be reflected in the container. + \endlist +*/ +bool QFxGraphicsObjectContainer::synchronizedResizing() const +{ + return _syncedResize; +} + +void QFxGraphicsObjectContainer::setSynchronizedResizing(bool on) +{ + if (on == _syncedResize) + return; + + if (_graphicsObject && _graphicsObject->isWidget()) { + if (!on) { + _graphicsObject->removeEventFilter(this); + disconnect(this, SIGNAL(widthChanged()), this, SLOT(_q_updateSize())); + disconnect(this, SIGNAL(heightChanged()), this, SLOT(_q_updateSize())); + } + } + + _syncedResize = on; + + if (_graphicsObject && _graphicsObject->isWidget()) { + if (on) { + _graphicsObject->installEventFilter(this); + connect(this, SIGNAL(widthChanged()), this, SLOT(_q_updateSize())); + connect(this, SIGNAL(heightChanged()), this, SLOT(_q_updateSize())); + } + } +} + +void QFxGraphicsObjectContainer::_q_updateSize() +{ + if (!_graphicsObject || !_graphicsObject->isWidget() || !_syncedResize) + return; + + QGraphicsWidget *gw = static_cast<QGraphicsWidget*>(_graphicsObject); + const QSizeF newSize(width(), height()); + gw->resize(newSize); + + //### will respecting the widgets min/max ever get us in trouble? (all other items always + // size to exactly what you tell them) + /*QSizeF constrainedSize = newSize.expandedTo(gw->minimumSize()).boundedTo(gw->maximumSize()); + gw->resize(constrainedSize); + if (constrainedSize != newSize) { + setImplicitWidth(constrainedSize.width()); + setImplicitHeight(constrainedSize.height()); + }*/ +} + QT_END_NAMESPACE diff --git a/src/declarative/fx/qfxgraphicsobjectcontainer.h b/src/declarative/fx/qfxgraphicsobjectcontainer.h index 165bc48..a8b7c8c 100644 --- a/src/declarative/fx/qfxgraphicsobjectcontainer.h +++ b/src/declarative/fx/qfxgraphicsobjectcontainer.h @@ -58,6 +58,7 @@ class Q_DECLARATIVE_EXPORT QFxGraphicsObjectContainer : public QFxItem Q_CLASSINFO("DefaultProperty", "graphicsObject") Q_PROPERTY(QGraphicsObject *graphicsObject READ graphicsObject WRITE setGraphicsObject) + Q_PROPERTY(bool synchronizedResizing READ synchronizedResizing WRITE setSynchronizedResizing) public: QFxGraphicsObjectContainer(QFxItem *parent = 0); @@ -66,11 +67,19 @@ public: QGraphicsObject *graphicsObject() const; void setGraphicsObject(QGraphicsObject *); + bool synchronizedResizing() const; + void setSynchronizedResizing(bool on); + protected: QVariant itemChange(GraphicsItemChange change, const QVariant &value); + bool eventFilter(QObject *watched, QEvent *e); + +private Q_SLOTS: + void _q_updateSize(); private: QGraphicsObject *_graphicsObject; + bool _syncedResize; }; QT_END_NAMESPACE diff --git a/src/declarative/fx/qfxrect.cpp b/src/declarative/fx/qfxrect.cpp index eb8103c..0648ac4 100644 --- a/src/declarative/fx/qfxrect.cpp +++ b/src/declarative/fx/qfxrect.cpp @@ -459,7 +459,7 @@ void QFxRect::drawRect(QPainter &p) QMargins margins(xOffset, yOffset, xOffset, yOffset); QTileRules rules(Qt::StretchTile, Qt::StretchTile); - qDrawBorderPixmap(&p, QRect(-pw/2, -pw/2, d->rectImage.width()/2 + xOffset*2, d->rectImage.height()/2 + yOffset*2), margins, d->rectImage, d->rectImage.rect(), margins, rules); + qDrawBorderPixmap(&p, QRect(-pw/2, -pw/2, width()+pw, height()+pw), margins, d->rectImage, d->rectImage.rect(), margins, rules); if (d->smooth) { p.setRenderHint(QPainter::Antialiasing, oldAA); diff --git a/src/declarative/fx/qfxscalegrid.cpp b/src/declarative/fx/qfxscalegrid.cpp index f0c5758..4c6a522 100644 --- a/src/declarative/fx/qfxscalegrid.cpp +++ b/src/declarative/fx/qfxscalegrid.cpp @@ -142,15 +142,15 @@ QFxGridScaledImage::QFxGridScaledImage(QIODevice *data) list[0] = list[0].trimmed(); list[1] = list[1].trimmed(); - if (list[0] == QLatin1String("gridLeft")) + if (list[0] == QLatin1String("border.left")) l = list[1].toInt(); - else if (list[0] == QLatin1String("gridRight")) + else if (list[0] == QLatin1String("border.right")) r = list[1].toInt(); - else if (list[0] == QLatin1String("gridTop")) + else if (list[0] == QLatin1String("border.top")) t = list[1].toInt(); - else if (list[0] == QLatin1String("gridBottom")) + else if (list[0] == QLatin1String("border.bottom")) b = list[1].toInt(); - else if (list[0] == QLatin1String("imageFile")) + else if (list[0] == QLatin1String("source")) imgFile = list[1]; else if (list[0] == QLatin1String("horizontalTileRule")) _h = stringToRule(list[1]); |