kpresenter

KPrGradient.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 "KPrGradient.h"
21#include <tqpainter.h>
22#include <kpixmapeffect.h>
23#include <kdebug.h>
24#include <KoTextZoomHandler.h>
25
26KPrGradient::KPrGradient( const TQColor &_color1, const TQColor &_color2, BCType _bcType,
27 bool _unbalanced, int _xfactor, int _yfactor )
28 : color1( _color1 ), color2( _color2 ), bcType( _bcType ),
29 m_pixmap(), refCount( 0 ),
30 xFactor( _xfactor ), yFactor( _yfactor ),
31 unbalanced( _unbalanced ), m_bDirty( true )
32{
33 //m_pixmap.resize( _size );
34}
35
36void KPrGradient::setParameters(const TQColor &c1, const TQColor &c2, BCType _type,
37 bool _unbalanced, int xf, int yf) {
38 color1=c1;
39 color2=c2;
40 bcType=_type;
41 unbalanced=_unbalanced;
42 xFactor=xf;
43 yFactor=yf;
44 m_bDirty = true;
45}
46
47void KPrGradient::addRef()
48{
49 ++refCount;
50}
51
52bool KPrGradient::removeRef()
53{
54 return ( --refCount == 0 );
55}
56
58{
59 TQPainter painter;
60 switch ( bcType ) {
61 case BCT_PLAIN:
62 painter.begin( &m_pixmap );
63
64 painter.setPen( TQt::NoPen );
65 painter.setBrush( color1 );
66 painter.drawRect( m_pixmap.rect() );
67
68 painter.end();
69 break;
70 case BCT_GHORZ: {
71 if ( !unbalanced )
72 KPixmapEffect::gradient( m_pixmap, color1, color2, KPixmapEffect::VerticalGradient );
73 else
74 KPixmapEffect::unbalancedGradient( m_pixmap, color1, color2, KPixmapEffect::VerticalGradient,
75 xFactor, yFactor );
76 } break;
77 case BCT_GVERT: {
78 if ( !unbalanced )
79 KPixmapEffect::gradient( m_pixmap, color1, color2, KPixmapEffect::HorizontalGradient );
80 else
81 KPixmapEffect::unbalancedGradient( m_pixmap, color1, color2, KPixmapEffect::HorizontalGradient,
82 xFactor, yFactor );
83 } break;
84 case BCT_GDIAGONAL1: {
85 if ( !unbalanced )
86 KPixmapEffect::gradient( m_pixmap, color1, color2, KPixmapEffect::DiagonalGradient );
87 else
88 KPixmapEffect::unbalancedGradient( m_pixmap, color1, color2, KPixmapEffect::DiagonalGradient,
89 xFactor, yFactor );
90 } break;
91 case BCT_GDIAGONAL2: {
92 if ( !unbalanced )
93 KPixmapEffect::gradient( m_pixmap, color1, color2, KPixmapEffect::CrossDiagonalGradient );
94 else
95 KPixmapEffect::unbalancedGradient( m_pixmap, color1, color2,
96 KPixmapEffect::CrossDiagonalGradient, xFactor, yFactor );
97 } break;
98 case BCT_GCIRCLE: {
99 if ( !unbalanced )
100 KPixmapEffect::gradient( m_pixmap, color1, color2, KPixmapEffect::EllipticGradient );
101 else
102 KPixmapEffect::unbalancedGradient( m_pixmap, color1, color2,
103 KPixmapEffect::EllipticGradient, xFactor, yFactor );
104 } break;
105 case BCT_GRECT: {
106 if ( !unbalanced )
107 KPixmapEffect::gradient( m_pixmap, color1, color2, KPixmapEffect::RectangleGradient );
108 else
109 KPixmapEffect::unbalancedGradient( m_pixmap, color1, color2,
110 KPixmapEffect::RectangleGradient, xFactor, yFactor );
111 } break;
112 case BCT_GPIPECROSS: {
113 if ( !unbalanced )
114 KPixmapEffect::gradient( m_pixmap, color1, color2, KPixmapEffect::PipeCrossGradient );
115 else
116 KPixmapEffect::unbalancedGradient( m_pixmap, color1, color2,
117 KPixmapEffect::PipeCrossGradient, xFactor, yFactor );
118 } break;
119 case BCT_GPYRAMID: {
120 if ( !unbalanced )
121 KPixmapEffect::gradient( m_pixmap, color1, color2, KPixmapEffect::PyramidGradient );
122 else
123 KPixmapEffect::unbalancedGradient( m_pixmap, color1, color2,
124 KPixmapEffect::PyramidGradient, xFactor, yFactor );
125 } break;
126 }
127 m_bDirty = false;
128}
129
130const TQPixmap& KPrGradient::pixmap() const
131{
132 if ( m_bDirty )
133 const_cast<KPrGradient *>(this)->paint();
134 return m_pixmap;
135}
Class: KPrGradient.
Definition KPrGradient.h:40
void paint()
Create the pixmap containing the gradient.
const TQPixmap & pixmap() const
Return the pixmap containing the gradient.