File indexing completed on 2024-12-22 04:18:19

0001 /***************************************************************************
0002  *                                                                         *
0003  *   copyright : (C) 2007 The University of Toronto                        *
0004  *                   netterfield@astro.utoronto.ca                         *
0005  *                                                                         *
0006  *   This program is free software; you can redistribute it and/or modify  *
0007  *   it under the terms of the GNU General Public License as published by  *
0008  *   the Free Software Foundation; either version 2 of the License, or     *
0009  *   (at your option) any later version.                                   *
0010  *                                                                         *
0011  ***************************************************************************/
0012 
0013 #ifndef GRADIENTEDITOR_H
0014 #define GRADIENTEDITOR_H
0015 
0016 #include <QHash>
0017 #include <QWidget>
0018 #include <QGradient>
0019 #include <QPainterPath>
0020 
0021 #include "kstwidgets_export.h"
0022 
0023 namespace Kst {
0024 
0025 class KSTWIDGETS_EXPORT GradientEditor : public QWidget {
0026   Q_OBJECT
0027 public:
0028   explicit GradientEditor(QWidget *parent = 0);
0029   virtual ~GradientEditor();
0030 
0031   virtual QSize sizeHint() const;
0032 
0033   QGradient gradient() const;
0034 
0035   void setDefaultGradientStops(QGradientStops stops);
0036 
0037   bool dirty() const { return _dirty; }
0038 
0039 public Q_SLOTS:
0040   void setGradient(const QGradient &gradient);
0041   void resetGradient();
0042 
0043 Q_SIGNALS:
0044   void changed(const QGradient &gradient);
0045 
0046 protected:
0047   virtual void mousePressEvent(QMouseEvent *event);
0048   virtual void mouseReleaseEvent(QMouseEvent *event);
0049   virtual void mouseMoveEvent(QMouseEvent *event);
0050   virtual void paintEvent(QPaintEvent *event);
0051 
0052 private:
0053   bool isStopAt(const QPoint &point) const;
0054   QPainterPath marker(int x) const;
0055 
0056   QGradientStops gradientStops() const;
0057   void setGradientStops(const QGradientStops &stops);
0058   void clearGradientStops();
0059 
0060   struct Stop {
0061     int pos;
0062     QColor color;
0063     QPainterPath path;
0064   };
0065 
0066 private:
0067   QGradient *_gradient;
0068   QHash<int, Stop> _stopHash;
0069   int _movingStop;
0070   QGradientStops _defaultGradientStops;
0071   bool _dirty;
0072 };
0073 
0074 }
0075 
0076 #endif
0077 
0078 // vim: ts=2 sw=2 et