Changeset 561 for trunk/src/gui/graphicsview/qgraphicswidget_p.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_p.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 ** … … 67 67 focusNext = focusPrev = q; 68 68 focusPolicy = Qt::NoFocus; 69 70 adjustWindowFlags(&wFlags); 71 windowFlags = wFlags; 72 69 73 q->setParentItem(parentItem); 70 74 q->setSizePolicy(QSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred, QSizePolicy::DefaultType)); … … 72 76 73 77 resolveLayoutDirection(); 74 75 if (!parentItem)76 adjustWindowFlags(&wFlags);77 windowFlags = wFlags;78 78 q->unsetWindowFrameMargins(); 79 } 79 q->setFlag(QGraphicsItem::ItemUsesExtendedStyleOption); 80 q->setFlag(QGraphicsItem::ItemSendsGeometryChanges); 81 } 82 80 83 qreal QGraphicsWidgetPrivate::titleBarHeight(const QStyleOptionTitleBar &options) const 81 84 { … … 90 93 } 91 94 92 void QGraphicsWidgetPrivate::getLayoutItemMargins(qreal *left, qreal *top, qreal *right, qreal *bottom) const 93 { 94 if (left) 95 *left = leftLayoutItemMargin; 96 if (top) 97 *top = topLayoutItemMargin; 98 if (right) 99 *right = rightLayoutItemMargin; 100 if (bottom) 101 *bottom = bottomLayoutItemMargin; 102 } 103 104 void QGraphicsWidgetPrivate::setLayoutItemMargins(qreal left, qreal top, qreal right, qreal bottom) 105 { 106 if (leftLayoutItemMargin == left 107 && topLayoutItemMargin == top 108 && rightLayoutItemMargin == right 109 && bottomLayoutItemMargin == bottom) 110 return; 111 112 Q_Q(QGraphicsWidget); 113 leftLayoutItemMargin = left; 114 topLayoutItemMargin = top; 115 rightLayoutItemMargin = right; 116 bottomLayoutItemMargin = bottom; 117 q->updateGeometry(); 118 } 119 120 void QGraphicsWidgetPrivate::setLayoutItemMargins(QStyle::SubElement element, const QStyleOption *opt) 121 { 122 Q_Q(QGraphicsWidget); 123 QStyleOption myOpt; 124 if (!opt) { 125 q->initStyleOption(&myOpt); 126 myOpt.rect.setRect(0, 0, 32768, 32768); // arbitrary 127 opt = &myOpt; 128 } 129 130 QRect liRect = q->style()->subElementRect(element, opt, /* q */ 0); 131 if (liRect.isValid()) { 132 leftLayoutItemMargin = (opt->rect.left() - liRect.left()); 133 topLayoutItemMargin = (opt->rect.top() - liRect.top()); 134 rightLayoutItemMargin = (liRect.right() - opt->rect.right()); 135 bottomLayoutItemMargin = (liRect.bottom() - opt->rect.bottom()); 136 } else { 137 leftLayoutItemMargin = 0; 138 topLayoutItemMargin = 0; 139 rightLayoutItemMargin = 0; 140 bottomLayoutItemMargin = 0; 141 } 95 /*! 96 \internal 97 */ 98 QGraphicsWidgetPrivate::~QGraphicsWidgetPrivate() 99 { 100 // Remove any lazily allocated data 101 delete[] margins; 102 delete[] windowFrameMargins; 103 delete windowData; 104 } 105 106 /*! 107 \internal 108 109 Ensures that margins is allocated. 110 This function must be called before any dereferencing. 111 */ 112 void QGraphicsWidgetPrivate::ensureMargins() const 113 { 114 if (!margins) { 115 margins = new qreal[4]; 116 for (int i = 0; i < 4; ++i) 117 margins[i] = 0; 118 } 119 } 120 121 /*! 122 \internal 123 124 Ensures that windowFrameMargins is allocated. 125 This function must be called before any dereferencing. 126 */ 127 void QGraphicsWidgetPrivate::ensureWindowFrameMargins() const 128 { 129 if (!windowFrameMargins) { 130 windowFrameMargins = new qreal[4]; 131 for (int i = 0; i < 4; ++i) 132 windowFrameMargins[i] = 0; 133 } 134 } 135 136 /*! 137 \internal 138 139 Ensures that windowData is allocated. 140 This function must be called before any dereferencing. 141 */ 142 void QGraphicsWidgetPrivate::ensureWindowData() 143 { 144 if (!windowData) 145 windowData = new WindowData; 142 146 } 143 147 … … 298 302 { 299 303 Q_Q(QGraphicsWidget); 304 ensureWindowData(); 300 305 q->initStyleOption(option); 301 306 option->rect.setHeight(titleBarHeight(*option)); 302 307 option->titleBarFlags = windowFlags; 303 308 option->subControls = QStyle::SC_TitleBarCloseButton | QStyle::SC_TitleBarLabel | QStyle::SC_TitleBarSysMenu; 304 option->activeSubControls = hoveredSubControl;309 option->activeSubControls = windowData->hoveredSubControl; 305 310 bool isActive = q->isActiveWindow(); 306 311 if (isActive) { … … 314 319 QFont windowTitleFont = QApplication::font("QWorkspaceTitleBar"); 315 320 QRect textRect = q->style()->subControlRect(QStyle::CC_TitleBar, option, QStyle::SC_TitleBarLabel, 0); 316 option->text = QFontMetrics(windowTitleFont).elidedText(windowTitle, Qt::ElideRight, textRect.width()); 321 option->text = QFontMetrics(windowTitleFont).elidedText( 322 windowData->windowTitle, Qt::ElideRight, textRect.width()); 317 323 } 318 324 … … 342 348 { 343 349 Q_Q(QGraphicsWidget); 344 if (grabbedSection != Qt::NoSection) { 345 if (grabbedSection == Qt::TitleBarArea) { 346 buttonSunken = false; 350 ensureWindowData(); 351 if (windowData->grabbedSection != Qt::NoSection) { 352 if (windowData->grabbedSection == Qt::TitleBarArea) { 353 windowData->buttonSunken = false; 347 354 QStyleOptionTitleBar bar; 348 355 initStyleOptionTitleBar(&bar); … … 352 359 bar.rect.setHeight(q->style()->pixelMetric(QStyle::PM_TitleBarHeight, &bar)); 353 360 QPointF pos = event->pos(); 354 pos.rx() += leftWindowFrameMargin; 355 pos.ry() += topWindowFrameMargin; 361 if (windowFrameMargins) { 362 pos.rx() += windowFrameMargins[Left]; 363 pos.ry() += windowFrameMargins[Top]; 364 } 356 365 bar.subControls = QStyle::SC_TitleBarCloseButton; 357 366 if (q->style()->subControlRect(QStyle::CC_TitleBar, &bar, … … 362 371 } 363 372 if (!(static_cast<QGraphicsSceneMouseEvent *>(event)->buttons())) 364 grabbedSection = Qt::NoSection;373 windowData->grabbedSection = Qt::NoSection; 365 374 event->accept(); 366 375 } … … 373 382 return; 374 383 375 startGeometry = q->geometry(); 376 grabbedSection = q->windowFrameSectionAt(event->pos()); 377 switch (grabbedSection) { 378 case Qt::LeftSection: 379 case Qt::TopLeftSection: 380 mouseDelta = event->pos() - q->rect().topLeft(); 381 break; 382 case Qt::TopSection: 383 case Qt::TopRightSection: 384 mouseDelta = event->pos() - q->rect().topRight(); 385 break; 386 case Qt::RightSection: 387 case Qt::BottomRightSection: 388 mouseDelta = event->pos() - q->rect().bottomRight(); 389 break; 390 case Qt::BottomSection: 391 case Qt::BottomLeftSection: 392 mouseDelta = event->pos() - q->rect().bottomLeft(); 393 break; 394 case Qt::TitleBarArea: 395 if (hoveredSubControl == QStyle::SC_TitleBarCloseButton) { 396 buttonSunken = true; 397 q->update(); 398 } 399 break; 400 case Qt::NoSection: 401 break; 402 } 403 event->setAccepted(grabbedSection != Qt::NoSection); 384 ensureWindowData(); 385 windowData->startGeometry = q->geometry(); 386 windowData->grabbedSection = q->windowFrameSectionAt(event->pos()); 387 ensureWindowData(); 388 if (windowData->grabbedSection == Qt::TitleBarArea 389 && windowData->hoveredSubControl == QStyle::SC_TitleBarCloseButton) { 390 windowData->buttonSunken = true; 391 q->update(); 392 } 393 event->setAccepted(windowData->grabbedSection != Qt::NoSection); 394 } 395 396 /*! 397 Used to calculate the 398 Precondition: 399 \a widget should support either hfw or wfh 400 401 If \a heightForWidth is set to false, this function will query the width for height 402 instead. \a width will then be interpreted as height, \a minh and \a maxh will be interpreted 403 as minimum width and maximum width. 404 */ 405 static qreal minimumHeightForWidth(qreal width, qreal minh, qreal maxh, 406 const QGraphicsWidget *widget, 407 bool heightForWidth = true) 408 { 409 qreal minimumHeightForWidth = -1; 410 const QSizePolicy sp = widget->layout() ? widget->layout()->sizePolicy() : widget->sizePolicy(); 411 const bool hasHFW = sp.hasHeightForWidth(); 412 if (hasHFW == heightForWidth) { 413 minimumHeightForWidth = hasHFW 414 ? widget->effectiveSizeHint(Qt::MinimumSize, QSizeF(width, -1)).height() 415 : widget->effectiveSizeHint(Qt::MinimumSize, QSizeF(-1, width)).width(); //"width" is here height! 416 } else { 417 // widthForHeight 418 const qreal constraint = width; 419 while (maxh - minh > 0.1) { 420 qreal middle = minh + (maxh - minh)/2; 421 // ### really bad, if we are a widget with a layout it will call 422 // layout->effectiveSizeHint(Qt::MiniumumSize), which again will call 423 // sizeHint three times because of how the cache works 424 qreal hfw = hasHFW 425 ? widget->effectiveSizeHint(Qt::MinimumSize, QSizeF(middle, -1)).height() 426 : widget->effectiveSizeHint(Qt::MinimumSize, QSizeF(-1, middle)).width(); 427 if (hfw > constraint) { 428 minh = middle; 429 } else if (hfw <= constraint) { 430 maxh = middle; 431 } 432 } 433 minimumHeightForWidth = maxh; 434 } 435 return minimumHeightForWidth; 436 } 437 438 static qreal minimumWidthForHeight(qreal height, qreal minw, qreal maxw, 439 const QGraphicsWidget *widget) 440 { 441 return minimumHeightForWidth(height, minw, maxw, widget, false); 442 } 443 444 static QSizeF closestAcceptableSize(const QSizeF &proposed, 445 const QGraphicsWidget *widget) 446 { 447 const QSizeF current = widget->size(); 448 449 qreal minw = proposed.width(); 450 qreal maxw = current.width(); 451 qreal minh = proposed.height(); 452 qreal maxh = current.height(); 453 454 qreal middlew = maxw; 455 qreal middleh = maxh; 456 qreal min_hfw; 457 min_hfw = minimumHeightForWidth(maxw, minh, maxh, widget); 458 459 do { 460 if (maxw - minw < 0.1) { 461 // we still havent found anything, cut off binary search 462 minw = maxw; 463 minh = maxh; 464 } 465 middlew = minw + (maxw - minw)/2.0; 466 middleh = minh + (maxh - minh)/2.0; 467 468 min_hfw = minimumHeightForWidth(middlew, minh, maxh, widget); 469 470 if (min_hfw > middleh) { 471 minw = middlew; 472 minh = middleh; 473 } else if (min_hfw <= middleh) { 474 maxw = middlew; 475 maxh = middleh; 476 } 477 } while (maxw != minw); 478 479 min_hfw = minimumHeightForWidth(middlew, minh, maxh, widget); 480 481 QSizeF result; 482 if (min_hfw < maxh) { 483 result = QSizeF(middlew, min_hfw); 484 } else { 485 // Needed because of the cut-off we do above. 486 result = QSizeF(minimumWidthForHeight(maxh, proposed.width(), current.width(), widget), maxh); 487 } 488 return result; 404 489 } 405 490 406 491 static void _q_boundGeometryToSizeConstraints(const QRectF &startGeometry, 407 492 QRectF *rect, Qt::WindowFrameSection section, 408 const QSizeF &min, const QSizeF &max) 409 { 410 int height; 411 int width; 493 const QSizeF &min, const QSizeF &max, 494 const QGraphicsWidget *widget) 495 { 496 const QRectF proposedRect = *rect; 497 qreal width = qBound(min.width(), proposedRect.width(), max.width()); 498 qreal height = qBound(min.height(), proposedRect.height(), max.height()); 499 500 QSizePolicy sp = widget->sizePolicy(); 501 if (const QGraphicsLayout *l = widget->layout()) { 502 sp = l->sizePolicy(); 503 } 504 const bool hasHFW = sp.hasHeightForWidth(); // || sp.hasWidthForHeight(); 505 506 const bool widthChanged = proposedRect.width() < widget->size().width(); 507 const bool heightChanged = proposedRect.height() < widget->size().height(); 508 509 if (hasHFW) { 510 if (widthChanged || heightChanged) { 511 const qreal minh = min.height(); 512 const qreal maxh = max.height(); 513 const qreal proposedHFW = minimumHeightForWidth(width, minh, maxh, widget); 514 if (proposedHFW > proposedRect.height()) { 515 QSizeF effectiveSize = closestAcceptableSize(QSizeF(width, height), widget); 516 width = effectiveSize.width(); 517 height = effectiveSize.height(); 518 } 519 } 520 } 521 412 522 switch (section) { 413 523 case Qt::LeftSection: 414 width = qRound(qBound(min.width(), rect->width(), max.width())); 415 rect->setRect(startGeometry.right() - width, startGeometry.top(), 416 width, startGeometry.height()); 524 rect->setRect(startGeometry.right() - qRound(width), startGeometry.top(), 525 qRound(width), startGeometry.height()); 417 526 break; 418 527 case Qt::TopLeftSection: 419 width = qRound(qBound(min.width(), rect->width(), max.width())); 420 height = qRound(qBound(min.height(), rect->height(), max.height())); 421 rect->setRect(startGeometry.right() - width, startGeometry.bottom() - height, 422 width, height); 528 rect->setRect(startGeometry.right() - qRound(width), startGeometry.bottom() - qRound(height), 529 qRound(width), qRound(height)); 423 530 break; 424 531 case Qt::TopSection: 425 height = qRound(qBound(min.height(), rect->height(), max.height())); 426 rect->setRect(startGeometry.left(), startGeometry.bottom() - height, 427 startGeometry.width(), height); 532 rect->setRect(startGeometry.left(), startGeometry.bottom() - qRound(height), 533 startGeometry.width(), qRound(height)); 428 534 break; 429 535 case Qt::TopRightSection: 430 height = qRound(qBound(min.height(), rect->height(), max.height())); 431 rect->setTop(rect->bottom() - height); 432 rect->setWidth(qBound(min.width(), rect->width(), max.width())); 536 rect->setTop(rect->bottom() - qRound(height)); 537 rect->setWidth(qRound(width)); 433 538 break; 434 539 case Qt::RightSection: 435 rect->setWidth(q Bound(min.width(), rect->width(), max.width()));540 rect->setWidth(qRound(width)); 436 541 break; 437 542 case Qt::BottomRightSection: 438 rect->setWidth(q Bound(min.width(), rect->width(), max.width()));439 rect->setHeight(q Bound(min.height(), rect->height(), max.height()));543 rect->setWidth(qRound(width)); 544 rect->setHeight(qRound(height)); 440 545 break; 441 546 case Qt::BottomSection: 442 rect->setHeight(q Bound(min.height(), rect->height(), max.height()));547 rect->setHeight(qRound(height)); 443 548 break; 444 549 case Qt::BottomLeftSection: 445 height = qRound(qBound(min.height(), rect->height(), max.height())); 446 width = qRound(qBound(min.width(), rect->width(), max.width())); 447 rect->setRect(startGeometry.right() - width, startGeometry.top(), 448 width, height); 550 rect->setRect(startGeometry.right() - qRound(width), startGeometry.top(), 551 qRound(width), qRound(height)); 449 552 break; 450 553 default: … … 456 559 { 457 560 Q_Q(QGraphicsWidget); 458 if (!(event->buttons() & Qt::LeftButton) || hoveredSubControl != QStyle::SC_TitleBarLabel) 561 ensureWindowData(); 562 if (!(event->buttons() & Qt::LeftButton) || windowData->hoveredSubControl != QStyle::SC_TitleBarLabel) 459 563 return; 460 564 … … 465 569 466 570 QRectF newGeometry; 467 switch ( grabbedSection) {571 switch (windowData->grabbedSection) { 468 572 case Qt::LeftSection: 469 newGeometry = QRectF(startGeometry.topLeft() + QPointF(parentXDelta.dx(), parentXDelta.dy()), 470 startGeometry.size() - QSizeF(delta.dx(), delta.dy())); 573 newGeometry = QRectF(windowData->startGeometry.topLeft() 574 + QPointF(parentXDelta.dx(), parentXDelta.dy()), 575 windowData->startGeometry.size() - QSizeF(delta.dx(), delta.dy())); 471 576 break; 472 577 case Qt::TopLeftSection: 473 newGeometry = QRectF(startGeometry.topLeft() + QPointF(parentDelta.dx(), parentDelta.dy()), 474 startGeometry.size() - QSizeF(delta.dx(), delta.dy())); 578 newGeometry = QRectF(windowData->startGeometry.topLeft() 579 + QPointF(parentDelta.dx(), parentDelta.dy()), 580 windowData->startGeometry.size() - QSizeF(delta.dx(), delta.dy())); 475 581 break; 476 582 case Qt::TopSection: 477 newGeometry = QRectF(startGeometry.topLeft() + QPointF(parentYDelta.dx(), parentYDelta.dy()), 478 startGeometry.size() - QSizeF(0, delta.dy())); 583 newGeometry = QRectF(windowData->startGeometry.topLeft() 584 + QPointF(parentYDelta.dx(), parentYDelta.dy()), 585 windowData->startGeometry.size() - QSizeF(0, delta.dy())); 479 586 break; 480 587 case Qt::TopRightSection: 481 newGeometry = QRectF(startGeometry.topLeft() + QPointF(parentYDelta.dx(), parentYDelta.dy()), 482 startGeometry.size() - QSizeF(-delta.dx(), delta.dy())); 588 newGeometry = QRectF(windowData->startGeometry.topLeft() 589 + QPointF(parentYDelta.dx(), parentYDelta.dy()), 590 windowData->startGeometry.size() - QSizeF(-delta.dx(), delta.dy())); 483 591 break; 484 592 case Qt::RightSection: 485 newGeometry = QRectF( startGeometry.topLeft(),486 startGeometry.size() + QSizeF(delta.dx(), 0));593 newGeometry = QRectF(windowData->startGeometry.topLeft(), 594 windowData->startGeometry.size() + QSizeF(delta.dx(), 0)); 487 595 break; 488 596 case Qt::BottomRightSection: 489 newGeometry = QRectF( startGeometry.topLeft(),490 startGeometry.size() + QSizeF(delta.dx(), delta.dy()));597 newGeometry = QRectF(windowData->startGeometry.topLeft(), 598 windowData->startGeometry.size() + QSizeF(delta.dx(), delta.dy())); 491 599 break; 492 600 case Qt::BottomSection: 493 newGeometry = QRectF( startGeometry.topLeft(),494 startGeometry.size() + QSizeF(0, delta.dy()));601 newGeometry = QRectF(windowData->startGeometry.topLeft(), 602 windowData->startGeometry.size() + QSizeF(0, delta.dy())); 495 603 break; 496 604 case Qt::BottomLeftSection: 497 newGeometry = QRectF(startGeometry.topLeft() + QPointF(parentXDelta.dx(), parentXDelta.dy()), 498 startGeometry.size() - QSizeF(delta.dx(), -delta.dy())); 605 newGeometry = QRectF(windowData->startGeometry.topLeft() 606 + QPointF(parentXDelta.dx(), parentXDelta.dy()), 607 windowData->startGeometry.size() - QSizeF(delta.dx(), -delta.dy())); 499 608 break; 500 609 case Qt::TitleBarArea: 501 newGeometry = QRectF(startGeometry.topLeft() + QPointF(parentDelta.dx(), parentDelta.dy()), 502 startGeometry.size()); 610 newGeometry = QRectF(windowData->startGeometry.topLeft() 611 + QPointF(parentDelta.dx(), parentDelta.dy()), 612 windowData->startGeometry.size()); 503 613 break; 504 614 case Qt::NoSection: … … 506 616 } 507 617 508 if (grabbedSection != Qt::NoSection) { 509 _q_boundGeometryToSizeConstraints(startGeometry, &newGeometry, grabbedSection, 618 if (windowData->grabbedSection != Qt::NoSection) { 619 _q_boundGeometryToSizeConstraints(windowData->startGeometry, &newGeometry, 620 windowData->grabbedSection, 510 621 q->effectiveSizeHint(Qt::MinimumSize), 511 q->effectiveSizeHint(Qt::MaximumSize)); 622 q->effectiveSizeHint(Qt::MaximumSize), 623 q); 512 624 q->setGeometry(newGeometry); 513 625 } … … 520 632 return; 521 633 634 ensureWindowData(); 635 522 636 if (q->rect().contains(event->pos())) { 523 if ( buttonMouseOver ||hoveredSubControl != QStyle::SC_None)637 if (windowData->buttonMouseOver || windowData->hoveredSubControl != QStyle::SC_None) 524 638 windowFrameHoverLeaveEvent(event); 525 639 return; 526 640 } 527 641 528 bool wasMouseOver = buttonMouseOver;529 QRect oldButtonRect = buttonRect;530 buttonRect = QRect();531 buttonMouseOver = false;642 bool wasMouseOver = windowData->buttonMouseOver; 643 QRect oldButtonRect = windowData->buttonRect; 644 windowData->buttonRect = QRect(); 645 windowData->buttonMouseOver = false; 532 646 QPointF pos = event->pos(); 533 647 QStyleOptionTitleBar bar; 534 648 // make sure that the coordinates (rect and pos) we send to the style are positive. 535 pos.rx() += leftWindowFrameMargin; 536 pos.ry() += topWindowFrameMargin; 649 if (windowFrameMargins) { 650 pos.rx() += windowFrameMargins[Left]; 651 pos.ry() += windowFrameMargins[Top]; 652 } 537 653 initStyleOptionTitleBar(&bar); 538 654 bar.rect = q->windowFrameRect().toRect(); … … 560 676 break; 561 677 case Qt::TitleBarArea: 562 buttonRect = q->style()->subControlRect(QStyle::CC_TitleBar, &bar, QStyle::SC_TitleBarCloseButton, 0); 678 windowData->buttonRect = q->style()->subControlRect( 679 QStyle::CC_TitleBar, &bar, QStyle::SC_TitleBarCloseButton, 0); 563 680 #ifdef Q_WS_MAC 564 681 // On mac we should hover if we are in the 'area' of the buttons 565 buttonRect |= q->style()->subControlRect(QStyle::CC_TitleBar, &bar, QStyle::SC_TitleBarMinButton, 0); 566 buttonRect |= q->style()->subControlRect(QStyle::CC_TitleBar, &bar, QStyle::SC_TitleBarMaxButton, 0); 682 windowData->buttonRect |= q->style()->subControlRect( 683 QStyle::CC_TitleBar, &bar, QStyle::SC_TitleBarMinButton, 0); 684 windowData->buttonRect |= q->style()->subControlRect( 685 QStyle::CC_TitleBar, &bar, QStyle::SC_TitleBarMaxButton, 0); 567 686 #endif 568 if ( buttonRect.contains(pos.toPoint()))569 buttonMouseOver = true;687 if (windowData->buttonRect.contains(pos.toPoint())) 688 windowData->buttonMouseOver = true; 570 689 event->ignore(); 571 690 break; … … 579 698 #endif 580 699 // update buttons if we hover over them 581 hoveredSubControl = q->style()->hitTestComplexControl(QStyle::CC_TitleBar, &bar, pos.toPoint(), 0);582 if ( hoveredSubControl != QStyle::SC_TitleBarCloseButton)583 hoveredSubControl = QStyle::SC_TitleBarLabel;584 585 if ( buttonMouseOver != wasMouseOver) {700 windowData->hoveredSubControl = q->style()->hitTestComplexControl(QStyle::CC_TitleBar, &bar, pos.toPoint(), 0); 701 if (windowData->hoveredSubControl != QStyle::SC_TitleBarCloseButton) 702 windowData->hoveredSubControl = QStyle::SC_TitleBarLabel; 703 704 if (windowData->buttonMouseOver != wasMouseOver) { 586 705 if (!oldButtonRect.isNull()) 587 706 q->update(QRectF(oldButtonRect).translated(q->windowFrameRect().topLeft())); 588 if (! buttonRect.isNull())589 q->update(QRectF( buttonRect).translated(q->windowFrameRect().topLeft()));707 if (!windowData->buttonRect.isNull()) 708 q->update(QRectF(windowData->buttonRect).translated(q->windowFrameRect().topLeft())); 590 709 } 591 710 } … … 601 720 #endif 602 721 722 ensureWindowData(); 723 603 724 bool needsUpdate = false; 604 if (hoveredSubControl == QStyle::SC_TitleBarCloseButton || buttonMouseOver) 725 if (windowData->hoveredSubControl == QStyle::SC_TitleBarCloseButton 726 || windowData->buttonMouseOver) 605 727 needsUpdate = true; 606 728 607 729 // update the hover state (of buttons etc...) 608 hoveredSubControl = QStyle::SC_None;609 buttonMouseOver = false;610 buttonRect = QRect();730 windowData->hoveredSubControl = QStyle::SC_None; 731 windowData->buttonMouseOver = false; 732 windowData->buttonRect = QRect(); 611 733 if (needsUpdate) 612 q->update( buttonRect);734 q->update(windowData->buttonRect); 613 735 } 614 736 } … … 617 739 { 618 740 return (windowFlags & Qt::Window) && (windowFlags & Qt::WindowTitleHint); 619 }620 621 /*!622 \internal623 */624 void QGraphicsWidgetPrivate::setFocusWidget()625 {626 // Update focus child chain.627 QGraphicsWidget *widget = static_cast<QGraphicsWidget *>(q_ptr);628 QGraphicsWidget *parent = widget;629 bool hidden = !visible;630 do {631 parent->d_func()->focusChild = widget;632 } while (!parent->isWindow() && (parent = parent->parentWidget()) && (!hidden || !parent->d_func()->visible));633 }634 635 /*!636 \internal637 */638 void QGraphicsWidgetPrivate::clearFocusWidget()639 {640 // Reset focus child chain.641 QGraphicsWidget *parent = static_cast<QGraphicsWidget *>(q_ptr);642 do {643 if (parent->d_func()->focusChild != q_ptr)644 break;645 parent->d_func()->focusChild = 0;646 } while (!parent->isWindow() && (parent = parent->parentWidget()));647 741 } 648 742 … … 650 744 * is called after a reparent has taken place to fix up the focus chain(s) 651 745 */ 652 void QGraphicsWidgetPrivate::fixFocusChainBeforeReparenting(QGraphicsWidget *newParent, QGraphicsScene * newScene)746 void QGraphicsWidgetPrivate::fixFocusChainBeforeReparenting(QGraphicsWidget *newParent, QGraphicsScene *oldScene, QGraphicsScene *newScene) 653 747 { 654 748 Q_Q(QGraphicsWidget); … … 663 757 QGraphicsWidget *firstOld = 0; 664 758 bool wasPreviousNew = true; 665 666 if (focusChild) {667 // Ensure that the current focus child doesn't leave pointers around668 // before reparenting.669 focusChild->clearFocus();670 }671 759 672 760 while (w != q) { … … 702 790 if (newParent) 703 791 newScene = newParent->scene(); 704 QGraphicsScene *oldScene = q->scene(); 792 705 793 if (oldScene && newScene != oldScene) 706 794 oldScene->d_func()->tabFocusFirst = firstOld;
Note:
See TracChangeset
for help on using the changeset viewer.