Skip to content

Commit 2472a60

Browse files
committed
fix(viewer): optimize image scaling behavior for selection states
- Selected state: Keep aspect ratio scaling without cropping - Unselected state: Expand to fill while maintaining aspect ratio - Ensures consistent visual presentation across different selection states log: use different scaling modes based on selection state bug: https://pms.uniontech.com/bug-view-346079.html
1 parent a7e0c4a commit 2472a60

1 file changed

Lines changed: 12 additions & 2 deletions

File tree

libimageviewer/viewpanel/contents/imgviewdelegate.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,10 +161,20 @@ void LibImgViewDelegate::paint(QPainter *painter, const QStyleOptionViewItem &op
161161
QPainterPath bp1;
162162
bp1.addRoundedRect(pixmapRect, 4, 4);
163163
painter->setClipPath(bp1);
164-
_pixmap = _pixmap.scaled(pixmapRect.size(), Qt::KeepAspectRatioByExpanding, Qt::SmoothTransformation);
164+
// 根据选中状态使用不同的缩放模式
165+
if (backgroundRect.width() != LibImgViewListView::ITEM_NORMAL_WIDTH) {
166+
// 选中状态:保持宽高比
167+
_pixmap = _pixmap.scaled(pixmapRect.size(), Qt::KeepAspectRatio, Qt::SmoothTransformation);
168+
} else {
169+
// 未选中状态:填充整个区域
170+
_pixmap = _pixmap.scaled(pixmapRect.size(), Qt::KeepAspectRatioByExpanding, Qt::SmoothTransformation);
171+
}
165172
qreal adjustx = _pixmap.width() - pixmapRect.width();
166173
qreal adjusty = _pixmap.height() - pixmapRect.height();
167-
painter->drawImage(pixmapRect,_pixmap,_pixmap.rect().adjusted(adjustx / 2, -adjusty / 2, -adjustx / 2, adjusty / 2));
174+
175+
// 修复:居中显示时,偏移量应该是正值,负责旋转时计算
176+
QRect sourceRect = _pixmap.rect().adjusted(adjustx / 2, adjusty / 2, -adjustx / 2, -adjusty / 2);
177+
painter->drawImage(pixmapRect, _pixmap, sourceRect);
168178

169179
painter->restore();
170180
}

0 commit comments

Comments
 (0)