forked from qt-creator/qt-creator
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 <tobias.hunger@qt.io>
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -129,7 +129,7 @@ CustomRelation StereotypeController::findCustomRelation(const QString &customRel
|
||||
|
||||
QIcon StereotypeController::createIcon(StereotypeIcon::Element element, const QList<QString> &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),
|
||||
|
||||
@@ -59,7 +59,7 @@ public:
|
||||
CustomRelation findCustomRelation(const QString &customRelationId) const;
|
||||
QIcon createIcon(StereotypeIcon::Element element, const QList<QString> &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);
|
||||
|
||||
@@ -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<int>(pixmap.width() / pixmap.devicePixelRatio())) / 2,
|
||||
margins.top() + static_cast<int>(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());
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user