kexi
kexigradientwidget.h00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
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
00032
00035 class KEXIGUIUTILS_EXPORT KexiGradientWidget : public QWidget {
00036 typedef QPtrList<QWidget> WidgetList;
00037
00038 Q_OBJECT
00039 Q_PROPERTY(DisplayMode displayMode READ displayMode WRITE setDisplayMode DESIGNABLE true)
00040 Q_PROPERTY(GradientType gradientType READ gradientType WRITE setGradientType DESIGNABLE true)
00041 Q_PROPERTY(QColor gradientColor1 READ gradientColor1 WRITE setGradientColor1 DESIGNABLE true)
00042 Q_PROPERTY(QColor gradientColor2 READ gradientColor2 WRITE setGradientColor2 DESIGNABLE true)
00043 Q_PROPERTY(double blendOpacity READ blendOpacity WRITE setBlendOpacity DESIGNABLE true)
00044 Q_ENUMS( DisplayMode GradientType )
00045
00046 public:
00050 enum DisplayMode {
00051 NoGradient,
00052 FadedGradient,
00053 SimpleGradient
00054 };
00055
00060 enum GradientType {
00061 VerticalGradient = KImageEffect::VerticalGradient,
00062 HorizontalGradient = KImageEffect::HorizontalGradient,
00063 DiagonalGradient = KImageEffect::DiagonalGradient,
00064 CrossDiagonalGradient = KImageEffect::CrossDiagonalGradient,
00065 PyramidGradient = KImageEffect::PyramidGradient,
00066 RectangleGradient = KImageEffect::RectangleGradient,
00067 PipeCrossGradient = KImageEffect::PipeCrossGradient,
00068 EllipticGradient = KImageEffect::EllipticGradient
00069 };
00070
00071 KexiGradientWidget( QWidget *parent = 0, const char *name = 0, WFlags f = 0 );
00072
00073 virtual ~KexiGradientWidget();
00074
00075 virtual void setPaletteBackgroundPixmap( const QPixmap& pixmap ) {
00076 p_backgroundPixmap = pixmap;
00077 p_rebuildDelayTimer.start( REBUILD_DELAY, true );
00078 }
00079
00080 virtual const QColor& paletteBackgroundColor() const;
00081
00086 void setDisplayMode( DisplayMode mode ) {
00087 p_displayMode = mode;
00088 p_cacheDirty = true;
00089 update();
00090 }
00091
00095 DisplayMode displayMode() const {
00096 return p_displayMode;
00097 }
00098
00102 void setGradientType( GradientType type ) {
00103 p_gradientType = type;
00104 p_cacheDirty = true;
00105 update();
00106 }
00107
00111 GradientType gradientType() const {
00112 return p_gradientType;
00113 }
00114
00117 void setGradientColor1( const QColor& color ) {
00118 p_color1 = color;
00119 p_cacheDirty = true;
00120 }
00121
00124 void setGradientColor2( const QColor& color ) {
00125 p_color2 = color;
00126 p_cacheDirty = true;
00127 }
00128
00134 void setGradientColors( const QColor& color1, const QColor& color2 ) {
00135 p_color1 = color1;
00136 p_color2 = color2;
00137 p_cacheDirty = true;
00138 }
00139
00141 QColor gradientColor1() const { return p_color1; }
00142
00144 QColor gradientColor2() const { return p_color2; }
00145
00150 void setBlendOpacity( double opacity ) {
00151 p_opacity = opacity;
00152 p_cacheDirty = true;
00153 }
00154
00155 double blendOpacity() const { return p_opacity; }
00156
00157 public slots:
00158 virtual void setPaletteBackgroundColor( const QColor& color );
00159
00160 protected:
00161 virtual bool eventFilter( QObject* object, QEvent* event );
00162 virtual void enabledChange( bool enabled ) {
00163 p_cacheDirty = true;
00164 QWidget::enabledChange( enabled );
00165 }
00166
00167 virtual void paletteChange( const QPalette& pal ) {
00168 p_cacheDirty = true;
00169 QWidget::paletteChange( pal );
00170 }
00171
00172 virtual void paintEvent( QPaintEvent* e );
00173
00174 virtual void resizeEvent( QResizeEvent* e ) {
00175 p_rebuildDelayTimer.start( REBUILD_DELAY, true );
00176 QWidget::resizeEvent( e );
00177 }
00178
00179 virtual void styleChange( QStyle& style ) {
00180 p_cacheDirty = true;
00181 QWidget::styleChange( style );
00182 }
00183
00184 private:
00193 static void buildChildrenList( WidgetList& list, QWidget* p );
00198 static bool isValidChildWidget( QObject* child );
00199
00204 void rebuildCache();
00205
00213 void updateChildBackground( QWidget* childWidget );
00214
00215 private:
00216 WidgetList p_knownWidgets;
00217 WidgetList p_customBackgroundWidgets;
00218 DisplayMode p_displayMode;
00219 GradientType p_gradientType;
00220 KPixmap p_backgroundPixmap;
00221 QColor p_color1;
00222 QColor p_color2;
00223 QTimer p_rebuildDelayTimer;
00224 QWidget* p_currentChild;
00225 double p_opacity;
00226 bool p_cacheDirty;
00227
00228 QColor p_backgroundColor;
00229
00230 public slots:
00235 virtual void polish() {
00236 QWidget::polish();
00237 rebuildCache();
00238 }
00239
00240 private slots:
00241 void setCacheDirty() {
00242 rebuildCache();
00243 }
00244
00245 };
00246
00247 #endif
|