Warning, file /office/calligra/libs/pigment/KoColor.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 /*
0002  *  Copyright (c) 2005 Boudewijn Rempt <boud@valdyas.org>
0003  *  Copyright (C) 2007 Thomas Zander <zander@kde.org>
0004  *
0005  * This library is free software; you can redistribute it and/or
0006  * modify it under the terms of the GNU Library General Public
0007  * License as published by the Free Software Foundation; either
0008  * version 2 of the License, or (at your option) any later version.
0009  *
0010  * This library is distributed in the hope that it will be useful,
0011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
0012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0013  * Library General Public License for more details.
0014  *
0015  * You should have received a copy of the GNU Library General Public License
0016  * along with this library; see the file COPYING.LIB.  If not, write to
0017  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0018  * Boston, MA 02110-1301, USA.
0019 */
0020 #ifndef KOCOLOR_H
0021 #define KOCOLOR_H
0022 
0023 #include <QColor>
0024 #include <QMetaType>
0025 #include "pigment_export.h"
0026 #include "KoColorConversionTransformation.h"
0027 
0028 
0029 class QDomDocument;
0030 class QDomElement;
0031 
0032 class KoColorProfile;
0033 class KoColorSpace;
0034 
0035 /**
0036  * A KoColor describes a color in a certain colorspace. The color is stored in a buffer
0037  * that can be manipulated by the function of the color space.
0038  */
0039 class PIGMENTCMS_EXPORT KoColor
0040 {
0041 
0042 public:
0043     /// Create an empty KoColor. It will be valid, but also black and transparent
0044     KoColor();
0045 
0046     ~KoColor();
0047 
0048     /// Create a null KoColor. It will be valid, but all channels will be set to 0
0049     explicit KoColor(const KoColorSpace * colorSpace);
0050     /// Create a KoColor from a QColor. The QColor is immediately converted to native. The QColor
0051     /// is assumed to have the current monitor profile.
0052     KoColor(const QColor & color, const KoColorSpace * colorSpace);
0053 
0054     /// Create a KoColor using a native color strategy. The data is copied.
0055     KoColor(const quint8 * data, const KoColorSpace * colorSpace);
0056 
0057     /// Create a KoColor by converting src into another colorspace
0058     KoColor(const KoColor &src, const KoColorSpace * colorSpace);
0059 
0060     /// Copy constructor -- deep copies the colors.
0061     KoColor(const KoColor & rhs);
0062 
0063     /**
0064      * assignment operator to copy the data from the param color into this one.
0065      * @param other the color we are going to copy
0066      * @return this color
0067      */
0068     KoColor &operator=(const KoColor &other);
0069 
0070     bool operator==(const KoColor &other) const;
0071 
0072     /// return the current colorSpace
0073     const KoColorSpace * colorSpace() const;
0074 
0075     /// return the current profile
0076     const KoColorProfile *  profile() const;
0077 
0078     /// Convert this KoColor to the specified colorspace. If the specified colorspace is the
0079     /// same as the original colorspace, do nothing. Returns the converted KoColor.
0080     void convertTo(const KoColorSpace * cs,
0081                    KoColorConversionTransformation::Intent renderingIntent,
0082                    KoColorConversionTransformation::ConversionFlags conversionFlags);
0083 
0084     void convertTo(const KoColorSpace * cs);
0085 
0086 
0087     /// Replace the existing color data, and colorspace with the specified data.
0088     /// The data is copied.
0089     void setColor(const quint8 * data, const KoColorSpace * colorSpace = 0);
0090 
0091     /// Convert the color from src and replace the value of the current color with the converted data.
0092     /// Don't convert the color if src and this have the same colorspace.
0093     void fromKoColor(const KoColor& src);
0094 
0095     /// a convenience method for the above.
0096     void toQColor(QColor *c) const;
0097     /// a convenience method for the above.
0098     QColor toQColor() const;
0099 
0100     /**
0101      * Convenient function to set the opacity of the color.
0102      */
0103     void setOpacity(quint8 alpha);
0104     void setOpacity(qreal alpha);
0105     /**
0106      * Convenient function that return the opacity of the color
0107      */
0108     quint8 opacityU8() const;
0109     qreal opacityF() const;
0110 
0111 // what about making the next two methods static factory methods?
0112     /// Convenient function for converting from a QColor
0113     void fromQColor(const QColor& c) const;
0114 
0115     /**
0116      * @return the buffer associated with this color object to be used with the
0117      *         transformation object created by the color space of this KoColor
0118      *         or to copy to a different buffer from the same color space
0119      */
0120     quint8 * data();
0121 
0122     /**
0123      * @return the buffer associated with this color object to be used with the
0124      *         transformation object created by the color space of this KoColor
0125      *         or to copy to a different buffer from the same color space
0126      */
0127     const quint8 * data() const;
0128 
0129     /**
0130      * Serialize this color following Create's swatch color specification available
0131      * at http://create.freedesktop.org/wiki/index.php/Swatches_-_colour_file_format
0132      *
0133      * This function doesn't create the <color /> element but rather the <CMYK />,
0134      * <sRGB />, <RGB /> ... elements. It is assumed that colorElt is the <color />
0135      * element.
0136      *
0137      * @param colorElt root element for the serialization, it is assumed that this
0138      *                 element is <color />
0139      * @param doc is the document containing colorElt
0140      */
0141     void toXML(QDomDocument& doc, QDomElement& colorElt) const;
0142 
0143     /**
0144      * Unserialize a color following Create's swatch color specification available
0145      * at http://create.freedesktop.org/wiki/index.php/Swatches_-_colour_file_format
0146      *
0147      * @param elt the element to unserialize (<CMYK />, <sRGB />, <RGB />)
0148      * @param bitDepthId the bit depth is unspecified by the spec, this allow to select
0149      *                   a preferred bit depth for creating the KoColor object (if that
0150      *                   bit depth isn't available, this function will randomly select
0151      *                   an other bit depth)
0152      * @param profileAliases alias between the profile name specified by the "space"
0153      *                       attribute and the profile name used inside pigment
0154      * @return the unserialize color, or an empty color object if the function failed
0155      *         to unserialize the color
0156      */
0157     static KoColor fromXML(const QDomElement& elt, const QString & bitDepthId, const QHash<QString, QString> & aliases);
0158 
0159     static QString toQString(const KoColor &color);
0160 
0161 #ifndef NODEBUG
0162     /// use qDebug calls to print internal info
0163     void dump() const;
0164 #endif
0165 
0166 private:
0167     class Private;
0168     Private * const d;
0169 };
0170 
0171 Q_DECLARE_METATYPE(KoColor)
0172 
0173 #endif