blob: 384989be2e7dab9048ccfc747b923eb23e04d568 [file] [log] [blame]
Sébastien Blin1f915762020-08-03 13:27:42 -04001/*
2 * Copyright (C) 2020 by Savoir-faire Linux
3 * Author: Mingrui Zhang <mingrui.zhang@savoirfairelinux.com>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <https://www.gnu.org/licenses/>.
17 */
18
19#pragma once
20
21#include "lrcinstance.h"
22#include "utils.h"
23
24#include <QImage>
25#include <QObject>
26#include <QPair>
27#include <QQuickImageProvider>
28#include <QString>
29
30class TintedButtonImageProvider : public QObject, public QQuickImageProvider
31{
32public:
33 TintedButtonImageProvider()
34 : QQuickImageProvider(QQuickImageProvider::Pixmap,
35 QQmlImageProviderBase::ForceAsynchronousImageLoading)
36 {}
37
38 QPixmap
39 requestPixmap(const QString &id, QSize *size, const QSize &requestedSize) override
40 {
41 Q_UNUSED(size);
42
43 QColor tintedColor;
44
45 auto list = id.split('+', QString::SkipEmptyParts);
46
47 if (list.size() == 2) {
48 QPixmap pixmapToSend(":/images/icons/" + list[0]);
49 if (!requestedSize.isEmpty()) {
50 pixmapToSend = pixmapToSend.scaled(requestedSize, Qt::KeepAspectRatio);
51 } else {
52 pixmapToSend = pixmapToSend.scaled(QSize(30, 30), Qt::KeepAspectRatio);
53 }
54 tintedColor.setNamedColor(list[1]);
55
56 return Utils::generateTintedPixmap(pixmapToSend, tintedColor);
57 }
58
59 return QPixmap();
60 }
61};