forked from qt-creator/qt-creator
AutoTest: HighDPI adjustments for TestResultDelegate
- Remove the gap between background rect and division line. - Consider the QWindow when drawing the icon Change-Id: Ie10f862f556049ec1bce78a6abe8f6170bd3abaf Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
@@ -33,6 +33,7 @@
|
|||||||
#include <QAbstractItemView>
|
#include <QAbstractItemView>
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
#include <QTextLayout>
|
#include <QTextLayout>
|
||||||
|
#include <QWindow>
|
||||||
|
|
||||||
namespace Autotest {
|
namespace Autotest {
|
||||||
namespace Internal {
|
namespace Internal {
|
||||||
@@ -57,20 +58,20 @@ void TestResultDelegate::paint(QPainter *painter, const QStyleOptionViewItem &op
|
|||||||
painter->save();
|
painter->save();
|
||||||
|
|
||||||
QFontMetrics fm(opt.font);
|
QFontMetrics fm(opt.font);
|
||||||
|
QBrush background;
|
||||||
QColor foreground;
|
QColor foreground;
|
||||||
|
|
||||||
const QAbstractItemView *view = qobject_cast<const QAbstractItemView *>(opt.widget);
|
const QAbstractItemView *view = qobject_cast<const QAbstractItemView *>(opt.widget);
|
||||||
const bool selected = opt.state & QStyle::State_Selected;
|
const bool selected = opt.state & QStyle::State_Selected;
|
||||||
|
|
||||||
if (selected) {
|
if (selected) {
|
||||||
painter->setBrush(opt.palette.highlight().color());
|
background = opt.palette.highlight().color();
|
||||||
foreground = opt.palette.highlightedText().color();
|
foreground = opt.palette.highlightedText().color();
|
||||||
} else {
|
} else {
|
||||||
painter->setBrush(opt.palette.window().color());
|
background = opt.palette.window().color();
|
||||||
foreground = opt.palette.text().color();
|
foreground = opt.palette.text().color();
|
||||||
}
|
}
|
||||||
painter->setPen(Qt::NoPen);
|
painter->fillRect(opt.rect, background);
|
||||||
painter->drawRect(opt.rect);
|
|
||||||
painter->setPen(foreground);
|
painter->setPen(foreground);
|
||||||
|
|
||||||
TestResultFilterModel *resultFilterModel = static_cast<TestResultFilterModel *>(view->model());
|
TestResultFilterModel *resultFilterModel = static_cast<TestResultFilterModel *>(view->model());
|
||||||
@@ -78,10 +79,13 @@ void TestResultDelegate::paint(QPainter *painter, const QStyleOptionViewItem &op
|
|||||||
const TestResult *testResult = resultFilterModel->testResult(index);
|
const TestResult *testResult = resultFilterModel->testResult(index);
|
||||||
QTC_ASSERT(testResult, painter->restore();return);
|
QTC_ASSERT(testResult, painter->restore();return);
|
||||||
|
|
||||||
|
const QWidget *widget = dynamic_cast<const QWidget*>(painter->device());
|
||||||
|
QWindow *window = widget ? widget->window()->windowHandle() : nullptr;
|
||||||
|
|
||||||
QIcon icon = index.data(Qt::DecorationRole).value<QIcon>();
|
QIcon icon = index.data(Qt::DecorationRole).value<QIcon>();
|
||||||
if (!icon.isNull())
|
if (!icon.isNull())
|
||||||
painter->drawPixmap(positions.left(), positions.top(),
|
painter->drawPixmap(positions.left(), positions.top(),
|
||||||
icon.pixmap(positions.iconSize(), positions.iconSize()));
|
icon.pixmap(window, QSize(positions.iconSize(), positions.iconSize())));
|
||||||
|
|
||||||
QString typeStr = TestResult::resultToString(testResult->result());
|
QString typeStr = TestResult::resultToString(testResult->result());
|
||||||
if (selected) {
|
if (selected) {
|
||||||
@@ -130,9 +134,10 @@ void TestResultDelegate::paint(QPainter *painter, const QStyleOptionViewItem &op
|
|||||||
painter->drawText(positions.lineAreaLeft(), positions.top() + fm.ascent(), line);
|
painter->drawText(positions.lineAreaLeft(), positions.top() + fm.ascent(), line);
|
||||||
}
|
}
|
||||||
|
|
||||||
painter->setClipRect(opt.rect);
|
painter->setClipping(false);
|
||||||
painter->setPen(opt.palette.mid().color());
|
painter->setPen(opt.palette.mid().color());
|
||||||
painter->drawLine(0, opt.rect.bottom(), opt.rect.right(), opt.rect.bottom());
|
const QRectF adjustedRect(QRectF(opt.rect).adjusted(0.5, 0.5, -0.5, -0.5));
|
||||||
|
painter->drawLine(adjustedRect.bottomLeft(), adjustedRect.bottomRight());
|
||||||
painter->restore();
|
painter->restore();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user