|
|
@ -30,6 +30,7 @@ |
|
|
|
|
|
|
|
|
|
|
|
#include <QApplication> |
|
|
|
#include <QApplication> |
|
|
|
#include <QDesktopWidget> |
|
|
|
#include <QDesktopWidget> |
|
|
|
|
|
|
|
#include <QPixmapCache> |
|
|
|
#include <QScreen> |
|
|
|
#include <QScreen> |
|
|
|
#include <QStyle> |
|
|
|
#include <QStyle> |
|
|
|
#include <QWidget> |
|
|
|
#include <QWidget> |
|
|
@ -45,16 +46,21 @@ void Utils::Gui::resize(QWidget *widget, const QSize &newSize) |
|
|
|
|
|
|
|
|
|
|
|
qreal Utils::Gui::screenScalingFactor(const QWidget *widget) |
|
|
|
qreal Utils::Gui::screenScalingFactor(const QWidget *widget) |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
if (!widget) |
|
|
|
|
|
|
|
return 1; |
|
|
|
|
|
|
|
|
|
|
|
#ifdef Q_OS_WIN |
|
|
|
#ifdef Q_OS_WIN |
|
|
|
const int screen = qApp->desktop()->screenNumber(widget); |
|
|
|
const int screen = qApp->desktop()->screenNumber(widget); |
|
|
|
return (QApplication::screens()[screen]->logicalDotsPerInch() / 96); |
|
|
|
return (QApplication::screens()[screen]->logicalDotsPerInch() / 96); |
|
|
|
|
|
|
|
#elif defined(Q_OS_MAC) |
|
|
|
|
|
|
|
return 1; |
|
|
|
#else |
|
|
|
#else |
|
|
|
#if (QT_VERSION >= QT_VERSION_CHECK(5, 6, 0)) |
|
|
|
#if (QT_VERSION >= QT_VERSION_CHECK(5, 6, 0)) |
|
|
|
return widget->devicePixelRatioF(); |
|
|
|
return widget->devicePixelRatioF(); |
|
|
|
#else |
|
|
|
#else |
|
|
|
return widget->devicePixelRatio(); |
|
|
|
return widget->devicePixelRatio(); |
|
|
|
#endif |
|
|
|
#endif |
|
|
|
#endif // Q_OS_WIN
|
|
|
|
#endif |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
QPixmap Utils::Gui::scaledPixmap(const QString &path, const QWidget *widget, const int height) |
|
|
|
QPixmap Utils::Gui::scaledPixmap(const QString &path, const QWidget *widget, const int height) |
|
|
@ -64,6 +70,20 @@ QPixmap Utils::Gui::scaledPixmap(const QString &path, const QWidget *widget, con |
|
|
|
return pixmap.scaledToHeight(scaledHeight, Qt::SmoothTransformation); |
|
|
|
return pixmap.scaledToHeight(scaledHeight, Qt::SmoothTransformation); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
QPixmap Utils::Gui::scaledPixmapSvg(const QString &path, const QWidget *widget, const int baseHeight) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
const int scaledHeight = baseHeight * Utils::Gui::screenScalingFactor(widget); |
|
|
|
|
|
|
|
const QString normalizedKey = path + "@" + QString::number(scaledHeight); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
QPixmap pm; |
|
|
|
|
|
|
|
QPixmapCache cache; |
|
|
|
|
|
|
|
if (!cache.find(normalizedKey, &pm)) { |
|
|
|
|
|
|
|
pm = QIcon(path).pixmap(scaledHeight); |
|
|
|
|
|
|
|
cache.insert(normalizedKey, pm); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return pm; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
QSize Utils::Gui::smallIconSize(const QWidget *widget) |
|
|
|
QSize Utils::Gui::smallIconSize(const QWidget *widget) |
|
|
|
{ |
|
|
|
{ |
|
|
|
// Get DPI scaled icon size (device-dependent), see QT source
|
|
|
|
// Get DPI scaled icon size (device-dependent), see QT source
|
|
|
|