kexi

kexigradientwidget.h

00001 /* This file is part of the KDE project
00002    Copyright (C) 2005 Christian Nitschkowski <segfault_ii@web.de>
00003 
00004    This program is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU Library General Public
00006    License as published by the Free Software Foundation; either
00007    version 2 of the License, or (at your option) any later version.
00008 
00009    This program is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012    Library General Public License for more details.
00013 
00014    You should have received a copy of the GNU Library General Public License
00015    along with this program; see the file COPYING.  If not, write to
00016    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00017  * Boston, MA 02110-1301, USA.
00018 */
00019 
00020 #ifndef KEXIGRADIENTWIDGET_H
00021 #define KEXIGRADIENTWIDGET_H
00022 
00023 #include <qtimer.h>
00024 #include <qwidget.h>
00025 
00026 #include <kimageeffect.h>
00027 #include <kpixmap.h>
00028 
00029 #define REBUILD_DELAY 100
00030 
00036 class KEXIGUIUTILS_EXPORT KexiGradientWidget : public QWidget {
00037     typedef QPtrList<QWidget> WidgetList;
00038 
00039     Q_OBJECT
00040     Q_PROPERTY(DisplayMode displayMode READ displayMode WRITE setDisplayMode DESIGNABLE true)
00041     Q_PROPERTY(GradientType gradientType READ gradientType WRITE setGradientType DESIGNABLE true)
00042     Q_PROPERTY(QColor gradientColor1 READ gradientColor1 WRITE setGradientColor1 DESIGNABLE true)
00043     Q_PROPERTY(QColor gradientColor2 READ gradientColor2 WRITE setGradientColor2 DESIGNABLE true)
00044     Q_PROPERTY(double blendOpacity READ blendOpacity WRITE setBlendOpacity DESIGNABLE true)
00045     Q_ENUMS( DisplayMode GradientType )
00046 
00047     public:
00051         enum DisplayMode {
00052             NoGradient, 
00053             FadedGradient, 
00054             SimpleGradient 
00055         };
00056 
00061         enum GradientType {
00062             VerticalGradient = KImageEffect::VerticalGradient,
00063             HorizontalGradient = KImageEffect::HorizontalGradient,
00064             DiagonalGradient = KImageEffect::DiagonalGradient,
00065             CrossDiagonalGradient = KImageEffect::CrossDiagonalGradient,
00066             PyramidGradient = KImageEffect::PyramidGradient,
00067             RectangleGradient = KImageEffect::RectangleGradient,
00068             PipeCrossGradient = KImageEffect::PipeCrossGradient,
00069             EllipticGradient = KImageEffect::EllipticGradient
00070         };
00071 
00072         KexiGradientWidget( QWidget *parent = 0, const char *name = 0, WFlags f = 0 );
00073 
00074         virtual ~KexiGradientWidget();
00075 
00076         virtual void setPaletteBackgroundPixmap( const QPixmap& pixmap ) {
00077             p_backgroundPixmap = pixmap;
00078             p_rebuildDelayTimer.start( REBUILD_DELAY, true );
00079         }
00080 
00081         virtual const QColor& paletteBackgroundColor() const;
00082 
00087         void setDisplayMode( DisplayMode mode ) {
00088             p_displayMode = mode;
00089             p_cacheDirty = true;
00090             update();
00091         }
00092 
00096         DisplayMode displayMode() const {
00097             return p_displayMode;
00098         }
00099 
00103         void setGradientType( GradientType type ) {
00104             p_gradientType = type;
00105             p_cacheDirty = true;
00106             update();
00107         }
00108 
00112         GradientType gradientType() const {
00113             return p_gradientType;
00114         }
00115 
00118         void setGradientColor1( const QColor& color ) {
00119             p_color1 = color;
00120             p_cacheDirty = true;
00121         }
00122 
00125         void setGradientColor2( const QColor& color ) {
00126             p_color2 = color;
00127             p_cacheDirty = true;
00128         }
00129 
00135         void setGradientColors( const QColor& color1, const QColor& color2 ) {
00136             p_color1 = color1;
00137             p_color2 = color2;
00138             p_cacheDirty = true;
00139             }
00140 
00142         QColor gradientColor1() const { return p_color1; }
00143 
00145         QColor gradientColor2() const { return p_color2; }
00146 
00151         void setBlendOpacity( double opacity ) {
00152             p_opacity = opacity;
00153             p_cacheDirty = true;
00154         }
00155 
00156         double blendOpacity() const { return p_opacity; }
00157 
00158     public slots:
00159         virtual void setPaletteBackgroundColor( const QColor& color );
00160 
00161     protected:
00162         virtual bool eventFilter( QObject* object, QEvent* event );
00163         virtual void enabledChange( bool enabled ) {
00164             p_cacheDirty = true;
00165             QWidget::enabledChange( enabled );
00166         }
00167 
00168         virtual void paletteChange( const QPalette& pal ) {
00169             p_cacheDirty = true;
00170             QWidget::paletteChange( pal );
00171         }
00172 
00173         virtual void paintEvent( QPaintEvent* e );
00174 
00175         virtual void resizeEvent( QResizeEvent* e ) {
00176             p_rebuildDelayTimer.start( REBUILD_DELAY, true );
00177             QWidget::resizeEvent( e );
00178         }
00179 
00180         virtual void styleChange( QStyle& style ) {
00181             p_cacheDirty = true;
00182             QWidget::styleChange( style );
00183         }
00184 
00185     private:
00194         static void buildChildrenList( WidgetList& list, QWidget* p );
00199         static bool isValidChildWidget( QObject* child );
00200 
00205         void rebuildCache();
00206 
00214         void updateChildBackground( QWidget* childWidget );
00215 
00216     private:
00217         WidgetList p_knownWidgets;
00218         WidgetList p_customBackgroundWidgets;
00219         DisplayMode p_displayMode;
00220         GradientType p_gradientType;
00221         KPixmap p_backgroundPixmap;
00222         QColor p_color1;
00223         QColor p_color2;
00224         QTimer p_rebuildDelayTimer;
00225         QWidget* p_currentChild;
00226         double p_opacity;
00227         bool p_cacheDirty;
00228 
00229         QColor p_backgroundColor;
00230 
00231     public slots:
00236         virtual void polish() {
00237             QWidget::polish();
00238             rebuildCache();
00239         }
00240 
00241     private slots:
00242         void setCacheDirty() {
00243             rebuildCache();
00244         }
00245 
00246     };
00247 
00248 #endif
KDE Home | KDE Accessibility Home | Description of Access Keys