From fb319c8f4abc52cd069f8d98ac0144fa2e145c28 Mon Sep 17 00:00:00 2001 From: Ivan Mahonin Date: Aug 28 2023 15:47:15 +0000 Subject: #assistants: spinner for TIntProperty --- diff --git a/toonz/sources/include/toonzqt/intfield.h b/toonz/sources/include/toonzqt/intfield.h index 61d14b2..f18125f 100644 --- a/toonz/sources/include/toonzqt/intfield.h +++ b/toonz/sources/include/toonzqt/intfield.h @@ -20,6 +20,7 @@ // forward declaration class QSlider; +class QPushButton; class QIntValidator; //============================================================================= @@ -166,12 +167,17 @@ class DVAPI IntField : public QWidget { RollerField *m_roller; IntLineEdit *m_lineEdit; QSlider *m_slider; + QPushButton *m_inc; + QPushButton *m_dec; + bool m_isMaxRangeLimited; bool m_isLinearSlider; public: - IntField(QWidget *parent = 0, bool isMaxRangeLimited = true, - bool isRollerHide = true); + IntField(QWidget *parent = 0, + bool isMaxRangeLimited = true, + bool isRollerHide = true, + bool isSpinnerHide = true ); ~IntField() {} /*! Set to \b minValue and \b maxValue slider and text field range. @@ -204,6 +210,10 @@ public: void enableRoller(bool enable); bool rollerIsEnabled(); + /*! If \b enable is false set spinner disable and hide it. */ + void enableSpinner(bool enable); + bool spinnerIsEnabled(); + void setLineEditBackgroundColor(QColor color); protected: @@ -220,6 +230,9 @@ protected slots: void onSliderChanged(int value); void onSliderReleased() { emit valueChanged(false); } + void onIncClicked(); + void onDecClicked(); + /*! Set slider and roller value to current value in text field. \n This protected slot is called when text editing is finished. \n If slider value is different from text field value emit signal diff --git a/toonz/sources/include/tproperty.h b/toonz/sources/include/tproperty.h index f7c2ea5..b9c52e0 100644 --- a/toonz/sources/include/tproperty.h +++ b/toonz/sources/include/tproperty.h @@ -122,7 +122,8 @@ public: , m_range(minValue, maxValue) , m_value(minValue) , m_isMaxRangeLimited(isMaxRangeLimited) - , m_isLinearSlider(true) { + , m_isLinearSlider(true) + , m_isSpinner(false) { setValue(value); } @@ -151,11 +152,16 @@ public: void setNonLinearSlider() { m_isLinearSlider = false; } bool isLinearSlider() { return m_isLinearSlider; } + //! has meaning for int properties only + void setSpinner() { m_isSpinner = true; } + bool isSpinner() { return m_isSpinner; } + private: Range m_range; T m_value; bool m_isMaxRangeLimited; bool m_isLinearSlider; + bool m_isSpinner; }; //--------------------------------------------------------- diff --git a/toonz/sources/tnztools/tooloptionscontrols.cpp b/toonz/sources/tnztools/tooloptionscontrols.cpp index f26ee4f..5857d47 100644 --- a/toonz/sources/tnztools/tooloptionscontrols.cpp +++ b/toonz/sources/tnztools/tooloptionscontrols.cpp @@ -267,13 +267,21 @@ ToolOptionIntSlider::ToolOptionIntSlider(TTool *tool, TIntProperty *property, ToolHandle *toolHandle) : IntField(0, property->isMaxRangeLimited()) , ToolOptionControl(tool, property->getName(), toolHandle) - , m_property(property) { + , m_property(property) +{ setLinearSlider(property->isLinearSlider()); m_property->addListener(this); TIntProperty::Range range = property->getRange(); setRange(range.first, range.second); - setMaximumWidth(300); - setMinimumWidth(50); + if (property->isSpinner()) { + enableSlider(false); + enableSpinner(true); + setMinimumWidth(60); + setMaximumWidth(80); + } else { + setMinimumWidth(50); + setMaximumWidth(300); + } updateStatus(); connect(this, SIGNAL(valueChanged(bool)), SLOT(onValueChanged(bool))); // synchronize the state with the same widgets in other tool option bars diff --git a/toonz/sources/toonzqt/intfield.cpp b/toonz/sources/toonzqt/intfield.cpp index e53c078..01ff0e6 100644 --- a/toonz/sources/toonzqt/intfield.cpp +++ b/toonz/sources/toonzqt/intfield.cpp @@ -10,6 +10,7 @@ #include #include #include +#include namespace { const int NonLinearSliderPrecision = 2; @@ -263,11 +264,14 @@ void IntLineEdit::mouseReleaseEvent(QMouseEvent *e) { // IntField //----------------------------------------------------------------------------- -IntField::IntField(QWidget *parent, bool isMaxRangeLimited, bool isRollerHide) +IntField::IntField(QWidget *parent, bool isMaxRangeLimited, bool isRollerHide, + bool isSpinnerHide) : QWidget(parent) + , m_roller(0) , m_lineEdit(0) , m_slider(0) - , m_roller(0) + , m_inc(0) + , m_dec(0) , m_isMaxRangeLimited(isMaxRangeLimited) , m_isLinearSlider(true) { setObjectName("IntField"); @@ -295,6 +299,19 @@ IntField::IntField(QWidget *parent, bool isMaxRangeLimited, bool isRollerHide) layout->addWidget(field); + m_inc = new QPushButton(QString("+")); + m_dec = new QPushButton(QString("-")); + m_inc->setFixedSize(QSize(20, 20)); + m_dec->setFixedSize(QSize(20, 20)); + ret = ret + && connect(m_inc, SIGNAL(clicked()), this, SLOT(onIncClicked())) + && connect(m_dec, SIGNAL(clicked()), this, SLOT(onDecClicked())); + + if (isSpinnerHide) enableSpinner(false); + + layout->addWidget(m_inc); + layout->addWidget(m_dec); + m_slider = new QSlider(Qt::Horizontal, this); ret = ret && connect(m_slider, SIGNAL(valueChanged(int)), this, SLOT(onSliderChanged(int))); @@ -386,6 +403,24 @@ bool IntField::rollerIsEnabled() { return m_roller->isEnabled(); } //----------------------------------------------------------------------------- +void IntField::enableSpinner(bool enable) { + m_inc->setEnabled(enable); + m_dec->setEnabled(enable); + if (enable) { + m_inc->show(); + m_dec->show(); + } else { + m_inc->hide(); + m_dec->hide(); + } +} + +//----------------------------------------------------------------------------- + +bool IntField::spinnerIsEnabled() { return m_inc->isEnabled(); } + +//----------------------------------------------------------------------------- + void IntField::setLineEditBackgroundColor(QColor color) { m_lineEdit->setLineEditBackgroundColor(color); } @@ -452,6 +487,30 @@ void IntField::onSliderChanged(int sliderPos) { //----------------------------------------------------------------------------- +void IntField::onIncClicked() { + int value = m_lineEdit->getValue() + 1; + m_lineEdit->setValue(value); + m_slider->setValue(value2pos(value)); + m_roller->setValue((double)value); + emit valueChanged(false); + m_lineEdit->setCursorPosition(0); + emit valueChanged(true); +} + +//----------------------------------------------------------------------------- + +void IntField::onDecClicked() { + int value = m_lineEdit->getValue() - 1; + m_lineEdit->setValue(value); + m_slider->setValue(value2pos(value)); + m_roller->setValue((double)value); + emit valueChanged(false); + m_lineEdit->setCursorPosition(0); + emit valueChanged(true); +} + +//----------------------------------------------------------------------------- + void IntField::onEditingFinished() { double value = m_lineEdit->getValue(); // Controllo necessario per evitare che il segnale di cambiamento venga emesso