1 
2 
3 #include "dvwidgets.h"
4 #include "toonzqt/dvdialog.h"
5 #include "toonzqt/checkbox.h"
6 
7 #include <QLayout>
8 #include <QLabel>
9 
10 using namespace DVGui;
11 
12 //=============================================================================
13 // PropertyComboBox
14 //-----------------------------------------------------------------------------
15 
PropertyComboBox(QWidget * parent,TEnumProperty * prop)16 PropertyComboBox::PropertyComboBox(QWidget *parent, TEnumProperty *prop)
17     : QComboBox(parent), PropertyWidget(prop) {
18   connect(this, SIGNAL(currentIndexChanged(const QString &)), this,
19           SLOT(onCurrentIndexChanged(const QString &)));
20   setMaximumHeight(WidgetHeight);
21 }
22 
23 //-----------------------------------------------------------------------------
24 
onCurrentIndexChanged(const QString & text)25 void PropertyComboBox::onCurrentIndexChanged(const QString &text) {
26   TEnumProperty *prop  = dynamic_cast<TEnumProperty *>(m_property);
27   std::wstring currVal = (currentData().isNull())
28                              ? currentText().toStdWString()
29                              : currentData().toString().toStdWString();
30   if (prop && prop->getValue() != currVal) prop->setValue(currVal);
31 }
32 
33 //-----------------------------------------------------------------------------
34 
onPropertyChanged()35 void PropertyComboBox::onPropertyChanged() {
36   TEnumProperty *prop = dynamic_cast<TEnumProperty *>(m_property);
37   if (prop) {
38     QString str  = QString::fromStdWString(prop->getValue());
39     int i        = findData(str);
40     if (i < 0) i = findText(str);
41     if (i >= 0 && i < count()) setCurrentIndex(i);
42   }
43 }
44 
45 //=============================================================================
46 // PropertyCheckBox
47 //-----------------------------------------------------------------------------
48 
PropertyCheckBox(const QString & text,QWidget * parent,TBoolProperty * prop)49 PropertyCheckBox::PropertyCheckBox(const QString &text, QWidget *parent,
50                                    TBoolProperty *prop)
51     : CheckBox(text, parent), PropertyWidget(prop) {
52   connect(this, SIGNAL(stateChanged(int)), this, SLOT(onStateChanged(int)));
53   setMaximumHeight(WidgetHeight);
54 }
55 
56 //-----------------------------------------------------------------------------
57 
onStateChanged(int state)58 void PropertyCheckBox::onStateChanged(int state) {
59   TBoolProperty *prop = dynamic_cast<TBoolProperty *>(m_property);
60   if (prop && prop->getValue() != isChecked()) prop->setValue(isChecked());
61 }
62 
63 //-----------------------------------------------------------------------------
64 
onPropertyChanged()65 void PropertyCheckBox::onPropertyChanged() {
66   TBoolProperty *prop = dynamic_cast<TBoolProperty *>(m_property);
67   if (prop) setChecked(prop->getValue());
68 }
69 
70 //=============================================================================
71 // PropertyLineEdit
72 //-----------------------------------------------------------------------------
73 
PropertyLineEdit(QWidget * parent,TStringProperty * prop)74 PropertyLineEdit::PropertyLineEdit(QWidget *parent, TStringProperty *prop)
75     : LineEdit(parent), PropertyWidget(prop) {
76   connect(this, SIGNAL(textChanged(const QString &)), this,
77           SLOT(onTextChanged(const QString &)));
78   setMaximumSize(100, WidgetHeight);
79 }
80 
81 //-----------------------------------------------------------------------------
82 
onTextChanged(const QString & text)83 void PropertyLineEdit::onTextChanged(const QString &text) {
84   TStringProperty *prop = dynamic_cast<TStringProperty *>(m_property);
85   if (prop && prop->getValue() != text.toStdWString())
86     prop->setValue(text.toStdWString());
87 }
88 
89 //-----------------------------------------------------------------------------
90 
onPropertyChanged()91 void PropertyLineEdit::onPropertyChanged() {
92   TStringProperty *prop = dynamic_cast<TStringProperty *>(m_property);
93   if (prop) setText(QString::fromStdWString(prop->getValue()));
94 }
95 
96 //=============================================================================
97 // PropertyIntField
98 //-----------------------------------------------------------------------------
99 
PropertyIntField(QWidget * parent,TIntProperty * prop)100 PropertyIntField::PropertyIntField(QWidget *parent, TIntProperty *prop)
101     : IntField(parent), PropertyWidget(prop) {
102   connect(this, SIGNAL(valueChanged(bool)), this, SLOT(onValueChanged(bool)));
103 }
104 
105 //-----------------------------------------------------------------------------
106 
onValueChanged(bool isDragging)107 void PropertyIntField::onValueChanged(bool isDragging) {
108   TIntProperty *prop = dynamic_cast<TIntProperty *>(m_property);
109   if (prop) prop->setValue(getValue());
110 }
111 
112 //-----------------------------------------------------------------------------
113 
onPropertyChanged()114 void PropertyIntField::onPropertyChanged() {
115   TIntProperty *prop = dynamic_cast<TIntProperty *>(m_property);
116   if (prop) this->setValue(prop->getValue());
117 }
118