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

158 lines
4.1 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 TONECURVEFIELD_H
#define TONECURVEFIELD_H
#include "tcommon.h"
#include "tstroke.h"
#include "toonzqt/histogram.h"
#include <QWidget>
#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
class TStroke;
class QPainterPath;
class QStackedWidget;
class FxHistogramRender;
//=============================================================================
2016-06-15 18:43:10 +12:00
namespace DVGui {
2016-03-19 06:57:51 +13:00
// forward declaration
class IntPairField;
class CheckBox;
//=============================================================================
// ChennelCurveEditor
//-----------------------------------------------------------------------------
class DVAPI ChennelCurveEditor 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
HistogramView *m_histogramView;
ChannelBar *m_verticalChannelBar;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
QList<QPointF> m_points;
int m_currentControlPointIndex;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
Qt::MouseButton m_mouseButton;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
int m_curveHeight;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
int m_LeftRightMargin;
int m_TopMargin;
int m_BottomMargin;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
bool m_isLinear;
2016-03-19 06:57:51 +13:00
public:
2016-06-15 18:43:10 +12:00
ChennelCurveEditor(QWidget *parent = 0, HistogramView *histogramView = 0);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
void setPoints(QList<TPointD> points);
QList<TPointD> getPoints();
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
int getCurrentControlPointIndex() { return m_currentControlPointIndex; };
void setCurrentControlPointIndex(int index) {
m_currentControlPointIndex = index;
};
2016-03-19 06:57:51 +13:00
2016-06-19 20:06:29 +12:00
bool eventFilter(QObject *object, QEvent *event) override;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
void setFirstLastXPosition(std::pair<int, int> values, bool isDragging);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
void setLinear(bool isLinear);
2016-03-19 06:57:51 +13:00
protected:
2016-06-15 18:43:10 +12:00
QPointF strokeToViewPoint(const TPointD p);
TPointD viewToStrokePoint(const QPointF &p);
int getClosestPointIndex(const QPointF &pos, double &minDistance2) const;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
bool isCentralControlPoint(int index) { return index % 3 == 0; }
bool isLeftControlPoint(int index) { return index % 3 == 2; }
bool isRightControlPoint(int index) { return index % 3 == 1; }
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
void movePoint(int index, const QPointF delta);
void setPoint(int index, const QPointF point);
QPointF checkPoint(const QPointF p);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
void moveCurrentControlPoint(const QPointF delta);
void moveCentralControlPoint(int index, const QPointF delta);
// bool eraseControlPointWhileMove(int index, const QPointF delta);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
void addControlPoint(double percent);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
void removeControlPoint(int index);
void removeCurrentControlPoint();
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
QPainterPath getPainterPath();
2016-03-19 06:57:51 +13:00
2016-06-19 20:06:29 +12:00
void paintEvent(QPaintEvent *) override;
void mouseMoveEvent(QMouseEvent *) override;
void mousePressEvent(QMouseEvent *) override;
void mouseReleaseEvent(QMouseEvent *) override;
void keyPressEvent(QKeyEvent *e) override;
void enterEvent(QEvent *) override;
void leaveEvent(QEvent *) override;
2016-03-19 06:57:51 +13:00
2016-06-19 20:06:29 +12:00
void focusInEvent(QFocusEvent *fe) override;
void focusOutEvent(QFocusEvent *fe) override;
2016-03-19 06:57:51 +13:00
signals:
2016-06-15 18:43:10 +12:00
void focusOut();
void controlPointChanged(bool isDragging);
void controlPointAdded(int index);
void controlPointRemoved(int index);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
void firstLastXPostionChanged(int, int);
2016-03-19 06:57:51 +13:00
};
//=============================================================================
// ToneCurveField
//-----------------------------------------------------------------------------
class DVAPI ToneCurveField 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
QStackedWidget *m_toneCurveStackedWidget;
QStackedWidget *m_sliderStackedWidget;
QComboBox *m_channelListChooser;
CheckBox *m_isLinearCheckBox;
2016-03-19 06:57:51 +13:00
public:
2016-06-15 18:43:10 +12:00
ToneCurveField(QWidget *parent = 0, FxHistogramRender *fxHistogramRender = 0);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
void setCurrentChannel(int currentChannel);
ChennelCurveEditor *getChannelEditor(int channel) const;
ChennelCurveEditor *getCurrentChannelEditor() const;
IntPairField *getCurrentSlider() const;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
int getChannelCount() { return m_toneCurveStackedWidget->count(); }
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
void setIsLinearCheckBox(bool isChecked);
2016-03-19 06:57:51 +13:00
protected slots:
2016-06-15 18:43:10 +12:00
void sliderValueChanged(bool);
void onFirstLastXPostionChanged(int, int);
2016-03-19 06:57:51 +13:00
public slots:
2016-06-15 18:43:10 +12:00
void setLinear(bool);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
void setLinearManually(bool);
2016-03-19 06:57:51 +13:00
signals:
2016-06-15 18:43:10 +12:00
void currentChannelIndexChanged(int);
void isLinearChanged(bool);
2016-03-19 06:57:51 +13:00
};
}
2016-06-15 18:43:10 +12:00
#endif // TONECURVEFIELD_H