summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorYann Bodson <yann.bodson@nokia.com>2009-08-18 01:04:31 (GMT)
committerYann Bodson <yann.bodson@nokia.com>2009-08-18 01:04:31 (GMT)
commite4fad48d5e5ac227381bb9fba05dfb31a8338ed5 (patch)
treed9cfe112d1bac0e3c84d98b9a0dbfe7dac124f7f /src
parent3c33ca1c0015bd632c2e527c5bb17fac840ae183 (diff)
parentb35582c2c08ffdbba91f83f0cdf775dda47af3a9 (diff)
downloadQt-e4fad48d5e5ac227381bb9fba05dfb31a8338ed5.zip
Qt-e4fad48d5e5ac227381bb9fba05dfb31a8338ed5.tar.gz
Qt-e4fad48d5e5ac227381bb9fba05dfb31a8338ed5.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/qfximage.cpp34
-rw-r--r--src/declarative/fx/qfxitem.cpp54
-rw-r--r--src/declarative/fx/qfxitem.h37
-rw-r--r--src/declarative/fx/qfxitem_p.h27
-rw-r--r--src/declarative/fx/qfxmouseregion.cpp46
-rw-r--r--src/declarative/fx/qfxmouseregion.h26
-rw-r--r--src/declarative/fx/qfxmouseregion_p.h2
7 files changed, 129 insertions, 97 deletions
diff --git a/src/declarative/fx/qfximage.cpp b/src/declarative/fx/qfximage.cpp
index 6e24fdf..99e1b72 100644
--- a/src/declarative/fx/qfximage.cpp
+++ b/src/declarative/fx/qfximage.cpp
@@ -250,77 +250,75 @@ void QFxImage::paint(QPainter *p, const QStyleOptionGraphicsItem *, QWidget *)
if (d->smooth)
p->setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform, d->smooth);
- QPixmap pix = d->pix;
-
- if (width() != pix.width() || height() != pix.height()) {
+ if (width() != d->pix.width() || height() != d->pix.height()) {
if (d->fillMode >= Tile) {
p->save();
p->setClipRect(0, 0, width(), height(), Qt::IntersectClip);
if (d->fillMode == Tile) {
- const int pw = pix.width();
- const int ph = pix.height();
+ const int pw = d->pix.width();
+ const int ph = d->pix.height();
int yy = 0;
while(yy < height()) {
int xx = 0;
while(xx < width()) {
- p->drawPixmap(xx, yy, pix);
+ p->drawPixmap(xx, yy, d->pix);
xx += pw;
}
yy += ph;
}
} else if (d->fillMode == TileVertically) {
- const int ph = pix.height();
+ const int ph = d->pix.height();
int yy = 0;
while(yy < height()) {
- p->drawPixmap(QRect(0, yy, width(), ph), pix);
+ p->drawPixmap(QRect(0, yy, width(), ph), d->pix);
yy += ph;
}
} else {
- const int pw = pix.width();
+ const int pw = d->pix.width();
int xx = 0;
while(xx < width()) {
- p->drawPixmap(QRect(xx, 0, pw, height()), pix);
+ p->drawPixmap(QRect(xx, 0, pw, height()), d->pix);
xx += pw;
}
}
p->restore();
} else {
- qreal widthScale = width() / qreal(pix.width());
- qreal heightScale = height() / qreal(pix.height());
+ qreal widthScale = width() / qreal(d->pix.width());
+ qreal heightScale = height() / qreal(d->pix.height());
QTransform scale;
if (d->fillMode == PreserveAspectFit) {
if (widthScale < heightScale) {
heightScale = widthScale;
- scale.translate(0, (height() - heightScale * pix.height()) / 2);
+ scale.translate(0, (height() - heightScale * d->pix.height()) / 2);
} else if(heightScale < widthScale) {
widthScale = heightScale;
- scale.translate((width() - widthScale * pix.width()) / 2, 0);
+ scale.translate((width() - widthScale * d->pix.width()) / 2, 0);
}
} else if (d->fillMode == PreserveAspectCrop) {
if (widthScale < heightScale) {
widthScale = heightScale;
- scale.translate((width() - widthScale * pix.width()) / 2, 0);
+ scale.translate((width() - widthScale * d->pix.width()) / 2, 0);
} else if(heightScale < widthScale) {
heightScale = widthScale;
- scale.translate(0, (height() - heightScale * pix.height()) / 2);
+ scale.translate(0, (height() - heightScale * d->pix.height()) / 2);
}
}
scale.scale(widthScale, heightScale);
QTransform old = p->transform();
p->setWorldTransform(scale * old);
- p->drawPixmap(0, 0, pix);
+ p->drawPixmap(0, 0, d->pix);
p->setWorldTransform(old);
}
} else {
- p->drawPixmap(0, 0, pix);
+ p->drawPixmap(0, 0, d->pix);
}
if (d->smooth) {
diff --git a/src/declarative/fx/qfxitem.cpp b/src/declarative/fx/qfxitem.cpp
index 04fc5d9..572fcc7 100644
--- a/src/declarative/fx/qfxitem.cpp
+++ b/src/declarative/fx/qfxitem.cpp
@@ -69,7 +69,6 @@ QT_BEGIN_NAMESPACE
#define FLT_MAX 1E+37
#endif
-QML_DEFINE_NOCREATE_TYPE(QFxContents)
QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,Item,QFxItem)
QML_DEFINE_NOCREATE_TYPE(QGraphicsTransform);
@@ -210,40 +209,30 @@ QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,Rotation,QGraphicsRotation)
*/
-QFxContents::QFxContents() : m_height(0), m_width(0)
+QFxContents::QFxContents() : m_x(0), m_y(0), m_width(0), m_height(0)
{
}
/*!
- \qmlproperty qreal Item::contents.width
- \qmlproperty qreal Item::contents.height
+ \qmlproperty qreal Item::childrenRect.x
+ \qmlproperty qreal Item::childrenRect.y
+ \qmlproperty qreal Item::childrenRect.width
+ \qmlproperty qreal Item::childrenRect.height
- The contents properties allow an item access to the size of its
+ The childrenRect properties allow an item access to the geometry of its
children. This property is useful if you have an item that needs to be
sized to fit its children.
*/
-/*!
- \property QFxContents::height
- \brief The height of the contents.
-*/
-qreal QFxContents::height() const
+QRectF QFxContents::rectF() const
{
- return m_height;
-}
-
-/*!
- \property QFxContents::width
- \brief The width of the contents.
-*/
-qreal QFxContents::width() const
-{
- return m_width;
+ return QRectF(m_x, m_y, m_width, m_height);
}
//TODO: optimization: only check sender(), if there is one
void QFxContents::calcHeight()
{
+ qreal oldy = m_y;
qreal oldheight = m_height;
qreal top = FLT_MAX;
@@ -258,15 +247,18 @@ void QFxContents::calcHeight()
if (y < top)
top = y;
}
+ if (!children.isEmpty())
+ m_y = top;
m_height = qMax(bottom - top, qreal(0.0));
- if (m_height != oldheight)
- emit heightChanged();
+ if (m_height != oldheight || m_y != oldy)
+ emit rectChanged();
}
//TODO: optimization: only check sender(), if there is one
void QFxContents::calcWidth()
{
+ qreal oldx = m_x;
qreal oldwidth = m_width;
qreal left = FLT_MAX;
@@ -281,10 +273,12 @@ void QFxContents::calcWidth()
if (x < left)
left = x;
}
+ if (!children.isEmpty())
+ m_x = left;
m_width = qMax(right - left, qreal(0.0));
- if (m_width != oldwidth)
- emit widthChanged();
+ if (m_width != oldwidth || m_x != oldx)
+ emit rectChanged();
}
void QFxContents::setItem(QFxItem *item)
@@ -298,6 +292,7 @@ void QFxContents::setItem(QFxItem *item)
connect(child, SIGNAL(yChanged()), this, SLOT(calcHeight()));
connect(child, SIGNAL(widthChanged()), this, SLOT(calcWidth()));
connect(child, SIGNAL(xChanged()), this, SLOT(calcWidth()));
+ connect(this, SIGNAL(rectChanged()), m_item, SIGNAL(childrenRectChanged()));
}
calcHeight();
@@ -1287,13 +1282,12 @@ QmlList<QObject *> *QFxItem::data()
}
/*!
- \property QFxItem::contents
- \brief An object that knows about the size of an item's children.
+ \property QFxItem::childrenRect
+ \brief The geometry of an item's children.
- contents provides an easy way to access the (collective) width and
- height of the item's children.
+ childrenRect provides an easy way to access the (collective) position and size of the item's children.
*/
-QFxContents *QFxItem::contents()
+QRectF QFxItem::childrenRect()
{
Q_D(QFxItem);
if (!d->_contents) {
@@ -1301,7 +1295,7 @@ QFxContents *QFxItem::contents()
d->_contents->setParent(this);
d->_contents->setItem(this);
}
- return d->_contents;
+ return d->_contents->rectF();
}
bool QFxItem::clip() const
diff --git a/src/declarative/fx/qfxitem.h b/src/declarative/fx/qfxitem.h
index d8fb983..3485985 100644
--- a/src/declarative/fx/qfxitem.h
+++ b/src/declarative/fx/qfxitem.h
@@ -57,37 +57,6 @@ QT_BEGIN_NAMESPACE
QT_MODULE(Declarative)
-class QGraphicsTransform;
-
-class QFxItem;
-class Q_DECLARATIVE_EXPORT QFxContents : public QObject
-{
- Q_OBJECT
- Q_PROPERTY(qreal height READ height NOTIFY heightChanged)
- Q_PROPERTY(qreal width READ width NOTIFY widthChanged)
-public:
- QFxContents();
-
- qreal height() const;
-
- qreal width() const;
-
- void setItem(QFxItem *item);
-
-public Q_SLOTS:
- void calcHeight();
- void calcWidth();
-
-Q_SIGNALS:
- void heightChanged();
- void widthChanged();
-
-private:
- QFxItem *m_item;
- qreal m_height;
- qreal m_width;
-};
-
class QmlState;
class QFxAnchorLine;
class QmlTransition;
@@ -109,7 +78,7 @@ class Q_DECLARATIVE_EXPORT QFxItem : public QGraphicsObject, public QmlParserSta
Q_PROPERTY(QString state READ state WRITE setState NOTIFY stateChanged)
Q_PROPERTY(qreal width READ width WRITE setWidth NOTIFY widthChanged FINAL)
Q_PROPERTY(qreal height READ height WRITE setHeight NOTIFY heightChanged FINAL)
- Q_PROPERTY(QFxContents * contents READ contents DESIGNABLE false CONSTANT FINAL)
+ Q_PROPERTY(QRectF childrenRect READ childrenRect NOTIFY childrenRectChanged DESIGNABLE false FINAL)
Q_PROPERTY(QFxAnchors * anchors READ anchors DESIGNABLE false CONSTANT FINAL)
Q_PROPERTY(QFxAnchorLine left READ left CONSTANT FINAL)
Q_PROPERTY(QFxAnchorLine right READ right CONSTANT FINAL)
@@ -147,7 +116,7 @@ public:
QmlList<QObject *> *resources();
QFxAnchors *anchors();
- QFxContents *contents();
+ QRectF childrenRect();
bool clip() const;
void setClip(bool);
@@ -190,6 +159,7 @@ Q_SIGNALS:
void yChanged();
void widthChanged();
void heightChanged();
+ void childrenRectChanged();
void baselineOffsetChanged();
void stateChanged(const QString &);
void focusChanged();
@@ -251,7 +221,6 @@ QDebug Q_DECLARATIVE_EXPORT operator<<(QDebug debug, QFxItem *item);
QT_END_NAMESPACE
-QML_DECLARE_TYPE(QFxContents)
QML_DECLARE_TYPE(QFxItem)
QML_DECLARE_TYPE(QGraphicsTransform)
QML_DECLARE_TYPE(QGraphicsScale)
diff --git a/src/declarative/fx/qfxitem_p.h b/src/declarative/fx/qfxitem_p.h
index 0e916b2..1d4bef3 100644
--- a/src/declarative/fx/qfxitem_p.h
+++ b/src/declarative/fx/qfxitem_p.h
@@ -69,6 +69,32 @@ QT_BEGIN_NAMESPACE
class QNetworkReply;
class QFxKeysAttached;
+//### merge into private?
+class QFxContents : public QObject
+{
+ Q_OBJECT
+public:
+ QFxContents();
+
+ QRectF rectF() const;
+
+ void setItem(QFxItem *item);
+
+public Q_SLOTS:
+ void calcHeight();
+ void calcWidth();
+
+Q_SIGNALS:
+ void rectChanged();
+
+private:
+ QFxItem *m_item;
+ qreal m_x;
+ qreal m_y;
+ qreal m_width;
+ qreal m_height;
+};
+
class QFxItemPrivate : public QGraphicsItemPrivate
{
Q_DECLARE_PUBLIC(QFxItem)
@@ -200,4 +226,5 @@ public:
};
QT_END_NAMESPACE
+
#endif // QFXITEM_P_H
diff --git a/src/declarative/fx/qfxmouseregion.cpp b/src/declarative/fx/qfxmouseregion.cpp
index e3eec04..514701d 100644
--- a/src/declarative/fx/qfxmouseregion.cpp
+++ b/src/declarative/fx/qfxmouseregion.cpp
@@ -272,7 +272,10 @@ bool QFxMouseRegion::isEnabled() const
void QFxMouseRegion::setEnabled(bool a)
{
Q_D(QFxMouseRegion);
- d->absorb = a;
+ if (a != d->absorb) {
+ d->absorb = a;
+ emit enabledChanged();
+ }
}
void QFxMouseRegion::mousePressEvent(QGraphicsSceneMouseEvent *event)
@@ -449,9 +452,9 @@ void QFxMouseRegion::timerEvent(QTimerEvent *event)
\warning This property is only partially implemented -- it is only valid when the mouse is pressed, and not for hover events.
*/
-bool QFxMouseRegion::hovered()
+bool QFxMouseRegion::hovered() const
{
- Q_D(QFxMouseRegion);
+ Q_D(const QFxMouseRegion);
return d->hovered;
}
@@ -459,9 +462,9 @@ bool QFxMouseRegion::hovered()
\qmlproperty bool MouseRegion::pressed
This property holds whether the mouse region is currently pressed.
*/
-bool QFxMouseRegion::pressed()
+bool QFxMouseRegion::pressed() const
{
- Q_D(QFxMouseRegion);
+ Q_D(const QFxMouseRegion);
return d->pressed;
}
@@ -475,6 +478,39 @@ void QFxMouseRegion::setHovered(bool h)
}
}
+/*!
+ \qmlproperty Qt::MouseButtons MouseRegion::acceptedButtons
+ This property holds the mouse buttons that the mouse region reacts to.
+
+ The available buttons are:
+ \list
+ \o Qt.LeftButton
+ \o Qt.RightButton
+ \o Qt.MiddleButton
+ \endlist
+
+ To accept more than one button the flags can be combined with the
+ "|" (or) operator:
+
+ \code
+ MouseRegion { acceptedButtons: Qt.LeftButton | Qt.RightButton }
+ \endcode
+
+ The default is to accept the Left button.
+*/
+Qt::MouseButtons QFxMouseRegion::acceptedButtons() const
+{
+ return acceptedMouseButtons();
+}
+
+void QFxMouseRegion::setAcceptedButtons(Qt::MouseButtons buttons)
+{
+ if (buttons != acceptedMouseButtons()) {
+ setAcceptedMouseButtons(buttons);
+ emit acceptedButtonsChanged();
+ }
+}
+
void QFxMouseRegion::setPressed(bool p)
{
Q_D(QFxMouseRegion);
diff --git a/src/declarative/fx/qfxmouseregion.h b/src/declarative/fx/qfxmouseregion.h
index 418434a..f2d22d3 100644
--- a/src/declarative/fx/qfxmouseregion.h
+++ b/src/declarative/fx/qfxmouseregion.h
@@ -55,11 +55,12 @@ class Q_DECLARATIVE_EXPORT QFxDrag : public QObject
Q_OBJECT
Q_PROPERTY(QFxItem *target READ target WRITE setTarget)
- Q_PROPERTY(QString axis READ axis WRITE setAxis)
- Q_PROPERTY(qreal xmin READ xmin WRITE setXmin)
- Q_PROPERTY(qreal xmax READ xmax WRITE setXmax)
- Q_PROPERTY(qreal ymin READ ymin WRITE setYmin)
- Q_PROPERTY(qreal ymax READ ymax WRITE setYmax)
+ Q_PROPERTY(QString axis READ axis WRITE setAxis) //### enum
+ Q_PROPERTY(qreal minimumX READ xmin WRITE setXmin)
+ Q_PROPERTY(qreal maximumX READ xmax WRITE setXmax)
+ Q_PROPERTY(qreal minimumY READ ymin WRITE setYmin)
+ Q_PROPERTY(qreal maximumY READ ymax WRITE setYmax)
+ //### consider drag and drop
public:
QFxDrag(QObject *parent=0);
~QFxDrag();
@@ -97,8 +98,10 @@ class Q_DECLARATIVE_EXPORT QFxMouseRegion : public QFxItem
Q_PROPERTY(qreal mouseY READ mouseY NOTIFY positionChanged)
Q_PROPERTY(bool containsMouse READ hovered NOTIFY hoveredChanged)
Q_PROPERTY(bool pressed READ pressed NOTIFY pressedChanged)
- Q_PROPERTY(bool enabled READ isEnabled WRITE setEnabled)
- Q_PROPERTY(QFxDrag *drag READ drag)
+ Q_PROPERTY(bool enabled READ isEnabled WRITE setEnabled NOTIFY enabledChanged)
+ Q_PROPERTY(Qt::MouseButtons acceptedButtons READ acceptedButtons WRITE setAcceptedButtons NOTIFY acceptedButtonsChanged)
+ Q_PROPERTY(QFxDrag *drag READ drag) //### add flicking to QFxDrag or add a QFxFlick ???
+ //### trackingEnabled?
public:
QFxMouseRegion(QFxItem *parent=0);
~QFxMouseRegion();
@@ -109,17 +112,22 @@ public:
bool isEnabled() const;
void setEnabled(bool);
- bool hovered();
- bool pressed();
+ bool hovered() const;
+ bool pressed() const;
void setHovered(bool);
void setPressed(bool);
+ Qt::MouseButtons acceptedButtons() const;
+ void setAcceptedButtons(Qt::MouseButtons buttons);
+
QFxDrag *drag();
Q_SIGNALS:
void hoveredChanged();
void pressedChanged();
+ void enabledChanged();
+ void acceptedButtonsChanged();
void positionChanged(QFxMouseEvent *mouse);
void pressed(QFxMouseEvent *mouse);
diff --git a/src/declarative/fx/qfxmouseregion_p.h b/src/declarative/fx/qfxmouseregion_p.h
index f03c334..1501a81 100644
--- a/src/declarative/fx/qfxmouseregion_p.h
+++ b/src/declarative/fx/qfxmouseregion_p.h
@@ -73,7 +73,7 @@ public:
void init()
{
Q_Q(QFxMouseRegion);
- q->setAcceptedMouseButtons(Qt::LeftButton | Qt::RightButton);
+ q->setAcceptedMouseButtons(Qt::LeftButton);
q->setAcceptHoverEvents(true);
}