Changeset 561 for trunk/src/gui/graphicsview/qgraphicswidget.cpp
- Timestamp:
- Feb 11, 2010, 11:19:06 PM (15 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk
-
Property svn:mergeinfo
set to (toggle deleted branches)
/branches/vendor/nokia/qt/4.6.1 merged eligible /branches/vendor/nokia/qt/current merged eligible /branches/vendor/trolltech/qt/current 3-149
-
Property svn:mergeinfo
set to (toggle deleted branches)
-
trunk/src/gui/graphicsview/qgraphicswidget.cpp
r2 r561 2 2 ** 3 3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). 4 ** Contact: Qt Software Information (qt-info@nokia.com) 4 ** All rights reserved. 5 ** Contact: Nokia Corporation (qt-info@nokia.com) 5 6 ** 6 7 ** This file is part of the QtGui module of the Qt Toolkit. … … 21 22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 22 23 ** 23 ** In addition, as a special exception, Nokia gives you certain 24 ** additional rights. These rights are described in the Nokia Qt LGPL 25 ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this 26 ** package. 24 ** In addition, as a special exception, Nokia gives you certain additional 25 ** rights. These rights are described in the Nokia Qt LGPL Exception 26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. 27 27 ** 28 28 ** GNU General Public License Usage … … 34 34 ** met: http://www.gnu.org/copyleft/gpl.html. 35 35 ** 36 ** If you are unsure which license is appropriate for your use, please37 ** contact the sales department at qt-sales@nokia.com.36 ** If you have questions regarding the use of this file, please contact 37 ** Nokia at qt-info@nokia.com. 38 38 ** $QT_END_LICENSE$ 39 39 ** … … 75 75 items in a QGraphicsScene. 76 76 \since 4.4 77 \ingroup multimedia78 77 \ingroup graphicsview-api 79 78 … … 171 170 172 171 /*! 173 \property QGraphicsWidget::enabled174 \brief whether the item is enabled or not175 176 This property is declared in QGraphicsItem.177 178 By default, this property is true.179 180 \sa QGraphicsItem::isEnabled(), QGraphicsItem::setEnabled()181 */182 183 /*!184 \property QGraphicsWidget::visible185 \brief whether the item is visible or not186 187 This property is declared in QGraphicsItem.188 189 By default, this property is true.190 191 \sa QGraphicsItem::isVisible(), QGraphicsItem::setVisible(), show(),192 hide()193 */194 195 /*!196 \property QGraphicsWidget::opacity197 \brief the opacity of the widget198 */199 200 /*!201 \property QGraphicsWidget::pos202 \brief the position of the widget203 */204 205 /*!206 172 Constructs a QGraphicsWidget instance. The optional \a parent argument is 207 173 passed to QGraphicsItem's constructor. The optional \a wFlags argument … … 210 176 */ 211 177 QGraphicsWidget::QGraphicsWidget(QGraphicsItem *parent, Qt::WindowFlags wFlags) 212 : QGraphics Item(*new QGraphicsWidgetPrivate, 0, 0), QGraphicsLayoutItem(0, false)178 : QGraphicsObject(*new QGraphicsWidgetPrivate, 0, 0), QGraphicsLayoutItem(0, false) 213 179 { 214 180 Q_D(QGraphicsWidget); … … 222 188 */ 223 189 QGraphicsWidget::QGraphicsWidget(QGraphicsWidgetPrivate &dd, QGraphicsItem *parent, QGraphicsScene *scene, Qt::WindowFlags wFlags) 224 : QGraphics Item(dd, 0, scene), QGraphicsLayoutItem(0, false)190 : QGraphicsObject(dd, 0, scene), QGraphicsLayoutItem(0, false) 225 191 { 226 192 Q_D(QGraphicsWidget); … … 292 258 //we check if we have a layout previously 293 259 if (d->layout) { 294 deleted->layout;260 QGraphicsLayout *temp = d->layout; 295 261 foreach (QGraphicsItem * item, childItems()) { 296 262 // In case of a custom layout which doesn't remove and delete items, we ensure that … … 303 269 } 304 270 } 271 d->layout = 0; 272 delete temp; 305 273 } 306 274 … … 351 319 352 320 /*! 321 \property QGraphicsWidget::sizePolicy 322 \brief the size policy for the widget 323 \sa sizePolicy(), setSizePolicy(), QWidget::sizePolicy() 324 */ 325 326 /*! 353 327 \property QGraphicsWidget::geometry 354 328 \brief the geometry of the widget … … 367 341 { 368 342 QGraphicsWidgetPrivate *wd = QGraphicsWidget::d_func(); 369 QGraphicsLayoutItemPrivate *d = QGraphicsLayoutItem::d_ptr ;343 QGraphicsLayoutItemPrivate *d = QGraphicsLayoutItem::d_ptr.data(); 370 344 QRectF newGeom; 371 345 QPointF oldPos = d->geom.topLeft(); … … 380 354 // setPos triggers ItemPositionChange, which can adjust position 381 355 wd->inSetGeometry = 1; 382 wd->setPosHelper(newGeom.topLeft());356 setPos(newGeom.topLeft()); 383 357 wd->inSetGeometry = 0; 384 358 newGeom.moveTopLeft(pos()); … … 441 415 442 416 /*! 417 \property QGraphicsWidget::minimumSize 418 \brief the minimum size of the widget 419 420 \sa setMinimumSize(), minimumSize(), preferredSize, maximumSize 421 */ 422 423 /*! 424 \property QGraphicsWidget::preferredSize 425 \brief the preferred size of the widget 426 427 \sa setPreferredSize(), preferredSize(), minimumSize, maximumSize 428 */ 429 430 /*! 431 \property QGraphicsWidget::maximumSize 432 \brief the maximum size of the widget 433 434 \sa setMaximumSize(), maximumSize(), minimumSize, preferredSize 435 */ 436 437 /*! 443 438 Sets the widget's contents margins to \a left, \a top, \a right and \a 444 439 bottom. … … 460 455 Q_D(QGraphicsWidget); 461 456 462 if (left == d->leftMargin 463 && top == d->topMargin 464 && right == d->rightMargin 465 && bottom == d->bottomMargin) { 457 if (!d->margins && left == 0 && top == 0 && right == 0 && bottom == 0) 466 458 return; 467 } 468 469 d->leftMargin = left; 470 d->topMargin = top; 471 d->rightMargin = right; 472 d->bottomMargin = bottom; 459 d->ensureMargins(); 460 if (left == d->margins[d->Left] 461 && top == d->margins[d->Top] 462 && right == d->margins[d->Right] 463 && bottom == d->margins[d->Bottom]) 464 return; 465 466 d->margins[d->Left] = left; 467 d->margins[d->Top] = top; 468 d->margins[d->Right] = right; 469 d->margins[d->Bottom] = bottom; 473 470 474 471 if (QGraphicsLayout *l = d->layout) … … 491 488 { 492 489 Q_D(const QGraphicsWidget); 490 if (left || top || right || bottom) 491 d->ensureMargins(); 493 492 if (left) 494 *left = d-> leftMargin;493 *left = d->margins[d->Left]; 495 494 if (top) 496 *top = d-> topMargin;495 *top = d->margins[d->Top]; 497 496 if (right) 498 *right = d-> rightMargin;497 *right = d->margins[d->Right]; 499 498 if (bottom) 500 *bottom = d-> bottomMargin;499 *bottom = d->margins[d->Bottom]; 501 500 } 502 501 … … 514 513 { 515 514 Q_D(QGraphicsWidget); 516 bool unchanged = left == d->leftWindowFrameMargin && top == d->topWindowFrameMargin 517 && right == d->rightWindowFrameMargin && bottom == d->bottomWindowFrameMargin; 515 516 if (!d->windowFrameMargins && left == 0 && top == 0 && right == 0 && bottom == 0) 517 return; 518 d->ensureWindowFrameMargins(); 519 bool unchanged = 520 d->windowFrameMargins[d->Left] == left 521 && d->windowFrameMargins[d->Top] == top 522 && d->windowFrameMargins[d->Right] == right 523 && d->windowFrameMargins[d->Bottom] == bottom; 518 524 if (d->setWindowFrameMargins && unchanged) 519 525 return; 520 526 if (!unchanged) 521 527 prepareGeometryChange(); 522 d-> leftWindowFrameMargin= left;523 d-> topWindowFrameMargin= top;524 d-> rightWindowFrameMargin= right;525 d-> bottomWindowFrameMargin= bottom;528 d->windowFrameMargins[d->Left] = left; 529 d->windowFrameMargins[d->Top] = top; 530 d->windowFrameMargins[d->Right] = right; 531 d->windowFrameMargins[d->Bottom] = bottom; 526 532 d->setWindowFrameMargins = true; 527 533 } … … 537 543 { 538 544 Q_D(const QGraphicsWidget); 545 if (left || top || right || bottom) 546 d->ensureWindowFrameMargins(); 539 547 if (left) 540 *left = d-> leftWindowFrameMargin;548 *left = d->windowFrameMargins[d->Left]; 541 549 if (top) 542 *top = d-> topWindowFrameMargin;550 *top = d->windowFrameMargins[d->Top]; 543 551 if (right) 544 *right = d-> rightWindowFrameMargin;552 *right = d->windowFrameMargins[d->Right]; 545 553 if (bottom) 546 *bottom = d-> bottomWindowFrameMargin;554 *bottom = d->windowFrameMargins[d->Bottom]; 547 555 } 548 556 … … 578 586 { 579 587 Q_D(const QGraphicsWidget); 580 return geometry().adjusted(-d->leftWindowFrameMargin, -d->topWindowFrameMargin, 581 d->rightWindowFrameMargin, d->bottomWindowFrameMargin); 588 return d->windowFrameMargins 589 ? geometry().adjusted(-d->windowFrameMargins[d->Left], -d->windowFrameMargins[d->Top], 590 d->windowFrameMargins[d->Right], d->windowFrameMargins[d->Bottom]) 591 : geometry(); 582 592 } 583 593 … … 590 600 { 591 601 Q_D(const QGraphicsWidget); 592 return rect().adjusted(-d->leftWindowFrameMargin, -d->topWindowFrameMargin, 593 d->rightWindowFrameMargin, d->bottomWindowFrameMargin); 602 return d->windowFrameMargins 603 ? rect().adjusted(-d->windowFrameMargins[d->Left], -d->windowFrameMargins[d->Top], 604 d->windowFrameMargins[d->Right], d->windowFrameMargins[d->Bottom]) 605 : rect(); 594 606 } 595 607 … … 699 711 QSizeF sh; 700 712 if (d->layout) { 701 sh = d->layout->effectiveSizeHint(which, constraint); 702 sh += QSizeF(d->leftMargin + d->rightMargin, d->topMargin + d->bottomMargin); 713 QSizeF marginSize(0,0); 714 if (d->margins) { 715 marginSize = QSizeF(d->margins[d->Left] + d->margins[d->Right], 716 d->margins[d->Top] + d->margins[d->Bottom]); 717 } 718 sh = d->layout->effectiveSizeHint(which, constraint - marginSize); 719 sh += marginSize; 703 720 } else { 704 721 switch (which) { … … 985 1002 very important that subclasses call the base implementation. 986 1003 987 For example, QGraphicsWidget uses ItemVisibleChange to deliver \l Show and 988 \l Hide events, ItemPositionHasChanged to deliver \l Move events, and 989 ItemParentChange both to deliver \l ParentChange events, and for managing 990 the focus chain. 991 992 \sa propertyChange() 1004 \a change specifies the type of change, and \a value is the new value. 1005 1006 For example, QGraphicsWidget uses ItemVisibleChange to deliver 1007 \l{QEvent::Show} {Show} and \l{QEvent::Hide}{Hide} events, 1008 ItemPositionHasChanged to deliver \l{QEvent::Move}{Move} events, 1009 and ItemParentChange both to deliver \l{QEvent::ParentChange} 1010 {ParentChange} events, and for managing the focus chain. 1011 1012 QGraphicsWidget enables the ItemSendsGeometryChanges flag by default in 1013 order to track position changes. 1014 1015 \sa QGraphicsItem::itemChange() 993 1016 */ 994 1017 QVariant QGraphicsWidget::itemChange(GraphicsItemChange change, const QVariant &value) … … 1032 1055 case ItemParentChange: { 1033 1056 QGraphicsItem *parent = qVariantValue<QGraphicsItem *>(value); 1034 d->fixFocusChainBeforeReparenting((parent && parent->isWidget()) ? static_cast<QGraphicsWidget *>(parent) : 0 );1057 d->fixFocusChainBeforeReparenting((parent && parent->isWidget()) ? static_cast<QGraphicsWidget *>(parent) : 0, scene()); 1035 1058 1036 1059 // Deliver ParentAboutToChange. … … 1040 1063 } 1041 1064 case ItemParentHasChanged: { 1042 // reset window type on parent change in order to automagically remove decorations etc.1043 Qt::WindowFlags wflags = d->windowFlags & ~Qt::WindowType_Mask;1044 d->adjustWindowFlags(&wflags);1045 setWindowFlags(wflags);1046 1065 // Deliver ParentChange. 1047 1066 QEvent event(QEvent::ParentChange); … … 1108 1127 bool QGraphicsWidget::sceneEvent(QEvent *event) 1109 1128 { 1110 return Q CoreApplication::sendEvent(this, event) || QGraphicsItem::sceneEvent(event);1129 return QGraphicsItem::sceneEvent(event); 1111 1130 } 1112 1131 … … 1132 1151 break; 1133 1152 case QEvent::GraphicsSceneMouseMove: 1134 if (d->grabbedSection != Qt::NoSection) { 1153 d->ensureWindowData(); 1154 if (d->windowData->grabbedSection != Qt::NoSection) { 1135 1155 d->windowFrameMouseMoveEvent(static_cast<QGraphicsSceneMouseEvent *>(event)); 1136 1156 event->accept(); … … 1187 1207 const qreal cornerMargin = 20; 1188 1208 //### Not sure of this one, it should be the same value for all edges. 1189 const qreal windowFrameWidth = d->leftWindowFrameMargin; 1209 const qreal windowFrameWidth = d->windowFrameMargins 1210 ? d->windowFrameMargins[d->Left] : 0; 1190 1211 1191 1212 Qt::WindowFrameSection s = Qt::NoSection; … … 1213 1234 if (s == Qt::NoSection) { 1214 1235 QRectF r1 = r; 1215 r1.setHeight(d->topWindowFrameMargin); 1236 r1.setHeight(d->windowFrameMargins 1237 ? d->windowFrameMargins[d->Top] : 0); 1216 1238 if (r1.contains(pos)) 1217 1239 s = Qt::TitleBarArea; … … 1223 1245 \reimp 1224 1246 1225 QGraphicsWidget handles the following events: 1247 Handles the \a event. QGraphicsWidget handles the following 1248 events: 1226 1249 1227 1250 \table \o Event \o Usage … … 1279 1302 polishEvent(); 1280 1303 d->polished = true; 1281 d->updateFont(d->font); 1304 if (!d->font.isCopyOf(QApplication::font())) 1305 d->updateFont(d->font); 1282 1306 break; 1283 1307 case QEvent::WindowActivate: 1284 1308 case QEvent::WindowDeactivate: 1285 1309 update(); 1286 foreach (QGraphicsItem *child, childItems()) {1287 if (child->isWidget())1288 QApplication::sendEvent(static_cast<QGraphicsWidget *>(child), event);1289 }1290 1310 break; 1291 1311 // Taken from QWidget::event … … 1321 1341 case QEvent::GraphicsSceneMouseRelease: 1322 1342 case QEvent::GraphicsSceneMouseDoubleClick: 1323 if (d->hasDecoration() && d->grabbedSection != Qt::NoSection) 1343 d->ensureWindowData(); 1344 if (d->hasDecoration() && d->windowData->grabbedSection != Qt::NoSection) 1324 1345 return windowFrameEvent(event); 1325 1346 break; … … 1358 1379 // ### Don't unset if the margins are explicitly set. 1359 1380 unsetWindowFrameMargins(); 1381 if (d->layout) 1382 d->layout->invalidate(); 1360 1383 case QEvent::FontChange: 1361 1384 update(); … … 1596 1619 /*! 1597 1620 Returns the widgets window type. 1621 1622 \sa windowFlags(), isWindow(), isPanel() 1598 1623 */ 1599 1624 Qt::WindowType QGraphicsWidget::windowType() const … … 1611 1636 1612 1637 By default, this property contains no window flags. 1638 1639 Windows are panels. If you set the Qt::Window flag, the ItemIsPanel flag 1640 will be set automatically. If you clear the Qt::Window flag, the 1641 ItemIsPanel flag is also cleared. Note that the ItemIsPanel flag can be 1642 set independently of Qt::Window. 1643 1644 \sa isWindow(), isPanel() 1613 1645 */ 1614 1646 Qt::WindowFlags QGraphicsWidget::windowFlags() const … … 1624 1656 bool wasPopup = (d->windowFlags & Qt::WindowType_Mask) == Qt::Popup; 1625 1657 1658 d->adjustWindowFlags(&wFlags); 1626 1659 d->windowFlags = wFlags; 1627 1660 if (!d->setWindowFrameMargins) 1628 1661 unsetWindowFrameMargins(); 1662 1663 setFlag(ItemIsPanel, d->windowFlags & Qt::Window); 1629 1664 1630 1665 bool isPopup = (d->windowFlags & Qt::WindowType_Mask) == Qt::Popup; … … 1636 1671 d->scene->d_func()->addPopup(this); 1637 1672 } 1673 1674 if (d->scene && d->scene->d_func()->allItemsIgnoreHoverEvents && d->hasDecoration()) { 1675 d->scene->d_func()->allItemsIgnoreHoverEvents = false; 1676 d->scene->d_func()->enableMouseTrackingOnViews(); 1677 } 1638 1678 } 1639 1679 … … 1646 1686 currently has input focus, or that itself has input focus. 1647 1687 1648 \sa QGraphicsScene::activeWindow(), QGraphicsScene::setActiveWindow() 1688 \sa QGraphicsScene::activeWindow(), QGraphicsScene::setActiveWindow(), isActive() 1649 1689 */ 1650 1690 bool QGraphicsWidget::isActiveWindow() const 1651 1691 { 1652 Q_D(const QGraphicsWidget); 1653 if (!d->scene) 1654 return false; 1655 const QGraphicsWidget *w = window(); 1656 return (!w && d->scene->d_func()->activationRefCount) || (w && d->scene->activeWindow() == w); 1692 return isActive(); 1657 1693 } 1658 1694 … … 1663 1699 This property is only used for windows. 1664 1700 1665 By default, if no title has been set, this property contains an empty string. 1701 By default, if no title has been set, this property contains an 1702 empty string. 1666 1703 */ 1667 1704 void QGraphicsWidget::setWindowTitle(const QString &title) 1668 1705 { 1669 1706 Q_D(QGraphicsWidget); 1670 d->windowTitle = title; 1707 d->ensureWindowData(); 1708 d->windowData->windowTitle = title; 1671 1709 } 1672 1710 QString QGraphicsWidget::windowTitle() const 1673 1711 { 1674 1712 Q_D(const QGraphicsWidget); 1675 return d->window Title;1713 return d->windowData ? d->windowData->windowTitle : QString(); 1676 1714 } 1677 1715 … … 1715 1753 If this widget, a child or descendant of this widget currently has input 1716 1754 focus, this function will return a pointer to that widget. If 1717 no descendant has input focus, 0 is returned.1718 1719 \sa Q Widget::focusWidget()1755 no descendant widget has input focus, 0 is returned. 1756 1757 \sa QGraphicsItem::focusItem(), QWidget::focusWidget() 1720 1758 */ 1721 1759 QGraphicsWidget *QGraphicsWidget::focusWidget() const 1722 1760 { 1723 1761 Q_D(const QGraphicsWidget); 1724 return d->focusChild; 1725 } 1726 1762 if (d->subFocusItem && d->subFocusItem->d_ptr->isWidget) 1763 return static_cast<QGraphicsWidget *>(d->subFocusItem); 1764 return 0; 1765 } 1727 1766 1728 1767 #ifndef QT_NO_SHORTCUT … … 1888 1927 d->actions.insert(pos, action); 1889 1928 1890 QActionPrivate *apriv = action->d_func(); 1891 apriv->graphicsWidgets.append(this); 1929 if (index == -1) { 1930 QActionPrivate *apriv = action->d_func(); 1931 apriv->graphicsWidgets.append(this); 1932 } 1892 1933 1893 1934 QActionEvent e(QEvent::ActionAdded, action, before); … … 2109 2150 bar.QStyleOption::operator=(*option); 2110 2151 d->initStyleOptionTitleBar(&bar); // this clear flags in bar.state 2111 if (d->buttonMouseOver) 2152 d->ensureWindowData(); 2153 if (d->windowData->buttonMouseOver) 2112 2154 bar.state |= QStyle::State_MouseOver; 2113 2155 else 2114 2156 bar.state &= ~QStyle::State_MouseOver; 2115 if (d-> buttonSunken)2157 if (d->windowData->buttonSunken) 2116 2158 bar.state |= QStyle::State_Sunken; 2117 2159 else … … 2248 2290 /*! 2249 2291 \fn const QObjectList &QGraphicsWidget::children() const 2292 \internal 2250 2293 2251 2294 This function returns the same value as QObject::children(). It's … … 2268 2311 break; 2269 2312 } 2270 qDebug() << i++ << QString::number(uint(next), 16) << next->className() << next->data(0) << QString::fromAscii("focusItem:%1").arg(next->hasFocus() ? "1" : "0") << QLatin1String("next:") << next->d_func()->focusNext->data(0) << QLatin1String("prev:") << next->d_func()->focusPrev->data(0);2313 qDebug() << i++ << QString::number(uint(next), 16) << next->className() << next->data(0) << QString::fromAscii("focusItem:%1").arg(next->hasFocus() ? '1' : '0') << QLatin1String("next:") << next->d_func()->focusNext->data(0) << QLatin1String("prev:") << next->d_func()->focusPrev->data(0); 2271 2314 if (visited.contains(next)) { 2272 2315 qWarning("Already visited this node. However, I expected to dump until I found myself.");
Note:
See TracChangeset
for help on using the changeset viewer.