00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "KPrGradientCollection.h"
00022 #include "KPrGradient.h"
00023 #include <qstring.h>
00024
00025 const QPixmap& KPrGradientCollection::getGradient( const QColor &_color1, const QColor &_color2,
00026 BCType _bcType, const QSize &_size,
00027 bool _unbalanced, int _xfactor, int _yfactor, bool addref )
00028 {
00029 KPrGradient *cachedGradient = inGradientList( _color1, _color2, _bcType, _size, _unbalanced, _xfactor, _yfactor );
00030
00031 if ( !cachedGradient ) {
00032 KPrGradient *kpgradient = new KPrGradient( _color1, _color2, _bcType, _unbalanced, _xfactor, _yfactor );
00033 kpgradient->setSize( _size );
00034 gradientList.append( kpgradient );
00035
00036 if ( addref )
00037 kpgradient->addRef();
00038
00039 return kpgradient->pixmap();
00040 } else {
00041 if ( addref )
00042 cachedGradient->addRef();
00043
00044 return cachedGradient->pixmap();
00045 }
00046 }
00047
00048 void KPrGradientCollection::removeRef( const QColor &_color1, const QColor &_color2,
00049 BCType _bcType, const QSize &_size,
00050 bool _unbalanced, int _xfactor, int _yfactor)
00051 {
00052 KPrGradient* cachedGradient = inGradientList( _color1, _color2, _bcType, _size, _unbalanced, _xfactor, _yfactor );
00053 if ( cachedGradient ) {
00054 if ( cachedGradient->removeRef() )
00055 gradientList.removeRef( cachedGradient );
00056 }
00057 }
00058
00059 KPrGradient* KPrGradientCollection::inGradientList( const QColor &_color1, const QColor &_color2,
00060 BCType _bcType, const QSize &_size,
00061 bool _unbalanced, int _xfactor, int _yfactor ) const
00062 {
00063 QPtrListIterator<KPrGradient> it( gradientList );
00064 for ( ; it.current() ; ++it ) {
00065 KPrGradient *kpgradient = it.current();
00066 if ( kpgradient->getColor1() == _color1 && kpgradient->getColor2() == _color2 &&
00067 kpgradient->getBackColorType() == _bcType && kpgradient->size() == _size &&
00068 kpgradient->getUnbalanced() == _unbalanced && kpgradient->getXFactor() == _xfactor &&
00069 kpgradient->getYFactor() == _yfactor )
00070 return kpgradient;
00071 }
00072 return 0L;
00073 }