Qt 4.8
Classes | Functions
qgraphicssvgitem.cpp File Reference
#include "qgraphicssvgitem.h"
#include "qpainter.h"
#include "qstyleoption.h"
#include "qsvgrenderer.h"
#include "qdebug.h"
#include "private/qobject_p.h"
#include "private/qgraphicsitem_p.h"
#include "moc_qgraphicssvgitem.cpp"

Go to the source code of this file.

Classes

class  QGraphicsSvgItemPrivate
 

Functions

static void qt_graphicsItem_highlightSelected (QGraphicsItem *item, QPainter *painter, const QStyleOptionGraphicsItem *option)
 Highlights item as selected. More...
 

Function Documentation

◆ qt_graphicsItem_highlightSelected()

static void qt_graphicsItem_highlightSelected ( QGraphicsItem item,
QPainter painter,
const QStyleOptionGraphicsItem option 
)
static

Highlights item as selected.

Warning
This function is not part of the public interface.

NOTE: This function is a duplicate of qt_graphicsItem_highlightSelected() in qgraphicsitem.cpp!

Definition at line 191 of file qgraphicssvgitem.cpp.

Referenced by QGraphicsSvgItem::paint().

193 {
194  const QRectF murect = painter->transform().mapRect(QRectF(0, 0, 1, 1));
195  if (qFuzzyIsNull(qMax(murect.width(), murect.height())))
196  return;
197 
198  const QRectF mbrect = painter->transform().mapRect(item->boundingRect());
199  if (qMin(mbrect.width(), mbrect.height()) < qreal(1.0))
200  return;
201 
202  qreal itemPenWidth;
203  switch (item->type()) {
205  itemPenWidth = static_cast<QGraphicsEllipseItem *>(item)->pen().widthF();
206  break;
208  itemPenWidth = static_cast<QGraphicsPathItem *>(item)->pen().widthF();
209  break;
211  itemPenWidth = static_cast<QGraphicsPolygonItem *>(item)->pen().widthF();
212  break;
214  itemPenWidth = static_cast<QGraphicsRectItem *>(item)->pen().widthF();
215  break;
217  itemPenWidth = static_cast<QGraphicsSimpleTextItem *>(item)->pen().widthF();
218  break;
220  itemPenWidth = static_cast<QGraphicsLineItem *>(item)->pen().widthF();
221  break;
222  default:
223  itemPenWidth = 1.0;
224  }
225  const qreal pad = itemPenWidth / 2;
226 
227  const qreal penWidth = 0; // cosmetic pen
228 
229  const QColor fgcolor = option->palette.windowText().color();
230  const QColor bgcolor( // ensure good contrast against fgcolor
231  fgcolor.red() > 127 ? 0 : 255,
232  fgcolor.green() > 127 ? 0 : 255,
233  fgcolor.blue() > 127 ? 0 : 255);
234 
235  painter->setPen(QPen(bgcolor, penWidth, Qt::SolidLine));
236  painter->setBrush(Qt::NoBrush);
237  painter->drawRect(item->boundingRect().adjusted(pad, pad, -pad, -pad));
238 
239  painter->setPen(QPen(option->palette.windowText(), 0, Qt::DashLine));
240  painter->setBrush(Qt::NoBrush);
241  painter->drawRect(item->boundingRect().adjusted(pad, pad, -pad, -pad));
242 }
The QColor class provides colors based on RGB, HSV or CMYK values.
Definition: qcolor.h:67
double qreal
Definition: qglobal.h:1193
Q_DECL_CONSTEXPR const T & qMin(const T &a, const T &b)
Definition: qglobal.h:1215
const QTransform & transform() const
Returns the world transformation matrix.
Definition: qpainter.cpp:9558
const QColor & color() const
Returns the brush color.
Definition: qbrush.h:183
The QGraphicsRectItem class provides a rectangle item that you can add to a QGraphicsScene.
virtual QRectF boundingRect() const =0
This pure virtual function defines the outer bounds of the item as a rectangle; all painting must be ...
The QGraphicsEllipseItem class provides an ellipse item that you can add to a QGraphicsScene.
ushort red
Returns the red color component of this color.
Definition: qcolor.h:243
The QGraphicsPolygonItem class provides a polygon item that you can add to a QGraphicsScene.
The QPen class defines how a QPainter should draw lines and outlines of shapes.
Definition: qpen.h:64
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
Definition: qglobal.h:1217
QRect mapRect(const QRect &) const
Creates and returns a QRect object that is a copy of the given rectangle, mapped into the coordinate ...
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
qreal height() const
Returns the height of the rectangle.
Definition: qrect.h:710
virtual int type() const
Returns the type of an item as an int.
qreal width() const
Returns the width of the rectangle.
Definition: qrect.h:707
QRectF adjusted(qreal x1, qreal y1, qreal x2, qreal y2) const
Returns a new rectangle with dx1, dy1, dx2 and dy2 added respectively to the existing coordinates of ...
Definition: qrect.h:781
QPalette palette
the palette that should be used when painting the control
Definition: qstyleoption.h:92
const QBrush & windowText() const
Returns the window text (general foreground) brush of the current color group.
Definition: qpalette.h:124
The QGraphicsSimpleTextItem class provides a simple text path item that you can add to a QGraphicsSce...
The QGraphicsLineItem class provides a line item that you can add to a QGraphicsScene.
ushort blue
Returns the blue color component of this color.
Definition: qcolor.h:245
void setBrush(const QBrush &brush)
Sets the painter&#39;s brush to the given brush.
Definition: qpainter.cpp:4171
void setPen(const QColor &color)
Sets the painter&#39;s pen to have style Qt::SolidLine, width 0 and the specified color.
Definition: qpainter.cpp:4047
void drawRect(const QRectF &rect)
Draws the current rectangle with the current pen and brush.
Definition: qpainter.h:650
static Q_DECL_CONSTEXPR bool qFuzzyIsNull(double d)
Definition: qglobal.h:2043
ushort green
Returns the green color component of this color.
Definition: qcolor.h:244
The QGraphicsPathItem class provides a path item that you can add to a QGraphicsScene.