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

0001 /*
0002  * This file is part of the KDE project
0003  *
0004  * SPDX-FileCopyrightText: 2005 Boudewijn Rempt <boud@valdyas.org>
0005  *
0006  * SPDX-License-Identifier: GPL-2.0-or-later
0007  */
0008 
0009 /**
0010  * @file kis_annotation.h
0011  * @brief This file is part of the Krita application in calligra
0012  * @author Boudewijn Rempt
0013  * @author comments by hscott
0014  * @since 1.4 or 2005
0015  */
0016 
0017 #ifndef _KIS_ANNOTATION_H_
0018 #define _KIS_ANNOTATION_H_
0019 
0020 #include <kis_shared.h>
0021 
0022 #include <QByteArray>
0023 #include <QString>
0024 
0025 #include "kritaimage_export.h"
0026 
0027 /**
0028  * @class KisAnnotation
0029  * @brief A data extension mechanism for Krita.
0030  *
0031  * An annotation can be of something like a QByteArray or a QString or
0032  * a more specific datatype that can be attached to an image (or maybe
0033  * later, if needed, to a layer) and contains data that must be
0034  * associated with an image for purposes of import/export.
0035  *
0036  * Annotations will be saved to krita images and may be exported in
0037  * filetypes that support them.
0038  *
0039  * Examples of annotations are EXIF data and ICC profiles.
0040  */
0041 class KRITAIMAGE_EXPORT KisAnnotation : public KisShared
0042 {
0043 
0044 public:
0045 
0046     /**
0047      * creates a new annotation object. The annotation object cannot
0048      * be changed later.
0049      *
0050      * @param type a non-localized string identifying the type of the
0051      * annotation. There can only be one annotation of a given type attached
0052      * to an image.
0053      * @param description a localized string describing the annotation
0054      * @param data a binary blob containing the annotation data
0055      */
0056     KisAnnotation(const QString & type, const QString & description, const QByteArray & data)
0057         : m_type(type)
0058         , m_description(description)
0059         , m_annotation(data) {}
0060 
0061     virtual ~KisAnnotation() {}
0062 
0063     virtual KisAnnotation* clone() const {
0064         return new KisAnnotation(*this);
0065     }
0066 
0067     /**
0068      * gets a non-localized string identifying the type of the
0069      * annotation.
0070      * @return a non-localized string identifiying the type of the
0071      * annotation
0072      */
0073     const QString & type() const {
0074         return m_type;
0075     }
0076 
0077     /**
0078      * gets a localized string describing the type of annotations for
0079      * used interface purposes.
0080      * @return a localized string describing the type of the
0081      * annotations for user interface purposes.
0082      */
0083     const QString & description() const {
0084         return m_description;
0085     }
0086 
0087     /**
0088      * gets a binary blob representation of this annotation
0089      * @return a binary blob representation of this annotation
0090      */
0091     const QByteArray & annotation() const {
0092         return m_annotation;
0093     }
0094 
0095     void setAnnotation(const QByteArray ba) {
0096         m_annotation = ba;
0097     }
0098 
0099     /**
0100      * @brief displayText: override this to return an interpreted version of the annotation
0101      */
0102     virtual QString displayText() const {
0103         return QString::fromUtf8(m_annotation);
0104     }
0105 
0106 protected:
0107     KisAnnotation(const KisAnnotation &rhs)
0108      : KisShared(),
0109        m_type(rhs.m_type),
0110        m_description(rhs.m_description),
0111        m_annotation(rhs.m_annotation)
0112     {
0113     }
0114 
0115 protected:
0116 
0117     QString m_type;
0118     QString m_description;
0119     QByteArray m_annotation;
0120 
0121 };
0122 
0123 #endif // _KIS_ANNOTATION_H_