demos/gradients/gradients.h

Go to the documentation of this file.
00001 /****************************************************************************
00002 **
00003 ** Copyright (C) 2005-2006 Trolltech ASA. All rights reserved.
00004 **
00005 ** This file is part of the demonstration applications of the Qt Toolkit.
00006 **
00007 ** This file may be used under the terms of the GNU General Public
00008 ** License version 2.0 as published by the Free Software Foundation
00009 ** and appearing in the file LICENSE.GPL included in the packaging of
00010 ** this file.  Please review the following information to ensure GNU
00011 ** General Public Licensing requirements will be met:
00012 ** http://www.trolltech.com/products/qt/opensource.html
00013 **
00014 ** If you are unsure which license is appropriate for your use, please
00015 ** review the following information:
00016 ** http://www.trolltech.com/products/qt/licensing.html or contact the
00017 ** sales department at sales@trolltech.com.
00018 **
00019 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00020 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00021 **
00022 ****************************************************************************/
00023 
00024 #ifndef GRADIENTS_H
00025 #define GRADIENTS_H
00026 
00027 #include "arthurwidgets.h"
00028 
00029 #include <QtGui>
00030 
00031 class HoverPoints;
00032 
00033 
00034 class ShadeWidget : public QWidget
00035 {
00036     Q_OBJECT
00037 public:
00038     enum ShadeType {
00039         RedShade,
00040         GreenShade,
00041         BlueShade,
00042         ARGBShade
00043     };
00044 
00045     ShadeWidget(ShadeType type, QWidget *parent);
00046 
00047     void setGradientStops(const QGradientStops &stops);
00048 
00049     void paintEvent(QPaintEvent *e);
00050 
00051     QSize sizeHint() const { return QSize(150, 40); }
00052     QPolygonF points() const;
00053 
00054     HoverPoints *hoverPoints() const { return m_hoverPoints; }
00055 
00056     uint colorAt(int x);
00057 
00058 signals:
00059     void colorsChanged();
00060 
00061 private:
00062     void generateShade();
00063 
00064     ShadeType m_shade_type;
00065     QImage m_shade;
00066     HoverPoints *m_hoverPoints;
00067     QLinearGradient m_alpha_gradient;
00068 };
00069 
00070 class GradientEditor : public QWidget
00071 {
00072     Q_OBJECT
00073 public:
00074     GradientEditor(QWidget *parent);
00075 
00076     void setGradientStops(const QGradientStops &stops);
00077 
00078 public slots:
00079     void pointsUpdated();
00080 
00081 signals:
00082     void gradientStopsChanged(const QGradientStops &stops);
00083 
00084 private:
00085     ShadeWidget *m_red_shade;
00086     ShadeWidget *m_green_shade;
00087     ShadeWidget *m_blue_shade;
00088     ShadeWidget *m_alpha_shade;
00089 };
00090 
00091 
00092 class GradientRenderer : public ArthurFrame
00093 {
00094     Q_OBJECT
00095 public:
00096     GradientRenderer(QWidget *parent);
00097     void paint(QPainter *p);
00098 
00099     QSize sizeHint() const { return QSize(400, 400); }
00100 
00101     HoverPoints *hoverPoints() const { return m_hoverPoints; }
00102     void mousePressEvent(QMouseEvent *e);
00103 
00104 public slots:
00105     void setGradientStops(const QGradientStops &stops);
00106 
00107     void setPadSpread() { m_spread = QGradient::PadSpread; update(); }
00108     void setRepeatSpread() { m_spread = QGradient::RepeatSpread; update(); }
00109     void setReflectSpread() { m_spread = QGradient::ReflectSpread; update(); }
00110 
00111     void setLinearGradient() { m_gradientType = Qt::LinearGradientPattern; update(); }
00112     void setRadialGradient() { m_gradientType = Qt::RadialGradientPattern; update(); }
00113     void setConicalGradient() { m_gradientType = Qt::ConicalGradientPattern; update(); }
00114 
00115 
00116 private:
00117     QGradientStops m_stops;
00118     HoverPoints *m_hoverPoints;
00119 
00120     QGradient::Spread m_spread;
00121     Qt::BrushStyle m_gradientType;
00122 };
00123 
00124 
00125 class GradientWidget : public QWidget
00126 {
00127     Q_OBJECT
00128 public:
00129     GradientWidget(QWidget *parent);
00130 
00131 public slots:
00132     void setDefault1() { setDefault(1); }
00133     void setDefault2() { setDefault(2); }
00134     void setDefault3() { setDefault(3); }
00135     void setDefault4() { setDefault(4); }
00136 
00137 private:
00138     void setDefault(int i);
00139 
00140     GradientRenderer *m_renderer;
00141     GradientEditor *m_editor;
00142 
00143     QRadioButton *m_linearButton;
00144     QRadioButton *m_radialButton;
00145     QRadioButton *m_conicalButton;
00146     QRadioButton *m_padSpreadButton;
00147     QRadioButton *m_reflectSpreadButton;
00148     QRadioButton *m_repeatSpreadButton;
00149 
00150 };
00151 
00152 #endif // GRADIENTS_H

Generated on Thu Mar 15 11:52:32 2007 for Qt 4.2 User's Guide by  doxygen 1.5.1