1 /****************************************************************************
2 * MeshLab                                                           o o     *
3 * A versatile mesh processing toolbox                             o     o   *
4 *                                                                _   O  _   *
5 * Copyright(C) 2005-2008                                           \/)\/    *
6 * Visual Computing Lab                                            /\/|      *
7 * ISTI - Italian National Research Council                           |      *
8 *                                                                    \      *
9 * All rights reserved.                                                      *
10 *                                                                           *
11 * This program is free software; you can redistribute it and/or modify      *
12 * it under the terms of the GNU General Public License as published by      *
13 * the Free Software Foundation; either version 2 of the License, or         *
14 * (at your option) any later version.                                       *
15 *                                                                           *
16 * This program is distributed in the hope that it will be useful,           *
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of            *
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the             *
19 * GNU General Public License (http://www.gnu.org/licenses/gpl.txt)          *
20 * for more details.                                                         *
21 *                                                                           *
22 ****************************************************************************/
23 
24 #ifndef RFX_COLORBOX_H_
25 #define RFX_COLORBOX_H_
26 
27 #include <cassert>
28 #include <climits>
29 #include <cfloat>
30 #include <QSignalMapper>
31 #include <QWidget>
32 #include <QFrame>
33 #include <QPushButton>
34 #include <QColor>
35 #include <QColorDialog>
36 #include <QGridLayout>
37 #include <QLineEdit>
38 #include <QVBoxLayout>
39 #include <QSlider>
40 #include <vcg/space/color4.h>
41 #include "rfx_dialog.h"
42 
43 class RfxColorBox : public QWidget
44 {
45 	Q_OBJECT
46 
47 public:
48      explicit RfxColorBox(const int&, const int&, const QColor&, QWidget *parent = 0);
49 	virtual ~RfxColorBox();
50 
51 	/*
52 		Returns the current color as an array of float value between 0 and 1.
53 		@return the current color as float array.
54 	*/
getColorf()55 	inline vcg::Color4f getColorf(){
56 		vcg::Color4f c(_redS->value() / 255.0f,_greenS->value() / 255.0f,_blueS->value() / 255.0f,_alphaS->value() / 255.0f);
57 		return c;
58 	}
59 
60 public slots:
61 	void setR(int);
62 	void setR();
63 	void setG(int);
64 	void setG();
65 	void setB(int);
66 	void setB();
67 	void setA(int);
68 	void setA();
69 
70 private slots:
71      void setBoxColorFromDialog();
72 
73 signals:
74      void colorChanged();
75      /*
76 	 Unused at the moment...maybe for further usages.
77 
78 	 void redChanged();
79      void greenChanged();
80      void blueChanged();
81      void alphaChanged();*/
82 
83 private:
84 	QFrame* _scacchiera;
85 	/*Colored box without alpha channel*/
86 	QFrame* _rgbBox;
87 	/*Colored box with alpha channel*/
88 	QPushButton* _rgbaBox;
89 
90 	/* The sliders */
91 	QSlider* _redS;
92 	QSlider* _greenS;
93 	QSlider* _blueS;
94 	QSlider* _alphaS;
95 
96 	/* The text boxes */
97 	QLineEdit* _redT;
98 	QLineEdit* _greenT;
99 	QLineEdit* _blueT;
100 	QLineEdit* _alphaT;
101 
102 	 enum Channels{
103 		 CHANNEL_R, CHANNEL_G, CHANNEL_B, CHANNEL_A, CHANNEL_ALL
104 	 };
105 
106      /*Returns a string rapresenting a new stylesheet(without alpha channel)*/
107 	 QString getNewRGBStylesheet(const QString&, RfxColorBox::Channels, int*[]);
108      /*Returns a string rapresenting a new stylesheet(with alpha channel)*/
109      QString getNewRGBAStylesheet(const QString&, RfxColorBox::Channels, int*[]);
110 
111      /* default basic style for the rgb box */
112      static const QString _BASE_RGB_BOX_STYLE;
113 
114      /* default basic style for the rgba box */
115      static const QString _BASE_RGBA_BOX_STYLE;
116 
117 	 /* Initialize a slider.
118 	 @param slider the slider to initialize
119 	 @param value the initial value
120 	 */
121 	 void initSlider(QSlider*, int);
122 
123 	 /* Initialize a text box.
124 	 @param box the text box to initialize
125 	 */
126 	 void initTextBox(QLineEdit*);
127 
128 	 /* Connects all the slider to the color box. */
129 	 void connectSliders();
130 
131 	 /* Disconnects all the slider to the color box. */
132 	 void disconnectSliders();
133 };
134 #endif /* RFX_COLORBOX_H_*/
135