1 #pragma once
2 
3 #ifndef HISTOGRAM_H
4 #define HISTOGRAM_H
5 
6 #include "tcommon.h"
7 #include "traster.h"
8 #include "ttoonzimage.h"
9 #include "tpalette.h"
10 
11 #include <QWidget>
12 #include <QStackedWidget>
13 
14 #undef DVAPI
15 #undef DVVAR
16 #ifdef TOONZQT_EXPORTS
17 #define DVAPI DV_EXPORT_API
18 #define DVVAR DV_EXPORT_VAR
19 #else
20 #define DVAPI DV_IMPORT_API
21 #define DVVAR DV_IMPORT_VAR
22 #endif
23 
24 #ifdef _MSC_VER
25 #pragma warning(disable : 4251)
26 #endif
27 
28 class QStackedWidget;
29 class QString;
30 class QComboBox;
31 class QColor;
32 
33 //=============================================================================
34 // HistogramGraph
35 //-----------------------------------------------------------------------------
36 
37 class DVAPI HistogramGraph final : public QWidget {
38   Q_OBJECT
39 
40   QColor m_color;
41   /*! Height of graph, without margin.*/
42   int m_height;
43 
44   QVector<int> m_values, m_viewValues, m_logViewValues;
45   bool m_logScale;
46 
47 public:
48   static const int drawMargin;
49 
50 public:
51   HistogramGraph(QWidget *parent = 0, QColor m_color = QColor());
52   ~HistogramGraph();
53 
54   void setAlphaMask(int value);
55 
setHeight(int height)56   void setHeight(int height) { m_height = height; }
getHeight()57   int getHeight() { return m_height; }
58 
59   void setValues(const int values[]);
values()60   const QVector<int> &values() const { return m_values; }
61 
setLogScale(bool onOff)62   void setLogScale(bool onOff) { m_logScale = onOff; }
logScale()63   bool logScale() const { return m_logScale; }
64 
65   void draw(QPainter *painter, QPoint translation = QPoint(0, 0),
66             int size = -1);
67 
68 protected:
69   void paintEvent(QPaintEvent *pe) override;
70 };
71 
72 //=============================================================================
73 // ChannelBar
74 //-----------------------------------------------------------------------------
75 
76 class DVAPI ChannelBar final : public QWidget {
77   Q_OBJECT
78 
79 public:
80   enum Range { Range_0_255, Range_0_1 };
81 
82 private:
83   QColor m_color;
84   int m_colorBarLength;
85 
86   bool m_isHorizontal;
87   bool m_drawNumbers;
88 
89   QColor m_textColor;
90   Range m_range;
91 
92   Q_PROPERTY(QColor TextColor READ getTextColor WRITE setTextColor)
93 
94   int m_size;
95 
96 public:
97   ChannelBar(QWidget *parent = 0, QColor m_color = QColor(),
98              bool isHorizontal = true);
99   ~ChannelBar();
100 
getColor()101   QColor getColor() const { return m_color; }
102 
103   void setDrawNumbers(bool onOff);
drawNumbers()104   bool drawNumbers() const { return m_drawNumbers; }
105 
106   void draw(QPainter *painter, QPoint translation = QPoint(0, 0),
107             int size = -1);
108 
setTextColor(const QColor & color)109   void setTextColor(const QColor &color) { m_textColor = color; }
getTextColor()110   QColor getTextColor() const { return m_textColor; }
111 
setLabelRange(Range range)112   void setLabelRange(Range range) { m_range = range; }
113 
114 protected:
115   void paintEvent(QPaintEvent *event) override;
116 };
117 
118 //=============================================================================
119 // HistogramView
120 //-----------------------------------------------------------------------------
121 
122 class DVAPI HistogramView final : public QWidget {
123   Q_OBJECT
124 
125   HistogramGraph *m_histogramGraph;
126   ChannelBar *m_colorBar;
127 
128   QWidget *m_drawnWidget;
129 
130 public:
131   HistogramView(QWidget *parent = 0, QColor color = Qt::black);
132   ~HistogramView();
133 
histogramGraph()134   const HistogramGraph *histogramGraph() const { return m_histogramGraph; }
histogramGraph()135   HistogramGraph *histogramGraph() { return m_histogramGraph; }
136 
channelBar()137   const ChannelBar *channelBar() const { return m_colorBar; }
channelBar()138   ChannelBar *channelBar() { return m_colorBar; }
139 
getChannelBarColor()140   QColor getChannelBarColor() const { return m_colorBar->getColor(); }
141 
142   // Deve essere fatto prima di chiamare setValues()
setGraphHeight(int height)143   void setGraphHeight(int height) { m_histogramGraph->setHeight(height); }
setGraphAlphaMask(int value)144   void setGraphAlphaMask(int value) { m_histogramGraph->setAlphaMask(value); }
145   void setDrawnWidget(QWidget *widget);
146 
147   void setValues(const int values[]);
values()148   const QVector<int> &values() const { return m_histogramGraph->values(); }
149 
150   void draw(QPainter *painter, QPoint translation = QPoint(0, 0),
151             int width = -1);
152 };
153 
154 //=============================================================================
155 // Histograms
156 //-----------------------------------------------------------------------------
157 
158 class DVAPI Histograms final : public QStackedWidget {
159   Q_OBJECT
160 
161   TRasterP m_raster;
162   TPaletteP m_palette;  // Necessario per le tlv
163   int m_channelValue[6][256];
164   int m_channelsCount;
165   bool m_computeAlsoRGBA;
166 
167 public:
168   Histograms(QWidget *parent = 0, bool rgba = false);
169   ~Histograms();
170 
getRaster()171   TRasterP getRaster() const { return m_raster; }
172   void setRaster(const TRasterP &raster, const TPaletteP &palette = 0);
173 
174   HistogramView *getHistogramView(int indexType) const;
channelsCount()175   int channelsCount() const { return m_channelsCount; }
176 
177 protected:
178   void computeChannelsValue();
179 };
180 
181 //=============================================================================
182 // Histogram
183 //-----------------------------------------------------------------------------
184 
185 class DVAPI Histogram final : public QWidget {
186   Q_OBJECT
187 
188   QComboBox *m_channelsListBox;
189   Histograms *m_histograms;
190 
191 public:
192   Histogram(QWidget *parent = 0);
~Histogram()193   ~Histogram() {}
194 
getHistograms()195   Histograms *getHistograms() const { return m_histograms; }
196 
getRaster()197   TRasterP getRaster() const { return m_histograms->getRaster(); }
198   void setRaster(const TRasterP &raster, const TPaletteP &palette = 0);
199 
200 public slots:
201 
202   void setLogScale(bool onOff);
203 
204 private:
205   void updateChannelsList();
206 };
207 
208 #endif  // HISTOGRAM_H
209