kpresenter

KPrGradient.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 "KPrGradient.h"
00022 #include <qpainter.h>
00023 #include <kpixmapeffect.h>
00024 #include <kdebug.h>
00025 #include <KoTextZoomHandler.h>
00026 
00027 KPrGradient::KPrGradient( const QColor &_color1, const QColor &_color2, BCType _bcType,
00028                         bool _unbalanced, int _xfactor, int _yfactor )
00029     : color1( _color1 ), color2( _color2 ), bcType( _bcType ),
00030       m_pixmap(), refCount( 0 ),
00031       xFactor( _xfactor ), yFactor( _yfactor ),
00032       unbalanced( _unbalanced ), m_bDirty( true )
00033 {
00034     //m_pixmap.resize( _size );
00035 }
00036 
00037 void KPrGradient::setParameters(const QColor &c1, const QColor &c2, BCType _type,
00038                                bool _unbalanced, int xf, int yf) {
00039     color1=c1;
00040     color2=c2;
00041     bcType=_type;
00042     unbalanced=_unbalanced;
00043     xFactor=xf;
00044     yFactor=yf;
00045     m_bDirty = true;
00046 }
00047 
00048 void KPrGradient::addRef()
00049 {
00050     ++refCount;
00051 }
00052 
00053 bool KPrGradient::removeRef()
00054 {
00055     return ( --refCount == 0 );
00056 }
00057 
00058 void KPrGradient::paint()
00059 {
00060     QPainter painter;
00061     switch ( bcType ) {
00062     case BCT_PLAIN:
00063         painter.begin( &m_pixmap );
00064 
00065         painter.setPen( Qt::NoPen );
00066         painter.setBrush( color1 );
00067         painter.drawRect( m_pixmap.rect() );
00068 
00069         painter.end();
00070         break;
00071     case BCT_GHORZ: {
00072         if ( !unbalanced )
00073             KPixmapEffect::gradient( m_pixmap, color1, color2, KPixmapEffect::VerticalGradient );
00074         else
00075             KPixmapEffect::unbalancedGradient( m_pixmap, color1, color2, KPixmapEffect::VerticalGradient,
00076                                                xFactor, yFactor );
00077     } break;
00078     case BCT_GVERT: {
00079         if ( !unbalanced )
00080             KPixmapEffect::gradient( m_pixmap, color1, color2, KPixmapEffect::HorizontalGradient );
00081         else
00082             KPixmapEffect::unbalancedGradient( m_pixmap, color1, color2, KPixmapEffect::HorizontalGradient,
00083                                                xFactor, yFactor );
00084     } break;
00085     case BCT_GDIAGONAL1: {
00086         if ( !unbalanced )
00087             KPixmapEffect::gradient( m_pixmap, color1, color2, KPixmapEffect::DiagonalGradient );
00088         else
00089             KPixmapEffect::unbalancedGradient( m_pixmap, color1, color2, KPixmapEffect::DiagonalGradient,
00090                                                xFactor, yFactor );
00091     } break;
00092     case BCT_GDIAGONAL2: {
00093         if ( !unbalanced )
00094             KPixmapEffect::gradient( m_pixmap, color1, color2, KPixmapEffect::CrossDiagonalGradient );
00095         else
00096             KPixmapEffect::unbalancedGradient( m_pixmap, color1, color2,
00097                                                KPixmapEffect::CrossDiagonalGradient,  xFactor, yFactor );
00098     } break;
00099     case BCT_GCIRCLE: {
00100         if ( !unbalanced )
00101             KPixmapEffect::gradient( m_pixmap, color1, color2, KPixmapEffect::EllipticGradient );
00102         else
00103             KPixmapEffect::unbalancedGradient( m_pixmap, color1, color2,
00104                                                KPixmapEffect::EllipticGradient, xFactor, yFactor );
00105     } break;
00106     case BCT_GRECT: {
00107         if ( !unbalanced )
00108             KPixmapEffect::gradient( m_pixmap, color1, color2, KPixmapEffect::RectangleGradient );
00109         else
00110             KPixmapEffect::unbalancedGradient( m_pixmap, color1, color2,
00111                                                KPixmapEffect::RectangleGradient, xFactor, yFactor );
00112     } break;
00113     case BCT_GPIPECROSS: {
00114         if ( !unbalanced )
00115             KPixmapEffect::gradient( m_pixmap, color1, color2, KPixmapEffect::PipeCrossGradient );
00116         else
00117             KPixmapEffect::unbalancedGradient( m_pixmap, color1, color2,
00118                                                KPixmapEffect::PipeCrossGradient, xFactor, yFactor );
00119     } break;
00120     case BCT_GPYRAMID: {
00121         if ( !unbalanced )
00122             KPixmapEffect::gradient( m_pixmap, color1, color2, KPixmapEffect::PyramidGradient );
00123         else
00124             KPixmapEffect::unbalancedGradient( m_pixmap, color1, color2,
00125                                                KPixmapEffect::PyramidGradient, xFactor, yFactor );
00126     } break;
00127     }
00128     m_bDirty = false;
00129 }
00130 
00131 const QPixmap& KPrGradient::pixmap() const
00132 {
00133     if ( m_bDirty )
00134         const_cast<KPrGradient *>(this)->paint();
00135     return m_pixmap;
00136 }
KDE Home | KDE Accessibility Home | Description of Access Keys