kexigradientwidget.h
1/* This file is part of the KDE project
2 Copyright (C) 2005 Christian Nitschkowski <segfault_ii@web.de>
3
4 This program 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 program 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 program; see the file COPYING. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18*/
19
20#ifndef KEXIGRADIENTWIDGET_H
21#define KEXIGRADIENTWIDGET_H
22
23#include <tqtimer.h>
24#include <tqwidget.h>
25
26#include <kimageeffect.h>
27#include <kpixmap.h>
28
29#define REBUILD_DELAY 100
30
32
35class KEXIGUIUTILS_EXPORT KexiGradientWidget : public TQWidget {
36 typedef TQPtrList<TQWidget> WidgetList;
37
38 TQ_OBJECT
39
40 TQ_PROPERTY(DisplayMode displayMode READ displayMode WRITE setDisplayMode DESIGNABLE true)
41 TQ_PROPERTY(GradientType gradientType READ gradientType WRITE setGradientType DESIGNABLE true)
42 TQ_PROPERTY(TQColor gradientColor1 READ gradientColor1 WRITE setGradientColor1 DESIGNABLE true)
43 TQ_PROPERTY(TQColor gradientColor2 READ gradientColor2 WRITE setGradientColor2 DESIGNABLE true)
44 TQ_PROPERTY(double blendOpacity READ blendOpacity WRITE setBlendOpacity DESIGNABLE true)
45 TQ_ENUMS( DisplayMode GradientType )
46
47 public:
54 SimpleGradient
55 };
56
62 VerticalGradient = KImageEffect::VerticalGradient,
63 HorizontalGradient = KImageEffect::HorizontalGradient,
64 DiagonalGradient = KImageEffect::DiagonalGradient,
65 CrossDiagonalGradient = KImageEffect::CrossDiagonalGradient,
66 PyramidGradient = KImageEffect::PyramidGradient,
67 RectangleGradient = KImageEffect::RectangleGradient,
68 PipeCrossGradient = KImageEffect::PipeCrossGradient,
69 EllipticGradient = KImageEffect::EllipticGradient
70 };
71
72 KexiGradientWidget( TQWidget *parent = 0, const char *name = 0, WFlags f = 0 );
73
74 virtual ~KexiGradientWidget();
75
76 virtual void setPaletteBackgroundPixmap( const TQPixmap& pixmap ) {
77 p_backgroundPixmap = pixmap;
78 p_rebuildDelayTimer.start( REBUILD_DELAY, true );
79 }
80
81 virtual const TQColor& paletteBackgroundColor() const;
82
88 p_displayMode = mode;
89 p_cacheDirty = true;
90 update();
91 }
92
97 return p_displayMode;
98 }
99
104 p_gradientType = type;
105 p_cacheDirty = true;
106 update();
107 }
108
113 return p_gradientType;
114 }
115
118 void setGradientColor1( const TQColor& color ) {
119 p_color1 = color;
120 p_cacheDirty = true;
121 }
122
125 void setGradientColor2( const TQColor& color ) {
126 p_color2 = color;
127 p_cacheDirty = true;
128 }
129
135 void setGradientColors( const TQColor& color1, const TQColor& color2 ) {
136 p_color1 = color1;
137 p_color2 = color2;
138 p_cacheDirty = true;
139 }
140
142 TQColor gradientColor1() const { return p_color1; }
143
145 TQColor gradientColor2() const { return p_color2; }
146
151 void setBlendOpacity( double opacity ) {
152 p_opacity = opacity;
153 p_cacheDirty = true;
154 }
155
156 double blendOpacity() const { return p_opacity; }
157
158 public slots:
159 virtual void setPaletteBackgroundColor( const TQColor& color );
160
161 protected:
162 virtual bool eventFilter( TQObject* object, TQEvent* event );
163 virtual void enabledChange( bool enabled ) {
164 p_cacheDirty = true;
165 TQWidget::enabledChange( enabled );
166 }
167
168 virtual void paletteChange( const TQPalette& pal ) {
169 p_cacheDirty = true;
170 TQWidget::paletteChange( pal );
171 }
172
173 virtual void paintEvent( TQPaintEvent* e );
174
175 virtual void resizeEvent( TQResizeEvent* e ) {
176 p_rebuildDelayTimer.start( REBUILD_DELAY, true );
177 TQWidget::resizeEvent( e );
178 }
179
180 virtual void styleChange( TQStyle& style ) {
181 p_cacheDirty = true;
182 TQWidget::styleChange( style );
183 }
184
185 private:
194 static void buildChildrenList( WidgetList& list, TQWidget* p );
199 static bool isValidChildWidget( TQObject* child );
200
205 void rebuildCache();
206
214 void updateChildBackground( TQWidget* childWidget );
215
216 private:
217 WidgetList p_knownWidgets;
218 WidgetList p_customBackgroundWidgets;
219 DisplayMode p_displayMode;
220 GradientType p_gradientType;
221 KPixmap p_backgroundPixmap;
222 TQColor p_color1;
223 TQColor p_color2;
224 TQTimer p_rebuildDelayTimer;
225 TQWidget* p_currentChild;
226 double p_opacity;
227 bool p_cacheDirty;
228
229 TQColor p_backgroundColor;
230
231 public slots:
236 virtual void polish() {
237 TQWidget::polish();
238 rebuildCache();
239 }
240
241 private slots:
242 void setCacheDirty() {
243 rebuildCache();
244 }
245
246 };
247
248#endif
A simple widget that can use different types of gradients as the background.
TQColor gradientColor1() const
void setGradientColors(const TQColor &color1, const TQColor &color2)
TQColor gradientColor2() const
void setGradientColor2(const TQColor &color)
GradientType gradientType() const
DisplayMode displayMode() const
void setDisplayMode(DisplayMode mode)
@ FadedGradient
Gradient will be faded with the widgets background.
@ NoGradient
No gradient at all. Will behave just like a TQWidget.
void setGradientColor1(const TQColor &color)
void setGradientType(GradientType type)
void setBlendOpacity(double opacity)
TQPtrList< TQWidget > WidgetList
A list of widget pointers.