File indexing completed on 2024-05-12 15:59:07

0001 /*
0002  *  SPDX-FileCopyrightText: 2016 Boudewijn Rempt <boud@valdyas.org>
0003  *
0004  *  SPDX-License-Identifier: LGPL-2.0-or-later
0005  */
0006 #ifndef LIBKIS_RESOURCE_H
0007 #define LIBKIS_RESOURCE_H
0008 
0009 #include <QObject>
0010 #include <QScopedPointer>
0011 #include <kis_types.h>
0012 #include "kritalibkis_export.h"
0013 #include "libkis.h"
0014 #include <KoResource.h>
0015 
0016 /**
0017  * A Resource represents a gradient, pattern, brush tip, brush preset, palette or 
0018  * workspace definition.
0019  * 
0020  * @code
0021  * allPresets = Application.resources("preset")
0022  * for preset in allPresets:
0023  *     print(preset.name())
0024  * @endcode
0025  * 
0026  * Resources are identified by their type, name and filename. If you want to change
0027  * the contents of a resource, you should read its data using data(), parse it and
0028  * write the changed contents back.
0029  */
0030 class KRITALIBKIS_EXPORT Resource : public QObject
0031 {
0032     Q_OBJECT
0033 
0034 public:
0035     Resource(int resourceId, const QString &type, const QString &name, const QString &filename, const QImage &image, QObject *parent = 0);
0036     Resource(KoResourceSP resource, const QString &type, QObject *parent = 0);
0037     ~Resource() override;
0038     Resource(const Resource &rhs);
0039 
0040     bool operator==(const Resource &other) const;
0041     bool operator!=(const Resource &other) const;
0042     Resource operator=(const Resource &rhs);
0043 
0044 
0045 public Q_SLOTS:
0046     
0047     /**
0048      * Return the type of this resource. Valid types are:
0049      * <ul>
0050      * <li>pattern: a raster image representing a pattern
0051      * <li>gradient: a gradient
0052      * <li>brush: a brush tip
0053      * <li>preset: a brush preset
0054      * <li>palette: a color set
0055      * <li>workspace: a workspace definition.
0056      * </ul>
0057      */
0058     QString type() const;
0059 
0060     /**
0061      * The user-visible name of the resource.
0062      */
0063     QString name() const;
0064     
0065     /**
0066      * setName changes the user-visible name of the current resource.
0067      */
0068     void setName(QString value);
0069 
0070     /**
0071      * The filename of the resource, if present. Not all resources
0072      * are loaded from files.
0073      */
0074     QString filename() const;
0075 
0076     /**
0077      * An image that can be used to represent the resource in the
0078      * user interface. For some resources, like patterns, the 
0079      * image is identical to the resource, for others it's a mere
0080      * icon.
0081      */
0082     QImage image() const;
0083     
0084     /**
0085      * Change the image for this resource.
0086      */
0087     void setImage(QImage image);
0088 
0089 private:
0090 
0091     friend class PresetChooser;
0092     friend class View;
0093     friend class Palette;
0094     KoResourceSP resource() const;
0095 
0096     struct Private;
0097     QScopedPointer<Private> d;
0098 
0099 };
0100 
0101 #endif // LIBKIS_RESOURCE_H