20#include <tqapplication.h>
23#include <tqobjectlist.h>
27#include <kimageeffect.h>
30#include "kexigradientwidget.h"
32KexiGradientWidget::KexiGradientWidget( TQWidget *parent,
const char *name, WFlags f )
33 : TQWidget( parent, name, f ), p_displayMode( NoGradient ),
34 p_gradientType( VerticalGradient ),
35 p_color1( TQt::white ), p_color2( TQt::blue ), p_currentChild( 0 ),
36 p_opacity( 0.5 ), p_cacheDirty( true )
38 p_customBackgroundWidgets.setAutoDelete(
false );
39 p_knownWidgets.setAutoDelete(
false );
41 p_backgroundColor = TQWidget::paletteBackgroundColor();
43 connect ( &p_rebuildDelayTimer, TQ_SIGNAL( timeout() ),
this, TQ_SLOT( setCacheDirty() ) );
45 installEventFilter(
this );
48KexiGradientWidget::~KexiGradientWidget()
52bool KexiGradientWidget::isValidChildWidget( TQObject* child ) {
53 const TQWidget* wgt =
dynamic_cast<TQWidget*
>( child );
58 if ( wgt->inherits(
"TQScrollView" ) )
60 if ( wgt->inherits(
"TQComboBox" ) )
62 if ( wgt->inherits(
"TQLineEdit" ) )
64 if ( wgt->inherits(
"KexiDBForm" ) )
70void KexiGradientWidget::buildChildrenList( WidgetList& list, TQWidget* p ) {
71 TQObjectList* objects = p->queryList(
"TQWidget", 0,
false,
false );
73 for ( TQObjectList::Iterator it = objects->begin(); it != objects->end(); ++it ) {
74 if ( isValidChildWidget( ( *it ) ) == false )
76 list.append(
dynamic_cast<TQWidget*
>( ( *it ) ) );
77 buildChildrenList( list,
dynamic_cast<TQWidget*
>( ( *it ) ) );
83void KexiGradientWidget::rebuildCache(
void ) {
84 WidgetList childWidgetList;
85 buildChildrenList( childWidgetList,
this );
94 TQWidget::setPaletteBackgroundPixmap( p_backgroundPixmap );
96 TQWidget::setPaletteBackgroundColor( p_backgroundColor );
98 for ( WidgetList::Iterator it = childWidgetList.begin();
99 it != childWidgetList.end(); ++it ) {
101 if ( p_customBackgroundWidgets.contains( ( *it ) ) == false ) {
102 ( *it )->unsetPalette();
108 p_cacheDirty =
false;
113 TQImage gradientImage;
119 gradientImage = KImageEffect::gradient( size(), p_color1, p_color2,
120 (KImageEffect::GradientType)p_gradientType );
126 tempPixmap.resize( size() );
127 TQPainter p( &tempPixmap,
this );
129 if ( p_backgroundPixmap.isNull() ) {
135 p.fillRect( 0, 0, width(), height(), palette().brush(
136 isEnabled() ? TQPalette::Active : TQPalette::Disabled,
137 TQColorGroup::Background ) );
139 p.drawTiledPixmap( 0, 0, width(), height(), p_backgroundPixmap );
144 bgImage = tempPixmap;
146 KImageEffect::blend( gradientImage, bgImage, (
float)p_opacity );
148 tempPixmap.convertFromImage( bgImage );
154 tempPixmap.convertFromImage( gradientImage );
162 TQWidget* childWidget = 0;
163 const TQPoint topLeft( 0, 0 );
165 for ( WidgetList::Iterator it = childWidgetList.begin();
166 it != childWidgetList.end(); ++it ) {
168 childWidget = ( *it );
173 if ( p_customBackgroundWidgets.contains( childWidget ) ) {
177 partPixmap.resize( childWidget->size() );
182 if ( childWidget->parent() == this ) {
183 area = childWidget->geometry();
185 area.setTopLeft( childWidget->mapTo(
this,
186 childWidget->clipRegion().boundingRect().topLeft() ) );
187 area.setSize( childWidget->size() );
189 bitBlt( &partPixmap, topLeft, &tempPixmap, area );
191 p_currentChild = childWidget;
192 childWidget->setPaletteBackgroundPixmap( partPixmap );
195 TQWidget::setPaletteBackgroundPixmap( tempPixmap );
202 p_cacheDirty =
false;
209 if ( p_cacheDirty ==
true ) {
216 TQWidget::paintEvent( e );
220 TQWidget* child =
dynamic_cast<TQWidget*
>( object );
225 if (
object ==
this ) {
226 if ( event->type() == TQEvent::ChildInserted ) {
227 child =
dynamic_cast<TQWidget*
>(
dynamic_cast<TQChildEvent*
>( event )->child() );
228 if ( isValidChildWidget( child ) == false ) {
234 p_knownWidgets.append( child );
238 child->installEventFilter(
this );
239 }
else if ( event->type() == TQEvent::ChildRemoved ) {
243 p_knownWidgets.remove(
dynamic_cast<TQWidget*
>(
dynamic_cast<TQChildEvent*
>( event )->child() ) );
251 if ( event->type() == TQEvent::PaletteChange ) {
257 if ( p_currentChild == 0L && child != 0L ) {
258 if ( p_customBackgroundWidgets.contains( child ) == false ) {
259 p_customBackgroundWidgets.append( child );
267 if ( child != p_currentChild && child != 0L ) {
272 if ( p_customBackgroundWidgets.contains( child ) == false ) {
273 if ( child->paletteBackgroundPixmap() != 0L ) {
274 p_customBackgroundWidgets.append( child );
282 if ( child->paletteBackgroundPixmap() == 0L ) {
283 p_customBackgroundWidgets.remove( child );
293 if ( event->type() == TQEvent::Move ) {
294 if ( p_customBackgroundWidgets.contains( child ) == false ) {
295 updateChildBackground( child );
301void KexiGradientWidget::updateChildBackground( TQWidget* childWidget )
306 const TQPoint topLeft( 0, 0 );
308 bgPixmap = paletteBackgroundPixmap() ? (*paletteBackgroundPixmap()) : TQPixmap();
309 if ( bgPixmap.isNull() )
317 if ( childWidget->parent() == 0L )
323 if ( p_customBackgroundWidgets.contains( childWidget ) ) {
327 partPixmap.resize( childWidget->size() );
332 if ( childWidget->parent() ==
this ) {
333 area = childWidget->geometry();
335 area.setTopLeft( childWidget->mapTo(
this,
336 childWidget->clipRegion().boundingRect().topLeft() ) );
337 area.setSize( childWidget->size() );
339 bitBlt( &partPixmap, topLeft, &bgPixmap, area );
341 p_currentChild = childWidget;
342 childWidget->setPaletteBackgroundPixmap( partPixmap );
345void KexiGradientWidget::setPaletteBackgroundColor(
const TQColor& color )
347 p_backgroundColor = color;
349 TQWidget::setPaletteBackgroundColor( p_backgroundColor );
353const TQColor& KexiGradientWidget::paletteBackgroundColor()
const
355 return p_backgroundColor;
358#include "kexigradientwidget.moc"