Scribus
Open source desktop publishing at your fingertips
vgradientex.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 __VGRADIENTEX_H__
27 #define __VGRADIENTEX_H__
28 
29 #include <QList>
30 #include <QTransform>
31 
32 #include "fpoint.h"
33 #include "sccolor.h"
34 #include "scribusapi.h"
35 class ScribusDoc;
36 class VGradient;
37 
38 class SCRIBUS_API VColorStopEx
39 {
40 public:
41  VColorStopEx( double r, double m, ScColor c, double o, QString n, int s )
42  {
43  rampPoint = r;
44  midPoint = m;
45  color = c;
46  opacity = o;
47  name = n;
48  shade = s;
49  };
50 
51  VColorStopEx( const VColorStopEx& colorStop )
52  {
53  rampPoint = colorStop.rampPoint;
54  midPoint = colorStop.midPoint;
55  color = colorStop.color;
56  opacity = colorStop.opacity;
57  name = colorStop.name;
58  shade = colorStop.shade;
59  };
60 
61  ScColor color;
62 
63  // relative position of color point (0.0-1.0):
64  double rampPoint;
65 
66  // relative position of midpoint (0.0-1.0)
67  // between two ramp points. ignored for last VColorStop.
68  double midPoint;
69  double opacity;
70  int shade;
71  QString name;
72  friend inline bool operator== ( VColorStopEx& s1, VColorStopEx& s2 )
73  { return s1.rampPoint == s2.rampPoint; };
74 }
75 ; // VColorStopEx
76 
77 // comparison function for use with stable_sort
78 bool compareStopsEx( const VColorStopEx* item1, const VColorStopEx* item2 );
79 
80 class SCRIBUS_API VGradientEx
81 {
82  // friend class VGradientWidget;
83 
84 public:
85  enum Type
86  {
87  linear = 0,
88  radial = 1,
89  fourcolor = 2,
90  diamond = 3,
91  mesh = 4,
92  freemesh = 5
93  };
94 
95  enum RepeatMethod
96  {
97  none = 0,
98  reflect = 1,
99  repeat = 2,
100  pad = 3
101  };
102 
103  VGradientEx( VGradientEx::Type type = linear );
104  VGradientEx( const VGradientEx& gradient );
105  VGradientEx( const VGradient& gradient, ScribusDoc& doc );
106  ~VGradientEx();
107 
108  VGradientEx& operator=(const VGradientEx& gradient);
109 
110  VGradientEx::Type type() const { return m_type; }
111  void setType( VGradientEx::Type type ) { m_type = type; }
112 
113  VGradientEx::RepeatMethod repeatMethod() const { return m_repeatMethod; }
114  void setRepeatMethod( VGradientEx::RepeatMethod repeatMethod ) { m_repeatMethod = repeatMethod; }
115 
116  const QList<VColorStopEx*> colorStops() const;
117  void addStop( const VColorStopEx& colorStop );
118  void addStop( const ScColor &color, double rampPoint, double midPoint, double opa, QString name = "", int shade = 100 );
119  void removeStop( VColorStopEx& colorStop );
120  void removeStop( uint n );
121  void clearStops();
122  uint Stops() { return m_colorStops.count(); }
123 
124  FPoint origin() const { return m_origin; }
125  void setOrigin( const FPoint &origin ) { m_origin = origin; }
126 
127  FPoint focalPoint() const { return m_focalPoint; }
128  void setFocalPoint( const FPoint &focalPoint ) { m_focalPoint = focalPoint; }
129 
130  FPoint vector() const { return m_vector; }
131  void setVector( const FPoint &vector ) { m_vector = vector; }
132 
133  void transform( const QTransform& m );
134 
135 protected:
136  QList<VColorStopEx*> m_colorStops;
137 
138  int compareItems( const VColorStopEx* item1, const VColorStopEx* item2 ) const;
139  void inSort( VColorStopEx* d );
140 
141 private:
142  VGradientEx::Type m_type;
143  VGradientEx::RepeatMethod m_repeatMethod : 3;
144 
145  // coordinates:
146  FPoint m_origin;
147  FPoint m_focalPoint;
148  FPoint m_vector;
149 }
150 ; // VGradientEx
151 
152 #endif /* __VGRADIENT_H__ */
Definition: sccolor.h:51
Definition: vgradientex.h:38
Definition: vgradient.h:78
A point with floating point precision.
Definition: fpoint.h:43
the Document Class
Definition: scribusdoc.h:90
Definition: vgradientex.h:80