tahoma2d/toonz/sources/include/toonzqt/histogram.h

190 lines
4.6 KiB
C
Raw Normal View History

2016-05-17 03:04:11 +12:00
#pragma once
2016-03-19 06:57:51 +13:00
#ifndef HISTOGRAM_H
#define HISTOGRAM_H
#include "tcommon.h"
#include "traster.h"
#include "ttoonzimage.h"
#include "tpalette.h"
#include <QWidget>
#include <QStackedWidget>
#undef DVAPI
#undef DVVAR
#ifdef TOONZQT_EXPORTS
#define DVAPI DV_EXPORT_API
#define DVVAR DV_EXPORT_VAR
#else
#define DVAPI DV_IMPORT_API
#define DVVAR DV_IMPORT_VAR
#endif
2016-04-15 17:11:23 +12:00
#ifdef _WIN32
2016-03-19 06:57:51 +13:00
#pragma warning(disable : 4251)
#endif
class QStackedWidget;
class QString;
class QComboBox;
class QColor;
//=============================================================================
// HistogramGraph
//-----------------------------------------------------------------------------
2016-06-15 18:43:10 +12:00
class DVAPI HistogramGraph : public QWidget {
Q_OBJECT
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
QColor m_color;
/*! Height of graph, without margin.*/
int m_height;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
QVector<int> m_values, m_viewValues, m_logViewValues;
bool m_logScale;
2016-03-19 06:57:51 +13:00
public:
2016-06-15 18:43:10 +12:00
static const int drawMargin;
2016-03-19 06:57:51 +13:00
public:
2016-06-15 18:43:10 +12:00
HistogramGraph(QWidget *parent = 0, QColor m_color = QColor());
~HistogramGraph();
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
void setAlphaMask(int value);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
void setHeight(int height) { m_height = height; }
int getHeight() { return m_height; }
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
void setValues(const int values[]);
const QVector<int> &values() const { return m_values; }
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
void setLogScale(bool onOff) { m_logScale = onOff; }
bool logScale() const { return m_logScale; }
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
void draw(QPainter *painter, QPoint translation = QPoint(0, 0));
2016-03-19 06:57:51 +13:00
protected:
2016-06-15 18:43:10 +12:00
void paintEvent(QPaintEvent *pe);
2016-03-19 06:57:51 +13:00
};
//=============================================================================
// ChannelBar
//-----------------------------------------------------------------------------
2016-06-15 18:43:10 +12:00
class DVAPI ChannelBar : public QWidget {
Q_OBJECT
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
QColor m_color;
int m_colorBarLength;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
bool m_isHorizontal;
bool m_drawNumbers;
2016-03-19 06:57:51 +13:00
public:
2016-06-15 18:43:10 +12:00
ChannelBar(QWidget *parent = 0, QColor m_color = QColor(),
bool isHorizontal = true);
~ChannelBar();
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
QColor getColor() const { return m_color; }
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
void setDrawNumbers(bool onOff);
bool drawNumbers() const { return m_drawNumbers; }
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
void draw(QPainter *painter, QPoint translation = QPoint(0, 0));
2016-03-19 06:57:51 +13:00
protected:
2016-06-15 18:43:10 +12:00
void paintEvent(QPaintEvent *event);
2016-03-19 06:57:51 +13:00
};
//=============================================================================
// HistogramView
//-----------------------------------------------------------------------------
2016-06-15 18:43:10 +12:00
class DVAPI HistogramView : public QWidget {
Q_OBJECT
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
HistogramGraph *m_histogramGraph;
ChannelBar *m_colorBar;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
QWidget *m_drawnWidget;
2016-03-19 06:57:51 +13:00
public:
2016-06-15 18:43:10 +12:00
HistogramView(QWidget *parent = 0, QColor color = Qt::black);
~HistogramView();
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
const HistogramGraph *histogramGraph() const { return m_histogramGraph; }
HistogramGraph *histogramGraph() { return m_histogramGraph; }
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
const ChannelBar *channelBar() const { return m_colorBar; }
ChannelBar *channelBar() { return m_colorBar; }
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
QColor getChannelBarColor() const { return m_colorBar->getColor(); }
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
// Deve essere fatto prima di chiamare setValues()
void setGraphHeight(int height) { m_histogramGraph->setHeight(height); }
void setGraphAlphaMask(int value) { m_histogramGraph->setAlphaMask(value); }
void setDrawnWidget(QWidget *widget);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
void setValues(const int values[]);
const QVector<int> &values() const { return m_histogramGraph->values(); }
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
void draw(QPainter *painter, QPoint translation = QPoint(0, 0));
2016-03-19 06:57:51 +13:00
};
//=============================================================================
// Histograms
//-----------------------------------------------------------------------------
2016-06-15 18:43:10 +12:00
class DVAPI Histograms : public QStackedWidget {
Q_OBJECT
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
TRasterP m_raster;
TPaletteP m_palette; // Necessario per le tlv
int m_channelValue[6][256];
int m_channelsCount;
bool m_computeAlsoRGBA;
2016-03-19 06:57:51 +13:00
public:
2016-06-15 18:43:10 +12:00
Histograms(QWidget *parent = 0, bool rgba = false);
~Histograms();
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
TRasterP getRaster() const { return m_raster; }
void setRaster(const TRasterP &raster, const TPaletteP &palette = 0);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
HistogramView *getHistogramView(int indexType) const;
int channelsCount() const { return m_channelsCount; }
2016-03-19 06:57:51 +13:00
protected:
2016-06-15 18:43:10 +12:00
void computeChannelsValue();
2016-03-19 06:57:51 +13:00
};
//=============================================================================
// Histogram
//-----------------------------------------------------------------------------
2016-06-15 18:43:10 +12:00
class DVAPI Histogram : public QWidget {
Q_OBJECT
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
QComboBox *m_channelsListBox;
Histograms *m_histograms;
2016-03-19 06:57:51 +13:00
public:
2016-06-15 18:43:10 +12:00
Histogram(QWidget *parent = 0);
~Histogram() {}
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
Histograms *getHistograms() const { return m_histograms; }
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
TRasterP getRaster() const { return m_histograms->getRaster(); }
void setRaster(const TRasterP &raster, const TPaletteP &palette = 0);
2016-03-19 06:57:51 +13:00
public slots:
2016-06-15 18:43:10 +12:00
void setLogScale(bool onOff);
2016-03-19 06:57:51 +13:00
private:
2016-06-15 18:43:10 +12:00
void updateChannelsList();
2016-03-19 06:57:51 +13:00
};
2016-06-15 18:43:10 +12:00
#endif // HISTOGRAM_H