Changeset 769 for trunk/src/gui/graphicsview/qgraphicsitem.cpp
- Timestamp:
- Aug 2, 2010, 9:27:30 PM (15 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk
- Property svn:mergeinfo changed
/branches/vendor/nokia/qt/4.6.3 (added) merged: 768 /branches/vendor/nokia/qt/current merged: 767 /branches/vendor/nokia/qt/4.6.2 removed
- Property svn:mergeinfo changed
-
trunk/src/gui/graphicsview/qgraphicsitem.cpp
r651 r769 320 320 321 321 \value ItemClipsToShape The item clips to its own shape. The item cannot 322 draw or receive mouse, tablet, drag and drop or hover events outside ts322 draw or receive mouse, tablet, drag and drop or hover events outside its 323 323 shape. It is disabled by default. This behavior is enforced by 324 324 QGraphicsView::drawItems() or QGraphicsScene::drawItems(). This flag was … … 358 358 this flag, the child will be stacked behind it. This flag is useful for 359 359 drop shadow effects and for decoration objects that follow the parent 360 item's geometry without drawing on top of it. 360 item's geometry without drawing on top of it. This flag was introduced 361 in Qt 4.5. 361 362 362 363 \value ItemUsesExtendedStyleOption The item makes use of either 363 \l{QStyleOptionGraphicsItem::}{exposedRect} or 364 \l{QStyleOptionGraphicsItem::}{matrix} in QStyleOptionGraphicsItem. By default, 365 the \l{QStyleOptionGraphicsItem::}{exposedRect} is initialized to the item's 366 boundingRect() and the \l{QStyleOptionGraphicsItem::}{matrix} is untransformed. 367 You can enable this flag for the style options to be set up with more 368 fine-grained values. 369 Note that QStyleOptionGraphicsItem::levelOfDetail is unaffected by this flag 364 \l{QStyleOptionGraphicsItem::} {exposedRect} or 365 \l{QStyleOptionGraphicsItem::} {matrix} in 366 QStyleOptionGraphicsItem. By default, the 367 \l{QStyleOptionGraphicsItem::} {exposedRect} is initialized to the 368 item's boundingRect() and the 369 \l{QStyleOptionGraphicsItem::}{matrix} is untransformed. You can 370 enable this flag for the style options to be set up with more 371 fine-grained values. Note that 372 QStyleOptionGraphicsItem::levelOfDetail is unaffected by this flag 370 373 and always initialized to 1. Use 371 QStyleOptionGraphicsItem::levelOfDetailFromTransform() if you need a higher372 value.374 QStyleOptionGraphicsItem::levelOfDetailFromTransform() if you need 375 a higher value. This flag was introduced in Qt 4.6. 373 376 374 377 \value ItemHasNoContents The item does not paint anything (i.e., calling … … 388 391 This flag was introduced in Qt 4.6. 389 392 390 \value ItemNegativeZStacksBehindParent The item automatically stacks behind 391 it's parent if it's z-value is negative. This flag enables setZValue() to 392 toggle ItemStacksBehindParent. 393 \value ItemNegativeZStacksBehindParent The item automatically 394 stacks behind it's parent if it's z-value is negative. This flag 395 enables setZValue() to toggle ItemStacksBehindParent. This flag 396 was introduced in Qt 4.6. 393 397 394 398 \value ItemIsPanel The item is a panel. A panel provides activation and … … 410 414 /*! 411 415 \enum QGraphicsItem::GraphicsItemChange 412 413 ItemVisibleHasChanged,414 ItemEnabledHasChanged,415 ItemSelectedHasChanged,416 ItemParentHasChanged,417 ItemSceneHasChanged418 416 419 417 This enum describes the state changes that are notified by … … 644 642 645 643 The values are: 646 \value NonModal The panel is not modal and does not block input to other panels. 647 \value PanelModal The panel is modal to a single item hierarchy and blocks input to its parent pane, all grandparent panels, and all siblings of its parent and grandparent panels. 648 \value SceneModal The window is modal to the entire scene and blocks input to all panels. 644 645 \value NonModal The panel is not modal and does not block input to 646 other panels. This is the default value for panels. 647 648 \value PanelModal The panel is modal to a single item hierarchy 649 and blocks input to its parent pane, all grandparent panels, and 650 all siblings of its parent and grandparent panels. 651 652 \value SceneModal The window is modal to the entire scene and 653 blocks input to all panels. 649 654 650 655 \sa QGraphicsItem::setPanelModality(), QGraphicsItem::panelModality(), QGraphicsItem::ItemIsPanel … … 1126 1131 } 1127 1132 1133 // Resolve depth. 1134 invalidateDepthRecursively(); 1135 1128 1136 if ((parent = newParent)) { 1129 1137 if (parent->d_func()->scene && parent->d_func()->scene != scene) { … … 1176 1184 } 1177 1185 1178 // Resolve depth.1179 invalidateDepthRecursively();1180 1186 dirtySceneTransform = 1; 1181 1187 … … 1393 1399 delete d_ptr->transformData; 1394 1400 1395 qt_dataStore()->data.remove(this); 1401 if (QGraphicsItemCustomDataStore *dataStore = qt_dataStore()) 1402 dataStore->data.remove(this); 1396 1403 } 1397 1404 … … 1571 1578 1572 1579 /*! 1573 Sets this item's parent item to \a parent. If this item already has a 1574 parent, it is first removed from the previous parent. If \a parent is 0, 1575 this item will become a top-level item. 1576 1577 Note that this implicitly adds this graphics item to the scene of 1578 the parent. You should not \l{QGraphicsScene::addItem()}{add} the 1579 item to the scene yourself. 1580 1581 Calling this function on an item that is an ancestor of \a parent have undefined behaviour. 1582 1583 \sa parentItem(), childItems() 1580 Sets this item's parent item to \a newParent. If this item already 1581 has a parent, it is first removed from the previous parent. If \a 1582 newParent is 0, this item will become a top-level item. 1583 1584 Note that this implicitly adds this graphics item to the scene of 1585 the parent. You should not \l{QGraphicsScene::addItem()}{add} the 1586 item to the scene yourself. 1587 1588 Calling this function on an item that is an ancestor of \a newParent 1589 have undefined behaviour. 1590 1591 \sa parentItem(), childItems() 1584 1592 */ 1585 1593 void QGraphicsItem::setParentItem(QGraphicsItem *newParent) … … 1876 1884 bool noVisualChange = (mode == NoCache && lastMode == NoCache) 1877 1885 || (mode == NoCache && lastMode == DeviceCoordinateCache) 1878 || (mode == DeviceCoordinateCache && lastMode == NoCache); 1886 || (mode == DeviceCoordinateCache && lastMode == NoCache) 1887 || (mode == DeviceCoordinateCache && lastMode == DeviceCoordinateCache); 1879 1888 if (mode == NoCache) { 1880 1889 d_ptr->removeExtraItemCache(); … … 2170 2179 if (c) 2171 2180 c->purge(); 2172 if (scene) 2181 if (scene) { 2182 #ifndef QT_NO_GRAPHICSEFFECT 2183 invalidateParentGraphicsEffectsRecursively(); 2184 #endif //QT_NO_GRAPHICSEFFECT 2173 2185 scene->d_func()->markDirty(q_ptr, QRectF(), /*invalidateChildren=*/false, /*force=*/true); 2186 } 2174 2187 } 2175 2188 2176 2189 // Certain properties are dropped as an item becomes invisible. 2190 bool hasFocus = q_ptr->hasFocus(); 2177 2191 if (!newVisible) { 2178 2192 if (scene) { … … 2184 2198 scene->d_func()->leaveModal(q_ptr); 2185 2199 } 2186 if ( q_ptr->hasFocus()&& scene) {2200 if (hasFocus && scene) { 2187 2201 // Hiding the closest non-panel ancestor of the focus item 2188 2202 QGraphicsItem *focusItem = scene->focusItem(); … … 2197 2211 } 2198 2212 if (clear) 2199 q_ptr->clearFocus();2213 clearFocusHelper(/* giveFocusToParent = */ false); 2200 2214 } 2201 2215 if (q_ptr->isSelected()) … … 2235 2249 2236 2250 // Enable subfocus 2237 if (scene && newVisible) { 2238 QGraphicsItem *p = parent; 2239 bool done = false; 2240 while (p) { 2241 if (p->flags() & QGraphicsItem::ItemIsFocusScope) { 2242 QGraphicsItem *fsi = p->d_ptr->focusScopeItem; 2243 if (q_ptr == fsi || q_ptr->isAncestorOf(fsi)) { 2244 done = true; 2245 while (fsi->d_ptr->focusScopeItem && fsi->d_ptr->focusScopeItem->isVisible()) 2246 fsi = fsi->d_ptr->focusScopeItem; 2247 scene->setFocusItem(fsi); 2251 if (scene) { 2252 if (newVisible) { 2253 // Item is shown 2254 QGraphicsItem *p = parent; 2255 bool done = false; 2256 while (p) { 2257 if (p->flags() & QGraphicsItem::ItemIsFocusScope) { 2258 QGraphicsItem *fsi = p->d_ptr->focusScopeItem; 2259 if (q_ptr == fsi || q_ptr->isAncestorOf(fsi)) { 2260 done = true; 2261 while (fsi->d_ptr->focusScopeItem && fsi->d_ptr->focusScopeItem->isVisible()) 2262 fsi = fsi->d_ptr->focusScopeItem; 2263 fsi->d_ptr->setFocusHelper(Qt::OtherFocusReason, /* climb = */ true, 2264 /* focusFromShow = */ true); 2265 } 2266 break; 2248 2267 } 2249 break;2268 p = p->d_ptr->parent; 2250 2269 } 2251 p = p->d_ptr->parent; 2252 } 2253 if (!done) { 2254 QGraphicsItem *fi = subFocusItem; 2255 if (fi && fi != scene->focusItem()) { 2256 scene->setFocusItem(fi); 2270 if (!done) { 2271 QGraphicsItem *fi = subFocusItem; 2272 if (fi && fi != scene->focusItem()) { 2273 scene->setFocusItem(fi); 2274 } 2275 } 2276 } else { 2277 // Item is hidden 2278 if (hasFocus) { 2279 QGraphicsItem *p = parent; 2280 while (p) { 2281 if (p->flags() & QGraphicsItem::ItemIsFocusScope) { 2282 if (p->d_ptr->visible) { 2283 p->d_ptr->setFocusHelper(Qt::OtherFocusReason, /* climb = */ true, 2284 /* focusFromShow = */ true); 2285 } 2286 break; 2287 } 2288 p = p->d_ptr->parent; 2289 } 2257 2290 } 2258 2291 } … … 3105 3138 void QGraphicsItem::setFocus(Qt::FocusReason focusReason) 3106 3139 { 3107 d_ptr->setFocusHelper(focusReason, /* climb = */ true );3140 d_ptr->setFocusHelper(focusReason, /* climb = */ true, /* focusFromShow = */ false); 3108 3141 } 3109 3142 … … 3111 3144 \internal 3112 3145 */ 3113 void QGraphicsItemPrivate::setFocusHelper(Qt::FocusReason focusReason, bool climb )3146 void QGraphicsItemPrivate::setFocusHelper(Qt::FocusReason focusReason, bool climb, bool focusFromShow) 3114 3147 { 3115 3148 // Disabled / unfocusable items cannot accept focus. … … 3131 3164 if (p->flags() & QGraphicsItem::ItemIsFocusScope) { 3132 3165 p->d_ptr->focusScopeItem = q_ptr; 3133 if (!p->focusItem() ) {3166 if (!p->focusItem() && !focusFromShow) { 3134 3167 // If you call setFocus on a child of a focus scope that 3135 3168 // doesn't currently have a focus item, then stop. … … 3172 3205 void QGraphicsItem::clearFocus() 3173 3206 { 3174 // Pass focus to the closest parent focus scope. 3175 if (!d_ptr->inDestructor) { 3176 QGraphicsItem *p = d_ptr->parent; 3177 while (p) { 3178 if (p->flags() & ItemIsFocusScope) { 3179 p->d_ptr->setFocusHelper(Qt::OtherFocusReason, /* climb = */ false); 3180 return; 3207 d_ptr->clearFocusHelper(/* giveFocusToParent = */ true); 3208 } 3209 3210 /*! 3211 \internal 3212 */ 3213 void QGraphicsItemPrivate::clearFocusHelper(bool giveFocusToParent) 3214 { 3215 if (giveFocusToParent) { 3216 // Pass focus to the closest parent focus scope 3217 if (!inDestructor) { 3218 QGraphicsItem *p = parent; 3219 while (p) { 3220 if (p->flags() & QGraphicsItem::ItemIsFocusScope) { 3221 p->d_ptr->setFocusHelper(Qt::OtherFocusReason, /* climb = */ false, 3222 /* focusFromShow = */ false); 3223 return; 3224 } 3225 p = p->d_ptr->parent; 3181 3226 } 3182 p = p->d_ptr->parent;3183 3227 } 3184 3228 } 3185 3229 3186 3230 // Invisible items with focus must explicitly clear subfocus. 3187 d_ptr->clearSubFocus(this);3188 3189 if ( hasFocus()) {3231 clearSubFocus(q_ptr); 3232 3233 if (q_ptr->hasFocus()) { 3190 3234 // If this item has the scene's input focus, clear it. 3191 d_ptr->scene->setFocusItem(0);3235 scene->setFocusItem(0); 3192 3236 } 3193 3237 } … … 3535 3579 if (!(d_ptr->flags & ItemSendsGeometryChanges)) { 3536 3580 d_ptr->setPosHelper(pos); 3581 if (d_ptr->isWidget) 3582 static_cast<QGraphicsWidget *>(this)->d_func()->setGeometryFromSetPos(); 3537 3583 return; 3538 3584 } … … 7257 7303 QGraphicsScenePrivate *scenePrivate = d_ptr->scene->d_func(); 7258 7304 scenePrivate->index->prepareBoundingRectChange(this); 7259 scenePrivate->markDirty(this, QRectF(), /*invalidateChildren=*/true); 7305 scenePrivate->markDirty(this, QRectF(), /*invalidateChildren=*/true, /*force=*/false, 7306 /*ignoreOpacity=*/ false, /*removingItemFromScene=*/ false, 7307 /*updateBoundingRect=*/true); 7260 7308 7261 7309 // For compatibility reasons, we have to update the item's old geometry … … 10802 10850 } 10803 10851 10852 // sourceRect must be in the given coordinate system 10804 10853 QRect QGraphicsItemEffectSourcePrivate::paddedEffectRect(Qt::CoordinateSystem system, QGraphicsEffect::PixmapPadMode mode, const QRectF &sourceRect, bool *unpadded) const 10805 10854 { … … 10811 10860 if (mode == QGraphicsEffect::PadToEffectiveBoundingRect) { 10812 10861 if (info) { 10813 effectRectF = item->graphicsEffect()->boundingRectFor(boundingRect(Qt::DeviceCoordinates)); 10862 QRectF deviceRect = system == Qt::DeviceCoordinates ? sourceRect : info->painter->worldTransform().mapRect(sourceRect); 10863 effectRectF = item->graphicsEffect()->boundingRectFor(deviceRect); 10814 10864 if (unpadded) 10815 10865 *unpadded = (effectRectF.size() == sourceRect.size()); … … 10860 10910 } 10861 10911 10862 if (deviceCoordinates) {10863 // Clip to viewport rect.10864 int left, top, right, bottom;10865 effectRect.getCoords(&left, &top, &right, &bottom);10866 if (left < 0) {10867 if (offset)10868 offset->rx() += -left;10869 effectRect.setX(0);10870 }10871 if (top < 0) {10872 if (offset)10873 offset->ry() += -top;10874 effectRect.setY(0);10875 }10876 // NB! We use +-1 for historical reasons (see QRect documentation).10877 QPaintDevice *device = info->painter->device();10878 const int deviceWidth = device->width();10879 const int deviceHeight = device->height();10880 if (right + 1 > deviceWidth)10881 effectRect.setRight(deviceWidth - 1);10882 if (bottom + 1 > deviceHeight)10883 effectRect.setBottom(deviceHeight -1);10884 10885 }10886 10912 if (effectRect.isEmpty()) 10887 10913 return QPixmap();
Note:
See TracChangeset
for help on using the changeset viewer.