Scribus
Open source desktop publishing at your fingertips
vgradient.h
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 /* This file is part of the KDE project
8  Copyright (C) 2002, The Karbon Developers
9 
10  This library is free software; you can redistribute it and/or
11  modify it under the terms of the GNU Library General Public
12  License as published by the Free Software Foundation; either
13  version 2 of the License, or (at your option) any later version.
14 
15  This library is distributed in the hope that it will be useful,
16  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18  Library General Public License for more details.
19 
20  You should have received a copy of the GNU Library General Public License
21  along with this library; see the file COPYING.LIB. If not, write to
22  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
23  Boston, MA 02110-1301, USA.
24 */
25 
26 #ifndef __VGRADIENT_H__
27 #define __VGRADIENT_H__
28 
29 #include <QColor>
30 #include <QList>
31 #include <QTransform>
32 
33 #include "fpoint.h"
34 #include "scribusapi.h"
35 
36 class SCRIBUS_API VColorStop
37 {
38 public:
39  VColorStop( double r, double m, QColor c, double o, QString n, int s )
40  {
41  rampPoint = r;
42  midPoint = m;
43  color = c;
44  opacity = o;
45  name = n;
46  shade = s;
47  };
48 
49  VColorStop( const VColorStop& colorStop )
50  {
51  rampPoint = colorStop.rampPoint;
52  midPoint = colorStop.midPoint;
53  color = colorStop.color;
54  opacity = colorStop.opacity;
55  name = colorStop.name;
56  shade = colorStop.shade;
57  };
58 
59  QColor color;
60 
61  // relative position of color point (0.0-1.0):
62  double rampPoint;
63 
64  // relative position of midpoint (0.0-1.0)
65  // between two ramp points. ignored for last VColorStop.
66  double midPoint;
67  double opacity;
68  int shade;
69  QString name;
70  friend inline bool operator== ( VColorStop& s1, VColorStop& s2 )
71  { return s1.rampPoint == s2.rampPoint; };
72 }
73 ; // VColorStop
74 
75 // comparison function for use with stable_sort
76 bool compareStops( const VColorStop* item1, const VColorStop* item2 );
77 
78 class SCRIBUS_API VGradient
79 {
80  // friend class VGradientWidget;
81 
82 public:
83  enum VGradientType
84  {
85  linear = 0,
86  radial = 1,
87  fourcolor = 2,
88  diamond = 3,
89  mesh = 4,
90  freemesh = 5
91  };
92 
93  enum VGradientRepeatMethod
94  {
95  none = 0,
96  reflect = 1,
97  repeat = 2,
98  pad = 3
99  };
100 
101  VGradient( VGradientType type = linear );
102  VGradient( const VGradient& gradient );
103  ~VGradient();
104 
105  VGradient& operator=(const VGradient& gradient);
106  bool operator==(const VGradient& gradient) const;
107 
108  VGradientType type() const { return m_type; }
109  void setType( VGradientType type ) { m_type = type; }
110 
111  VGradientRepeatMethod repeatMethod() const { return m_repeatMethod; }
112  void setRepeatMethod( VGradientRepeatMethod repeatMethod ) { m_repeatMethod = repeatMethod; }
113 
114  const QList<VColorStop*>& colorStops() const;
115  void addStop( const VColorStop& colorStop );
116  void addStop( const QColor &color, double rampPoint, double midPoint, double opa, QString name = "", int shade = 100 );
117  void setStop( const QColor &color, double rampPoint, double midPoint, double opa, QString name = "", int shade = 100 );
118  void removeStop( VColorStop& colorStop );
119  void removeStop( uint n );
120  void clearStops();
121  uint Stops() const { return m_colorStops.count(); }
122 
123  // This function let only one stop with offset value equal to 0 and 1.0
124  // by removing the firsts with 0.0 value and the lasts with 1.0 value;
125  void filterStops(void);
126 
127  FPoint origin() const { return m_origin; }
128  void setOrigin( const FPoint &origin ) { m_origin = origin; }
129 
130  FPoint focalPoint() const { return m_focalPoint; }
131  void setFocalPoint( const FPoint &focalPoint ) { m_focalPoint = focalPoint; }
132 
133  FPoint vector() const { return m_vector; }
134  void setVector( const FPoint &vector ) { m_vector = vector; }
135 
136  void transform( const QTransform& m );
137 
138 protected:
139  QList<VColorStop*> m_colorStops;
140 
141  int compareItems(const VColorStop* item1, const VColorStop* item2 ) const;
142  void inSort( VColorStop* d );
143 
144 private:
145  VGradientType m_type;
146  VGradientRepeatMethod m_repeatMethod : 3;
147 
148  // coordinates:
149  FPoint m_origin;
150  FPoint m_focalPoint;
151  FPoint m_vector;
152 }
153 ; // VGradient
154 
155 #endif /* __VGRADIENT_H__ */
Definition: vgradient.h:36
Definition: vgradient.h:78
A point with floating point precision.
Definition: fpoint.h:43