karbon

vgradient.h

00001 /* This file is part of the KDE project
00002    Copyright (C) 2002 - 2005, The Karbon Developers
00003 
00004    This library is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU Library General Public
00006    License as published by the Free Software Foundation; either
00007    version 2 of the License, or (at your option) any later version.
00008 
00009    This library is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012    Library General Public License for more details.
00013 
00014    You should have received a copy of the GNU Library General Public License
00015    along with this library; see the file COPYING.LIB.  If not, write to
00016    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00017  * Boston, MA 02110-1301, USA.
00018 */
00019 
00020 #ifndef __VGRADIENT_H__
00021 #define __VGRADIENT_H__
00022 
00023 #include <qptrlist.h>
00024 #include <qptrvector.h>
00025 
00026 #include <koffice_export.h>
00027 #include <KoPoint.h>
00028 
00029 #include "vcolor.h"
00030 
00031 class QDomElement;
00032 class KoGenStyle;
00033 class KoGenStyles;
00034 class KoStyleStack;
00035 class VObject;
00036 
00037 class VColorStop
00038 {
00039     public:
00040         VColorStop( double r, double m, VColor c )
00041             { rampPoint = r; midPoint = m; color = c; };
00042         VColorStop( const VColorStop& colorStop )
00043             { rampPoint = colorStop.rampPoint; midPoint = colorStop.midPoint; color = colorStop.color; };
00044 
00045         VColor color;
00046 
00047         // relative position of color point (0.0-1.0):
00048         float rampPoint;
00049 
00050         // relative position of midpoint (0.0-1.0)
00051         // between two ramp points. ignored for last VColorStop.
00052         float midPoint;
00053 
00054         friend inline bool operator== ( VColorStop& s1, VColorStop& s2 )
00055                 { return s1.rampPoint == s2.rampPoint; };
00056 }; // VColorStop
00057 
00058 class KARBONBASE_EXPORT VGradient
00059 {
00060 friend class VGradientWidget;
00061 
00062 public:
00063     enum VGradientType
00064     {
00065         linear = 0,
00066         radial = 1,
00067         conic  = 2
00068     };
00069 
00070     enum VGradientRepeatMethod
00071     {
00072         none    = 0,
00073         reflect = 1,
00074         repeat  = 2
00075     };
00076 
00077     class VColorStopList : public QPtrList<VColorStop>
00078     {
00079         protected:
00080             virtual int compareItems( QPtrCollection::Item item1, QPtrCollection::Item item2 );
00081     }; // VColorStopList
00082 
00083     VGradient( VGradientType type = linear );
00084     VGradient( const VGradient& gradient );
00085 
00086     VGradient& operator=(const VGradient& gradient);
00087 
00088     VGradientType type() const { return m_type; }
00089     void setType( VGradientType type ) { m_type = type; }
00090 
00091     VGradientRepeatMethod repeatMethod() const { return m_repeatMethod; }
00092     void setRepeatMethod( VGradientRepeatMethod repeatMethod ) { m_repeatMethod = repeatMethod; }
00093 
00094     const QPtrVector<VColorStop> colorStops() const;
00095     void addStop( const VColorStop& colorStop );
00096     void addStop( const VColor &color, float rampPoint, float midPoint );
00097     void removeStop( const VColorStop& colorStop );
00098     void clearStops();
00099 
00100     KoPoint origin() const { return m_origin; }
00101     void setOrigin( const KoPoint &origin ) { m_origin = origin; }
00102 
00103     KoPoint focalPoint() const { return m_focalPoint; }
00104     void setFocalPoint( const KoPoint &focalPoint ) { m_focalPoint = focalPoint; }
00105 
00106     KoPoint vector() const { return m_vector; }
00107     void setVector( const KoPoint &vector ) { m_vector = vector; }
00108 
00109     void save( QDomElement& element ) const;
00110     QString saveOasis( KoGenStyles &mainStyles ) const;
00111     void load( const QDomElement& element );
00112     void loadOasis( const QDomElement &object, KoStyleStack &stack, VObject* parent = 0L );
00113 
00114     void transform( const QWMatrix& m );
00115 
00116 protected:
00117     VColorStopList        m_colorStops;
00118   
00119 private:
00120     VGradientType         m_type        : 2;
00121     VGradientRepeatMethod m_repeatMethod    : 2;
00122 
00123     // coordinates:
00124     KoPoint m_origin;
00125     KoPoint m_focalPoint;
00126     KoPoint m_vector;
00127 }; // VGradient
00128 
00129 #endif /* __VGRADIENT_H__ */
KDE Home | KDE Accessibility Home | Description of Access Keys