kpresenter

KPrGradientCollection.cpp
1/* This file is part of the KDE project
2 Copyright (C) 1998, 1999 Reginald Stadlbauer <reggie@kde.org>
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#include "KPrGradientCollection.h"
21#include "KPrGradient.h"
22#include <tqstring.h>
23
24const TQPixmap& KPrGradientCollection::getGradient( const TQColor &_color1, const TQColor &_color2,
25 BCType _bcType, const TQSize &_size,
26 bool _unbalanced, int _xfactor, int _yfactor, bool addref )
27{
28 KPrGradient *cachedGradient = inGradientList( _color1, _color2, _bcType, _size, _unbalanced, _xfactor, _yfactor );
29
30 if ( !cachedGradient ) {
31 KPrGradient *kpgradient = new KPrGradient( _color1, _color2, _bcType, _unbalanced, _xfactor, _yfactor );
32 kpgradient->setSize( _size );
33 gradientList.append( kpgradient );
34
35 if ( addref )
36 kpgradient->addRef();
37
38 return kpgradient->pixmap();
39 } else {
40 if ( addref )
41 cachedGradient->addRef();
42
43 return cachedGradient->pixmap();
44 }
45}
46
47void KPrGradientCollection::removeRef( const TQColor &_color1, const TQColor &_color2,
48 BCType _bcType, const TQSize &_size,
49 bool _unbalanced, int _xfactor, int _yfactor)
50{
51 KPrGradient* cachedGradient = inGradientList( _color1, _color2, _bcType, _size, _unbalanced, _xfactor, _yfactor );
52 if ( cachedGradient ) {
53 if ( cachedGradient->removeRef() ) // does deref say it was the last use?
54 gradientList.removeRef( cachedGradient ); // yes -> remove from list
55 }
56}
57
58KPrGradient* KPrGradientCollection::inGradientList( const TQColor &_color1, const TQColor &_color2,
59 BCType _bcType, const TQSize &_size,
60 bool _unbalanced, int _xfactor, int _yfactor ) const
61{
62 TQPtrListIterator<KPrGradient> it( gradientList );
63 for ( ; it.current() ; ++it ) {
64 KPrGradient *kpgradient = it.current();
65 if ( kpgradient->getColor1() == _color1 && kpgradient->getColor2() == _color2 &&
66 kpgradient->getBackColorType() == _bcType && kpgradient->size() == _size &&
67 kpgradient->getUnbalanced() == _unbalanced && kpgradient->getXFactor() == _xfactor &&
68 kpgradient->getYFactor() == _yfactor )
69 return kpgradient;
70 }
71 return 0L;
72}
const TQPixmap & getGradient(const TQColor &_color1, const TQColor &_color2, BCType _bcType, const TQSize &_size, bool _unbalanced, int _xfactor, int _yfactor, bool addref=true)
Retrieve or create gradient for the given parameters.
void removeRef(const TQColor &_color1, const TQColor &_color2, BCType _bcType, const TQSize &_size, bool _unbalanced, int _xfactor, int _yfactor)
Remove reference to gradient with the given parameters.
Class: KPrGradient.
Definition KPrGradient.h:40
const TQPixmap & pixmap() const
Return the pixmap containing the gradient.