42 #include "private/qdeclarativeanchors_p_p.h" 45 #include "private/qdeclarativeitem_p.h" 63 return (width + 1) / 2;
75 return (height + 1) / 2;
91 ret = item->
x() + d->
width();
154 qFatal(
"QDeclarativeAnchors::QDeclarativeAnchors(QObject*) called");
165 d->remDepend(
d->fill);
166 d->remDepend(
d->centerIn);
167 d->remDepend(
d->left.item);
168 d->remDepend(
d->right.item);
169 d->remDepend(
d->top.item);
170 d->remDepend(
d->bottom.item);
171 d->remDepend(
d->vCenter.item);
172 d->remDepend(
d->hCenter.item);
173 d->remDepend(
d->baseline.item);
179 if (!
fill || !isItemComplete())
182 if (updatingFill < 2) {
209 if (updatingCenterIn < 2) {
212 qreal effectiveHCenterOffset = q->mirrored() ? -hCenterOffset : hCenterOffset;
255 if (vCenter.item == item) {
259 if (hCenter.item == item) {
311 d->componentComplete =
false;
317 d->componentComplete =
true;
368 static_cast<QDeclarativeItem *>(item)->setSize(v);
381 updateHorizontalAnchors();
382 updateVerticalAnchors();
389 updateHorizontalAnchors();
390 updateVerticalAnchors();
395 clearItem(qobject_cast<QGraphicsObject*>(obj));
402 updateHorizontalAnchors();
403 updateVerticalAnchors();
410 if (newG.
x() != oldG.
x() || newG.
width() != oldG.
width())
411 updateHorizontalAnchors();
413 updateVerticalAnchors();
429 d->remDepend(
d->fill);
434 if (f !=
d->item->parentItem() && f->
parentItem() !=
d->item->parentItem()){
435 qmlInfo(
d->item) <<
tr(
"Cannot anchor to an item that isn't a parent or sibling.");
438 d->remDepend(
d->fill);
440 d->addDepend(
d->fill);
459 if (
d->centerIn == c)
463 d->remDepend(
d->centerIn);
468 if (c !=
d->item->parentItem() && c->
parentItem() !=
d->item->parentItem()){
469 qmlInfo(
d->item) <<
tr(
"Cannot anchor to an item that isn't a parent or sibling.");
473 d->remDepend(
d->centerIn);
475 d->addDepend(
d->centerIn);
477 d->centerInChanged();
497 bool invalid =
false;
498 if ((edge2IsParent && edge1IsParent) || (edge2IsSibling && edge1IsSibling)) {
501 }
else if (edge2IsParent && edge1IsSibling) {
503 - (
position(item->parentObject(), line)
505 }
else if (edge2IsSibling && edge1IsParent) {
519 if (updatingVerticalAnchor < 2) {
520 ++updatingVerticalAnchor;
533 setItemHeight(height);
548 setItemHeight(height*2);
561 if (vCenter.item == item->parentItem()) {
563 -
vcenter(item) + vCenterOffset);
564 }
else if (vCenter.item->parentItem() == item->parentItem()) {
565 setItemY(
position(vCenter.item, vCenter.anchorLine) -
vcenter(item) + vCenterOffset);
572 - static_cast<QDeclarativeItem *>(item)->baselineOffset() +
baselineOffset);
576 - static_cast<QDeclarativeItem *>(item)->baselineOffset() +
baselineOffset);
579 --updatingVerticalAnchor;
602 if (updatingHorizontalAnchor < 3) {
603 ++updatingHorizontalAnchor;
604 qreal effectiveRightMargin, effectiveLeftMargin, effectiveHorizontalCenterOffset;
614 effectiveHorizontalCenter.
item = hCenter.item;
618 effectiveHorizontalCenterOffset = -hCenterOffset;
622 effectiveLeft =
left;
623 effectiveRight =
right;
624 effectiveHorizontalCenter = hCenter;
627 effectiveHorizontalCenterOffset = hCenterOffset;
638 invalid = calcStretch(effectiveLeft, effectiveHorizontalCenter, effectiveLeftMargin, effectiveHorizontalCenterOffset,
QDeclarativeAnchorLine::Left, width);
654 bool invalid = calcStretch(effectiveHorizontalCenter, effectiveRight, effectiveHorizontalCenterOffset, -effectiveRightMargin,
657 setItemWidth(width*2);
674 --updatingHorizontalAnchor;
690 if (!
d->checkVAnchorValid(edge) ||
d->top == edge)
695 if (!
d->checkVValid()) {
700 d->remDepend(
d->top.item);
702 d->addDepend(
d->top.item);
704 d->updateVerticalAnchors();
711 d->remDepend(
d->top.item);
714 d->updateVerticalAnchors();
726 if (!
d->checkVAnchorValid(edge) ||
d->bottom == edge)
731 if (!
d->checkVValid()) {
736 d->remDepend(
d->bottom.item);
738 d->addDepend(
d->bottom.item);
740 d->updateVerticalAnchors();
747 d->remDepend(
d->bottom.item);
750 d->updateVerticalAnchors();
762 if (!
d->checkVAnchorValid(edge) ||
d->vCenter == edge)
767 if (!
d->checkVValid()) {
772 d->remDepend(
d->vCenter.item);
774 d->addDepend(
d->vCenter.item);
776 d->updateVerticalAnchors();
783 d->remDepend(
d->vCenter.item);
786 d->updateVerticalAnchors();
798 if (!
d->checkVAnchorValid(edge) ||
d->baseline == edge)
803 if (!
d->checkVValid()) {
808 d->remDepend(
d->baseline.item);
810 d->addDepend(
d->baseline.item);
812 d->updateVerticalAnchors();
819 d->remDepend(
d->baseline.item);
822 d->updateVerticalAnchors();
834 if (!
d->checkHAnchorValid(edge) ||
d->left == edge)
839 if (!
d->checkHValid()) {
844 d->remDepend(
d->left.item);
846 d->addDepend(
d->left.item);
848 d->updateHorizontalAnchors();
855 d->remDepend(
d->left.item);
858 d->updateHorizontalAnchors();
870 if (!
d->checkHAnchorValid(edge) ||
d->right == edge)
875 if (!
d->checkHValid()) {
880 d->remDepend(
d->right.item);
882 d->addDepend(
d->right.item);
884 d->updateHorizontalAnchors();
891 d->remDepend(
d->right.item);
894 d->updateHorizontalAnchors();
906 if (!
d->checkHAnchorValid(edge) ||
d->hCenter == edge)
911 if (!
d->checkHValid()) {
916 d->remDepend(
d->hCenter.item);
918 d->addDepend(
d->hCenter.item);
920 d->updateHorizontalAnchors();
927 d->remDepend(
d->hCenter.item);
930 d->updateHorizontalAnchors();
936 return d->leftMargin;
942 if (
d->leftMargin == offset)
944 d->leftMargin = offset;
948 d->updateHorizontalAnchors();
955 return d->rightMargin;
961 if (
d->rightMargin == offset)
963 d->rightMargin = offset;
967 d->updateHorizontalAnchors();
980 if (
d->margins == offset)
983 if(!
d->rightMargin ||
d->rightMargin ==
d->margins)
985 if(!
d->leftMargin ||
d->leftMargin ==
d->margins)
987 if(!
d->topMargin ||
d->topMargin ==
d->margins)
989 if(!
d->bottomMargin ||
d->bottomMargin ==
d->margins)
999 return d->hCenterOffset;
1005 if (
d->hCenterOffset == offset)
1007 d->hCenterOffset = offset;
1009 d->centerInChanged();
1011 d->updateHorizontalAnchors();
1018 return d->topMargin;
1024 if (
d->topMargin == offset)
1026 d->topMargin = offset;
1030 d->updateVerticalAnchors();
1037 return d->bottomMargin;
1043 if (
d->bottomMargin == offset)
1045 d->bottomMargin = offset;
1049 d->updateVerticalAnchors();
1056 return d->vCenterOffset;
1062 if (
d->vCenterOffset == offset)
1064 d->vCenterOffset = offset;
1066 d->centerInChanged();
1068 d->updateVerticalAnchors();
1075 return d->baselineOffset;
1081 if (
d->baselineOffset == offset)
1083 d->baselineOffset = offset;
1084 d->updateVerticalAnchors();
1091 return d->usedAnchors;
1117 }
else if (anchor.
item == item) {
1135 usedAnchors & QDeclarativeAnchors::VCenterAnchor)) {
1154 }
else if (anchor.
item == item){
1164 #include <moc_qdeclarativeanchors_p.cpp> QDeclarativeAnchorLine baseline() const
void verticalCenterChanged()
qreal y() const
Returns the y-coordinate of the rectangle's top edge.
#define QT_END_NAMESPACE
This macro expands to.
void addDepend(QGraphicsObject *)
QPointer< QWidget > widget
void resetHorizontalCenter()
qreal y
the y position of the item
virtual qreal height() const
void setLeftMargin(qreal)
QDeclarativeAnchorLine horizontalCenter() const
void itemGeometryChanged(QDeclarativeItem *, const QRectF &, const QRectF &)
void setCenterIn(QGraphicsObject *)
qreal rightMargin() const
void remDepend(QGraphicsObject *)
void setHorizontalCenterOffset(qreal)
The QPointF class defines a point in the plane using floating point precision.
The QGraphicsItem class is the base class for all graphical items in a QGraphicsScene.
static qreal position(QGraphicsObject *item, QDeclarativeAnchorLine::AnchorLine anchorLine)
QDeclarativeAnchorLine bottom() const
QGraphicsObject * centerIn() const
static QString tr(const char *sourceText, const char *comment=0, int n=-1)
void updateVerticalAnchors()
The QObject class is the base class of all Qt objects.
void setBaselineOffset(qreal)
The QSizeF class defines the size of a two-dimensional object using floating point precision...
QDeclarativeAnchorLine verticalCenter() const
static qreal vcenter(QGraphicsItem *i)
static qreal adjustedPosition(QGraphicsObject *item, QDeclarativeAnchorLine::AnchorLine anchorLine)
virtual void setWidth(qreal)
bool calcStretch(const QDeclarativeAnchorLine &edge1, const QDeclarativeAnchorLine &edge2, qreal offset1, qreal offset2, QDeclarativeAnchorLine::AnchorLine line, qreal &stretch)
void setLeft(const QDeclarativeAnchorLine &edge)
#define QT_BEGIN_NAMESPACE
This macro expands to.
The QRectF class defines a rectangle in the plane using floating point precision. ...
void destroyed(QObject *=0)
This signal is emitted immediately before the object obj is destroyed, and can not be blocked...
The QDeclarativeItem class provides the most basic of all visual items in QML.
static bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
Creates a connection of the given type from the signal in the sender object to the method in the rece...
void addItemChangeListener(QDeclarativeItemChangeListener *listener, ChangeTypes types)
qreal height() const
Returns the height of the rectangle.
bool checkHAnchorValid(QDeclarativeAnchorLine anchor) const
QDeclarativeAnchorLine::AnchorLine reverseAnchorLine(QDeclarativeAnchorLine::AnchorLine anchorLine)
void _q_widgetGeometryChanged()
void setBaseline(const QDeclarativeAnchorLine &edge)
qreal horizontalCenterOffset() const
qreal width() const
Returns the width of the rectangle.
void clearItem(QGraphicsObject *)
void _q_widgetDestroyed(QObject *)
bool checkVAnchorValid(QDeclarativeAnchorLine anchor) const
void setTop(const QDeclarativeAnchorLine &edge)
bool isItemComplete() const
QDeclarativeAnchorLine top() const
static bool disconnect(const QObject *sender, const char *signal, const QObject *receiver, const char *member)
Disconnects signal in object sender from method in object receiver.
void removeItemChangeListener(QDeclarativeItemChangeListener *, ChangeTypes types)
void updateHorizontalAnchors()
void setItemSize(const QSizeF &)
qreal verticalCenterOffset() const
Q_CORE_EXPORT void qFatal(const char *,...)
QGraphicsItem * parentItem() const
Returns a pointer to this item's parent item.
void setHorizontalCenter(const QDeclarativeAnchorLine &edge)
void setBottomMargin(qreal)
void rightMarginChanged()
Anchors usedAnchors() const
virtual ~QDeclarativeAnchors()
qreal x() const
Returns the x-coordinate of the rectangle's left edge.
virtual qreal width() const
void setVerticalCenter(const QDeclarativeAnchorLine &edge)
QObject * parent() const
Returns a pointer to the parent object.
void verticalCenterOffsetChanged()
QDeclarativeAnchorLine left() const
QDeclarativeAnchors(QObject *parent=0)
void horizontalCenterOffsetChanged()
void resetVerticalCenter()
static const QGraphicsItemPrivate * get(const QGraphicsItem *item)
static qreal hcenter(QGraphicsItem *i)
void setRightMargin(qreal)
void setItemHeight(qreal)
QGraphicsObject * fill() const
qreal bottomMargin() const
void baselineOffsetChanged()
quint32 isDeclarativeItem
qreal x
the x position of the item
QDeclarativeInfo qmlInfo(const QObject *me)
QDeclarativeAnchorLine right() const
void setItemPos(const QPointF &)
void horizontalCenterChanged()
The QGraphicsObject class provides a base class for all graphics items that require signals...
void setFill(QGraphicsObject *)
void setRight(const QDeclarativeAnchorLine &edge)
void bottomMarginChanged()
qreal baselineOffset() const
virtual void setHeight(qreal)
void setBottom(const QDeclarativeAnchorLine &edge)
void setVerticalCenterOffset(qreal)