diff options
| author | Scott Harvey <[email protected]> | 2018-03-28 07:46:12 -0600 |
|---|---|---|
| committer | Nathaniel Graham <[email protected]> | 2018-03-29 16:29:51 -0600 |
| commit | e0f7fe87bdc2e32778cd6ce997b59b883cb245b8 (patch) | |
| tree | 525793c4be8c0674a84c1014dd78b26b133f97f2 | |
| parent | eed695710d0eac9251df5a4dd22440b2f57c863f (diff) | |
Fix alignment of icons in Places panel and Compact view mode
Summary:
Adjust calculation of icon pixmap Y value; now based off center of text label bounding rectangle. Previously, icons appeared top-aligned when text size was larger than icon size.
Centering is done by obtaining the center point of the text frame (`m_textRect.center().y()`) and setting the top `Y` point of the icon to one-half of the scaled icon height (`m_scaled_PixmapSize.height()`) Division is done by `2.0`, to ensure calculations are done with floating-point math, in keeping with `QPointF`, which returns floating-point values.
Also includes an adjustment named `midlineShift` (contributed by @zzag), which takes into account the font's midline in respect to the center of the text frame. Certain fonts (i.e. Noto Sans) can have a slightly offset midline, resulting in imperfect alignment of the icon. This small adjustment resolves that potential issue.
See before and after screenshots.
{F5764918}
Before, showing misalignment (with and without debugging wireframes)
{F5764920}
After, showing correction
BUG: 390771
Test Plan:
-- Compile Dolphin with patch
-- Increase system font size by several points (i.e. 15pt)
-- Check that Places panel icons remain centered with the text label
-- Select Compact View mode
-- Adjust icon size slider to minimum
-- Ensure that icons also remain centered in file listing
-- Check several combinations of icon size & font size to ensure centering is consistent
Reviewers: #dolphin, ngraham, cfeck, elvisangelaccio
Reviewed By: #dolphin, ngraham, elvisangelaccio
Subscribers: zzag, elvisangelaccio, #dolphin
Differential Revision: https://phabricator.kde.org/D11650
| -rw-r--r-- | src/kitemviews/kstandarditemlistwidget.cpp | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/src/kitemviews/kstandarditemlistwidget.cpp b/src/kitemviews/kstandarditemlistwidget.cpp index 1aca250dd..bc3bb29de 100644 --- a/src/kitemviews/kstandarditemlistwidget.cpp +++ b/src/kitemviews/kstandarditemlistwidget.cpp @@ -1015,15 +1015,21 @@ void KStandardItemListWidget::updatePixmapCache() if (iconOnTop) { // Center horizontally and align on bottom within the icon-area - m_pixmapPos.setX((widgetSize.width() - m_scaledPixmapSize.width()) / 2); + m_pixmapPos.setX((widgetSize.width() - m_scaledPixmapSize.width()) / 2.0); m_pixmapPos.setY(padding + scaledIconSize - m_scaledPixmapSize.height()); } else { // Center horizontally and vertically within the icon-area const TextInfo* textInfo = m_textInfo.value("text"); - m_pixmapPos.setX(textInfo->pos.x() - 2 * padding - - (scaledIconSize + m_scaledPixmapSize.width()) / 2); - m_pixmapPos.setY(padding - + (scaledIconSize - m_scaledPixmapSize.height()) / 2); + m_pixmapPos.setX(textInfo->pos.x() - 2.0 * padding + - (scaledIconSize + m_scaledPixmapSize.width()) / 2.0); + + // Derive icon's vertical center from the center of the text frame, including + // any necessary adjustment if the font's midline is offset from the frame center + const qreal midlineShift = m_customizedFontMetrics.height() / 2.0 + - m_customizedFontMetrics.descent() + - m_customizedFontMetrics.capHeight() / 2.0; + m_pixmapPos.setY(m_textRect.center().y() + midlineShift - m_scaledPixmapSize.height() / 2.0); + } m_iconRect = QRectF(m_pixmapPos, QSizeF(m_scaledPixmapSize)); |
