59 | QDeclarativeItemPrivate::SiblingOrder |
59 | QDeclarativeItemPrivate::SiblingOrder |
60 | QDeclarativeItemPrivate::Visibility |
60 | QDeclarativeItemPrivate::Visibility |
61 | QDeclarativeItemPrivate::Opacity |
61 | QDeclarativeItemPrivate::Opacity |
62 | QDeclarativeItemPrivate::Destroyed; |
62 | QDeclarativeItemPrivate::Destroyed; |
63 |
63 |
64 void QDeclarativeBasePositionerPrivate::watchChanges(QDeclarativeItem *other) |
64 void QDeclarativeBasePositionerPrivate::watchChanges(QGraphicsObject *other) |
65 { |
65 { |
66 QDeclarativeItemPrivate *otherPrivate = static_cast<QDeclarativeItemPrivate*>(QGraphicsItemPrivate::get(other)); |
66 if (QGraphicsItemPrivate::get(other)->isDeclarativeItem) { |
67 otherPrivate->addItemChangeListener(this, watchedChanges); |
67 QDeclarativeItemPrivate *otherPrivate = static_cast<QDeclarativeItemPrivate*>(QGraphicsItemPrivate::get(other)); |
68 } |
68 otherPrivate->addItemChangeListener(this, watchedChanges); |
69 |
69 } else { |
70 void QDeclarativeBasePositionerPrivate::unwatchChanges(QDeclarativeItem* other) |
70 Q_Q(QDeclarativeBasePositioner); |
71 { |
71 QObject::connect(other, SIGNAL(widthChanged()), q, SLOT(graphicsWidgetGeometryChanged())); |
72 QDeclarativeItemPrivate *otherPrivate = static_cast<QDeclarativeItemPrivate*>(QGraphicsItemPrivate::get(other)); |
72 QObject::connect(other, SIGNAL(heightChanged()), q, SLOT(graphicsWidgetGeometryChanged())); |
73 otherPrivate->removeItemChangeListener(this, watchedChanges); |
73 QObject::connect(other, SIGNAL(opacityChanged()), q, SLOT(graphicsWidgetGeometryChanged())); |
|
74 QObject::connect(other, SIGNAL(visibleChanged()), q, SLOT(graphicsWidgetGeometryChanged())); |
|
75 } |
|
76 } |
|
77 |
|
78 void QDeclarativeBasePositionerPrivate::unwatchChanges(QGraphicsObject* other) |
|
79 { |
|
80 if (QGraphicsItemPrivate::get(other)->isDeclarativeItem) { |
|
81 QDeclarativeItemPrivate *otherPrivate = static_cast<QDeclarativeItemPrivate*>(QGraphicsItemPrivate::get(other)); |
|
82 otherPrivate->removeItemChangeListener(this, watchedChanges); |
|
83 } else { |
|
84 Q_Q(QDeclarativeBasePositioner); |
|
85 QObject::disconnect(other, SIGNAL(widthChanged()), q, SLOT(graphicsWidgetGeometryChanged())); |
|
86 QObject::disconnect(other, SIGNAL(heightChanged()), q, SLOT(graphicsWidgetGeometryChanged())); |
|
87 QObject::disconnect(other, SIGNAL(opacityChanged()), q, SLOT(graphicsWidgetGeometryChanged())); |
|
88 QObject::disconnect(other, SIGNAL(visibleChanged()), q, SLOT(graphicsWidgetGeometryChanged())); |
|
89 } |
|
90 } |
|
91 |
|
92 void QDeclarativeBasePositioner::graphicsWidgetGeometryChanged() |
|
93 { |
|
94 prePositioning(); |
74 } |
95 } |
75 |
96 |
76 /*! |
97 /*! |
77 \internal |
98 \internal |
78 \class QDeclarativeBasePositioner |
99 \class QDeclarativeBasePositioner |
85 position are provided in order as the protected member positionedItems. |
106 position are provided in order as the protected member positionedItems. |
86 |
107 |
87 You also need to set a PositionerType, to declare whether you are positioning the x, y or both |
108 You also need to set a PositionerType, to declare whether you are positioning the x, y or both |
88 for the child items. Depending on the chosen type, only x or y changes will be applied. |
109 for the child items. Depending on the chosen type, only x or y changes will be applied. |
89 |
110 |
90 Note that the subclass is responsible for adding the |
111 Note that the subclass is responsible for adding the spacing in between items. |
91 spacing in between items. |
|
92 */ |
112 */ |
93 QDeclarativeBasePositioner::QDeclarativeBasePositioner(PositionerType at, QDeclarativeItem *parent) |
113 QDeclarativeBasePositioner::QDeclarativeBasePositioner(PositionerType at, QDeclarativeItem *parent) |
94 : QDeclarativeItem(*(new QDeclarativeBasePositionerPrivate), parent) |
114 : QDeclarativeItem(*(new QDeclarativeBasePositionerPrivate), parent) |
95 { |
115 { |
96 Q_D(QDeclarativeBasePositioner); |
116 Q_D(QDeclarativeBasePositioner); |
172 const QVariant &value) |
192 const QVariant &value) |
173 { |
193 { |
174 Q_D(QDeclarativeBasePositioner); |
194 Q_D(QDeclarativeBasePositioner); |
175 if (change == ItemChildAddedChange){ |
195 if (change == ItemChildAddedChange){ |
176 QGraphicsItem* item = value.value<QGraphicsItem*>(); |
196 QGraphicsItem* item = value.value<QGraphicsItem*>(); |
177 QDeclarativeItem* child = 0; |
197 QGraphicsObject* child = 0; |
178 if(item) |
198 if(item) |
179 child = qobject_cast<QDeclarativeItem*>(item->toGraphicsObject()); |
199 child = item->toGraphicsObject(); |
180 if (child) |
200 if (child) |
181 prePositioning(); |
201 prePositioning(); |
182 } else if (change == ItemChildRemovedChange) { |
202 } else if (change == ItemChildRemovedChange) { |
183 QGraphicsItem* item = value.value<QGraphicsItem*>(); |
203 QGraphicsItem* item = value.value<QGraphicsItem*>(); |
184 QDeclarativeItem* child = 0; |
204 QGraphicsObject* child = 0; |
185 if(item) |
205 if(item) |
186 child = qobject_cast<QDeclarativeItem*>(item->toGraphicsObject()); |
206 child = item->toGraphicsObject(); |
187 if (child) { |
207 if (child) { |
188 QDeclarativeBasePositioner::PositionedItem posItem(child); |
208 QDeclarativeBasePositioner::PositionedItem posItem(child); |
189 int idx = positionedItems.find(posItem); |
209 int idx = positionedItems.find(posItem); |
190 if (idx >= 0) { |
210 if (idx >= 0) { |
191 d->unwatchChanges(child); |
211 d->unwatchChanges(child); |
192 positionedItems.remove(idx); |
212 positionedItems.remove(idx); |
193 } |
213 } |
194 prePositioning(); |
214 prePositioning(); |
195 } |
215 } |
196 } |
216 } |
197 |
|
198 return QDeclarativeItem::itemChange(change, value); |
217 return QDeclarativeItem::itemChange(change, value); |
199 } |
218 } |
200 |
219 |
201 void QDeclarativeBasePositioner::prePositioning() |
220 void QDeclarativeBasePositioner::prePositioning() |
202 { |
221 { |
214 qSort(children.begin(), children.end(), d->insertionOrder); |
233 qSort(children.begin(), children.end(), d->insertionOrder); |
215 |
234 |
216 QPODVector<PositionedItem,8> oldItems; |
235 QPODVector<PositionedItem,8> oldItems; |
217 positionedItems.copyAndClear(oldItems); |
236 positionedItems.copyAndClear(oldItems); |
218 for (int ii = 0; ii < children.count(); ++ii) { |
237 for (int ii = 0; ii < children.count(); ++ii) { |
219 QDeclarativeItem *child = qobject_cast<QDeclarativeItem *>(children.at(ii)); |
238 QGraphicsObject *child = children.at(ii)->toGraphicsObject(); |
220 if (!child) |
239 if (!child) |
221 continue; |
240 continue; |
222 QDeclarativeItemPrivate *childPrivate = static_cast<QDeclarativeItemPrivate*>(QGraphicsItemPrivate::get(child)); |
241 QGraphicsItemPrivate *childPrivate = static_cast<QGraphicsItemPrivate*>(QGraphicsItemPrivate::get(child)); |
223 PositionedItem *item = 0; |
242 PositionedItem *item = 0; |
224 PositionedItem posItem(child); |
243 PositionedItem posItem(child); |
225 int wIdx = oldItems.find(posItem); |
244 int wIdx = oldItems.find(posItem); |
226 if (wIdx < 0) { |
245 if (wIdx < 0) { |
227 d->watchChanges(child); |
246 d->watchChanges(child); |
228 positionedItems.append(posItem); |
247 positionedItems.append(posItem); |
229 item = &positionedItems[positionedItems.count()-1]; |
248 item = &positionedItems[positionedItems.count()-1]; |
230 item->isNew = true; |
249 item->isNew = true; |
231 if (child->opacity() <= 0.0 || childPrivate->explicitlyHidden) |
250 if (child->opacity() <= 0.0 || childPrivate->explicitlyHidden || !childPrivate->width() || !childPrivate->height()) |
232 item->isVisible = false; |
251 item->isVisible = false; |
233 } else { |
252 } else { |
234 item = &oldItems[wIdx]; |
253 item = &oldItems[wIdx]; |
235 // Items are only omitted from positioning if they are explicitly hidden |
254 // Items are only omitted from positioning if they are explicitly hidden |
236 // i.e. their positioning is not affected if an ancestor is hidden. |
255 // i.e. their positioning is not affected if an ancestor is hidden. |
237 if (child->opacity() <= 0.0 || childPrivate->explicitlyHidden) { |
256 if (child->opacity() <= 0.0 || childPrivate->explicitlyHidden || !childPrivate->width() || !childPrivate->height()) { |
238 item->isVisible = false; |
257 item->isVisible = false; |
239 } else if (!item->isVisible) { |
258 } else if (!item->isVisible) { |
240 item->isVisible = true; |
259 item->isVisible = true; |
241 item->isNew = true; |
260 item->isNew = true; |
242 } else { |
261 } else { |
300 d->moveTransitionManager.transition(d->moveActions, d->moveTransition); |
319 d->moveTransitionManager.transition(d->moveActions, d->moveTransition); |
301 d->addActions.clear(); |
320 d->addActions.clear(); |
302 d->moveActions.clear(); |
321 d->moveActions.clear(); |
303 } |
322 } |
304 |
323 |
305 static inline bool isInvisible(QDeclarativeItem *child) |
|
306 { |
|
307 QDeclarativeItemPrivate *childPrivate = static_cast<QDeclarativeItemPrivate*>(QGraphicsItemPrivate::get(child)); |
|
308 return child->opacity() == 0.0 || childPrivate->explicitlyHidden || !child->width() || !child->height(); |
|
309 } |
|
310 |
|
311 /*! |
324 /*! |
312 \qmlclass Column QDeclarativeColumn |
325 \qmlclass Column QDeclarativeColumn |
|
326 \ingroup qml-positioning-elements |
313 \since 4.7 |
327 \since 4.7 |
314 \brief The Column item arranges its children vertically. |
328 \brief The Column item arranges its children vertically. |
315 \inherits Item |
329 \inherits Item |
316 |
330 |
317 The Column item positions its child items so that they are vertically |
331 The Column item positions its child items so that they are vertically |
432 { |
441 { |
433 int voffset = 0; |
442 int voffset = 0; |
434 |
443 |
435 for (int ii = 0; ii < positionedItems.count(); ++ii) { |
444 for (int ii = 0; ii < positionedItems.count(); ++ii) { |
436 const PositionedItem &child = positionedItems.at(ii); |
445 const PositionedItem &child = positionedItems.at(ii); |
437 if (!child.item || isInvisible(child.item)) |
446 if (!child.item || !child.isVisible) |
438 continue; |
447 continue; |
439 |
448 |
440 if(child.item->y() != voffset) |
449 if(child.item->y() != voffset) |
441 positionY(voffset, child); |
450 positionY(voffset, child); |
442 |
451 |
443 contentSize->setWidth(qMax(contentSize->width(), child.item->width())); |
452 contentSize->setWidth(qMax(contentSize->width(), QGraphicsItemPrivate::get(child.item)->width())); |
444 |
453 |
445 voffset += child.item->height(); |
454 voffset += QGraphicsItemPrivate::get(child.item)->height(); |
446 voffset += spacing(); |
455 voffset += spacing(); |
447 } |
456 } |
448 |
457 |
449 contentSize->setHeight(voffset - spacing()); |
458 contentSize->setHeight(voffset - spacing()); |
450 } |
459 } |
452 void QDeclarativeColumn::reportConflictingAnchors() |
461 void QDeclarativeColumn::reportConflictingAnchors() |
453 { |
462 { |
454 QDeclarativeBasePositionerPrivate *d = static_cast<QDeclarativeBasePositionerPrivate*>(QDeclarativeBasePositionerPrivate::get(this)); |
463 QDeclarativeBasePositionerPrivate *d = static_cast<QDeclarativeBasePositionerPrivate*>(QDeclarativeBasePositionerPrivate::get(this)); |
455 for (int ii = 0; ii < positionedItems.count(); ++ii) { |
464 for (int ii = 0; ii < positionedItems.count(); ++ii) { |
456 const PositionedItem &child = positionedItems.at(ii); |
465 const PositionedItem &child = positionedItems.at(ii); |
457 if (child.item) { |
466 if (child.item && QGraphicsItemPrivate::get(child.item)->isDeclarativeItem) { |
458 QDeclarativeAnchors *anchors = QDeclarativeItemPrivate::get(child.item)->_anchors; |
467 QDeclarativeAnchors *anchors = QDeclarativeItemPrivate::get(static_cast<QDeclarativeItem *>(child.item))->_anchors; |
459 if (anchors) { |
468 if (anchors) { |
460 QDeclarativeAnchors::Anchors usedAnchors = anchors->usedAnchors(); |
469 QDeclarativeAnchors::Anchors usedAnchors = anchors->usedAnchors(); |
461 if (usedAnchors & QDeclarativeAnchors::TopAnchor || |
470 if (usedAnchors & QDeclarativeAnchors::TopAnchor || |
462 usedAnchors & QDeclarativeAnchors::BottomAnchor || |
471 usedAnchors & QDeclarativeAnchors::BottomAnchor || |
463 usedAnchors & QDeclarativeAnchors::VCenterAnchor || |
472 usedAnchors & QDeclarativeAnchors::VCenterAnchor || |
571 { |
576 { |
572 int hoffset = 0; |
577 int hoffset = 0; |
573 |
578 |
574 for (int ii = 0; ii < positionedItems.count(); ++ii) { |
579 for (int ii = 0; ii < positionedItems.count(); ++ii) { |
575 const PositionedItem &child = positionedItems.at(ii); |
580 const PositionedItem &child = positionedItems.at(ii); |
576 if (!child.item || isInvisible(child.item)) |
581 if (!child.item || !child.isVisible) |
577 continue; |
582 continue; |
578 |
583 |
579 if(child.item->x() != hoffset) |
584 if(child.item->x() != hoffset) |
580 positionX(hoffset, child); |
585 positionX(hoffset, child); |
581 |
586 |
582 contentSize->setHeight(qMax(contentSize->height(), child.item->height())); |
587 contentSize->setHeight(qMax(contentSize->height(), QGraphicsItemPrivate::get(child.item)->height())); |
583 |
588 |
584 hoffset += child.item->width(); |
589 hoffset += QGraphicsItemPrivate::get(child.item)->width(); |
585 hoffset += spacing(); |
590 hoffset += spacing(); |
586 } |
591 } |
587 |
592 |
588 contentSize->setWidth(hoffset - spacing()); |
593 contentSize->setWidth(hoffset - spacing()); |
589 } |
594 } |
591 void QDeclarativeRow::reportConflictingAnchors() |
596 void QDeclarativeRow::reportConflictingAnchors() |
592 { |
597 { |
593 QDeclarativeBasePositionerPrivate *d = static_cast<QDeclarativeBasePositionerPrivate*>(QDeclarativeBasePositionerPrivate::get(this)); |
598 QDeclarativeBasePositionerPrivate *d = static_cast<QDeclarativeBasePositionerPrivate*>(QDeclarativeBasePositionerPrivate::get(this)); |
594 for (int ii = 0; ii < positionedItems.count(); ++ii) { |
599 for (int ii = 0; ii < positionedItems.count(); ++ii) { |
595 const PositionedItem &child = positionedItems.at(ii); |
600 const PositionedItem &child = positionedItems.at(ii); |
596 if (child.item) { |
601 if (child.item && QGraphicsItemPrivate::get(child.item)->isDeclarativeItem) { |
597 QDeclarativeAnchors *anchors = QDeclarativeItemPrivate::get(child.item)->_anchors; |
602 QDeclarativeAnchors *anchors = QDeclarativeItemPrivate::get(static_cast<QDeclarativeItem *>(child.item))->_anchors; |
598 if (anchors) { |
603 if (anchors) { |
599 QDeclarativeAnchors::Anchors usedAnchors = anchors->usedAnchors(); |
604 QDeclarativeAnchors::Anchors usedAnchors = anchors->usedAnchors(); |
600 if (usedAnchors & QDeclarativeAnchors::LeftAnchor || |
605 if (usedAnchors & QDeclarativeAnchors::LeftAnchor || |
601 usedAnchors & QDeclarativeAnchors::RightAnchor || |
606 usedAnchors & QDeclarativeAnchors::RightAnchor || |
602 usedAnchors & QDeclarativeAnchors::HCenterAnchor || |
607 usedAnchors & QDeclarativeAnchors::HCenterAnchor || |
611 qmlInfo(this) << "Cannot specify left, right, horizontalCenter, fill or centerIn anchors for items inside Row"; |
616 qmlInfo(this) << "Cannot specify left, right, horizontalCenter, fill or centerIn anchors for items inside Row"; |
612 } |
617 } |
613 |
618 |
614 /*! |
619 /*! |
615 \qmlclass Grid QDeclarativeGrid |
620 \qmlclass Grid QDeclarativeGrid |
|
621 \ingroup qml-positioning-elements |
616 \since 4.7 |
622 \since 4.7 |
617 \brief The Grid item positions its children in a grid. |
623 \brief The Grid item positions its children in a grid. |
618 \inherits Item |
624 \inherits Item |
619 |
625 |
620 The Grid item positions its child items so that they are |
626 The Grid item positions its child items so that they are |
784 } |
785 } |
785 } |
786 } |
786 |
787 |
787 void QDeclarativeGrid::doPositioning(QSizeF *contentSize) |
788 void QDeclarativeGrid::doPositioning(QSizeF *contentSize) |
788 { |
789 { |
|
790 |
789 int c = m_columns; |
791 int c = m_columns; |
790 int r = m_rows; |
792 int r = m_rows; |
791 int numVisible = positionedItems.count(); |
793 //Is allocating the extra QPODVector too much overhead? |
|
794 QPODVector<PositionedItem, 8> visibleItems;//we aren't concerned with invisible items |
|
795 visibleItems.reserve(positionedItems.count()); |
|
796 for(int i=0; i<positionedItems.count(); i++) |
|
797 if(positionedItems[i].item && positionedItems[i].isVisible) |
|
798 visibleItems.append(positionedItems[i]); |
|
799 |
|
800 int numVisible = visibleItems.count(); |
792 if (m_columns <= 0 && m_rows <= 0){ |
801 if (m_columns <= 0 && m_rows <= 0){ |
793 c = 4; |
802 c = 4; |
794 r = (numVisible+3)/4; |
803 r = (numVisible+3)/4; |
795 } else if (m_rows <= 0){ |
804 } else if (m_rows <= 0){ |
796 r = (numVisible+(m_columns-1))/m_columns; |
805 r = (numVisible+(m_columns-1))/m_columns; |
807 if (j==0) |
816 if (j==0) |
808 maxRowHeight << 0; |
817 maxRowHeight << 0; |
809 if (i==0) |
818 if (i==0) |
810 maxColWidth << 0; |
819 maxColWidth << 0; |
811 |
820 |
812 if (childIndex == positionedItems.count()) |
821 if (childIndex == visibleItems.count()) |
813 continue; |
822 break; |
814 const PositionedItem &child = positionedItems.at(childIndex++); |
823 |
815 if (!child.item || isInvisible(child.item)) |
824 const PositionedItem &child = visibleItems.at(childIndex++); |
816 continue; |
825 QGraphicsItemPrivate *childPrivate = QGraphicsItemPrivate::get(child.item); |
817 if (child.item->width() > maxColWidth[j]) |
826 if (childPrivate->width() > maxColWidth[j]) |
818 maxColWidth[j] = child.item->width(); |
827 maxColWidth[j] = childPrivate->width(); |
819 if (child.item->height() > maxRowHeight[i]) |
828 if (childPrivate->height() > maxRowHeight[i]) |
820 maxRowHeight[i] = child.item->height(); |
829 maxRowHeight[i] = childPrivate->height(); |
821 } |
830 } |
822 } |
831 } |
823 } else { |
832 } else { |
824 for (int j=0; j < c; j++){ |
833 for (int j=0; j < c; j++){ |
825 for (int i=0; i < r; i++){ |
834 for (int i=0; i < r; i++){ |
827 maxRowHeight << 0; |
836 maxRowHeight << 0; |
828 if (i==0) |
837 if (i==0) |
829 maxColWidth << 0; |
838 maxColWidth << 0; |
830 |
839 |
831 if (childIndex == positionedItems.count()) |
840 if (childIndex == positionedItems.count()) |
832 continue; |
841 break; |
833 const PositionedItem &child = positionedItems.at(childIndex++); |
842 |
834 if (!child.item || isInvisible(child.item)) |
843 const PositionedItem &child = visibleItems.at(childIndex++); |
835 continue; |
844 QGraphicsItemPrivate *childPrivate = QGraphicsItemPrivate::get(child.item); |
836 if (child.item->width() > maxColWidth[j]) |
845 if (childPrivate->width() > maxColWidth[j]) |
837 maxColWidth[j] = child.item->width(); |
846 maxColWidth[j] = childPrivate->width(); |
838 if (child.item->height() > maxRowHeight[i]) |
847 if (childPrivate->height() > maxRowHeight[i]) |
839 maxRowHeight[i] = child.item->height(); |
848 maxRowHeight[i] = childPrivate->height(); |
840 } |
849 } |
841 } |
850 } |
842 } |
851 } |
843 |
852 |
844 int xoffset=0; |
853 int xoffset=0; |
845 int yoffset=0; |
854 int yoffset=0; |
846 int curRow =0; |
855 int curRow =0; |
847 int curCol =0; |
856 int curCol =0; |
848 for (int i = 0; i < positionedItems.count(); ++i) { |
857 for (int i = 0; i < visibleItems.count(); ++i) { |
849 const PositionedItem &child = positionedItems.at(i); |
858 const PositionedItem &child = visibleItems.at(i); |
850 if (!child.item || isInvisible(child.item)) |
|
851 continue; |
|
852 if((child.item->x()!=xoffset)||(child.item->y()!=yoffset)){ |
859 if((child.item->x()!=xoffset)||(child.item->y()!=yoffset)){ |
853 positionX(xoffset, child); |
860 positionX(xoffset, child); |
854 positionY(yoffset, child); |
861 positionY(yoffset, child); |
855 } |
862 } |
856 |
863 |
857 if (m_flow == LeftToRight) { |
864 if (m_flow == LeftToRight) { |
858 contentSize->setWidth(qMax(contentSize->width(), xoffset + child.item->width())); |
865 contentSize->setWidth(qMax(contentSize->width(), xoffset + QGraphicsItemPrivate::get(child.item)->width())); |
859 contentSize->setHeight(yoffset + maxRowHeight[curRow]); |
866 contentSize->setHeight(yoffset + maxRowHeight[curRow]); |
860 |
867 |
861 xoffset+=maxColWidth[curCol]+spacing(); |
868 xoffset+=maxColWidth[curCol]+spacing(); |
862 curCol++; |
869 curCol++; |
863 curCol%=c; |
870 curCol%=c; |
889 void QDeclarativeGrid::reportConflictingAnchors() |
896 void QDeclarativeGrid::reportConflictingAnchors() |
890 { |
897 { |
891 QDeclarativeBasePositionerPrivate *d = static_cast<QDeclarativeBasePositionerPrivate*>(QDeclarativeBasePositionerPrivate::get(this)); |
898 QDeclarativeBasePositionerPrivate *d = static_cast<QDeclarativeBasePositionerPrivate*>(QDeclarativeBasePositionerPrivate::get(this)); |
892 for (int ii = 0; ii < positionedItems.count(); ++ii) { |
899 for (int ii = 0; ii < positionedItems.count(); ++ii) { |
893 const PositionedItem &child = positionedItems.at(ii); |
900 const PositionedItem &child = positionedItems.at(ii); |
894 if (child.item) { |
901 if (child.item && QGraphicsItemPrivate::get(child.item)->isDeclarativeItem) { |
895 QDeclarativeAnchors *anchors = QDeclarativeItemPrivate::get(child.item)->_anchors; |
902 QDeclarativeAnchors *anchors = QDeclarativeItemPrivate::get(static_cast<QDeclarativeItem *>(child.item))->_anchors; |
896 if (anchors && (anchors->usedAnchors() || anchors->fill() || anchors->centerIn())) { |
903 if (anchors && (anchors->usedAnchors() || anchors->fill() || anchors->centerIn())) { |
897 d->anchorConflict = true; |
904 d->anchorConflict = true; |
898 break; |
905 break; |
899 } |
906 } |
900 } |
907 } |
903 qmlInfo(this) << "Cannot specify anchors for items inside Grid"; |
910 qmlInfo(this) << "Cannot specify anchors for items inside Grid"; |
904 } |
911 } |
905 |
912 |
906 /*! |
913 /*! |
907 \qmlclass Flow QDeclarativeFlow |
914 \qmlclass Flow QDeclarativeFlow |
|
915 \ingroup qml-positioning-elements |
908 \since 4.7 |
916 \since 4.7 |
909 \brief The Flow item arranges its children side by side, wrapping as necessary. |
917 \brief The Flow item arranges its children side by side, wrapping as necessary. |
910 \inherits Item |
918 \inherits Item |
911 |
919 |
912 The Flow item positions its child items so that they are side by side and are |
920 The Flow item positions its child items so that they are side by side and are |
1021 int voffset = 0; |
1029 int voffset = 0; |
1022 int linemax = 0; |
1030 int linemax = 0; |
1023 |
1031 |
1024 for (int i = 0; i < positionedItems.count(); ++i) { |
1032 for (int i = 0; i < positionedItems.count(); ++i) { |
1025 const PositionedItem &child = positionedItems.at(i); |
1033 const PositionedItem &child = positionedItems.at(i); |
1026 if (!child.item || isInvisible(child.item)) |
1034 if (!child.item || !child.isVisible) |
1027 continue; |
1035 continue; |
1028 |
1036 |
|
1037 QGraphicsItemPrivate *childPrivate = QGraphicsItemPrivate::get(child.item); |
1029 if (d->flow == LeftToRight) { |
1038 if (d->flow == LeftToRight) { |
1030 if (widthValid() && hoffset && hoffset + child.item->width() > width()) { |
1039 if (widthValid() && hoffset && hoffset + childPrivate->width() > width()) { |
1031 hoffset = 0; |
1040 hoffset = 0; |
1032 voffset += linemax + spacing(); |
1041 voffset += linemax + spacing(); |
1033 linemax = 0; |
1042 linemax = 0; |
1034 } |
1043 } |
1035 } else { |
1044 } else { |
1036 if (heightValid() && voffset && voffset + child.item->height() > height()) { |
1045 if (heightValid() && voffset && voffset + childPrivate->height() > height()) { |
1037 voffset = 0; |
1046 voffset = 0; |
1038 hoffset += linemax + spacing(); |
1047 hoffset += linemax + spacing(); |
1039 linemax = 0; |
1048 linemax = 0; |
1040 } |
1049 } |
1041 } |
1050 } |
1043 if(child.item->x() != hoffset || child.item->y() != voffset){ |
1052 if(child.item->x() != hoffset || child.item->y() != voffset){ |
1044 positionX(hoffset, child); |
1053 positionX(hoffset, child); |
1045 positionY(voffset, child); |
1054 positionY(voffset, child); |
1046 } |
1055 } |
1047 |
1056 |
1048 contentSize->setWidth(qMax(contentSize->width(), hoffset + child.item->width())); |
1057 contentSize->setWidth(qMax(contentSize->width(), hoffset + childPrivate->width())); |
1049 contentSize->setHeight(qMax(contentSize->height(), voffset + child.item->height())); |
1058 contentSize->setHeight(qMax(contentSize->height(), voffset + childPrivate->height())); |
1050 |
1059 |
1051 if (d->flow == LeftToRight) { |
1060 if (d->flow == LeftToRight) { |
1052 hoffset += child.item->width(); |
1061 hoffset += childPrivate->width(); |
1053 hoffset += spacing(); |
1062 hoffset += spacing(); |
1054 linemax = qMax(linemax, qCeil(child.item->height())); |
1063 linemax = qMax(linemax, qCeil(childPrivate->height())); |
1055 } else { |
1064 } else { |
1056 voffset += child.item->height(); |
1065 voffset += childPrivate->height(); |
1057 voffset += spacing(); |
1066 voffset += spacing(); |
1058 linemax = qMax(linemax, qCeil(child.item->width())); |
1067 linemax = qMax(linemax, qCeil(childPrivate->width())); |
1059 } |
1068 } |
1060 } |
1069 } |
1061 } |
1070 } |
1062 |
1071 |
1063 void QDeclarativeFlow::reportConflictingAnchors() |
1072 void QDeclarativeFlow::reportConflictingAnchors() |
1064 { |
1073 { |
1065 Q_D(QDeclarativeFlow); |
1074 Q_D(QDeclarativeFlow); |
1066 for (int ii = 0; ii < positionedItems.count(); ++ii) { |
1075 for (int ii = 0; ii < positionedItems.count(); ++ii) { |
1067 const PositionedItem &child = positionedItems.at(ii); |
1076 const PositionedItem &child = positionedItems.at(ii); |
1068 if (child.item) { |
1077 if (child.item && QGraphicsItemPrivate::get(child.item)->isDeclarativeItem) { |
1069 QDeclarativeAnchors *anchors = QDeclarativeItemPrivate::get(child.item)->_anchors; |
1078 QDeclarativeAnchors *anchors = QDeclarativeItemPrivate::get(static_cast<QDeclarativeItem *>(child.item))->_anchors; |
1070 if (anchors && (anchors->usedAnchors() || anchors->fill() || anchors->centerIn())) { |
1079 if (anchors && (anchors->usedAnchors() || anchors->fill() || anchors->centerIn())) { |
1071 d->anchorConflict = true; |
1080 d->anchorConflict = true; |
1072 break; |
1081 break; |
1073 } |
1082 } |
1074 } |
1083 } |