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

138 lines
3.4 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 SPECTRUMFIELD_H
#define SPECTRUMFIELD_H
#include <QWidget>
#include "toonzqt/colorfield.h"
#include "tpixel.h"
#include "tspectrum.h"
#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
// forward declaration
//=============================================================================
2016-06-15 18:43:10 +12:00
namespace DVGui {
2016-03-19 06:57:51 +13:00
//=============================================================================
// SpectrumBar
//-----------------------------------------------------------------------------
2016-06-15 18:43:10 +12:00
class DVAPI SpectrumBar : public QWidget {
Q_OBJECT
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
int m_x0;
int m_currentKeyIndex;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
QPixmap m_chessBg;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
TSpectrum m_spectrum;
2016-03-19 06:57:51 +13:00
public:
2016-06-15 18:43:10 +12:00
SpectrumBar(QWidget *parent = 0, TPixel32 color = TPixel32(0, 0, 0, 255));
~SpectrumBar();
int getCurrentKeyIndex() { return m_currentKeyIndex; }
void setCurrentKeyIndex(int index);
int getCurrentPos();
TPixel32 getCurrentColor();
TSpectrum &getSpectrum() { return m_spectrum; }
void setSpectrum(TSpectrum &spectrum) {
m_spectrum = spectrum;
/*-- Undoの場合、Spectrumの差し替えによってIndexがあふれてしまうことがある
* --*/
if (m_currentKeyIndex >= m_spectrum.getKeyCount())
setCurrentKeyIndex(getMaxPosKeyIndex());
update();
}
2016-03-19 06:57:51 +13:00
public slots:
2016-06-15 18:43:10 +12:00
void setCurrentPos(int pos, bool isDragging);
void setCurrentColor(const TPixel32 &color);
void addKeyAt(int pos);
2016-03-19 06:57:51 +13:00
signals:
2016-06-15 18:43:10 +12:00
void currentPosChanged(bool isDragging);
void currentKeyChanged();
void currentKeyAdded(int);
void currentKeyRemoved(int);
2016-03-19 06:57:51 +13:00
protected:
2016-06-15 18:43:10 +12:00
double posToSpectrumValue(int pos);
int spectrumValueToPos(double spectrumValue);
2016-03-19 06:57:51 +13:00
2016-06-19 20:06:29 +12:00
void paintEvent(QPaintEvent *e) override;
void mousePressEvent(QMouseEvent *e) override;
void mouseMoveEvent(QMouseEvent *e) override;
2016-03-19 06:57:51 +13:00
2016-06-19 20:06:29 +12:00
void mouseReleaseEvent(QMouseEvent *e) override;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
int getMaxPosKeyIndex();
int getMinPosKeyIndex();
int getNearPosKeyIndex(int pos);
2016-03-19 06:57:51 +13:00
};
//=============================================================================
// SpectrumField
//-----------------------------------------------------------------------------
2016-06-15 18:43:10 +12:00
class DVAPI SpectrumField : public QWidget {
Q_OBJECT
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
int m_margin;
int m_spacing;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
ColorField *m_colorField;
SpectrumBar *m_spectrumbar;
2016-03-19 06:57:51 +13:00
public:
2016-06-15 18:43:10 +12:00
SpectrumField(QWidget *parent = 0, TPixel32 color = TPixel32(0, 0, 0, 255));
~SpectrumField();
TSpectrum &getSpectrum() { return m_spectrumbar->getSpectrum(); }
void setSpectrum(TSpectrum &spectrum) {
m_spectrumbar->setSpectrum(spectrum);
m_colorField->setColor(m_spectrumbar->getCurrentColor());
}
int getCurrentKeyIndex() { return m_spectrumbar->getCurrentKeyIndex(); }
void setCurrentKeyIndex(int index) {
m_spectrumbar->setCurrentKeyIndex(index);
m_colorField->setColor(m_spectrumbar->getCurrentColor());
}
2016-03-19 06:57:51 +13:00
protected slots:
2016-06-15 18:43:10 +12:00
void onCurrentPosChanged(bool isDragging);
void onCurrentKeyChanged();
void onColorChanged(const TPixel32 &color, bool isDragging);
2016-03-19 06:57:51 +13:00
protected:
2016-06-19 20:06:29 +12:00
void paintEvent(QPaintEvent *e) override;
2016-03-19 06:57:51 +13:00
signals:
2016-06-15 18:43:10 +12:00
void keyColorChanged(bool);
void keyPositionChanged(bool);
void keyAdded(int);
void keyRemoved(int);
2016-03-19 06:57:51 +13:00
};
//-----------------------------------------------------------------------------
2016-06-15 18:43:10 +12:00
} // namespace DVGui
2016-03-19 06:57:51 +13:00
//-----------------------------------------------------------------------------
2016-06-15 18:43:10 +12:00
#endif // SPECTRUMFIELD_H