karbon

vgradient.h
1/* This file is part of the KDE project
2 Copyright (C) 2002 - 2005, The Karbon Developers
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License as published by the Free Software Foundation; either
7 version 2 of the License, or (at your option) any later version.
8
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18*/
19
20#ifndef __VGRADIENT_H__
21#define __VGRADIENT_H__
22
23#include <tqptrlist.h>
24#include <tqptrvector.h>
25
26#include <koffice_export.h>
27#include <KoPoint.h>
28
29#include "vcolor.h"
30
31class TQDomElement;
32class KoGenStyle;
33class KoGenStyles;
34class KoStyleStack;
35class VObject;
36
37class VColorStop
38{
39 public:
40 VColorStop( double r, double m, VColor c )
41 { rampPoint = r; midPoint = m; color = c; };
42 VColorStop( const VColorStop& colorStop )
43 { rampPoint = colorStop.rampPoint; midPoint = colorStop.midPoint; color = colorStop.color; };
44
45 VColor color;
46
47 // relative position of color point (0.0-1.0):
48 float rampPoint;
49
50 // relative position of midpoint (0.0-1.0)
51 // between two ramp points. ignored for last VColorStop.
52 float midPoint;
53
54 friend inline bool operator== ( VColorStop& s1, VColorStop& s2 )
55 { return s1.rampPoint == s2.rampPoint; };
56}; // VColorStop
57
58class KARBONBASE_EXPORT VGradient
59{
60friend class VGradientWidget;
61
62public:
63 enum VGradientType
64 {
65 linear = 0,
66 radial = 1,
67 conic = 2
68 };
69
70 enum VGradientRepeatMethod
71 {
72 none = 0,
73 reflect = 1,
74 repeat = 2
75 };
76
77 class VColorStopList : public TQPtrList<VColorStop>
78 {
79 protected:
80 virtual int compareItems( TQPtrCollection::Item item1, TQPtrCollection::Item item2 );
81 }; // VColorStopList
82
83 VGradient( VGradientType type = linear );
84 VGradient( const VGradient& gradient );
85
86 VGradient& operator=(const VGradient& gradient);
87
88 VGradientType type() const { return m_type; }
89 void setType( VGradientType type ) { m_type = type; }
90
91 VGradientRepeatMethod repeatMethod() const { return m_repeatMethod; }
92 void setRepeatMethod( VGradientRepeatMethod repeatMethod ) { m_repeatMethod = repeatMethod; }
93
94 const TQPtrVector<VColorStop> colorStops() const;
95 void addStop( const VColorStop& colorStop );
96 void addStop( const VColor &color, float rampPoint, float midPoint );
97 void removeStop( const VColorStop& colorStop );
98 void clearStops();
99
100 KoPoint origin() const { return m_origin; }
101 void setOrigin( const KoPoint &origin ) { m_origin = origin; }
102
103 KoPoint focalPoint() const { return m_focalPoint; }
104 void setFocalPoint( const KoPoint &focalPoint ) { m_focalPoint = focalPoint; }
105
106 KoPoint vector() const { return m_vector; }
107 void setVector( const KoPoint &vector ) { m_vector = vector; }
108
109 void save( TQDomElement& element ) const;
110 TQString saveOasis( KoGenStyles &mainStyles ) const;
111 void load( const TQDomElement& element );
112 void loadOasis( const TQDomElement &object, KoStyleStack &stack, VObject* parent = 0L );
113
114 void transform( const TQWMatrix& m );
115
116protected:
117 VColorStopList m_colorStops;
118
119private:
120 VGradientType m_type : 2;
121 VGradientRepeatMethod m_repeatMethod : 2;
122
123 // coordinates:
124 KoPoint m_origin;
125 KoPoint m_focalPoint;
126 KoPoint m_vector;
127}; // VGradient
128
129#endif /* __VGRADIENT_H__ */
The base class for all karbon objects.
Definition vobject.h:50