File indexing completed on 2024-05-12 17:12:40
0001 /*************************************************************************** 0002 * Copyright (C) 2011 by Renaud Guezennec * 0003 * https://rolisteam.org/contact * 0004 * * 0005 * Rolisteam is free software; you can redistribute it and/or modify * 0006 * it under the terms of the GNU General Public License as published by * 0007 * the Free Software Foundation; either version 2 of the License, or * 0008 * (at your option) any later version. * 0009 * * 0010 * This program is distributed in the hope that it will be useful, * 0011 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 0012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 0013 * GNU General Public License for more details. * 0014 * * 0015 * You should have received a copy of the GNU General Public License * 0016 * along with this program; if not, write to the * 0017 * Free Software Foundation, Inc., * 0018 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * 0019 ***************************************************************************/ 0020 0021 #ifndef COLORTABLE_H 0022 #define COLORTABLE_H 0023 0024 #include "rwidgets/rwidgets_global.h" 0025 #include <QColor> 0026 #include <QWidget> 0027 #include <QtWidgets> 0028 0029 class QVBoxLayout; 0030 /** 0031 * @brief SaturationChooser is a widget which stores and manages saturation value 0032 */ 0033 class RWIDGET_EXPORT SaturationChooser : public QWidget 0034 { 0035 Q_OBJECT 0036 public: 0037 /** 0038 * @brief default constructor 0039 */ 0040 SaturationChooser(); 0041 /** 0042 * @brief accessor for the current value 0043 * @return int value 0044 */ 0045 int getValue() const; 0046 /** 0047 * @brief setter for current color 0048 * @param base color 0049 */ 0050 void setColor(QColor& color); 0051 0052 public slots: 0053 /** 0054 * @brief slot to handle change in the base color 0055 * @param new color's hue 0056 * @param new color's lightness 0057 */ 0058 void colorHasChanged(int, int); 0059 0060 signals: 0061 /** 0062 * @brief emited when saturation changes 0063 */ 0064 void valueChanged(int); 0065 0066 protected: 0067 /** 0068 * @brief redefines the painting method to display the appropriate gradiant 0069 */ 0070 void paintEvent(QPaintEvent* event); 0071 /** 0072 * @brief redefines mouse click behaviour to make it easier to use 0073 */ 0074 void mousePressEvent(QMouseEvent* e); 0075 /** 0076 * @brief redefines mouse move behaviour to make it easier to use 0077 */ 0078 void mouseMoveEvent(QMouseEvent* e); 0079 /** 0080 * @brief redefines mouse wheel behaviour to make it easier to use 0081 */ 0082 void wheelEvent(QWheelEvent* event); 0083 0084 private: 0085 int m_currentValue; ///< stores current saturation value 0086 QColor m_color; ///< stores the current color 0087 QRect m_gradianRect; ///< selector zone 0088 QPolygon m_polygon; ///< zone's geometry 0089 }; 0090 /** 0091 * @brief ColorTable is a widget which display a large panel of color, and allows user to chose one of them. 0092 */ 0093 class RWIDGET_EXPORT ColorTable : public QWidget 0094 { 0095 Q_OBJECT 0096 public: 0097 /** 0098 * @brief default constructor 0099 */ 0100 ColorTable(); 0101 int heightForWidth(int width) const; 0102 QSize sizeHint() const; 0103 signals: 0104 /** 0105 * @brief emited when user click on the widget to select another color. 0106 */ 0107 int dataChanged(int, int); 0108 0109 protected: 0110 /** 0111 * @brief displays the large set of color thanks of gradiant use. 0112 */ 0113 virtual void paintEvent(QPaintEvent* event); 0114 /** 0115 * @brief manages the resize event to make sure, it keeps square shape. 0116 */ 0117 virtual void resizeEvent(QResizeEvent* event); 0118 /** 0119 * @brief manages the click and emit the selected color's values 0120 */ 0121 void mousePressEvent(QMouseEvent*); 0122 }; 0123 0124 /** 0125 * @brief ColorTableChooser is the parent widget of ColorTable and SaturationChooser 0126 */ 0127 class RWIDGET_EXPORT ColorTableChooser : public QWidget 0128 { 0129 Q_OBJECT 0130 public: 0131 /** 0132 * @brief constructor 0133 * @param parent widget 0134 */ 0135 ColorTableChooser(QWidget* parent= nullptr); 0136 ~ColorTableChooser(); 0137 0138 public slots: 0139 /** 0140 * @brief handle current color change, users click on the colortable 0141 */ 0142 void colorHasChanged(int, int); 0143 /** 0144 * @brief handle the current saturation of the current color, users click on saturationchooser 0145 */ 0146 void valueHasChanged(int); 0147 0148 protected: 0149 /** 0150 * @brief resize the widget 0151 */ 0152 void resizeEvent(QResizeEvent* event); 0153 signals: 0154 /** 0155 * @brief emitted when user has selected another color. 0156 */ 0157 void currentColorChanged(QColor); 0158 0159 private: 0160 QColor m_color; /// current color. 0161 QVBoxLayout* m_layout; /// vertical layout 0162 ColorTable* m_colorTable; /// colortable 0163 SaturationChooser* m_valueChooser; /// saturation chooser 0164 int m_h; /// current hue 0165 int m_s; /// current saturation 0166 }; 0167 0168 #endif // COLORTABLE_H