Shinya Kitaoka 810553
#pragma once
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#ifndef INTFIELD_H
Toshihiro Shimizu 890ddd
#define INTFIELD_H
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "tcommon.h"
Toshihiro Shimizu 890ddd
#include "toonzqt/lineedit.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include <qtoolbar></qtoolbar>
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 QIntValidator;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
namespace DVGui {
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
/*! \brief The RollerField class provides an object to change an integer value.
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
                Inherits \b QWidget.
Toshihiro Shimizu 890ddd
*/
Shinya Kitaoka 120a6e
class DVAPI RollerField : public QWidget {
Shinya Kitaoka 120a6e
  Q_OBJECT
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  double m_value;
Shinya Kitaoka 120a6e
  double m_minValue;
Shinya Kitaoka 120a6e
  double m_maxValue;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  double m_step;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  int m_xPos;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  RollerField(QWidget *parent = 0);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  ~RollerField() {}
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  void setValue(double value);
Shinya Kitaoka 120a6e
  double getValue() const;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  void setRange(double minValue, double maxValue);
Shinya Kitaoka 120a6e
  void getRange(double &minValue, double &maxValue);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  void setStep(double _step) { m_step = _step; }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
protected:
Shinya Kitaoka 473e70
  void paintEvent(QPaintEvent *e) override;
Shinya Kitaoka 473e70
  void mousePressEvent(QMouseEvent *) override;
Shinya Kitaoka 473e70
  void mouseMoveEvent(QMouseEvent *) override;
Shinya Kitaoka 473e70
  void mouseReleaseEvent(QMouseEvent *) override;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  void addValue(bool isDragging);
Shinya Kitaoka 120a6e
  void removeValue(bool isDragging);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
signals:
Shinya Kitaoka 120a6e
  void valueChanged(bool isDragging);
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Shinya Kitaoka 120a6e
/*! \brief The IntLineEdit class provides an object to manage an integer line
Shinya Kitaoka 120a6e
   edit.
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
                Inherits \b LineEdit, set an integer validator \b QIntValidator.
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
                You can pass to constructor current value, minimum and max value
Shinya Kitaoka 120a6e
   field
Shinya Kitaoka 120a6e
                or set this value using setValue(), setRange() .
Toshihiro Shimizu 890ddd
*/
Shinya Kitaoka 120a6e
class DVAPI IntLineEdit : public LineEdit {
Shinya Kitaoka 120a6e
  Q_OBJECT
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  QIntValidator *m_validator;
Shinya Kitaoka 120a6e
  //! The number of digits showed int the line edit.
Shinya Kitaoka 120a6e
  //! If digits is less than 1 the line edit show the natural number without
Shinya Kitaoka 120a6e
  //! prepend zeros.
Shinya Kitaoka 120a6e
  int m_showedDigits;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  IntLineEdit(QWidget *parent = 0, int value = 1,
Shinya Kitaoka 120a6e
              int minValue     = (-(std::numeric_limits<int>::max)()),</int>
Shinya Kitaoka 120a6e
              int maxValue     = ((std::numeric_limits<int>::max)()),</int>
Shinya Kitaoka 120a6e
              int showedDigits = 0);
Shinya Kitaoka 120a6e
  ~IntLineEdit() {}
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  /*! Set text in field to \b value. */
Shinya Kitaoka 120a6e
  void setValue(int value);
Shinya Kitaoka 120a6e
  /*! Return an integer with text field value. */
Shinya Kitaoka 120a6e
  int getValue();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  /*! Set the range of field from \b minValue to \b maxValue;
Shinya Kitaoka 120a6e
                  set validator value. */
Shinya Kitaoka 120a6e
  void setRange(int minValue, int maxValue);
Shinya Kitaoka 120a6e
  /*! Set to \b minValue minimum range value.
Shinya Kitaoka 120a6e
                  \sa setRange() */
Shinya Kitaoka 120a6e
  void setBottomRange(int minValue);
Shinya Kitaoka 120a6e
  /*! Set to \b maxValue maximum range value.
Shinya Kitaoka 120a6e
                  \sa getRange() */
Shinya Kitaoka 120a6e
  void setTopRange(int maxValue);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  /*! Set \b minValue an \b maxValue to current range; to current
Shinya Kitaoka 120a6e
                  validator minimum and maximum value. */
Shinya Kitaoka 120a6e
  void getRange(int &minValue, int &maxValue);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  void setLineEditBackgroundColor(QColor color);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
protected:
Shinya Kitaoka 120a6e
  /*! If focus is lost and current text value is out of range emit signal
Shinya Kitaoka 120a6e
                  \b editingFinished.*/
Shinya Kitaoka 473e70
  void focusOutEvent(QFocusEvent *) override;
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
/*! \brief The IntField class provides to view an object to manage an integer
Shinya Kitaoka 120a6e
                parameter.
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
                Inherits \b QWidget.
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
                The class is composed of an horizontal layout which contains two
Shinya Kitaoka 120a6e
object,
Shinya Kitaoka 120a6e
                \li a vertical layout with a text field \b IntLineEdit and a
Shinya Kitaoka 120a6e
roller
Shinya Kitaoka 120a6e
                \li an horizontal slider QSlider.
Shinya Kitaoka 120a6e
                This objects are connected, so if you change one the other
Shinya Kitaoka 120a6e
automatically change.
Shinya Kitaoka 120a6e
                You can set current value getValue(), minimum and max value
Shinya Kitaoka 120a6e
using setValue(),
Shinya Kitaoka 120a6e
                setRange() or setValues(); by default is value = 0, minimum
Shinya Kitaoka 120a6e
value = 0
Shinya Kitaoka 120a6e
                and maximum value = 100.
Toshihiro Shimizu 890ddd
\n	Maximum height object is fixed to \b DVGui::WidgetHeight, width depend
Shinya Kitaoka 120a6e
                on parent width.
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
                To know when integer parameter value change class provides a
Shinya Kitaoka 120a6e
signal, valueChanged();
Shinya Kitaoka 120a6e
                class emit signal when slider value change or when editing text
Shinya Kitaoka 120a6e
field is
Shinya Kitaoka 120a6e
                finished and current value is changed. Editing text field
Shinya Kitaoka 120a6e
finished may occur
Shinya Kitaoka 120a6e
                if focus is lost or enter key is pressed. See SLOT:
Shinya Kitaoka 120a6e
onSliderChanged(int value),
Shinya Kitaoka 120a6e
                onEditingFinished().
Toshihiro Shimizu 890ddd
*/
Shinya Kitaoka 120a6e
class DVAPI IntField : public QWidget {
Shinya Kitaoka 120a6e
  Q_OBJECT
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  RollerField *m_roller;
Shinya Kitaoka 120a6e
  IntLineEdit *m_lineEdit;
Shinya Kitaoka 120a6e
  QSlider *m_slider;
Shinya Kitaoka 120a6e
  bool m_isMaxRangeLimited;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  IntField(QWidget *parent = 0, bool isMaxRangeLimited = true,
Shinya Kitaoka 120a6e
           bool isRollerHide = true);
Shinya Kitaoka 120a6e
  ~IntField() {}
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  /*! Set to \b minValue and \b maxValue slider and text field range.
Shinya Kitaoka 120a6e
                  \sa getRange() */
Shinya Kitaoka 120a6e
  void setRange(int minValue, int maxValue);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  /*! Set \b minValue and \b maxValue to IntField range.
Shinya Kitaoka 120a6e
                  \sa setRange() */
Shinya Kitaoka 120a6e
  void getRange(int &minValue, int &maxValue);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  /*! Set to \b value current value IntField.
Shinya Kitaoka 120a6e
                  \sa getValue() */
Shinya Kitaoka 120a6e
  void setValue(int value);
Shinya Kitaoka 120a6e
  /*! Return current value.
Shinya Kitaoka 120a6e
                  \sa setValue() */
Shinya Kitaoka 120a6e
  int getValue();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  /*! This is provided for convenience.
Shinya Kitaoka 120a6e
                  Set to \b value current value IntField; set to \b minValue and
Shinya Kitaoka 120a6e
     \b maxValue
Shinya Kitaoka 120a6e
                  slider and text field range.
Shinya Kitaoka 120a6e
                  \sa getValue() */
Shinya Kitaoka 120a6e
  void setValues(int value, int minValue, int maxValue);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  /*! If \b enable is false set slider disable and hide it. */
Shinya Kitaoka 120a6e
  void enableSlider(bool enable);
Shinya Kitaoka 120a6e
  bool sliderIsEnabled();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  /*! If \b enable is false set roller disable and hide it. */
Shinya Kitaoka 120a6e
  void enableRoller(bool enable);
Shinya Kitaoka 120a6e
  bool rollerIsEnabled();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  void setLineEditBackgroundColor(QColor color);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
protected slots:
Shinya Kitaoka 120a6e
  /*! Set to value the text field. If text field value is different from \b
Shinya Kitaoka 120a6e
     value
Shinya Kitaoka 120a6e
                  emit signal valueChanged(). */
Shinya Kitaoka 120a6e
  void onSliderChanged(int value);
Shinya Kitaoka 120a6e
  void onSliderReleased() { emit valueChanged(false); }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  /*! Set slider and roller value to current value in text field.
Shinya Kitaoka 120a6e
  \n	This protected slot is called when text editing is finished.
Shinya Kitaoka 120a6e
  \n	If slider value is different from text field value emit signal
Shinya Kitaoka 120a6e
  valueChanged(). */
Shinya Kitaoka 120a6e
  void onEditingFinished();
Shinya Kitaoka 120a6e
  /*! Set text field and slider to roller current value.
Shinya Kitaoka 120a6e
  \n	If slider and text field value are different from roller value
Shinya Kitaoka 120a6e
                  emit signal valueChanged(). */
Shinya Kitaoka 120a6e
  void onRollerValueChanged(bool isDragging);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
signals:
Shinya Kitaoka 120a6e
  /*! This is a signal emitted when IntField, slider or text field, value
Shinya Kitaoka 120a6e
     change;
Shinya Kitaoka 120a6e
                  if slider position change or text field editing is finished.
Shinya Kitaoka 120a6e
                  \sa onEditingFinished() and onSliderChanged(int value). */
Shinya Kitaoka 120a6e
  void valueChanged(bool isDragging);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  /*! This signal is emitted only when the user edit the value by hand */
Shinya Kitaoka 120a6e
  void valueEditedByHand();
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Shinya Kitaoka 120a6e
}  // namespace DVGui
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
#endif  // INTFIELD_H