1 /* 2 For general Scribus (>=1.3.2) copyright and licensing information please refer 3 to the COPYING file provided with the program. Following this notice may exist 4 a copyright and/or license notice that predates the release of Scribus 1.3.2 5 for which a new license (GPL+exception) is in place. 6 */ 7 /*************************************************************************** 8 sccolor.h - description 9 ------------------- 10 begin : Sun Sep 9 2001 11 copyright : (C) 2001 by Franz Schmid 12 email : Franz.Schmid@altmuehlnet.de 13 ***************************************************************************/ 14 15 /*************************************************************************** 16 * * 17 * This program is free software; you can redistribute it and/or modify * 18 * it under the terms of the GNU General Public License as published by * 19 * the Free Software Foundation; either version 2 of the License, or * 20 * (at your option) any later version. * 21 * * 22 ***************************************************************************/ 23 24 #ifndef SCCOLOR_H 25 #define SCCOLOR_H 26 27 #include <QColor> 28 #include <QMap> 29 #include <QPointer> 30 #include <QString> 31 32 #include "scribusapi.h" 33 34 class ScribusDoc; 35 struct RGBColorF; 36 37 /** 38 *@author Franz Schmid 39 * \brief This Class adds support for CMYK-Colors to Qt. 40 * its API is based on the API of QColor 41 */ 42 43 /** Scribus color models */ 44 enum colorModel 45 { 46 colorModelRGB, 47 colorModelCMYK, 48 colorModelLab 49 }; 50 51 class SCRIBUS_API ScColor 52 { 53 public: 54 55 friend class ScColorEngine; 56 57 /** \brief Constructs a ScColor with 4 Components set to 0 */ 58 ScColor(); 59 /** \brief Constructs a ScColor with 4 Components in the range from 0 - 255 */ 60 ScColor(int c, int m, int y, int k); 61 /** \brief Constructs a RGB color with 3 Components in the range from 0 - 255 */ 62 ScColor(int r, int g, int b); 63 /** \brief Constructs a Lab color with 3 Components */ 64 ScColor(double l, double a, double b); 65 66 bool operator==(const ScColor& other) const; 67 68 /** \brief Same as the Constructor but for an existing Color */ 69 void setColor(int c, int m, int y, int k); 70 71 /** \brief Same as the Constructor but for an existing Color */ 72 void setColorF(double c, double m, double y, double k); 73 74 /** \brief Define color as a CMYK color with specified values */ 75 void setCmykColor(int c, int m, int y, int k); 76 77 /** \brief Define color as a CMYK color with specified values */ 78 void setCmykColorF(double c, double m, double y, double k); 79 80 /** \brief Define color as a RGB color with specified values */ 81 void setRgbColor(int r, int g, int b); 82 83 /** \brief Define color as a RGB color with specified values */ 84 void setRgbColorF(double r, double g, double b); 85 86 /** \brief Define color as a Lab color with specified values */ 87 void setLabColor(double l, double a, double b); 88 89 /** \brief get the color model */ 90 colorModel getColorModel () const; 91 92 /** \brief Computes a ScColor for a QColor */ 93 void fromQColor(QColor color); 94 95 /** \brief Returns the RGB color 96 * Must not be called if color is the None Color. */ 97 void getRawRGBColor(RGBColorF* rgb) const; 98 void getRawRGBColor(int *r, int *g, int *b) const; 99 QColor getRawRGBColor() const; 100 101 /** \brief Returns the 4 Values that form an ScColor. 102 * Returns meaningful results only if color is a cmyk color. 103 * Must not be called if color is the None Color. */ 104 void getCMYK(int *c, int *m, int *y, int *k) const; 105 106 /** \brief Returns the 4 Values that form an ScColor. 107 * Returns meaningful results only if color is a cmyk color. 108 * Must not be called if color is the None Color. */ 109 void getCMYK(double *c, double *m, double *y, double *k) const; 110 111 /** \brief Returns the 3 Values that form an RGBColor 112 * Returns meaningful results only if color is a rgb color. 113 * Must not be called if color is the None Color. */ 114 void getRGB(int *r, int *g, int *b) const; 115 116 /** \brief Returns the 3 Values that form an RGBColor 117 * Returns meaningful results only if color is a rgb color. 118 * Must not be called if color is the None Color. */ 119 void getRGB(double *r, double *g, double *b) const; 120 121 /** \brief Returns the 3 Values that form an LabColor 122 * Returns meaningful results only if color is a Lab color. 123 * Must not be called if color is the None Color. */ 124 void getLab(double *L, double *a, double *b) const; 125 126 /** \brief Returns the ScColor as an Hex-String in the Form #CCYYMMKK for a CMYK color or ##RRGGBB for a RGB color. 127 * For the None color return the "None" string. */ 128 QString name() const; 129 /** \brief Returns the ScColor as an Hex-String in the Form #RRGGBB 130 * If doc member is not specified, return meaningful result only for RGB colors. */ 131 QString nameRGB(const ScribusDoc* doc = nullptr) const; 132 /** \brief Returns the ScColor as an Hex-String in the Form #CCYYMMKK 133 * If doc member is not specified, return meaningful result only for CMYK colors. */ 134 QString nameCMYK(const ScribusDoc* doc = nullptr) const; 135 136 /** \brief Sets the Values of a color from an Hex-String in the Form #CCMMYYKK or #RRGGBB */ 137 void setNamedColor(QString colorName); 138 139 /** \brief If the color is a process color (ie neither spot, nor registration) */ 140 bool isProcessColor() const; 141 /** \brief If the color is a spot color */ 142 bool isSpotColor() const; 143 /** \brief Set a color to be a spot color or not. No effect if color is the None color. */ 144 void setSpotColor(bool s); 145 /** \brief If the color is a registration color */ 146 bool isRegistrationColor() const; 147 /** \brief Set a color to be a registration color or not. No effect if color is the None color. */ 148 void setRegistrationColor(bool s); 149 150 private: 151 /** \brief Color values (depends of color model) */ 152 double m_values[4] {0.0, 0.0, 0.0, 0.0}; 153 /** \brief L component of Color */ 154 double m_L_val {0.0}; 155 /** \brief a component of Color */ 156 double m_a_val {0.0}; 157 /** \brief b component of Color */ 158 double m_b_val {0.0}; 159 160 /** \brief Flag, true if the Color is a Spotcolor */ 161 bool m_Spot {false}; 162 /** \brief Flag, true if the Color is a Registration color */ 163 bool m_Regist {false}; 164 /** \brief Color model of the current color */ 165 colorModel m_Model {colorModelRGB}; 166 }; 167 168 class SCRIBUS_API ColorList : public QMap<QString, ScColor> 169 { 170 protected: 171 QPointer<ScribusDoc> m_doc; 172 bool m_retainDoc; 173 174 /** \brief Ensure availability of black color. */ 175 void ensureBlack(); 176 177 /** \brief Ensure availability of white color. */ 178 void ensureWhite(); 179 180 /** \brief Ensure availability of registration color. */ 181 void ensureRegistration(); 182 183 public: 184 ColorList(ScribusDoc* doc = nullptr, bool retainDoc = false); 185 186 ColorList& operator= (const ColorList& list); 187 188 /** \brief Get the document the list is related , return in cpp due to scribusdoc class delcaration */ 189 ScribusDoc* document() const; 190 191 /** \brief Assign the doc to which the list belong to.*/ 192 void setDocument(ScribusDoc* doc); 193 194 /** \brief Add colors from the specified list. Colors are added using shadow copy.*/ 195 void addColors(const ColorList& colorList, bool overwrite = true); 196 197 /** \brief Copy colors from the specified list.*/ 198 void copyColors(const ColorList& colorList, bool overwrite = true); 199 200 /** \brief Ensure availability of black and white colors. */ 201 void ensureDefaultColors(); 202 203 /** \brief Try to add ScColor col to the list, if col already exists either by name or by value the existing color name is returned. */ 204 QString tryAddColor(QString name, ScColor col); 205 }; 206 207 #endif 208