Krita Source Code Documentation
Loading...
Searching...
No Matches
KisTemplate.cpp
Go to the documentation of this file.
1/* This file is part of the KDE project
2 SPDX-FileCopyrightText: 2000 Werner Trobin <trobin@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6
7#include "KisTemplate.h"
8
9#include <QImage>
10#include <QPixmap>
11#include <QFile>
12#include <kis_debug.h>
13#include <KoResourcePaths.h>
14#include <kis_icon.h>
15
16
17KisTemplate::KisTemplate(const QString &name, const QString &description, const QString &file,
18 const QString &picture, const QString &fileName, const QString &_measureSystem,
19 bool hidden, bool touched)
20 : m_name(name)
21 , m_descr(description)
22 , m_file(file)
23 , m_picture(picture)
24 , m_fileName(fileName)
25 , m_hidden(hidden)
26 , m_touched(touched)
27 , m_cached(false)
28 , m_measureSystem(_measureSystem)
29{
30}
31
33{
34 if (m_cached)
35 return m_pixmap;
36
37 m_cached = true;
38
39 if (QFile::exists(m_picture)) {
40 QImage img(m_picture);
41 if (img.isNull()) {
42 dbgKrita << "Couldn't find icon " << m_picture;
43 m_pixmap = QPixmap();
44 return m_pixmap;
45 }
46 const int maxHeightWidth = 128; // ### TODO: some people would surely like to have 128x128
47 if (img.width() > maxHeightWidth || img.height() > maxHeightWidth) {
48 img = img.scaled(maxHeightWidth, maxHeightWidth, Qt::KeepAspectRatio, Qt::SmoothTransformation);
49 }
50 m_pixmap = QPixmap::fromImage(img);
51 return m_pixmap;
52 }
53 else { // relative path
54
55
56 // each template folder should have a light and dark version of the icon that will be for light and dark themes
57 QString themePrefix;
59 themePrefix = "dark_";
60 } else {
61 themePrefix = "light_";
62 }
63
64
65 QString filenameBuilder = themePrefix.append(m_picture).append(".png");
66 QString filename = KoResourcePaths::findAsset("kis_pics", filenameBuilder);
67
68 if (filename.isEmpty()) {
69
70 }
71 m_pixmap = QPixmap(filename);
72 return m_pixmap;
73 }
74}
75
KisTemplate(const QString &name, const QString &description=QString(), const QString &file=QString(), const QString &picture=QString(), const QString &fileName=QString(), const QString &_measureSystem=QString(), bool hidden=false, bool touched=false)
QString m_picture
Definition KisTemplate.h:64
const QPixmap & loadPicture()
QPixmap m_pixmap
Definition KisTemplate.h:68
static QString findAsset(const QString &type, const QString &fileName)
#define dbgKrita
Definition kis_debug.h:45