Back to index

scribus-ng  1.3.4.dfsg+svn20071115
vgradient.h
Go to the documentation of this file.
00001 /*
00002 For general Scribus (>=1.3.2) copyright and licensing information please refer
00003 to the COPYING file provided with the program. Following this notice may exist
00004 a copyright and/or license notice that predates the release of Scribus 1.3.2
00005 for which a new license (GPL+exception) is in place.
00006 */
00007 /* This file is part of the KDE project
00008    Copyright (C) 2002, The Karbon Developers
00009  
00010    This library is free software; you can redistribute it and/or
00011    modify it under the terms of the GNU Library General Public
00012    License as published by the Free Software Foundation; either
00013    version 2 of the License, or (at your option) any later version.
00014  
00015    This library is distributed in the hope that it will be useful,
00016    but WITHOUT ANY WARRANTY; without even the implied warranty of
00017    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018    Library General Public License for more details.
00019  
00020    You should have received a copy of the GNU Library General Public License
00021    along with this library; see the file COPYING.LIB.  If not, write to
00022    the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00023    Boston, MA 02111-1307, USA.
00024 */
00025 
00026 #ifndef __VGRADIENT_H__
00027 #define __VGRADIENT_H__
00028 
00029 #include <qptrlist.h>
00030 #include <qptrvector.h>
00031 #include "scribusapi.h"
00032 #include "fpoint.h"
00033 #include <qcolor.h>
00034 #include <qwmatrix.h>
00035 
00036 class SCRIBUS_API VColorStop
00037 {
00038 public:
00039        VColorStop( double r, double m, QColor c, double o, QString n, int s )
00040        {
00041               rampPoint = r;
00042               midPoint = m; 
00043               color = c;
00044               opacity = o; 
00045               name = n;
00046               shade = s;
00047        };
00048        
00049        VColorStop( const VColorStop& colorStop )
00050        {
00051               rampPoint = colorStop.rampPoint;
00052               midPoint = colorStop.midPoint;
00053               color = colorStop.color;
00054               opacity = colorStop.opacity;
00055               name = colorStop.name;
00056               shade = colorStop.shade;
00057        };
00058 
00059        QColor color;
00060 
00061        // relative position of color point (0.0-1.0):
00062        double rampPoint;
00063 
00064        // relative position of midpoint (0.0-1.0)
00065        // between two ramp points. ignored for last VColorStop.
00066        double midPoint;
00067        double opacity;
00068        int shade;
00069        QString name;
00070        friend inline bool operator== ( VColorStop& s1, VColorStop& s2 )
00071        { return s1.rampPoint == s2.rampPoint; };
00072 }
00073 ; // VColorStop
00074 
00075 // comparison function for use with stable_sort
00076 bool compareStops( const VColorStop* item1, const VColorStop* item2 );
00077 
00078 class SCRIBUS_API VGradient
00079 {
00080        // friend class VGradientWidget;
00081 
00082 public:
00083        enum VGradientType
00084        {
00085            linear = 0,
00086            radial = 1,
00087            conic  = 2
00088        };
00089 
00090        enum VGradientRepeatMethod
00091        {
00092            none    = 0,
00093            reflect = 1,
00094            repeat  = 2
00095        };
00096 
00097        class SCRIBUS_API VColorStopList : public QPtrList<VColorStop>
00098        {
00099        protected:
00100               virtual int compareItems( QPtrCollection::Item item1, QPtrCollection::Item item2 ) const;
00101        public:
00102               // Reimplement inSort so that two color stop with same offset can be found
00103               // in the same order they are inserted
00104               void inSort( QPtrCollection::Item d );
00105        }; // VColorStopList
00106 
00107        VGradient( VGradientType type = linear );
00108        VGradient( const VGradient& gradient );
00109 
00110        VGradient& operator=(const VGradient& gradient);
00111 
00112        VGradientType type() const { return m_type; }
00113        void setType( VGradientType type ) { m_type = type; }
00114 
00115        VGradientRepeatMethod repeatMethod() const { return m_repeatMethod; }
00116        void setRepeatMethod( VGradientRepeatMethod repeatMethod ) { m_repeatMethod = repeatMethod; }
00117 
00118        const QPtrVector<VColorStop> colorStops() const;
00119        void addStop( const VColorStop& colorStop );
00120        void addStop( const QColor &color, double rampPoint, double midPoint, double opa, QString name = "", int shade = 100 );
00121        void removeStop( const VColorStop& colorStop );
00122        void removeStop( uint n );
00123        void clearStops();
00124        uint Stops()  const { return m_colorStops.count(); }
00125 
00126        // This function let only one stop with offset value equal to 0 and 1.0
00127        // by removing the firsts with 0.0 value and the lasts with 1.0 value;
00128        void filterStops(void);
00129 
00130        FPoint origin() const { return m_origin; }
00131        void setOrigin( const FPoint &origin ) { m_origin = origin; }
00132 
00133        FPoint focalPoint() const { return m_focalPoint; }
00134        void setFocalPoint( const FPoint &focalPoint ) { m_focalPoint = focalPoint; }
00135 
00136        FPoint vector() const { return m_vector; }
00137        void setVector( const FPoint &vector ) { m_vector = vector; }
00138 
00139        void transform( const QWMatrix& m );
00140 
00141 protected:
00142        VColorStopList        m_colorStops;
00143 
00144 private:
00145 VGradientType         m_type                     : 2;
00146 VGradientRepeatMethod m_repeatMethod      : 2;
00147 
00148        // coordinates:
00149        FPoint m_origin;
00150        FPoint m_focalPoint;
00151        FPoint m_vector;
00152 }
00153 ; // VGradient
00154 
00155 #endif /* __VGRADIENT_H__ */