summaryrefslogtreecommitdiffstats
path: root/src/declarative
diff options
context:
space:
mode:
authorMichael Brasser <michael.brasser@nokia.com>2009-06-30 03:13:55 (GMT)
committerMichael Brasser <michael.brasser@nokia.com>2009-06-30 03:18:22 (GMT)
commit518cbf7d241cdbd2a4414df289f4bc91e7583edc (patch)
tree571749e96d3549a6624ac5b56f0494dbdac3ff26 /src/declarative
parent3c6648385e8637536292c1351ef0d52708bd07d2 (diff)
downloadQt-518cbf7d241cdbd2a4414df289f4bc91e7583edc.zip
Qt-518cbf7d241cdbd2a4414df289f4bc91e7583edc.tar.gz
Qt-518cbf7d241cdbd2a4414df289f4bc91e7583edc.tar.bz2
Change geometry-related properties from int to qreal.
Most related properties were already qreal.
Diffstat (limited to 'src/declarative')
-rw-r--r--src/declarative/fx/qfxanchors.cpp25
-rw-r--r--src/declarative/fx/qfxanchors.h45
-rw-r--r--src/declarative/fx/qfxanchors_p.h14
-rw-r--r--src/declarative/fx/qfxitem.cpp74
-rw-r--r--src/declarative/fx/qfxitem.h26
-rw-r--r--src/declarative/fx/qfxitem_p.h2
6 files changed, 92 insertions, 94 deletions
diff --git a/src/declarative/fx/qfxanchors.cpp b/src/declarative/fx/qfxanchors.cpp
index 84ccadf..9a5c516 100644
--- a/src/declarative/fx/qfxanchors.cpp
+++ b/src/declarative/fx/qfxanchors.cpp
@@ -51,7 +51,6 @@ QT_BEGIN_NAMESPACE
QML_DEFINE_TYPE(QFxAnchors,Anchors)
//TODO: should we cache relationships, so we don't have to check each time (parent-child or sibling)?
-//TODO: baseline support
//TODO: support non-parent, non-sibling (need to find lowest common ancestor)
//### const item?
@@ -760,13 +759,13 @@ void QFxAnchors::resetHorizontalCenter()
d->updateHorizontalAnchors();
}
-int QFxAnchors::leftMargin() const
+qreal QFxAnchors::leftMargin() const
{
Q_D(const QFxAnchors);
return d->leftMargin;
}
-void QFxAnchors::setLeftMargin(int offset)
+void QFxAnchors::setLeftMargin(qreal offset)
{
Q_D(QFxAnchors);
if (d->leftMargin == offset)
@@ -776,13 +775,13 @@ void QFxAnchors::setLeftMargin(int offset)
emit leftMarginChanged();
}
-int QFxAnchors::rightMargin() const
+qreal QFxAnchors::rightMargin() const
{
Q_D(const QFxAnchors);
return d->rightMargin;
}
-void QFxAnchors::setRightMargin(int offset)
+void QFxAnchors::setRightMargin(qreal offset)
{
Q_D(QFxAnchors);
if (d->rightMargin == offset)
@@ -792,13 +791,13 @@ void QFxAnchors::setRightMargin(int offset)
emit rightMarginChanged();
}
-int QFxAnchors::horizontalCenterOffset() const
+qreal QFxAnchors::horizontalCenterOffset() const
{
Q_D(const QFxAnchors);
return d->hCenterOffset;
}
-void QFxAnchors::setHorizontalCenterOffset(int offset)
+void QFxAnchors::setHorizontalCenterOffset(qreal offset)
{
Q_D(QFxAnchors);
if (d->hCenterOffset == offset)
@@ -808,13 +807,13 @@ void QFxAnchors::setHorizontalCenterOffset(int offset)
emit horizontalCenterOffsetChanged();
}
-int QFxAnchors::topMargin() const
+qreal QFxAnchors::topMargin() const
{
Q_D(const QFxAnchors);
return d->topMargin;
}
-void QFxAnchors::setTopMargin(int offset)
+void QFxAnchors::setTopMargin(qreal offset)
{
Q_D(QFxAnchors);
if (d->topMargin == offset)
@@ -824,13 +823,13 @@ void QFxAnchors::setTopMargin(int offset)
emit topMarginChanged();
}
-int QFxAnchors::bottomMargin() const
+qreal QFxAnchors::bottomMargin() const
{
Q_D(const QFxAnchors);
return d->bottomMargin;
}
-void QFxAnchors::setBottomMargin(int offset)
+void QFxAnchors::setBottomMargin(qreal offset)
{
Q_D(QFxAnchors);
if (d->bottomMargin == offset)
@@ -840,13 +839,13 @@ void QFxAnchors::setBottomMargin(int offset)
emit bottomMarginChanged();
}
-int QFxAnchors::verticalCenterOffset() const
+qreal QFxAnchors::verticalCenterOffset() const
{
Q_D(const QFxAnchors);
return d->vCenterOffset;
}
-void QFxAnchors::setVerticalCenterOffset(int offset)
+void QFxAnchors::setVerticalCenterOffset(qreal offset)
{
Q_D(QFxAnchors);
if (d->vCenterOffset == offset)
diff --git a/src/declarative/fx/qfxanchors.h b/src/declarative/fx/qfxanchors.h
index 206a05c..94c22a6 100644
--- a/src/declarative/fx/qfxanchors.h
+++ b/src/declarative/fx/qfxanchors.h
@@ -46,15 +46,13 @@
#include <QtDeclarative/qfxglobal.h>
#include <QtDeclarative/qml.h>
-
QT_BEGIN_HEADER
QT_BEGIN_NAMESPACE
QT_MODULE(Declarative)
-class QFxItem;
-class QFxAnchorsPrivate;
+class QFxItem;
class QFxAnchorLine
{
public:
@@ -93,12 +91,12 @@ class Q_DECLARATIVE_EXPORT QFxAnchors : public QObject
Q_PROPERTY(QFxAnchorLine bottom READ bottom WRITE setBottom RESET resetBottom)
Q_PROPERTY(QFxAnchorLine verticalCenter READ verticalCenter WRITE setVerticalCenter RESET resetVerticalCenter)
Q_PROPERTY(QFxAnchorLine baseline READ baseline WRITE setBaseline RESET resetBaseline)
- Q_PROPERTY(int leftMargin READ leftMargin WRITE setLeftMargin NOTIFY leftMarginChanged)
- Q_PROPERTY(int rightMargin READ rightMargin WRITE setRightMargin NOTIFY rightMarginChanged)
- Q_PROPERTY(int horizontalCenterOffset READ horizontalCenterOffset WRITE setHorizontalCenterOffset NOTIFY horizontalCenterOffsetChanged())
- Q_PROPERTY(int topMargin READ topMargin WRITE setTopMargin NOTIFY topMarginChanged)
- Q_PROPERTY(int bottomMargin READ bottomMargin WRITE setBottomMargin NOTIFY bottomMarginChanged)
- Q_PROPERTY(int verticalCenterOffset READ verticalCenterOffset WRITE setVerticalCenterOffset NOTIFY verticalCenterOffsetChanged())
+ Q_PROPERTY(qreal leftMargin READ leftMargin WRITE setLeftMargin NOTIFY leftMarginChanged)
+ Q_PROPERTY(qreal rightMargin READ rightMargin WRITE setRightMargin NOTIFY rightMarginChanged)
+ Q_PROPERTY(qreal horizontalCenterOffset READ horizontalCenterOffset WRITE setHorizontalCenterOffset NOTIFY horizontalCenterOffsetChanged())
+ Q_PROPERTY(qreal topMargin READ topMargin WRITE setTopMargin NOTIFY topMarginChanged)
+ Q_PROPERTY(qreal bottomMargin READ bottomMargin WRITE setBottomMargin NOTIFY bottomMarginChanged)
+ Q_PROPERTY(qreal verticalCenterOffset READ verticalCenterOffset WRITE setVerticalCenterOffset NOTIFY verticalCenterOffsetChanged())
Q_PROPERTY(QFxItem *fill READ fill WRITE setFill)
Q_PROPERTY(QFxItem *centeredIn READ centeredIn WRITE setCenteredIn)
@@ -121,7 +119,7 @@ public:
QFxAnchorLine left() const;
void setLeft(const QFxAnchorLine &edge);
- Q_INVOKABLE void resetLeft(); //### temporarily invokable for testing
+ void resetLeft();
QFxAnchorLine right() const;
void setRight(const QFxAnchorLine &edge);
@@ -147,23 +145,23 @@ public:
void setBaseline(const QFxAnchorLine &edge);
void resetBaseline();
- int leftMargin() const;
- void setLeftMargin(int);
+ qreal leftMargin() const;
+ void setLeftMargin(qreal);
- int rightMargin() const;
- void setRightMargin(int);
+ qreal rightMargin() const;
+ void setRightMargin(qreal);
- int horizontalCenterOffset() const;
- void setHorizontalCenterOffset(int);
+ qreal horizontalCenterOffset() const;
+ void setHorizontalCenterOffset(qreal);
- int topMargin() const;
- void setTopMargin(int);
+ qreal topMargin() const;
+ void setTopMargin(qreal);
- int bottomMargin() const;
- void setBottomMargin(int);
+ qreal bottomMargin() const;
+ void setBottomMargin(qreal);
- int verticalCenterOffset() const;
- void setVerticalCenterOffset(int);
+ qreal verticalCenterOffset() const;
+ void setVerticalCenterOffset(qreal);
QFxItem *fill() const;
void setFill(QFxItem *);
@@ -188,11 +186,10 @@ private:
Q_DISABLE_COPY(QFxAnchors)
Q_DECLARE_PRIVATE(QFxAnchors)
};
-
QML_DECLARE_TYPE(QFxAnchors)
-
QT_END_NAMESPACE
QT_END_HEADER
+
#endif
diff --git a/src/declarative/fx/qfxanchors_p.h b/src/declarative/fx/qfxanchors_p.h
index 9ff6869..a7c904b 100644
--- a/src/declarative/fx/qfxanchors_p.h
+++ b/src/declarative/fx/qfxanchors_p.h
@@ -56,8 +56,8 @@
#include "qfxanchors.h"
#include "private/qobject_p.h"
-
QT_BEGIN_NAMESPACE
+
class QFxAnchorsPrivate : public QObjectPrivate
{
Q_DECLARE_PUBLIC(QFxAnchors)
@@ -119,12 +119,12 @@ public:
QFxAnchorLine hCenter;
QFxAnchorLine baseline;
- int leftMargin;
- int rightMargin;
- int topMargin;
- int bottomMargin;
- int vCenterOffset;
- int hCenterOffset;
+ qreal leftMargin;
+ qreal rightMargin;
+ qreal topMargin;
+ qreal bottomMargin;
+ qreal vCenterOffset;
+ qreal hCenterOffset;
};
diff --git a/src/declarative/fx/qfxitem.cpp b/src/declarative/fx/qfxitem.cpp
index 73786a8..3764e3d 100644
--- a/src/declarative/fx/qfxitem.cpp
+++ b/src/declarative/fx/qfxitem.cpp
@@ -65,10 +65,10 @@
#include <qsimplecanvasfilter.h>
#include <qmlcomponent.h>
-
QT_BEGIN_NAMESPACE
-#ifndef INT_MAX
-#define INT_MAX 2147483647
+
+#ifndef FLT_MAX
+#define FLT_MAX 1E+37
#endif
QML_DEFINE_NOCREATE_TYPE(QFxContents)
@@ -123,7 +123,7 @@ QML_DEFINE_NOCREATE_TYPE(QSimpleCanvasFilter)
*/
-QFxContents::QFxContents() : _height(0), _width(0)
+QFxContents::QFxContents() : m_height(0), m_width(0)
{
}
@@ -131,70 +131,71 @@ QFxContents::QFxContents() : _height(0), _width(0)
\property QFxContents::height
\brief The height of the contents.
*/
-int QFxContents::height() const
+qreal QFxContents::height() const
{
- return _height;
+ return m_height;
}
/*!
\property QFxContents::width
\brief The width of the contents.
*/
-int QFxContents::width() const
+qreal QFxContents::width() const
{
- return _width;
+ return m_width;
}
//TODO: optimization: only check sender(), if there is one
void QFxContents::calcHeight()
{
- int oldheight = _height;
+ qreal oldheight = m_height;
- int top = INT_MAX;
- int bottom = 0;
+ qreal top = FLT_MAX;
+ qreal bottom = 0;
- const QList<QSimpleCanvasItem *> &children = _item->QSimpleCanvasItem::children();
+ const QList<QSimpleCanvasItem *> &children = m_item->QSimpleCanvasItem::children();
for (int i = 0; i < children.count(); ++i) {
const QSimpleCanvasItem *child = children.at(i);
- int y = int(child->y());
+ qreal y = child->y();
if (y + child->height() > bottom)
bottom = y + child->height();
if (y < top)
top = y;
}
- _height = bottom - top;
+ m_height = qMax(bottom - top, qreal(0.0));
- if (_height != oldheight)
+ if (m_height != oldheight)
emit heightChanged();
}
//TODO: optimization: only check sender(), if there is one
void QFxContents::calcWidth()
{
- int oldwidth = _width;
+ qreal oldwidth = m_width;
+
+ qreal left = FLT_MAX;
+ qreal right = 0;
- int left = INT_MAX;
- int right = 0;
- const QList<QSimpleCanvasItem *> &children = _item->QSimpleCanvasItem::children();
+ const QList<QSimpleCanvasItem *> &children = m_item->QSimpleCanvasItem::children();
for (int i = 0; i < children.count(); ++i) {
const QSimpleCanvasItem *child = children.at(i);
- int x = int(child->x());
+ qreal x = int(child->x());
if (x + child->width() > right)
right = x + child->width();
if (x < left)
left = x;
}
- _width = right - left;
+ m_width = qMax(right - left, qreal(0.0));
- if (_width != oldwidth)
+ if (m_width != oldwidth)
emit widthChanged();
}
void QFxContents::setItem(QFxItem *item)
{
- _item = item;
+ m_item = item;
- const QList<QSimpleCanvasItem *> &children = _item->QSimpleCanvasItem::children();
+ const QList<QSimpleCanvasItem *> &children = m_item->QSimpleCanvasItem::children();
for (int i = 0; i < children.count(); ++i) {
const QSimpleCanvasItem *child = children.at(i);
connect(child, SIGNAL(heightChanged()), this, SLOT(calcHeight()));
@@ -925,8 +926,8 @@ void QFxItem::qmlLoaded()
/*!
\qmlproperty real Item::x
\qmlproperty real Item::y
- \qmlproperty int Item::width
- \qmlproperty int Item::height
+ \qmlproperty real Item::width
+ \qmlproperty real Item::height
Defines the item's position and size relative to its parent.
@@ -1346,13 +1347,14 @@ QFxAnchorLine QFxItem::baseline() const
\qmlproperty AnchorLine Item::anchors.baseline
\qmlproperty Item Item::anchors.fill
-
- \qmlproperty int Item::anchors.topMargin
- \qmlproperty int Item::anchors.bottomMargin
- \qmlproperty int Item::anchors.leftMargin
- \qmlproperty int Item::anchors.rightMargin
- \qmlproperty int Item::anchors.horizontalCenterOffset
- \qmlproperty int Item::anchors.verticalCenterOffset
+ \qmlproperty Item Item::anchors.centeredIn
+
+ \qmlproperty real Item::anchors.topMargin
+ \qmlproperty real Item::anchors.bottomMargin
+ \qmlproperty real Item::anchors.leftMargin
+ \qmlproperty real Item::anchors.rightMargin
+ \qmlproperty real Item::anchors.horizontalCenterOffset
+ \qmlproperty real Item::anchors.verticalCenterOffset
Anchors provide a way to position an item by specifying its
relationship with other items.
@@ -1411,11 +1413,11 @@ QFxAnchorLine QFxItem::baseline() const
For non-text items, a default baseline offset of 0 is used.
*/
-int QFxItem::baselineOffset() const
+qreal QFxItem::baselineOffset() const
{
Q_D(const QFxItem);
if (!d->_baselineOffset.isValid()) {
- return 0;
+ return 0.0;
} else
return d->_baselineOffset;
}
@@ -1423,7 +1425,7 @@ int QFxItem::baselineOffset() const
/*!
\internal
*/
-void QFxItem::setBaselineOffset(int offset)
+void QFxItem::setBaselineOffset(qreal offset)
{
Q_D(QFxItem);
if (offset == d->_baselineOffset)
diff --git a/src/declarative/fx/qfxitem.h b/src/declarative/fx/qfxitem.h
index 3c872e1..f0f1177 100644
--- a/src/declarative/fx/qfxitem.h
+++ b/src/declarative/fx/qfxitem.h
@@ -53,7 +53,6 @@
#include <QtDeclarative/qmlcomponent.h>
#include <QtDeclarative/qmlstate.h>
-
QT_BEGIN_HEADER
QT_BEGIN_NAMESPACE
@@ -63,14 +62,14 @@ QT_MODULE(Declarative)
class Q_DECLARATIVE_EXPORT QFxContents : public QObject
{
Q_OBJECT
- Q_PROPERTY(int height READ height NOTIFY heightChanged)
- Q_PROPERTY(int width READ width NOTIFY widthChanged)
+ Q_PROPERTY(qreal height READ height NOTIFY heightChanged)
+ Q_PROPERTY(qreal width READ width NOTIFY widthChanged)
public:
QFxContents();
- int height() const;
+ qreal height() const;
- int width() const;
+ qreal width() const;
void setItem(QFxItem *item);
@@ -83,9 +82,9 @@ Q_SIGNALS:
void widthChanged();
private:
- QFxItem *_item;
- int _height;
- int _width;
+ QFxItem *m_item;
+ qreal m_height;
+ qreal m_width;
};
QML_DECLARE_TYPE(QFxContents)
Q_DECLARE_OPERATORS_FOR_FLAGS(QFxAnchors::UsedAnchors)
@@ -116,11 +115,11 @@ class Q_DECLARATIVE_EXPORT QFxItem : public QSimpleCanvasItem, public QmlParserS
Q_PROPERTY(qreal x READ x WRITE setX NOTIFY leftChanged)
Q_PROPERTY(qreal y READ y WRITE setY NOTIFY topChanged)
Q_PROPERTY(qreal z READ z WRITE setZ)
- Q_PROPERTY(int width READ width WRITE setWidth NOTIFY widthChanged)
+ Q_PROPERTY(qreal width READ width WRITE setWidth NOTIFY widthChanged)
Q_PROPERTY(bool flipVertically READ flipVertically WRITE setFlipVertically)
Q_PROPERTY(bool flipHorizontally READ flipHorizontally WRITE setFlipHorizontally)
- Q_PROPERTY(int height READ height WRITE setHeight NOTIFY heightChanged)
- Q_PROPERTY(int baselineOffset READ baselineOffset WRITE setBaselineOffset NOTIFY baselineOffsetChanged)
+ Q_PROPERTY(qreal height READ height WRITE setHeight NOTIFY heightChanged)
+ Q_PROPERTY(qreal baselineOffset READ baselineOffset WRITE setBaselineOffset NOTIFY baselineOffsetChanged)
Q_PROPERTY(QFxAnchorLine left READ left)
Q_PROPERTY(QFxAnchorLine right READ right)
Q_PROPERTY(QFxAnchorLine horizontalCenter READ horizontalCenter)
@@ -179,8 +178,8 @@ public:
bool flipHorizontally() const;
void setFlipHorizontally(bool);
- int baselineOffset() const;
- void setBaselineOffset(int);
+ qreal baselineOffset() const;
+ void setBaselineOffset(qreal);
qreal rotation() const;
void setRotation(qreal);
@@ -274,4 +273,5 @@ QML_DECLARE_TYPE(QSimpleCanvasFilter)
QT_END_NAMESPACE
QT_END_HEADER
+
#endif // QFXITEM_H
diff --git a/src/declarative/fx/qfxitem_p.h b/src/declarative/fx/qfxitem_p.h
index b38d877..32e8aef 100644
--- a/src/declarative/fx/qfxitem_p.h
+++ b/src/declarative/fx/qfxitem_p.h
@@ -138,7 +138,7 @@ public:
QList<QUrl> _qmlnewloading;
QList<QmlComponent*> _qmlnewcomp;
- QmlNullableValue<int> _baselineOffset;
+ QmlNullableValue<qreal> _baselineOffset;
float _rotation;
bool _classComplete:1;