Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class RetinaImageProvider : public QQuickImageProvider {
- public:
- RetinaImageProvider()
- : QQuickImageProvider(QQuickImageProvider::Pixmap)
- {
- }
- virtual QPixmap requestPixmap(const QString &id, QSize *size, const QSize &requestedSize)
- {
- #ifdef Q_OS_ANDROID
- QString localFile("assets:/qml/img/" + id);
- #else
- QString localFile("qml/img/" + id);
- #endif
- bool retina(false);
- if (qApp->devicePixelRatio() * QGuiApplication::primaryScreen()->geometry().height() > 768) {
- const int dotIndex = localFile.lastIndexOf(QLatin1Char('.'));
- if (dotIndex != -1) {
- QString retinaFile = localFile;
- retinaFile.insert(dotIndex, QStringLiteral("@2x"));
- if (QFile(retinaFile).exists()) {
- localFile = retinaFile;
- retina = true;
- }
- }
- }
- QPixmap pixmap(localFile);
- int width(pixmap.width());
- int height(pixmap.height());
- *size = QSize(width, height);
- if (requestedSize.width() > 0 || requestedSize.height() > 0) {
- pixmap = pixmap.scaled(QSize(
- requestedSize.width() > 0 ? requestedSize.width() : width,
- requestedSize.height() > 0 ? requestedSize.height() : height));
- }
- return pixmap;
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment