summaryrefslogtreecommitdiff
path: root/app/pebbleappiconprovider.cpp
blob: 0e694ffa649ed339e3c88bcfc29fdf161320d5dd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include <QDebug>
#include <QUrl>
#include "pebbleappiconprovider.h"

PebbleAppIconProvider::PebbleAppIconProvider(PebbledInterface *interface)
    : QQuickImageProvider(QQmlImageProviderBase::Image), pebbled(interface)
{
}

QImage PebbleAppIconProvider::requestImage(const QString &id, QSize *size, const QSize &requestedSize)
{
    QUuid uuid(QUrl::fromPercentEncoding(id.toLatin1()));
    QImage img = pebbled->menuIconForApp(uuid);

    if (requestedSize.width() > 0 && requestedSize.height() > 0) {
        img = img.scaled(requestedSize, Qt::KeepAspectRatio);
    } else if (requestedSize.width() > 0) {
        img = img.scaledToWidth(requestedSize.width());
    } else if (requestedSize.height() > 0) {
        img = img.scaledToHeight(requestedSize.height());
    }

    if (size) {
        *size = img.size();
    }

    return img;
}