summaryrefslogtreecommitdiffstats
path: root/src/plugins/platforms/windows/qwindowstheme.cpp
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2016-07-14 09:35:50 +0200
committerFriedemann Kleint <Friedemann.Kleint@qt.io>2016-07-15 09:07:59 +0000
commit6bb0bc73c809d1defdcedc31c4c464a129d3de4d (patch)
tree01338f0e0167e87b93d01a188f0f49efcb2812ef /src/plugins/platforms/windows/qwindowstheme.cpp
parent5d8a33a86cb6d852716a9c871576b2f9361a61a1 (diff)
QWindowsTheme: Fix the available file icon sizes
Previously, QWindowsTheme had a hardcoded list of of available file icon sizes. As the sizes depend on the Windows display scale factor, this can lead to undesired scaling of icons. Maintain an array of the standard sizes against which the sizes are matched; refresh in display change. Task-number: QTBUG-54561 Change-Id: If36de2f30c8a230cc7bd8eeb4dfc9f201aeda5e4 Reviewed-by: Oliver Wolff <oliver.wolff@qt.io>
Diffstat (limited to 'src/plugins/platforms/windows/qwindowstheme.cpp')
-rw-r--r--src/plugins/platforms/windows/qwindowstheme.cpp49
1 files changed, 37 insertions, 12 deletions
diff --git a/src/plugins/platforms/windows/qwindowstheme.cpp b/src/plugins/platforms/windows/qwindowstheme.cpp
index f673ce5c25..ce0c69f9ed 100644
--- a/src/plugins/platforms/windows/qwindowstheme.cpp
+++ b/src/plugins/platforms/windows/qwindowstheme.cpp
@@ -329,6 +329,7 @@ QWindowsTheme::QWindowsTheme()
std::fill(m_fonts, m_fonts + NFonts, static_cast<QFont *>(0));
std::fill(m_palettes, m_palettes + NPalettes, static_cast<QPalette *>(0));
refresh();
+ refreshIconPixmapSizes();
}
QWindowsTheme::~QWindowsTheme()
@@ -394,16 +395,8 @@ QVariant QWindowsTheme::themeHint(ThemeHint hint) const
return QVariant(int(WindowsKeyboardScheme));
case UiEffects:
return QVariant(uiEffects());
- case IconPixmapSizes: {
- QList<int> sizes;
- sizes << 16 << 32;
-#ifdef USE_IIMAGELIST
- sizes << 48; // sHIL_EXTRALARGE
- if (QSysInfo::WindowsVersion >= QSysInfo::WV_VISTA)
- sizes << 256; // SHIL_JUMBO
-#endif // USE_IIMAGELIST
- return QVariant::fromValue(sizes);
- }
+ case IconPixmapSizes:
+ return m_fileIconSizes;
case DialogSnapToDefaultButton:
return QVariant(booleanSystemParametersInfo(SPI_GETSNAPTODEFBUTTON, false));
case ContextMenuOnMouseRelease:
@@ -473,6 +466,15 @@ void QWindowsTheme::refreshFonts()
#endif // !Q_OS_WINCE
}
+enum FileIconSize {
+ // Standard icons obtainable via shGetFileInfo(), SHGFI_SMALLICON, SHGFI_LARGEICON
+ SmallFileIcon, LargeFileIcon,
+ // Larger icons obtainable via SHGetImageList()
+ ExtraLargeFileIcon,
+ JumboFileIcon, // Vista onwards
+ FileIconSizeCount
+};
+
bool QWindowsTheme::usePlatformNativeDialog(DialogType type) const
{
return QWindowsDialogs::useHelper(type);
@@ -489,6 +491,27 @@ void QWindowsTheme::windowsThemeChanged(QWindow * window)
QWindowSystemInterface::handleThemeChange(window);
}
+static int fileIconSizes[FileIconSizeCount];
+
+void QWindowsTheme::refreshIconPixmapSizes()
+{
+ // Standard sizes: 16, 32, 48, 256
+ fileIconSizes[SmallFileIcon] = GetSystemMetrics(SM_CXSMICON); // corresponds to SHGFI_SMALLICON);
+ fileIconSizes[LargeFileIcon] = GetSystemMetrics(SM_CXICON); // corresponds to SHGFI_LARGEICON
+ fileIconSizes[ExtraLargeFileIcon] =
+ fileIconSizes[LargeFileIcon] + fileIconSizes[LargeFileIcon] / 2;
+ fileIconSizes[JumboFileIcon] = 8 * fileIconSizes[LargeFileIcon]; // empirical, has not been observed to work
+ QList<int> sizes;
+ sizes << fileIconSizes[SmallFileIcon] << fileIconSizes[LargeFileIcon];
+#ifdef USE_IIMAGELIST
+ sizes << fileIconSizes[ExtraLargeFileIcon]; // sHIL_EXTRALARGE
+ if (QSysInfo::WindowsVersion >= QSysInfo::WV_VISTA)
+ sizes << fileIconSizes[JumboFileIcon]; // SHIL_JUMBO
+#endif // USE_IIMAGELIST
+ qCDebug(lcQpaWindows) << __FUNCTION__ << sizes;
+ m_fileIconSizes = QVariant::fromValue(sizes);
+}
+
// Defined in qpixmap_win.cpp
Q_GUI_EXPORT QPixmap qt_pixmapFromWinHICON(HICON icon);
@@ -706,10 +729,12 @@ QPixmap QWindowsTheme::fileIconPixmap(const QFileInfo &fileInfo, const QSizeF &s
QPixmap pixmap;
const QString filePath = QDir::toNativeSeparators(fileInfo.filePath());
const int width = int(size.width());
- const int iconSize = width > 16 ? SHGFI_LARGEICON : SHGFI_SMALLICON;
+ const int iconSize = width > fileIconSizes[SmallFileIcon] ? SHGFI_LARGEICON : SHGFI_SMALLICON;
const int requestedImageListSize =
#ifdef USE_IIMAGELIST
- width > 48 ? sHIL_JUMBO : (width > 32 ? sHIL_EXTRALARGE : 0);
+ width > fileIconSizes[ExtraLargeFileIcon]
+ ? sHIL_JUMBO
+ : (width > fileIconSizes[LargeFileIcon] ? sHIL_EXTRALARGE : 0);
#else
0;
#endif // !USE_IIMAGELIST