Verified Commit 1c155481 authored by snooxx 💤's avatar snooxx 💤
Browse files

KExtendableItemDelegate: Fix HiDPI positioning of indicator arrows

After fixing pixelated indicator arrows in `KShortcutsEditorDelegate`
(i.e. a subclass, see kxmlgui!104) used in the
"Configure Keyboard Shortcuts" dialog, they were not drawn centered
anymore, e.g. slightly moved upwards. The same problem can be observed
in the download list of KGet.

This is because the increased size of the pixmap is not accounted for.

By transforming the pixmap size to device independent dimensions
again, as used in the positioning calculations, the arrows will finally
be shown correctly.

Note that running `KItemViews` in conjunction with a version of
`KXmlGUI` not including the fix will still work fine, since the
`devicePixelRatio` will only ever be set to `1` in that case.

CCBUG: 414904

Test Plan:
  - Launch `QT_SCALE_FACTOR=1.7 ./bin/kxmlguiwindowtest`
    (from KXmlGui, including the fix mentioned above).
  - Open "Configure Keyboard Shortcuts" dialog.
  - Arrows in "Shortcut" column positioned correctly, for both their
    expanded and collapsed states.
  - Test with `-style Fusion` and other scaling factors, too.
  - `QT_SCALE_FACTOR=1.7 kget`, start download, observe indicator arrow
    in download list.
parent fc6dbc72
Pipeline #155038 passed with stage
in 1 minute and 55 seconds
......@@ -161,7 +161,7 @@ QSize KExtendableItemDelegate::sizeHint(const QStyleOptionViewItem &option, cons
bool showExtensionIndicator = index.model() ? index.model()->data(index, ShowExtensionIndicatorRole).toBool() : false;
if (showExtensionIndicator) {
ret.rwidth() += d->extendPixmap.width();
ret.rwidth() += d->extendPixmap.width() / d->extendPixmap.devicePixelRatio();
}
return ret;
......@@ -195,16 +195,17 @@ void KExtendableItemDelegate::paint(QPainter *painter, const QStyleOptionViewIte
const bool showExtensionIndicator = index.model()->data(index, ShowExtensionIndicatorRole).toBool();
if (showExtensionIndicator) {
const QSize extendPixmapSize = d->extendPixmap.size() / d->extendPixmap.devicePixelRatio();
if (QApplication::isRightToLeft()) {
indicatorX = option.rect.right() - d->extendPixmap.width();
itemOption.rect.setRight(option.rect.right() - d->extendPixmap.width());
indicatorOption.rect.setLeft(option.rect.right() - d->extendPixmap.width());
indicatorX = option.rect.right() - extendPixmapSize.width();
itemOption.rect.setRight(indicatorX);
indicatorOption.rect.setLeft(indicatorX);
} else {
indicatorX = option.rect.left();
indicatorOption.rect.setRight(option.rect.left() + d->extendPixmap.width());
itemOption.rect.setLeft(option.rect.left() + d->extendPixmap.width());
indicatorOption.rect.setRight(indicatorX + extendPixmapSize.width());
itemOption.rect.setLeft(indicatorX + extendPixmapSize.width());
}
indicatorY = option.rect.top() + ((option.rect.height() - d->extendPixmap.height()) >> 1);
indicatorY = option.rect.top() + ((option.rect.height() - extendPixmapSize.height()) >> 1);
}
// fast path
......@@ -265,8 +266,9 @@ void KExtendableItemDelegate::paint(QPainter *painter, const QStyleOptionViewIte
QStyledItemDelegate::paint(painter, itemOption, index);
if (showExtensionIndicator) {
const int extendPixmapHeight = d->extendPixmap.height() / d->extendPixmap.devicePixelRatio();
// indicatorOption's height changed, change this too
indicatorY = indicatorOption.rect.top() + ((indicatorOption.rect.height() - d->extendPixmap.height()) >> 1);
indicatorY = indicatorOption.rect.top() + ((indicatorOption.rect.height() - extendPixmapHeight) >> 1);
painter->save();
QApplication::style()->drawPrimitive(QStyle::PE_PanelItemViewItem, &indicatorOption, painter);
painter->restore();
......
Supports Markdown
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