kpresenter

KPrGradientCollection.cpp

00001 // -*- Mode: c++; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 4; -*-
00002 /* This file is part of the KDE project
00003    Copyright (C) 1998, 1999 Reginald Stadlbauer <reggie@kde.org>
00004 
00005    This library is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Library General Public
00007    License as published by the Free Software Foundation; either
00008    version 2 of the License, or (at your option) any later version.
00009 
00010    This library is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Library General Public License for more details.
00014 
00015    You should have received a copy of the GNU Library General Public License
00016    along with this library; see the file COPYING.LIB.  If not, write to
00017    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00018  * Boston, MA 02110-1301, USA.
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() ) // does deref say it was the last use?
00055             gradientList.removeRef( cachedGradient ); // yes -> remove from list
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 }
KDE Home | KDE Accessibility Home | Description of Access Keys