1 /*
2 * Copyright Disney Enterprises, Inc.  All rights reserved.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License
6 * and the following modification to it: Section 6 Trademarks.
7 * deleted and replaced with:
8 *
9 * 6. Trademarks. This License does not grant permission to use the
10 * trade names, trademarks, service marks, or product names of the
11 * Licensor and its affiliates, except as required for reproducing
12 * the content of the NOTICE file.
13 *
14 * You may obtain a copy of the License at
15 * http://www.apache.org/licenses/LICENSE-2.0
16 */
17 
18 #ifndef _ExprColorSwatch_h_
19 #define _ExprColorSwatch_h_
20 
21 #include <vector>
22 #include <QObject>
23 #include <QFrame>
24 #include <QWidget>
25 #include <SeExpr2/Vec.h>
26 
27 class QGridLayout;
28 
29 class ExprColorFrame : public QFrame {
30     Q_OBJECT
31   public:
32     ExprColorFrame(SeExpr2::Vec3d value, QWidget *parent = 0);
~ExprColorFrame()33     ~ExprColorFrame() {}
34 
35     void setValue(const SeExpr2::Vec3d &value);
36     SeExpr2::Vec3d getValue() const;
selected()37     bool selected() {
38         return _selected;
39     };
40 
41   protected:
42     virtual void paintEvent(QPaintEvent *event);
43     virtual void mouseReleaseEvent(QMouseEvent *event);
44 
45   private
46 Q_SLOTS:
47     void deleteSwatchMenu(const QPoint &pos);
48 
49 Q_SIGNALS:
50     void selValChangedSignal(SeExpr2::Vec3d value);
51     void swatchChanged(QColor color);
52     void deleteSwatch(ExprColorFrame *swatch);
53 
54   private:
55     SeExpr2::Vec3d _value;
56     QColor _color;
57     bool _selected;
58 };
59 
60 // Simple color widget with or without index label
61 class ExprColorWidget : public QWidget {
62     Q_OBJECT
63   public:
64     ExprColorWidget(SeExpr2::Vec3d value, int index, bool indexLabel, QWidget *parent);
65     ExprColorFrame *getColorFrame();
66 
67   private:
68     ExprColorFrame *_colorFrame;
69 };
70 
71 class ExprColorSwatchWidget : public QWidget {
72     Q_OBJECT
73 
74   public:
75     ExprColorSwatchWidget(bool indexLabel, QWidget *parent = 0);
~ExprColorSwatchWidget()76     ~ExprColorSwatchWidget() {}
77 
78     // Convenience Functions
79     void addSwatch(SeExpr2::Vec3d &val, int index = -1);
80     void setSwatchColor(int index, QColor color);
81     QColor getSwatchColor(int index);
82 
83   private
84 Q_SLOTS:
85     void addNewColor();
86     void removeSwatch(ExprColorFrame *);
87     void internalSwatchChanged(QColor color);
88 
89 Q_SIGNALS:
90     void selValChangedSignal(SeExpr2::Vec3d val);
91     void swatchChanged(int index, SeExpr2::Vec3d val);
92     void swatchAdded(int index, SeExpr2::Vec3d val);
93     void swatchRemoved(int index);
94 
95   private:
96     QGridLayout *_gridLayout;
97     int _columns;
98     bool _indexLabel;
99 };
100 #endif
101