~ubuntu-branches/ubuntu/breezy/koffice/breezy

« back to all changes in this revision

Viewing changes to lib/kopainter/koColor.h

  • Committer: Bazaar Package Importer
  • Author(s): Ben Burton
  • Date: 2004-05-09 11:33:00 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20040509113300-vfrdadqsvjfuhn3b
Tags: 1:1.3.1-1
* New upstream bugfix release.
* Built against newer imagemagick (closes: #246623).
* Made koffice-libs/kformula recommend/depend on latex-xft-fonts, which
  provides mathematical fonts that the formula editor can use.  Also
  patched the kformula part to make these fonts the default.
* Changed kword menu hint from "WordProcessors" to "Word processors"
  (closes: #246209).
* Spellchecker configuration is now fixed (closes: #221256, #227568).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* This file is part of the KDE project
 
2
  Copyright (c) 1999 Matthias Elter (me@kde.org)
 
3
  Copyright (c) 2001-2002 Igor Jansen (rm@kde.org)
 
4
 
 
5
   This library is free software; you can redistribute it and/or
 
6
   modify it under the terms of the GNU Library General Public
 
7
   License as published by the Free Software Foundation; either
 
8
   version 2 of the License, or (at your option) any later version.
 
9
 
 
10
   This library is distributed in the hope that it will be useful,
 
11
   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
13
   Library General Public License for more details.
 
14
 
 
15
   You should have received a copy of the GNU Library General Public License
 
16
   along with this library; see the file COPYING.LIB.  If not, write to
 
17
   the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 
18
   Boston, MA 02111-1307, USA.
 
19
*/
 
20
 
 
21
#ifndef __ko_color_h__
 
22
#define __ko_color_h__
 
23
 
 
24
#include <qcolor.h>
 
25
 
 
26
class KoColor
 
27
{
 
28
public:
 
29
  enum cSpace{ csIndexed, csRGB, csHSV, csCMYK, csLab };
 
30
 
 
31
  KoColor();
 
32
  KoColor(int a, int b, int c,  cSpace m = csRGB);
 
33
  KoColor(int c, int m, int y,  int k);
 
34
  KoColor(const QString &name);
 
35
  KoColor(const QColor &c);
 
36
 
 
37
  cSpace native() const {return mNative; }
 
38
 
 
39
  int R() const;
 
40
  int G() const;
 
41
  int B() const;
 
42
  int H() const;
 
43
  int S() const;
 
44
  int V() const;
 
45
  int L() const;
 
46
  int a() const;
 
47
  int b() const;
 
48
  int C() const;
 
49
  int M() const;
 
50
  int Y() const;
 
51
  int K() const;
 
52
 
 
53
  void rgb(int *R, int *G, int *B) const;
 
54
  void hsv(int *H, int *S, int *V) const;
 
55
  void lab(int *L, int *a, int *b) const;
 
56
  void cmyk(int *C, int *M, int *Y, int *K) const;
 
57
  QString name() const;
 
58
  QColor color() const;
 
59
 
 
60
  void setRGB(int R, int G, int B);
 
61
  void setHSV(int H, int S, int V);
 
62
  void setLab(int L, int a, int b);
 
63
  void setCMYK(int C, int M, int Y, int K);
 
64
  void setNamedColor(const QString &name);
 
65
  void setColor(const QColor &c);
 
66
  
 
67
  static void RGBtoHSV(int R, int G, int B, int *H, int *S, int *V);
 
68
  static void RGBtoLAB(int R, int G, int B, int *L, int *a, int *b);
 
69
  static void RGBtoCMYK(int R, int G, int B, int *C, int *M, int *Y, int *K);
 
70
 
 
71
  static void HSVtoRGB(int H, int S, int V, int *R, int *G, int *B);
 
72
  static void HSVtoLAB(int H, int S, int V, int *L, int *a, int *b);
 
73
  static void HSVtoCMYK(int H, int S, int V, int *C, int *M, int *Y, int*K);
 
74
 
 
75
  static void LABtoRGB(int L, int a, int b, int *R, int *G, int *B);
 
76
  static void LABtoHSV(int L, int a, int b, int *H, int *S, int *V);
 
77
  static void LABtoCMYK(int L, int a, int b, int *C, int *M, int *Y, int*K);
 
78
 
 
79
  static void CMYKtoRGB(int C, int M, int Y, int K, int *R, int *G, int *B);
 
80
  static void CMYKtoHSV(int C, int M, int Y, int K, int *H, int *S, int *V);
 
81
  static void CMYKtoLAB(int C, int M, int Y, int K, int *L, int *a, int *b);
 
82
 
 
83
  static const KoColor black();
 
84
  static const KoColor white();
 
85
  static const KoColor gray();
 
86
  static const KoColor lightGray();
 
87
  static const KoColor darkGray();
 
88
  static const KoColor red();
 
89
  static const KoColor darkRed();
 
90
  static const KoColor green();
 
91
  static const KoColor darkGreen();
 
92
  static const KoColor blue();
 
93
  static const KoColor darkBlue();
 
94
  static const KoColor cyan();
 
95
  static const KoColor darkCyan();
 
96
  static const KoColor magenta();
 
97
  static const KoColor darkMagenta();
 
98
  static const KoColor yellow();
 
99
  static const KoColor darkYellow();
 
100
 
 
101
protected:
 
102
  int hex2int(QChar c);
 
103
 
 
104
  void calcRGB() const;
 
105
  void calcHSV() const;
 
106
  void calcCMYK() const;
 
107
  void calcLAB() const;
 
108
 
 
109
  void rgbChanged() const;
 
110
  void hsvChanged() const;
 
111
  void cmykChanged() const;
 
112
  void labChanged() const;
 
113
 
 
114
private:
 
115
  /*
 
116
   * Mutable to make it possible for const objects to transform the native cModel
 
117
   * in functions like KoColor::rgb(...) to the requested.
 
118
   */
 
119
  mutable int mR, mG, mB;        // RGB
 
120
  mutable int mC, mM, mY, mK;    // CMYK
 
121
  mutable int mH, mS, mV;        // HSV
 
122
  mutable int mL, ma, mb;        // LAB
 
123
 
 
124
  mutable bool mRGBvalid;
 
125
  mutable bool mHSVvalid;
 
126
  mutable bool mCMYKvalid;
 
127
  mutable bool mLABvalid;
 
128
 
 
129
  cSpace mNative; 
 
130
};
 
131
 
 
132
inline const KoColor KoColor::white()
 
133
{
 
134
  return KoColor(255, 255, 255, csRGB);
 
135
}
 
136
 
 
137
inline const KoColor KoColor::black()
 
138
{
 
139
  return KoColor(0, 0, 0, csRGB);
 
140
}
 
141
 
 
142
inline const KoColor KoColor::gray()
 
143
{
 
144
  return KoColor(160, 160, 164, csRGB);
 
145
}
 
146
 
 
147
inline const KoColor KoColor::lightGray()
 
148
{
 
149
  return KoColor(192, 192, 192, csRGB);
 
150
}
 
151
 
 
152
inline const KoColor KoColor::darkGray()
 
153
{
 
154
  return KoColor(128, 128, 128, csRGB);
 
155
}
 
156
 
 
157
inline const KoColor KoColor::red()
 
158
{
 
159
  return KoColor(255, 0, 0, csRGB);
 
160
}
 
161
 
 
162
inline const KoColor KoColor::darkRed()
 
163
{
 
164
  return KoColor(128, 0, 0, csRGB);
 
165
}
 
166
 
 
167
inline const KoColor KoColor::green()
 
168
{
 
169
  return KoColor(0, 255, 0, csRGB);
 
170
}
 
171
 
 
172
inline const KoColor KoColor::darkGreen()
 
173
{
 
174
  return KoColor(0, 128, 0, csRGB);
 
175
}
 
176
 
 
177
inline const KoColor KoColor::blue()
 
178
{
 
179
  return KoColor(0, 0, 255, csRGB);
 
180
}
 
181
 
 
182
inline const KoColor KoColor::darkBlue()
 
183
{
 
184
  return KoColor(0, 0, 128, csRGB);
 
185
}
 
186
 
 
187
inline const KoColor KoColor::cyan()
 
188
{
 
189
  return KoColor(0, 255, 255, csRGB);
 
190
}
 
191
 
 
192
inline const KoColor KoColor::darkCyan()
 
193
{
 
194
  return KoColor(0, 128, 128, csRGB);
 
195
}
 
196
 
 
197
inline const KoColor KoColor::magenta()
 
198
{
 
199
  return KoColor(255, 0, 255, csRGB);
 
200
}
 
201
 
 
202
inline const KoColor KoColor::darkMagenta()
 
203
{
 
204
  return KoColor(128, 0, 128, csRGB);
 
205
}
 
206
 
 
207
inline const KoColor KoColor::yellow()
 
208
{
 
209
  return KoColor(255, 255, 0, csRGB);
 
210
}
 
211
 
 
212
inline const KoColor KoColor::darkYellow()
 
213
{
 
214
  return KoColor(128, 128, 0, csRGB);
 
215
}
 
216
 
 
217
#endif