00001 #ifndef GRADIENTS_H
00002 #define GRADIENTS_H
00003
00004 #include <QtGui>
00005
00006 class HoverPoints;
00007
00008 class ShadeWidget : public QWidget
00009 {
00010 Q_OBJECT
00011 public:
00012 enum ShadeType {
00013 RedShade,
00014 GreenShade,
00015 BlueShade,
00016 ARGBShade
00017 };
00018
00019 ShadeWidget(ShadeType type, QWidget *parent);
00020
00021 void setGradientStops(const QGradientStops &stops);
00022
00023 void paintEvent(QPaintEvent *e);
00024
00025 QSize sizeHint() const { return QSize(150, 40); }
00026 QPolygonF points() const;
00027
00028 void setPoints(QPolygonF points);
00029
00030 void setPixmap(QPixmap pixmap);
00031
00032 HoverPoints *hoverPoints() const { return m_hoverPoints; }
00033
00034 uint colorAt(int x);
00035
00036 signals:
00037 void colorsChanged();
00038
00039 private:
00040 void generateShade();
00041
00042 ShadeType m_shade_type;
00043 QImage m_shade;
00044 QImage m_histogram;
00045 HoverPoints *m_hoverPoints;
00046 QLinearGradient m_alpha_gradient;
00047 };
00048
00049 class GradientEditor : public QWidget
00050 {
00051 Q_OBJECT
00052 public:
00053 GradientEditor(QWidget *parent);
00054
00055 void setGradientStops(const QGradientStops &stops);
00056
00057 QColor getColorAt(int i);
00058 ShadeWidget *m_alpha_shade;
00059
00060 public slots:
00061 void pointsUpdated();
00062 void saveToFile(QString filename);
00063 void loadFromFile(QString filename);
00064
00065 signals:
00066 void gradientStopsChanged(const QGradientStops &stops);
00067 void transferFunctionChanged(unsigned char *new_texture_data);
00068
00069 private:
00070 ShadeWidget *m_red_shade;
00071 ShadeWidget *m_green_shade;
00072 ShadeWidget *m_blue_shade;
00073
00074
00075 unsigned char * prepareTransferFunctionData();
00076 };
00077
00078 #endif // GRADIENTS_H