kpresenter

KPrBackground.h
1/* This file is part of the KDE project
2 Copyright (C) 1998, 1999 Reginald Stadlbauer <reggie@kde.org>
3 Copyright (C) 2004,2006 Thorsten Zachmann <zachmann@kde.org>
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
19*/
20
21#ifndef kpbackground_h
22#define kpbackground_h
23
24#include <tqsize.h>
25#include <tqdatetime.h>
26#include <KoBrush.h>
27#include <KoStyleStack.h>
28#include <KoOasisStyles.h>
29#include <KoOasisContext.h>
30
31#include <KoPictureCollection.h>
32
33#include "global.h"
34
35class KPrDocument;
36class TQPainter;
37class TQPixmap;
39class TQDomDocument;
40class TQDomElement;
41class KoTextZoomHandler;
42class KPrPage;
43class KoXmlWriter;
44class KoGenStyles;
45class KoGenStyle;
46
47
48class KPrBackGround
49{
50public:
51 struct Settings
52 {
53 Settings( const BackType backType, const TQColor backColor1, const TQColor backColor2,
54 const BCType bcType, const bool unbalanced, const int xfactor, const int yfactor,
55 const KoPictureKey &key, const BackView backView )
56 : m_backType( backType )
57 , m_backColor1( backColor1 )
58 , m_backColor2( backColor2 )
59 , m_bcType( bcType )
60 , m_unbalanced( unbalanced )
61 , m_xfactor( xfactor )
62 , m_yfactor( yfactor )
63 , m_backPictureKey( key )
64 , m_backView( backView )
65 {}
66
67 BackType m_backType;
68 TQColor m_backColor1;
69 TQColor m_backColor2;
70 // Gradient setting
71 BCType m_bcType;
72 bool m_unbalanced;
73 // Gradient factors
74 int m_xfactor, m_yfactor;
75
76 KoPictureKey m_backPictureKey;
77 BackView m_backView;
78 };
79
80 KPrBackGround( KPrPage *_page );
81 ~KPrBackGround() {}
82
83 void setBackType( BackType _backType )
84 {
85 backType = _backType;
86 if (backType==BT_PICTURE || backType==BT_CLIPART)
87 removeGradient();
88 }
89 void setBackView( BackView _backView )
90 { backView = _backView; }
91 void setBackColor1( const TQColor &_color )
92 { removeGradient(); backColor1 = _color; }
93 void setBackColor2( const TQColor &_color )
94 { removeGradient(); backColor2 = _color; }
95 void setBackColorType( BCType _bcType )
96 { removeGradient(); bcType = _bcType; }
97 void setBackUnbalanced( bool _unbalanced )
98 { removeGradient(); unbalanced = _unbalanced; }
99 void setBackXFactor( int _xfactor )
100 { removeGradient(); xfactor = _xfactor; }
101 void setBackYFactor( int _yfactor )
102 { removeGradient(); yfactor = _yfactor; }
104 void setBackPicture( const KoPicture& picture );
105 void setBackPicture ( const KoPictureKey& key );
106 void setBackGround( const struct Settings &settings );
107 struct Settings getBackGround() const;
108
109 KoPicture picture() const { return backPicture;}
110
111 BackType getBackType() const
112 { return backType; }
113 BackView getBackView() const
114 { return backView; }
115 TQColor getBackColor1() const
116 { return backColor1; }
117 TQColor getBackColor2() const
118 { return backColor2; }
119 BCType getBackColorType() const
120 { return bcType; }
121 KoPictureKey getBackPictureKey() const
122 { return backPicture.getKey(); }
123 KoPicture getBackPicture() const
124 { return backPicture;}
125
126 bool getBackUnbalanced() const
127 { return unbalanced; }
128 int getBackXFactor() const
129 { return xfactor; }
130 int getBackYFactor() const
131 { return yfactor; }
132
133 // Draw the background.
134 // Uses the @p zoomHandler to determine the size of the background
135 void drawBackground( TQPainter *_painter, const KoTextZoomHandler* zoomHandler,
136 const TQRect& crect, bool _drawBorders );
137 // Draw the background. The size of the background is passed explicitly
138 void drawBackground( TQPainter *_painter, const TQSize& ext,
139 const TQRect& crect, bool _drawBorders );
140
141 void reload();
142
143 TQDomElement save( TQDomDocument &doc );
144 void load( const TQDomElement &element );
145 void loadOasis( KoOasisContext & context );
146 void saveOasisBackgroundPageStyle( KoGenStyle &stylepageauto, KoGenStyles &mainStyles );
147
148protected:
149 void drawBackColor( TQPainter *_painter, const TQSize& ext, const TQRect& crect );
150 void drawBackPix( TQPainter *_painter, const TQSize& ext, const TQRect& crect );
151 void drawBorders( TQPainter *_painter, const TQSize& ext, const TQRect& crect );
152 // The current gradient isn't valid anymore (e.g. size or settings changed) -> discard it
153 void removeGradient();
154 // Generate a new gradient pixmap, for the given size
155 void generateGradient( const TQSize& size );
156
157 KoPictureCollection *pictureCollection() const;
158 KPrGradientCollection *gradientCollection() const;
159
160 TQString saveOasisPictureStyle( KoGenStyles& mainStyles );
161
162private:
163 BackType backType;
164 BackView backView;
165 TQColor backColor1;
166 TQColor backColor2;
167 BCType bcType;
168
169 // Background picture
170 KoPicture backPicture;
171
172 // Pixmap used to cache the drawing of the gradient, at the current size
173 const TQPixmap *gradientPixmap;
174
175 // The page for which this background exists
176 KPrPage *m_page;
177
178 //int footerHeight;
179
180 // Gradient factors
181 int xfactor, yfactor;
182
183 // Gradient setting
184 bool unbalanced;
185};
186
187#endif
Class: KPrGradientCollection Holds a collection of gradients, and is able to provide a gradient for a...