File indexing completed on 2025-01-12 04:25:49
0001 /* 0002 SPDX-FileCopyrightText: 2017 Nicolas Carion 0003 SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL 0004 */ 0005 0006 #include "asseticonprovider.hpp" 0007 #include "effects/effectsrepository.hpp" 0008 #include "transitions/transitionsrepository.hpp" 0009 0010 #include <QDebug> 0011 #include <QFont> 0012 #include <QPainter> 0013 0014 AssetIconProvider::AssetIconProvider(bool effect, QObject *parent) 0015 : QObject(parent) 0016 , m_effect(effect) 0017 { 0018 } 0019 0020 QImage AssetIconProvider::makeIcon(const QString &effectName) 0021 { 0022 QPixmap pix = makePixmap(effectName); 0023 return pix.toImage(); 0024 } 0025 0026 const QPixmap AssetIconProvider::makePixmap(const QString &effectName) 0027 { 0028 QPixmap pix(30, 30); 0029 if (effectName.isEmpty()) { 0030 pix.fill(Qt::red); 0031 return pix; 0032 } 0033 QFont ft = QFont(); 0034 // ft.setBold(true); 0035 ft.setPixelSize(25); 0036 uint hex = qHash(effectName.section(QLatin1Char('/'), 0, -2)); 0037 QString t = QStringLiteral("#") + QString::number(hex, 16).toUpper().left(6); 0038 QColor col(t); 0039 bool isAudio = false; 0040 bool isCustom = false; 0041 bool isGroup = false; 0042 AssetListType::AssetType type = AssetListType::AssetType(effectName.section(QLatin1Char('/'), -2, -2).toInt()); 0043 if (m_effect) { 0044 isAudio = type == AssetListType::AssetType::Audio || type == AssetListType::AssetType::CustomAudio || type == AssetListType::AssetType::TemplateAudio; 0045 isCustom = type == AssetListType::AssetType::CustomAudio || type == AssetListType::AssetType::Custom || type == AssetListType::AssetType::Template || 0046 type == AssetListType::AssetType::TemplateAudio; 0047 if (isCustom) { 0048 // isGroup = EffectsRepository::get()->isGroup(effectId); 0049 } 0050 } else { 0051 isAudio = (type == AssetListType::AssetType::AudioComposition) || (type == AssetListType::AssetType::AudioTransition); 0052 } 0053 QPainter p; 0054 if (isCustom) { 0055 pix.fill(Qt::transparent); 0056 p.begin(&pix); 0057 p.setPen(Qt::NoPen); 0058 p.setBrush(isGroup ? Qt::magenta : Qt::red); 0059 p.drawRoundedRect(pix.rect(), 4, 4); 0060 p.setPen(QPen()); 0061 } else if (isAudio) { 0062 pix.fill(Qt::transparent); 0063 p.begin(&pix); 0064 p.setPen(Qt::NoPen); 0065 p.setBrush(col); 0066 p.drawEllipse(pix.rect()); 0067 p.setPen(QPen()); 0068 } else { 0069 pix.fill(col); 0070 p.begin(&pix); 0071 } 0072 p.setFont(ft); 0073 p.drawText(pix.rect(), Qt::AlignCenter, effectName.at(effectName.length() - 1)); 0074 p.end(); 0075 return pix; 0076 }