File indexing completed on 2024-05-19 04:29:19
0001 /* This file is part of the KDE project 0002 SPDX-FileCopyrightText: 2000 Werner Trobin <trobin@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #include "KisTemplate.h" 0008 0009 #include <QImage> 0010 #include <QPixmap> 0011 #include <QIcon> 0012 #include <QFile> 0013 #include <kis_debug.h> 0014 #include <KoResourcePaths.h> 0015 #include <kis_icon.h> 0016 0017 0018 KisTemplate::KisTemplate(const QString &name, const QString &description, const QString &file, 0019 const QString &picture, const QString &fileName, const QString &_measureSystem, 0020 bool hidden, bool touched) 0021 : m_name(name) 0022 , m_descr(description) 0023 , m_file(file) 0024 , m_picture(picture) 0025 , m_fileName(fileName) 0026 , m_hidden(hidden) 0027 , m_touched(touched) 0028 , m_cached(false) 0029 , m_measureSystem(_measureSystem) 0030 { 0031 } 0032 0033 const QPixmap &KisTemplate::loadPicture() 0034 { 0035 if (m_cached) 0036 return m_pixmap; 0037 0038 m_cached = true; 0039 0040 if (QFile::exists(m_picture)) { 0041 QImage img(m_picture); 0042 if (img.isNull()) { 0043 dbgKrita << "Couldn't find icon " << m_picture; 0044 m_pixmap = QPixmap(); 0045 return m_pixmap; 0046 } 0047 const int maxHeightWidth = 128; // ### TODO: some people would surely like to have 128x128 0048 if (img.width() > maxHeightWidth || img.height() > maxHeightWidth) { 0049 img = img.scaled(maxHeightWidth, maxHeightWidth, Qt::KeepAspectRatio, Qt::SmoothTransformation); 0050 } 0051 m_pixmap = QPixmap::fromImage(img); 0052 return m_pixmap; 0053 } 0054 else { // relative path 0055 0056 0057 // each template folder should have a light and dark version of the icon that will be for light and dark themes 0058 QString themePrefix; 0059 if( KisIconUtils::useDarkIcons() ) { 0060 themePrefix = "dark_"; 0061 } else { 0062 themePrefix = "light_"; 0063 } 0064 0065 0066 QString filenameBuilder = themePrefix.append(m_picture).append(".png"); 0067 QString filename = KoResourcePaths::findAsset("kis_pics", filenameBuilder); 0068 0069 if (filename.isEmpty()) { 0070 0071 } 0072 m_pixmap = QPixmap(filename); 0073 return m_pixmap; 0074 } 0075 } 0076