Krita

Resource.cpp
1/*
2 * SPDX-FileCopyrightText: 2016 Boudewijn Rempt <boud@valdyas.org>
3 *
4 * SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6#include "Resource.h"
7#include <KoResource.h>
8#include <QByteArray>
9#include <QBuffer>
10
11#include <KoPattern.h>
12#include <KoAbstractGradient.h>
13#include <kis_brush.h>
14#include <kis_paintop_preset.h>
15#include <KoColorSet.h>
16#include <kis_workspace_resource.h>
17#include <KisResourceLocator.h>
18
19struct Resource::Private {
20 Private() {}
21
22 int id {-1};
23 QString type;
24 QString name;
25 QString filename;
26 QImage image;
27};
28
29Resource::Resource(int resourceId, const QString &type, const QString &name, const QString &filename, const QImage &image, QObject *parent)
30 : QObject(parent)
31 , d(new Private())
32{
33 d->id = resourceId;
34 d->type = type;
35 d->name = name;
36 d->filename = filename;
37 d->image = image;
38}
39
40Resource::Resource(KoResourceSP resource, const QString &type, QObject *parent)
41 : QObject(parent)
42 , d(new Private())
43{
44 d->id = resource->resourceId();
45 d->type = type;
46 d->name = resource->name();
47 d->filename = resource->filename();
48 d->image = resource->image();
49}
50
51Resource::~Resource()
52{
53}
54
55Resource::Resource(const Resource &rhs)
56 : QObject()
57 , d(new Private())
58{
59 d->id = rhs.d->id;
60 d->type = rhs.d->type;
61 d->name = rhs.d->name;
62 d->filename = rhs.d->filename;
63 d->image = rhs.d->image;
64}
65
66bool Resource::operator==(const Resource &other) const
67{
68 return (d->id == other.d->id);
69}
70
71bool Resource::operator!=(const Resource &other) const
72{
73 return !(operator==(other));
74}
75
76Resource Resource::operator=(const Resource &rhs)
77{
78 Resource res(rhs.d->id,
79 rhs.d->type,
80 rhs.d->name,
81 rhs.d->filename,
82 rhs.d->image);
83 return res;
84}
85
87{
88 return d->type;
89}
90
92{
93 return d->name;
94}
95
97{
98 d->name = value;
99}
100
102{
103 return d->filename;
104}
105
106
108{
109 return d->image;
110}
111
113{
114 d->image = image;
115}
116
117KoResourceSP Resource::resource() const
118{
119 KoResourceSP res = KisResourceLocator::instance()->resourceForId(d->id);
120 Q_ASSERT(res);
121 return res;
122}
123
124
125
126
127
128
A Resource represents a gradient, pattern, brush tip, brush preset, palette or workspace definition.
Definition Resource.h:31
QString name() const
The user-visible name of the resource.
Definition Resource.cpp:91
void setName(QString value)
setName changes the user-visible name of the current resource.
Definition Resource.cpp:96
QString type() const
Return the type of this resource.
Definition Resource.cpp:86
QImage image() const
An image that can be used to represent the resource in the user interface.
Definition Resource.cpp:107
QString filename() const
The filename of the resource, if present.
Definition Resource.cpp:101
void setImage(QImage image)
Change the image for this resource.
Definition Resource.cpp:112
QString name(GameStandardAction id)
VehicleSection::Type type(QStringView coachNumber, QStringView coachClassification)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Nov 22 2024 12:06:52 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.