Shinya Kitaoka 810553
#pragma once
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#ifndef SPECTRUMFIELD_H
Toshihiro Shimizu 890ddd
#define SPECTRUMFIELD_H
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include <qwidget></qwidget>
Toshihiro Shimizu 890ddd
#include "toonzqt/colorfield.h"
Toshihiro Shimizu 890ddd
#include "tpixel.h"
Toshihiro Shimizu 890ddd
#include "tspectrum.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#undef DVAPI
Toshihiro Shimizu 890ddd
#undef DVVAR
Toshihiro Shimizu 890ddd
#ifdef TOONZQT_EXPORTS
Toshihiro Shimizu 890ddd
#define DVAPI DV_EXPORT_API
Toshihiro Shimizu 890ddd
#define DVVAR DV_EXPORT_VAR
Toshihiro Shimizu 890ddd
#else
Toshihiro Shimizu 890ddd
#define DVAPI DV_IMPORT_API
Toshihiro Shimizu 890ddd
#define DVVAR DV_IMPORT_VAR
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// forward declaration
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
namespace DVGui {
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
// SpectrumBar
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka d1f6c4
class DVAPI SpectrumBar final : public QWidget {
Shinya Kitaoka 120a6e
  Q_OBJECT
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  int m_x0;
Shinya Kitaoka 120a6e
  int m_currentKeyIndex;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  QPixmap m_chessBg;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  TSpectrum m_spectrum;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  SpectrumBar(QWidget *parent = 0, TPixel32 color = TPixel32(0, 0, 0, 255));
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  ~SpectrumBar();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  int getCurrentKeyIndex() { return m_currentKeyIndex; }
Shinya Kitaoka 120a6e
  void setCurrentKeyIndex(int index);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  int getCurrentPos();
Shinya Kitaoka 120a6e
  TPixel32 getCurrentColor();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  TSpectrum &getSpectrum() { return m_spectrum; }
Shinya Kitaoka 120a6e
  void setSpectrum(TSpectrum &spectrum) {
Shinya Kitaoka 120a6e
    m_spectrum = spectrum;
Shinya Kitaoka 120a6e
    /*-- Undoの場合、Spectrumの差し替えによってIndexがあふれてしまうことがある
Shinya Kitaoka 120a6e
     * --*/
Shinya Kitaoka 120a6e
    if (m_currentKeyIndex >= m_spectrum.getKeyCount())
Shinya Kitaoka 120a6e
      setCurrentKeyIndex(getMaxPosKeyIndex());
Shinya Kitaoka 120a6e
    update();
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public slots:
Shinya Kitaoka 120a6e
  void setCurrentPos(int pos, bool isDragging);
Shinya Kitaoka 120a6e
  void setCurrentColor(const TPixel32 &color);
Shinya Kitaoka 120a6e
  void addKeyAt(int pos);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
signals:
Shinya Kitaoka 120a6e
  void currentPosChanged(bool isDragging);
Shinya Kitaoka 120a6e
  void currentKeyChanged();
Shinya Kitaoka 120a6e
  void currentKeyAdded(int);
Shinya Kitaoka 120a6e
  void currentKeyRemoved(int);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
protected:
Shinya Kitaoka 120a6e
  double posToSpectrumValue(int pos);
Shinya Kitaoka 120a6e
  int spectrumValueToPos(double spectrumValue);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 473e70
  void paintEvent(QPaintEvent *e) override;
Shinya Kitaoka 473e70
  void mousePressEvent(QMouseEvent *e) override;
Shinya Kitaoka 473e70
  void mouseMoveEvent(QMouseEvent *e) override;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 473e70
  void mouseReleaseEvent(QMouseEvent *e) override;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  int getMaxPosKeyIndex();
Shinya Kitaoka 120a6e
  int getMinPosKeyIndex();
Shinya Kitaoka 120a6e
  int getNearPosKeyIndex(int pos);
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
// SpectrumField
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka d1f6c4
class DVAPI SpectrumField final : public QWidget {
Shinya Kitaoka 120a6e
  Q_OBJECT
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  int m_margin;
Shinya Kitaoka 120a6e
  int m_spacing;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  ColorField *m_colorField;
Shinya Kitaoka 120a6e
  SpectrumBar *m_spectrumbar;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  SpectrumField(QWidget *parent = 0, TPixel32 color = TPixel32(0, 0, 0, 255));
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  ~SpectrumField();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  TSpectrum &getSpectrum() { return m_spectrumbar->getSpectrum(); }
Shinya Kitaoka 120a6e
  void setSpectrum(TSpectrum &spectrum) {
Shinya Kitaoka 120a6e
    m_spectrumbar->setSpectrum(spectrum);
Shinya Kitaoka 120a6e
    m_colorField->setColor(m_spectrumbar->getCurrentColor());
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  int getCurrentKeyIndex() { return m_spectrumbar->getCurrentKeyIndex(); }
Shinya Kitaoka 120a6e
  void setCurrentKeyIndex(int index) {
Shinya Kitaoka 120a6e
    m_spectrumbar->setCurrentKeyIndex(index);
Shinya Kitaoka 120a6e
    m_colorField->setColor(m_spectrumbar->getCurrentColor());
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
protected slots:
Shinya Kitaoka 120a6e
  void onCurrentPosChanged(bool isDragging);
Shinya Kitaoka 120a6e
  void onCurrentKeyChanged();
Shinya Kitaoka 120a6e
  void onColorChanged(const TPixel32 &color, bool isDragging);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
protected:
Shinya Kitaoka 473e70
  void paintEvent(QPaintEvent *e) override;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
signals:
Shinya Kitaoka 120a6e
  void keyColorChanged(bool);
Shinya Kitaoka 120a6e
  void keyPositionChanged(bool);
Shinya Kitaoka 120a6e
  void keyAdded(int);
Shinya Kitaoka 120a6e
  void keyRemoved(int);
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Shinya Kitaoka 120a6e
}  // namespace DVGui
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
#endif  // SPECTRUMFIELD_H