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

205 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 COMBOHISTOGRAM_H
#define COMBOHISTOGRAM_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
#ifdef _MSC_VER
2016-03-19 06:57:51 +13:00
#pragma warning(disable : 4251)
#endif
class QStackedWidget;
class QString;
class QComboBox;
class QColor;
class RGBLabel;
class QLabel;
#define COMBOHIST_RESOLUTION_W 256
#define COMBOHIST_RESOLUTION_H 100
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
// 120405
//-----------------------------------------------------------------------------
class DVAPI ComboHistoRGBLabel final : public QWidget {
2019-08-19 21:52:45 +12:00
Q_OBJECT
2021-10-14 18:13:07 +13:00
public:
enum DisplayMode { Display_8bit = 0, Display_16bit, Display_0_1 };
private:
2016-06-15 18:43:10 +12:00
QColor m_color;
2016-03-19 06:57:51 +13:00
2021-10-14 18:13:07 +13:00
DisplayMode m_mode;
2016-03-19 06:57:51 +13:00
public:
2016-06-15 18:43:10 +12:00
ComboHistoRGBLabel(QColor color, QWidget *parent);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
~ComboHistoRGBLabel() {}
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
void setColorAndUpdate(QColor color);
2021-10-14 18:13:07 +13:00
void setDisplayMode(DisplayMode mode) { m_mode = mode; }
2016-03-19 06:57:51 +13:00
protected:
2016-06-19 20:06:29 +12:00
void paintEvent(QPaintEvent *pe) override;
2016-03-19 06:57:51 +13:00
};
//-----------------------------------------------------------------------------
2016-06-15 18:43:10 +12:00
class DVAPI ChannelHistoGraph : public QWidget {
Q_OBJECT
2016-03-19 06:57:51 +13:00
2021-10-14 18:13:07 +13:00
QVector<int> m_values[2]; // 0: current raster 1: snapshot
int m_maxValue[2];
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
int m_pickedValue;
2021-10-14 18:13:07 +13:00
int m_channelIndex;
2016-03-19 06:57:51 +13:00
public:
2021-10-14 18:13:07 +13:00
bool *m_showComparePtr;
2016-03-19 06:57:51 +13:00
2021-10-14 18:13:07 +13:00
ChannelHistoGraph(int index, QWidget *parent = nullptr,
bool *showComparePtr = nullptr);
2016-06-15 18:43:10 +12:00
~ChannelHistoGraph();
2016-03-19 06:57:51 +13:00
2021-10-14 18:13:07 +13:00
virtual void setValues(int *buf, bool isComp);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
void showCurrentChannelValue(int val);
2016-03-19 06:57:51 +13:00
protected:
2016-06-19 20:06:29 +12:00
void paintEvent(QPaintEvent *event) override;
2016-03-19 06:57:51 +13:00
};
//-----------------------------------------------------------------------------
class DVAPI RGBHistoGraph final : public ChannelHistoGraph {
2016-06-15 18:43:10 +12:00
Q_OBJECT
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
QVector<int> m_rgbValues[3];
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
QImage m_histoImg;
2016-03-19 06:57:51 +13:00
public:
2021-10-14 18:13:07 +13:00
RGBHistoGraph(int index, QWidget *parent = 0);
2016-06-15 18:43:10 +12:00
~RGBHistoGraph();
2016-03-19 06:57:51 +13:00
2021-10-14 18:13:07 +13:00
void setValues(int *buf, bool isComp) override;
2016-03-19 06:57:51 +13:00
protected:
2016-06-19 20:06:29 +12:00
void paintEvent(QPaintEvent *event) override;
2016-03-19 06:57:51 +13:00
};
//-----------------------------------------------------------------------------
class DVAPI ChannelColorBar final : public QWidget {
2016-06-15 18:43:10 +12:00
Q_OBJECT
QColor m_color;
2016-03-19 06:57:51 +13:00
public:
2016-06-15 18:43:10 +12:00
ChannelColorBar(QWidget *parent = 0, QColor m_color = QColor());
~ChannelColorBar() {}
2016-03-19 06:57:51 +13:00
protected:
2016-06-19 20:06:29 +12:00
void paintEvent(QPaintEvent *event) override;
2016-03-19 06:57:51 +13:00
};
//-----------------------------------------------------------------------------
class DVAPI ChannelHisto final : public QWidget {
2016-06-15 18:43:10 +12:00
Q_OBJECT
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
ChannelHistoGraph *m_histogramGraph;
ChannelColorBar *m_colorBar;
2016-03-19 06:57:51 +13:00
public:
2021-10-14 18:13:07 +13:00
ChannelHisto(int channelIndex, bool *showComparePtr, QWidget *parent = 0);
2016-06-15 18:43:10 +12:00
~ChannelHisto() {}
2016-03-19 06:57:51 +13:00
2021-10-14 18:13:07 +13:00
void refleshValue(int *buf, bool isComp = false) {
m_histogramGraph->setValues(buf, isComp);
}
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
void showCurrentChannelValue(int val);
2016-03-19 06:57:51 +13:00
protected slots:
2016-06-15 18:43:10 +12:00
void onShowAlphaButtonToggled(bool visible);
2016-03-19 06:57:51 +13:00
};
//-----------------------------------------------------------------------------
class DVAPI ComboHistogram final : public QWidget {
2016-06-15 18:43:10 +12:00
Q_OBJECT
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
TRasterP m_raster;
TPaletteP m_palette;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
// rgba channels
int m_channelValue[4][COMBOHIST_RESOLUTION_W];
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
// rgba channels + composited
ChannelHisto *m_histograms[5];
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
ComboHistoRGBLabel *m_rgbLabel;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
ComboHistoRGBLabel *m_rectAverageRgbLabel;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
QLabel *m_xPosLabel;
QLabel *m_yPosLabel;
2016-03-19 06:57:51 +13:00
2021-10-14 18:13:07 +13:00
QComboBox *m_displayModeCombo;
bool m_showCompare;
bool m_compHistoIsValid;
int m_channelValueComp[4][COMBOHIST_RESOLUTION_W];
2016-03-19 06:57:51 +13:00
public:
2016-06-15 18:43:10 +12:00
ComboHistogram(QWidget *parent = 0);
~ComboHistogram();
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);
void updateInfo(const TPixel32 &pix, const TPointD &imagePos);
2021-10-14 18:13:07 +13:00
void updateInfo(const TPixel64 &pix, const TPointD &imagePos);
2016-06-15 18:43:10 +12:00
void updateAverageColor(const TPixel32 &pix);
2021-10-14 18:13:07 +13:00
void updateAverageColor(const TPixel64 &pix);
void updateCompHistogram();
void setShowCompare(bool on) {
m_showCompare = on;
if (isVisible() && !m_compHistoIsValid) updateCompHistogram();
}
void invalidateCompHisto() {
m_compHistoIsValid = false;
if (isVisible() && m_showCompare) updateCompHistogram();
}
2016-03-19 06:57:51 +13:00
protected:
2021-10-14 18:13:07 +13:00
void computeChannelsValue(int *buf, size_t size, TRasterP ras,
TPalette *extPlt = nullptr);
void showEvent(QShowEvent *) override;
protected slots:
void onDisplayModeChanged();
2016-03-19 06:57:51 +13:00
};
#endif