nextcloud-desktop/src/gui/tray/svgimageprovider.cpp
Claudio Cambra 04e1736616 Ensure svg icons generated by svgimageprovider have a reasonable default size
Signed-off-by: Claudio Cambra <claudio.cambra@nextcloud.com>
2024-06-07 00:17:40 +08:00

55 lines
1.8 KiB
C++

/*
* Copyright (C) by Oleksandr Zolotov <alex@nextcloud.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*/
#include "svgimageprovider.h"
#include "iconutils.h"
#include <QLoggingCategory>
namespace OCC {
namespace Ui {
Q_LOGGING_CATEGORY(lcSvgImageProvider, "nextcloud.gui.svgimageprovider", QtInfoMsg)
SvgImageProvider::SvgImageProvider()
: QQuickImageProvider(QQuickImageProvider::Image)
{
}
QImage SvgImageProvider::requestImage(const QString &id, QSize *size, const QSize &requestedSize)
{
Q_ASSERT(!id.isEmpty());
const auto idSplit = id.split(QStringLiteral("/"), Qt::SkipEmptyParts);
if (idSplit.isEmpty()) {
qCWarning(lcSvgImageProvider) << "Image id is incorrect!";
return {};
}
const auto pixmapName = idSplit.at(0);
const auto pixmapColor = idSplit.size() > 1 ? QColor(idSplit.at(1)) : QColorConstants::Svg::black;
if (pixmapName.isEmpty() || !pixmapColor.isValid()) {
qCWarning(lcSvgImageProvider) << "Image id is incorrect!";
return {};
}
if (size != nullptr && (size->width() <= 0 || size->height() <= 0)) {
*size = QSize(64, 64);
}
return IconUtils::createSvgImageWithCustomColor(pixmapName, pixmapColor, size, requestedSize);
}
}
}