Commit 4db3209c authored by Alessandro Portale's avatar Alessandro Portale

BinEditor: HighDPI fixes

The cursor drawing caused graphical artifacts under HighDPI.

Change-Id: I542346673ad8111ef03fbd80143de484fdb2d455
Task-number: QTCREATORBUG-15222
Reviewed-by: default avatarhjk <hjk@theqtcompany.com>
parent 18365814
...@@ -697,6 +697,16 @@ QString BinEditorWidget::addressString(quint64 address) ...@@ -697,6 +697,16 @@ QString BinEditorWidget::addressString(quint64 address)
return m_addressString; return m_addressString;
} }
static void paintCursorBorder(QPainter *painter, const QRect &cursorRect)
{
painter->save();
QPen borderPen(Qt::red);
borderPen.setJoinStyle(Qt::MiterJoin);
painter->setPen(borderPen);
painter->drawRect(QRectF(cursorRect).adjusted(0.5, 0.5, -0.5, -0.5));
painter->restore();
}
void BinEditorWidget::paintEvent(QPaintEvent *e) void BinEditorWidget::paintEvent(QPaintEvent *e)
{ {
QPainter painter(viewport()); QPainter painter(viewport());
...@@ -869,10 +879,7 @@ void BinEditorWidget::paintEvent(QPaintEvent *e) ...@@ -869,10 +879,7 @@ void BinEditorWidget::paintEvent(QPaintEvent *e)
if (cursor >= 0) { if (cursor >= 0) {
int w = fm.boundingRect(itemString.mid(cursor*3, 2)).width(); int w = fm.boundingRect(itemString.mid(cursor*3, 2)).width();
QRect cursorRect(x + cursor * m_columnWidth, y - m_ascent, w + 1, m_lineHeight); QRect cursorRect(x + cursor * m_columnWidth, y - m_ascent, w + 1, m_lineHeight);
painter.save(); paintCursorBorder(&painter, cursorRect);
painter.setPen(Qt::red);
painter.drawRect(cursorRect.adjusted(0, 0, 0, -1));
painter.restore();
if (m_hexCursor && m_cursorVisible) { if (m_hexCursor && m_cursorVisible) {
if (m_lowNibble) if (m_lowNibble)
cursorRect.adjust(fm.width(itemString.left(1)), 0, 0, 0); cursorRect.adjust(fm.width(itemString.left(1)), 0, 0, 0);
...@@ -911,17 +918,16 @@ void BinEditorWidget::paintEvent(QPaintEvent *e) ...@@ -911,17 +918,16 @@ void BinEditorWidget::paintEvent(QPaintEvent *e)
y-m_ascent, y-m_ascent,
fm.width(printable.at(cursor)), fm.width(printable.at(cursor)),
m_lineHeight); m_lineHeight);
painter.save();
if (m_hexCursor || !m_cursorVisible) { if (m_hexCursor || !m_cursorVisible) {
painter.setPen(Qt::red); paintCursorBorder(&painter, cursorRect);
painter.drawRect(cursorRect.adjusted(0, 0, 0, -1));
} else { } else {
painter.save();
painter.setClipRect(cursorRect); painter.setClipRect(cursorRect);
painter.fillRect(cursorRect, Qt::red); painter.fillRect(cursorRect, Qt::red);
painter.setPen(Qt::white); painter.setPen(Qt::white);
painter.drawText(text_x, y, printable); painter.drawText(text_x, y, printable);
painter.restore();
} }
painter.restore();
} }
} }
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment