From b567a080e27abd589d44d323fe9c1fa9a2d68028 Mon Sep 17 00:00:00 2001 From: Jochen Becher Date: Thu, 28 Dec 2017 22:04:45 +0100 Subject: [PATCH] ModelEditor: Fix toolbar icon rendering on HDPI screens Some high DPI icons are still missing. But icons rendered from stereotype definitions get the correct size and look much better. Change-Id: Iabd8283e9bd0ae7e074471a065d009ac5c5836cc Reviewed-by: Tobias Hunger --- src/libs/modelinglib/qmt/model_ui/treemodel.cpp | 2 +- .../modelinglib/qmt/stereotype/stereotypecontroller.cpp | 5 +++-- .../modelinglib/qmt/stereotype/stereotypecontroller.h | 2 +- src/plugins/modeleditor/dragtool.cpp | 9 +++------ src/plugins/modeleditor/modeleditor.cpp | 2 +- 5 files changed, 9 insertions(+), 11 deletions(-) diff --git a/src/libs/modelinglib/qmt/model_ui/treemodel.cpp b/src/libs/modelinglib/qmt/model_ui/treemodel.cpp index 69cdf186610..671f769ba59 100644 --- a/src/libs/modelinglib/qmt/model_ui/treemodel.cpp +++ b/src/libs/modelinglib/qmt/model_ui/treemodel.cpp @@ -831,7 +831,7 @@ QIcon TreeModel::createIcon(StereotypeIcon::Element stereotypeIconElement, Style { const Style *style = m_styleController->adaptStyle(styleElementType); return m_stereotypeController->createIcon(stereotypeIconElement, stereotypes, defaultIconPath, style, - QSize(48, 48), QMarginsF(3.0, 2.0, 3.0, 4.0)); + QSize(48, 48), QMarginsF(3.0, 2.0, 3.0, 4.0), 3.0); } } // namespace qmt diff --git a/src/libs/modelinglib/qmt/stereotype/stereotypecontroller.cpp b/src/libs/modelinglib/qmt/stereotype/stereotypecontroller.cpp index 5e5e4b73fde..0eda3182639 100644 --- a/src/libs/modelinglib/qmt/stereotype/stereotypecontroller.cpp +++ b/src/libs/modelinglib/qmt/stereotype/stereotypecontroller.cpp @@ -129,7 +129,7 @@ CustomRelation StereotypeController::findCustomRelation(const QString &customRel QIcon StereotypeController::createIcon(StereotypeIcon::Element element, const QList &stereotypes, const QString &defaultIconPath, const Style *style, const QSize &size, - const QMarginsF &margins) + const QMarginsF &margins, qreal lineWidth) { // TODO implement cache with key build from element, stereotypes, defaultIconPath, style, size and margins // TODO implement unique id for style which can be used as key @@ -158,10 +158,11 @@ QIcon StereotypeController::createIcon(StereotypeIcon::Element element, const QL iconBoundingRect.height() + margins.top() + margins.bottom()); pixmap.fill(Qt::transparent); QPainter painter(&pixmap); + painter.setRenderHints(QPainter::Antialiasing | QPainter::TextAntialiasing | QPainter::SmoothPixmapTransform); painter.setBrush(Qt::NoBrush); painter.translate(-iconBoundingRect.topLeft() + QPointF(margins.left(), margins.top())); QPen linePen = style->linePen(); - linePen.setWidthF(2.0); + linePen.setWidthF(lineWidth); painter.setPen(linePen); painter.setBrush(style->fillBrush()); ShapePaintVisitor visitor(&painter, QPointF(0.0, 0.0), diff --git a/src/libs/modelinglib/qmt/stereotype/stereotypecontroller.h b/src/libs/modelinglib/qmt/stereotype/stereotypecontroller.h index a010352e361..1cf7c3e64f9 100644 --- a/src/libs/modelinglib/qmt/stereotype/stereotypecontroller.h +++ b/src/libs/modelinglib/qmt/stereotype/stereotypecontroller.h @@ -59,7 +59,7 @@ public: CustomRelation findCustomRelation(const QString &customRelationId) const; QIcon createIcon(StereotypeIcon::Element element, const QList &stereotypes, const QString &defaultIconPath, const Style *style, - const QSize &size, const QMarginsF &margins); + const QSize &size, const QMarginsF &margins, qreal lineWidth); void addStereotypeIcon(const StereotypeIcon &stereotypeIcon); void addCustomRelation(const CustomRelation &customRelation); diff --git a/src/plugins/modeleditor/dragtool.cpp b/src/plugins/modeleditor/dragtool.cpp index 2e343e37213..f7ece9c4871 100644 --- a/src/plugins/modeleditor/dragtool.cpp +++ b/src/plugins/modeleditor/dragtool.cpp @@ -99,12 +99,9 @@ void DragTool::paintEvent(QPaintEvent *event) QMargins margins = contentsMargins(); QPixmap pixmap = d->icon.pixmap(d->iconSize, isEnabled() ? QIcon::Normal : QIcon::Disabled, QIcon::Off); QPainter painter(this); - QRect targetRect((width() - pixmap.width()) / 2, - margins.top() + (d->iconSize.height() - pixmap.height()) / 2, - pixmap.width(), - pixmap.height()); - QRect sourceRect(0, 0, pixmap.width(), pixmap.height()); - painter.drawPixmap(targetRect, pixmap, sourceRect); + painter.drawPixmap((width() - static_cast(pixmap.width() / pixmap.devicePixelRatio())) / 2, + margins.top() + static_cast(d->iconSize.height() - pixmap.height() / pixmap.devicePixelRatio()) / 2, + pixmap); QRect textRect = painter.boundingRect(QRect(), Qt::AlignLeft | Qt::TextSingleLine, d->title); QRect boundingRect(0, d->iconSize.height(), width(), textRect.height()); diff --git a/src/plugins/modeleditor/modeleditor.cpp b/src/plugins/modeleditor/modeleditor.cpp index 1f906927d4e..aadfa1c6705 100644 --- a/src/plugins/modeleditor/modeleditor.cpp +++ b/src/plugins/modeleditor/modeleditor.cpp @@ -1063,7 +1063,7 @@ void ModelEditor::initToolbars() const qmt::Style *style = documentController->styleController()->adaptStyle(styleEngineElementType); icon = stereotypeController->createIcon( stereotypeIconElement, QStringList() << tool.m_stereotype, - QString(), style, QSize(48, 48), QMarginsF(3.0, 2.0, 3.0, 4.0)); + QString(), style, QSize(256, 256), QMarginsF(12.0, 8.0, 12.0, 16.0), 16.0); if (!icon.isNull()) { QString stereotypeIconId = stereotypeController->findStereotypeIconId( stereotypeIconElement, QStringList() << tool.m_stereotype);