src/gui/graphicsview/qgraphicsitem.cpp
branchRCL_3
changeset 4 3b1da2848fc7
parent 3 41300fa6a67c
child 5 d3bac044e0f0
equal deleted inserted replaced
3:41300fa6a67c 4:3b1da2848fc7
     1 /****************************************************************************
     1 /****************************************************************************
     2 **
     2 **
     3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
     3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     4 ** All rights reserved.
     4 ** All rights reserved.
     5 ** Contact: Nokia Corporation (qt-info@nokia.com)
     5 ** Contact: Nokia Corporation (qt-info@nokia.com)
     6 **
     6 **
     7 ** This file is part of the QtGui module of the Qt Toolkit.
     7 ** This file is part of the QtGui module of the Qt Toolkit.
     8 **
     8 **
  2995 
  2995 
  2996     \sa focusItem(), setFocus(), QGraphicsScene::setFocusItem(), isActive()
  2996     \sa focusItem(), setFocus(), QGraphicsScene::setFocusItem(), isActive()
  2997 */
  2997 */
  2998 bool QGraphicsItem::hasFocus() const
  2998 bool QGraphicsItem::hasFocus() const
  2999 {
  2999 {
       
  3000     if (!d_ptr->scene || !d_ptr->scene->isActive())
       
  3001         return false;
       
  3002 
  3000     if (d_ptr->focusProxy)
  3003     if (d_ptr->focusProxy)
  3001         return d_ptr->focusProxy->hasFocus();
  3004         return d_ptr->focusProxy->hasFocus();
  3002     return isActive() && (d_ptr->scene && d_ptr->scene->focusItem() == this);
  3005 
       
  3006     if (d_ptr->scene->d_func()->focusItem != this)
       
  3007         return false;
       
  3008 
       
  3009     return panel() == d_ptr->scene->d_func()->activePanel;
  3003 }
  3010 }
  3004 
  3011 
  3005 /*!
  3012 /*!
  3006     Gives keyboard input focus to this item. The \a focusReason argument will
  3013     Gives keyboard input focus to this item. The \a focusReason argument will
  3007     be passed into any \l{QFocusEvent}{focus event} generated by this function;
  3014     be passed into any \l{QFocusEvent}{focus event} generated by this function;
 10713                      info->widget, info->opacity, &effectTransform, info->wasDirtySceneTransform,
 10720                      info->widget, info->opacity, &effectTransform, info->wasDirtySceneTransform,
 10714                      info->drawItem);
 10721                      info->drawItem);
 10715     }
 10722     }
 10716 }
 10723 }
 10717 
 10724 
 10718 QPixmap QGraphicsItemEffectSourcePrivate::pixmap(Qt::CoordinateSystem system, QPoint *offset,
 10725 QRect QGraphicsItemEffectSourcePrivate::paddedEffectRect(Qt::CoordinateSystem system, QGraphicsEffect::PixmapPadMode mode, const QRectF &sourceRect, bool *unpadded) const
 10719                                                  QGraphicsEffect::PixmapPadMode mode) const
 10726 {
 10720 {
       
 10721     const bool deviceCoordinates = (system == Qt::DeviceCoordinates);
       
 10722     if (!info && deviceCoordinates) {
       
 10723         // Device coordinates without info not yet supported.
       
 10724         qWarning("QGraphicsEffectSource::pixmap: Not yet implemented, lacking device context");
       
 10725         return QPixmap();
       
 10726     }
       
 10727     if (!item->d_ptr->scene)
       
 10728         return QPixmap();
       
 10729     QGraphicsScenePrivate *scened = item->d_ptr->scene->d_func();
       
 10730 
       
 10731     const QRectF sourceRect = boundingRect(system);
       
 10732     QRectF effectRectF;
 10727     QRectF effectRectF;
 10733 
 10728 
 10734     bool unpadded = false;
 10729     if (unpadded)
       
 10730         *unpadded = false;
       
 10731 
 10735     if (mode == QGraphicsEffect::PadToEffectiveBoundingRect) {
 10732     if (mode == QGraphicsEffect::PadToEffectiveBoundingRect) {
 10736         if (info) {
 10733         if (info) {
 10737             effectRectF = item->graphicsEffect()->boundingRectFor(boundingRect(Qt::DeviceCoordinates));
 10734             effectRectF = item->graphicsEffect()->boundingRectFor(boundingRect(Qt::DeviceCoordinates));
 10738             unpadded = (effectRectF.size() == sourceRect.size());
 10735             if (unpadded)
       
 10736                 *unpadded = (effectRectF.size() == sourceRect.size());
 10739             if (info && system == Qt::LogicalCoordinates)
 10737             if (info && system == Qt::LogicalCoordinates)
 10740                 effectRectF = info->painter->worldTransform().inverted().mapRect(effectRectF);
 10738                 effectRectF = info->painter->worldTransform().inverted().mapRect(effectRectF);
 10741         } else {
 10739         } else {
 10742             // no choice but to send a logical coordinate bounding rect to boundingRectFor
 10740             // no choice but to send a logical coordinate bounding rect to boundingRectFor
 10743             effectRectF = item->graphicsEffect()->boundingRectFor(sourceRect);
 10741             effectRectF = item->graphicsEffect()->boundingRectFor(sourceRect);
 10745     } else if (mode == QGraphicsEffect::PadToTransparentBorder) {
 10743     } else if (mode == QGraphicsEffect::PadToTransparentBorder) {
 10746         // adjust by 1.5 to account for cosmetic pens
 10744         // adjust by 1.5 to account for cosmetic pens
 10747         effectRectF = sourceRect.adjusted(-1.5, -1.5, 1.5, 1.5);
 10745         effectRectF = sourceRect.adjusted(-1.5, -1.5, 1.5, 1.5);
 10748     } else {
 10746     } else {
 10749         effectRectF = sourceRect;
 10747         effectRectF = sourceRect;
 10750         unpadded = true;
 10748         if (unpadded)
 10751     }
 10749             *unpadded = true;
 10752 
 10750     }
 10753     QRect effectRect = effectRectF.toAlignedRect();
 10751 
       
 10752     return effectRectF.toAlignedRect();
       
 10753 }
       
 10754 
       
 10755 QPixmap QGraphicsItemEffectSourcePrivate::pixmap(Qt::CoordinateSystem system, QPoint *offset,
       
 10756                                                  QGraphicsEffect::PixmapPadMode mode) const
       
 10757 {
       
 10758     const bool deviceCoordinates = (system == Qt::DeviceCoordinates);
       
 10759     if (!info && deviceCoordinates) {
       
 10760         // Device coordinates without info not yet supported.
       
 10761         qWarning("QGraphicsEffectSource::pixmap: Not yet implemented, lacking device context");
       
 10762         return QPixmap();
       
 10763     }
       
 10764     if (!item->d_ptr->scene)
       
 10765         return QPixmap();
       
 10766     QGraphicsScenePrivate *scened = item->d_ptr->scene->d_func();
       
 10767 
       
 10768     bool unpadded;
       
 10769     const QRectF sourceRect = boundingRect(system);
       
 10770     QRect effectRect = paddedEffectRect(system, mode, sourceRect, &unpadded);
 10754 
 10771 
 10755     if (offset)
 10772     if (offset)
 10756         *offset = effectRect.topLeft();
 10773         *offset = effectRect.topLeft();
 10757 
 10774 
 10758     bool untransformed = !deviceCoordinates
 10775     bool untransformed = !deviceCoordinates