Back to index

scribus-ng  1.3.4.dfsg+svn20071115
vgradientex.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 __VGRADIENTEX_H__
00027 #define __VGRADIENTEX_H__
00028 
00029 #include <qptrlist.h>
00030 #include <qptrvector.h>
00031 #include "scribusapi.h"
00032 #include "scribusdoc.h"
00033 #include "fpoint.h"
00034 #include "sccolor.h"
00035 #include <qwmatrix.h>
00036 
00037 class SCRIBUS_API VColorStopEx
00038 {
00039 public:
00040        VColorStopEx( double r, double m, ScColor c, double o, QString n, int s )
00041        {
00042               rampPoint = r;
00043               midPoint = m; 
00044               color = c;
00045               opacity = o; 
00046               name = n;
00047               shade = s;
00048        };
00049        
00050        VColorStopEx( const VColorStopEx& colorStop )
00051        {
00052               rampPoint = colorStop.rampPoint;
00053               midPoint = colorStop.midPoint;
00054               color = colorStop.color;
00055               opacity = colorStop.opacity;
00056               name = colorStop.name;
00057               shade = colorStop.shade;
00058        };
00059 
00060        ScColor color;
00061 
00062        // relative position of color point (0.0-1.0):
00063        double rampPoint;
00064 
00065        // relative position of midpoint (0.0-1.0)
00066        // between two ramp points. ignored for last VColorStop.
00067        double midPoint;
00068        double opacity;
00069        int shade;
00070        QString name;
00071        friend inline bool operator== ( VColorStopEx& s1, VColorStopEx& s2 )
00072        { return s1.rampPoint == s2.rampPoint; };
00073 }
00074 ; // VColorStopEx
00075 
00076 // comparison function for use with stable_sort
00077 bool compareStopsEx( const VColorStopEx* item1, const VColorStopEx* item2 );
00078 
00079 class SCRIBUS_API VGradientEx
00080 {
00081        // friend class VGradientWidget;
00082 
00083 public:
00084        enum Type
00085        {
00086            linear = 0,
00087            radial = 1,
00088            conic  = 2
00089        };
00090 
00091        enum RepeatMethod
00092        {
00093            none    = 0,
00094            reflect = 1,
00095            repeat  = 2
00096        };
00097 
00098        class SCRIBUS_API VColorStopExList : public QPtrList<VColorStopEx>
00099        {
00100        protected:
00101               virtual int compareItems( QPtrCollection::Item item1, QPtrCollection::Item item2 );
00102        public:
00103               void inSort( QPtrCollection::Item d );
00104        }; // VColorStopExList
00105 
00106        VGradientEx( VGradientEx::Type type = linear );
00107        VGradientEx( const VGradientEx& gradient );
00108        VGradientEx( const VGradient& gradient, ScribusDoc& doc );
00109 
00110        VGradientEx& operator=(const VGradientEx& gradient);
00111 
00112        VGradientEx::Type type() const { return m_type; }
00113        void setType( VGradientEx::Type type ) { m_type = type; }
00114 
00115        VGradientEx::RepeatMethod repeatMethod() const { return m_repeatMethod; }
00116        void setRepeatMethod( VGradientEx::RepeatMethod repeatMethod ) { m_repeatMethod = repeatMethod; }
00117 
00118        const QPtrVector<VColorStopEx> colorStops() const;
00119        void addStop( const VColorStopEx& colorStop );
00120        void addStop( const ScColor &color, double rampPoint, double midPoint, double opa, QString name = "", int shade = 100 );
00121        void removeStop( const VColorStopEx& colorStop );
00122        void removeStop( uint n );
00123        void clearStops();
00124        uint Stops() { return m_colorStops.count(); }
00125 
00126        FPoint origin() const { return m_origin; }
00127        void setOrigin( const FPoint &origin ) { m_origin = origin; }
00128 
00129        FPoint focalPoint() const { return m_focalPoint; }
00130        void setFocalPoint( const FPoint &focalPoint ) { m_focalPoint = focalPoint; }
00131 
00132        FPoint vector() const { return m_vector; }
00133        void setVector( const FPoint &vector ) { m_vector = vector; }
00134 
00135        void transform( const QWMatrix& m );
00136 
00137 protected:
00138        VColorStopExList        m_colorStops;
00139 
00140 private:
00141        VGradientEx::Type         m_type                 : 2;
00142        VGradientEx::RepeatMethod m_repeatMethod  : 2;
00143 
00144        // coordinates:
00145        FPoint m_origin;
00146        FPoint m_focalPoint;
00147        FPoint m_vector;
00148 }
00149 ; // VGradientEx
00150 
00151 #endif /* __VGRADIENT_H__ */