Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#ifndef DOUBLEPAIRFIELD_H
Toshihiro Shimizu 890ddd
#define DOUBLEPAIRFIELD_H
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "toonzqt/doublefield.h"
Toshihiro Shimizu 890ddd
#include "tcommon.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
class QSlider;
Toshihiro Shimizu 890ddd
class QLabel;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
namespace DVGui
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
/*! \brief The DoubleValuePairField class provides to view an object to manage a pair
Toshihiro Shimizu 890ddd
					 of double parameter.
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		Inherits \b QWidget.
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		The object is composed of an horizontal layout \b QHBoxLayout which contains
Toshihiro Shimizu 890ddd
		two pair [label, text field] and a slider with two grab, one for each double
Toshihiro Shimizu 890ddd
		value to manage. [label, text field] are a \b QLabel and a \b DoubleLineEdit.
Toshihiro Shimizu 890ddd
		Objects are inserted in the following order: a label and respective text field,
Toshihiro Shimizu 890ddd
		the slider and the other pair [lebel,text field].
Toshihiro Shimizu 890ddd
		Object size width is not fixed, while height is equal to DVGui::WidgetHeight, 20;
Toshihiro Shimizu 890ddd
		labels width depend from its text lenght, text fields has fixed size, while
Toshihiro Shimizu 890ddd
		slider width change in according with widget size.
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		Objects contained in this widget are connected, so if you change one value the
Toshihiro Shimizu 890ddd
		other automatically change, if it is necessary. You can set current value,
Toshihiro Shimizu 890ddd
		getValues(), minimum and max value, getRange(), using setValues(), setRange().
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		To know when one of two double parameter value change class provides a signal,
Toshihiro Shimizu 890ddd
		valuesChanged(); class emit signal when a grab slider position change or when
Toshihiro Shimizu 890ddd
		editing text field, left or right is finished and current value is changed.
Toshihiro Shimizu 890ddd
		Editing text field finished may occur if focus is lost or enter key is pressed.
Toshihiro Shimizu 890ddd
		See SLOT: onLeftEditingFinished() and onRightEditingFinished().
Toshihiro Shimizu 890ddd
*/
Toshihiro Shimizu 890ddd
class DVAPI DoubleValuePairField : public QWidget
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	Q_OBJECT
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
protected:
Toshihiro Shimizu 890ddd
	QPixmap m_handleLeftPixmap, m_handleRightPixmap, m_handleLeftGrayPixmap, m_handleRightGrayPixmap;
Toshihiro Shimizu 890ddd
	Q_PROPERTY(QPixmap HandleLeftPixmap READ getHandleLeftPixmap WRITE setHandleLeftPixmap);
Toshihiro Shimizu 890ddd
	Q_PROPERTY(QPixmap HandleRightPixmap READ getHandleRightPixmap WRITE setHandleRightPixmap);
Toshihiro Shimizu 890ddd
	Q_PROPERTY(QPixmap HandleLeftGrayPixmap READ getHandleLeftGrayPixmap WRITE setHandleLeftGrayPixmap);
Toshihiro Shimizu 890ddd
	Q_PROPERTY(QPixmap HandleRightGrayPixmap READ getHandleRightGrayPixmap WRITE setHandleRightGrayPixmap);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	QColor m_lightLineColor; /*-- スライダ溝の明るい色(白) --*/
Toshihiro Shimizu 890ddd
	QColor m_darkLineColor;  /*-- スライダ溝の暗い色(128,128,128) --*/
Toshihiro Shimizu 890ddd
	Q_PROPERTY(QColor LightLineColor READ getLightLineColor WRITE setLightLineColor);
Toshihiro Shimizu 890ddd
	Q_PROPERTY(QColor DarkLineColor READ getDarkLineColor WRITE setDarkLineColor);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	DoubleValueLineEdit *m_leftLineEdit;
Toshihiro Shimizu 890ddd
	DoubleValueLineEdit *m_rightLineEdit;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	QLabel *m_leftLabel, *m_rightLabel;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	std::pair<double, double=""> m_values;</double,>
Toshihiro Shimizu 890ddd
	double m_minValue, m_maxValue;
Toshihiro Shimizu 890ddd
	int m_grabOffset, m_grabIndex;
Toshihiro Shimizu 890ddd
	int m_leftMargin, m_rightMargin;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	bool m_isMaxRangeLimited;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
	DoubleValuePairField(QWidget *parent, bool isMaxRangeLimited,
Toshihiro Shimizu 890ddd
						 DoubleValueLineEdit *leftLineEdit, DoubleValueLineEdit *rightLineEdit);
Toshihiro Shimizu 890ddd
	~DoubleValuePairField() {}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	/*! Set current values to \b values. */
Toshihiro Shimizu 890ddd
	void setValues(const std::pair<double, double=""> &values);</double,>
Toshihiro Shimizu 890ddd
	/*!	Return a pair containing current values. */
Toshihiro Shimizu 890ddd
	std::pair<double, double=""> getValues() const { return m_values; }</double,>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	/*! Set left label string to \b QString \b text. Recompute left margin adding
Toshihiro Shimizu 890ddd
			label width. */
Toshihiro Shimizu 890ddd
	void setLeftText(const QString &text);
Toshihiro Shimizu 890ddd
	/*! Set right label string to \b QString \b text. Recompute right margin adding
Toshihiro Shimizu 890ddd
			label width. */
Toshihiro Shimizu 890ddd
	void setRightText(const QString &text);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void setLabelsEnabled(bool enable);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	/*! Set range of \b DoublePairField to \b minValue, \b maxValue. */
Toshihiro Shimizu 890ddd
	void setRange(double minValue, double maxValue);
Toshihiro Shimizu 890ddd
	/*! Set \b minValue and \b maxValue to DoublePairField range. */
Toshihiro Shimizu 890ddd
	void getRange(double &minValue, double &maxValue);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	QPixmap getHandleLeftPixmap() const { return m_handleLeftPixmap; }
Toshihiro Shimizu 890ddd
	void setHandleLeftPixmap(const QPixmap &pixmap) { m_handleLeftPixmap = pixmap; }
Toshihiro Shimizu 890ddd
	QPixmap getHandleRightPixmap() const { return m_handleRightPixmap; }
Toshihiro Shimizu 890ddd
	void setHandleRightPixmap(const QPixmap &pixmap) { m_handleRightPixmap = pixmap; }
Toshihiro Shimizu 890ddd
	QPixmap getHandleLeftGrayPixmap() const { return m_handleLeftGrayPixmap; }
Toshihiro Shimizu 890ddd
	void setHandleLeftGrayPixmap(const QPixmap &pixmap) { m_handleLeftGrayPixmap = pixmap; }
Toshihiro Shimizu 890ddd
	QPixmap getHandleRightGrayPixmap() const { return m_handleRightGrayPixmap; }
Toshihiro Shimizu 890ddd
	void setHandleRightGrayPixmap(const QPixmap &pixmap) { m_handleRightGrayPixmap = pixmap; }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void setLightLineColor(const QColor &color) { m_lightLineColor = color; }
Toshihiro Shimizu 890ddd
	QColor getLightLineColor() const { return m_lightLineColor; }
Toshihiro Shimizu 890ddd
	void setDarkLineColor(const QColor &color) { m_darkLineColor = color; }
Toshihiro Shimizu 890ddd
	QColor getDarkLineColor() const { return m_darkLineColor; }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
protected:
Toshihiro Shimizu 890ddd
	/*! Return value corresponding \b x position. */
Toshihiro Shimizu 890ddd
	double pos2value(int x) const;
Toshihiro Shimizu 890ddd
	/*! Return x position corresponding \b value. */
Toshihiro Shimizu 890ddd
	int value2pos(double v) const;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	/*! Set current value to \b value.
Toshihiro Shimizu 890ddd
			Set left or right value, or both, to value depending on current slider
Toshihiro Shimizu 890ddd
			grab edited and \b value. */
Toshihiro Shimizu 890ddd
	void setValue(double v);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void paintEvent(QPaintEvent *);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void mousePressEvent(QMouseEvent *event);
Toshihiro Shimizu 890ddd
	void mouseMoveEvent(QMouseEvent *event);
Toshihiro Shimizu 890ddd
	void mouseReleaseEvent(QMouseEvent *event);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
protected slots:
Toshihiro Shimizu 890ddd
	/*! Set current left value to value in left text field; if necessary, if left
Toshihiro Shimizu 890ddd
			value is greater than right, change also current right value.
Toshihiro Shimizu 890ddd
	\n	This protected slot is called when text editing is finished.
Toshihiro Shimizu 890ddd
	\n	Emit valuesChanged().
Toshihiro Shimizu 890ddd
	\n	If current left value is equal to left text field value, return and do nothing. */
Toshihiro Shimizu 890ddd
	void onLeftEditingFinished();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	/*! Set current right value to value in right text field; if necessary, if right
Toshihiro Shimizu 890ddd
			value is lower than left, change also current left value.
Toshihiro Shimizu 890ddd
	\n	This protected slot is called when text editing is finished.
Toshihiro Shimizu 890ddd
	\n	Emit valuesChanged().
Toshihiro Shimizu 890ddd
	\n	If current right value is equal to right text field value return and do nothing. */
Toshihiro Shimizu 890ddd
	void onRightEditingFinished();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
signals:
Toshihiro Shimizu 890ddd
	/*!	This signal is emitted when change one of two DoubleField value;
Toshihiro Shimizu 890ddd
			if one slider grab position change or if one text field editing is finished. */
Toshihiro Shimizu 890ddd
	void valuesChanged(bool isDragging);
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
/*! \brief The DoublePairField class provides a DoubleValuePairField with
Toshihiro Shimizu 890ddd
		left DoubleLineEdit and right DoubleLineEdit.
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		Inherits \b DoubleValuePairField.
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		\b Example:
Toshihiro Shimizu 890ddd
		\code
Toshihiro Shimizu 890ddd
			DoublePairField* doublePairFieldExample = new DoublePairField(this);
Toshihiro Shimizu 890ddd
			doublePairFieldExample->setLeftText(tr("Left Value:"));
Toshihiro Shimizu 890ddd
			doublePairFieldExample->setRightText(tr("Rigth Value:"));
Toshihiro Shimizu 890ddd
			doublePairFieldExample->setRange(0,10);
Toshihiro Shimizu 890ddd
			doublePairFieldExample->setValues(std::make_pair(3.58,7.65));
Toshihiro Shimizu 890ddd
		\endcode
Toshihiro Shimizu 890ddd
		\b Result:
Toshihiro Shimizu 890ddd
			\image html DoublePairField.jpg
Toshihiro Shimizu 890ddd
*/
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
class DVAPI DoublePairField : public DoubleValuePairField
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
	DoublePairField(QWidget *parent = 0, bool isMaxRangeLimited = true);
Toshihiro Shimizu 890ddd
	~DoublePairField() {}
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
/*! \brief The MeasuredDoublePairField class provides a DoubleValuePairField with
Toshihiro Shimizu 890ddd
		left MeasuredDoubleLineEdit and right DoubleLineEdit.
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		Inherits \b DoubleValuePairField.
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		\b Example:
Toshihiro Shimizu 890ddd
		\code
Toshihiro Shimizu 890ddd
			MeasuredDoublePairField* doublePairFieldExample = new MeasuredDoublePairField(this);
Toshihiro Shimizu 890ddd
			doublePairFieldExample->setLeftText(tr("Left Value:"));
Toshihiro Shimizu 890ddd
			doublePairFieldExample->setRightText(tr("Rigth Value:"));
Toshihiro Shimizu 890ddd
			doublePairFieldExample->setRange(0,10);
Toshihiro Shimizu 890ddd
			doublePairFieldExample->setValues(std::make_pair(3.58,7.65));
Toshihiro Shimizu 890ddd
		\endcode
Toshihiro Shimizu 890ddd
		\b Result:
Toshihiro Shimizu 890ddd
			\image html DoublePairField.jpg
Toshihiro Shimizu 890ddd
*/
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
class DVAPI MeasuredDoublePairField : public DoubleValuePairField
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
	MeasuredDoublePairField(QWidget *parent = 0, bool isMaxRangeLimited = true);
Toshihiro Shimizu 890ddd
	~MeasuredDoublePairField() {}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void setMeasure(string measureName);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void setPrecision(int precision);
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
} //namespace DVGui
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#endif // DOUBLEPAIRFIELD_H