From ef1f7eab355ad82963449e76b0da9fba20aca10e Mon Sep 17 00:00:00 2001 From: Volker Hilsheimer Date: Fri, 29 May 2020 11:33:04 +0200 Subject: Use exported highlighter from QtWidgets rather than duplicating code Change-Id: Ib868993fd9a205c9b7d05df74fedbcdb953b4712 Reviewed-by: Lars Knoll --- src/svgwidgets/qgraphicssvgitem.cpp | 62 ++----------------------------------- 1 file changed, 3 insertions(+), 59 deletions(-) (limited to 'src') diff --git a/src/svgwidgets/qgraphicssvgitem.cpp b/src/svgwidgets/qgraphicssvgitem.cpp index f1dd252..89fdabd 100644 --- a/src/svgwidgets/qgraphicssvgitem.cpp +++ b/src/svgwidgets/qgraphicssvgitem.cpp @@ -174,65 +174,9 @@ QRectF QGraphicsSvgItem::boundingRect() const return d->boundingRect; } -/*! - \internal - - Highlights \a item as selected. - - NOTE: This function is a duplicate of qt_graphicsItem_highlightSelected() in qgraphicsitem.cpp! -*/ -static void qt_graphicsItem_highlightSelected( - QGraphicsItem *item, QPainter *painter, const QStyleOptionGraphicsItem *option) -{ - const QRectF murect = painter->transform().mapRect(QRectF(0, 0, 1, 1)); - if (qFuzzyIsNull(qMax(murect.width(), murect.height()))) - return; - - const QRectF mbrect = painter->transform().mapRect(item->boundingRect()); - if (qMin(mbrect.width(), mbrect.height()) < qreal(1.0)) - return; - - qreal itemPenWidth; - switch (item->type()) { - case QGraphicsEllipseItem::Type: - itemPenWidth = static_cast(item)->pen().widthF(); - break; - case QGraphicsPathItem::Type: - itemPenWidth = static_cast(item)->pen().widthF(); - break; - case QGraphicsPolygonItem::Type: - itemPenWidth = static_cast(item)->pen().widthF(); - break; - case QGraphicsRectItem::Type: - itemPenWidth = static_cast(item)->pen().widthF(); - break; - case QGraphicsSimpleTextItem::Type: - itemPenWidth = static_cast(item)->pen().widthF(); - break; - case QGraphicsLineItem::Type: - itemPenWidth = static_cast(item)->pen().widthF(); - break; - default: - itemPenWidth = 1.0; - } - const qreal pad = itemPenWidth / 2; - - const qreal penWidth = 0; // cosmetic pen - - const QColor fgcolor = option->palette.windowText().color(); - const QColor bgcolor( // ensure good contrast against fgcolor - fgcolor.red() > 127 ? 0 : 255, - fgcolor.green() > 127 ? 0 : 255, - fgcolor.blue() > 127 ? 0 : 255); - - painter->setPen(QPen(bgcolor, penWidth, Qt::SolidLine)); - painter->setBrush(Qt::NoBrush); - painter->drawRect(item->boundingRect().adjusted(pad, pad, -pad, -pad)); - - painter->setPen(QPen(option->palette.windowText(), 0, Qt::DashLine)); - painter->setBrush(Qt::NoBrush); - painter->drawRect(item->boundingRect().adjusted(pad, pad, -pad, -pad)); -} +// from qgraphicsitem.cpp +void Q_WIDGETS_EXPORT qt_graphicsItem_highlightSelected(QGraphicsItem *item, QPainter *painter, + const QStyleOptionGraphicsItem *option); /*! \reimp -- cgit v1.2.1