From 6e910bce6ace206d8ea000cb34851ff1da1e8582 Mon Sep 17 00:00:00 2001 From: shun-iwasawa Date: Jul 13 2020 09:39:58 +0000 Subject: mode sensitive fx settings --- diff --git a/stuff/profiles/layouts/fxs/STD_iwa_TextFx.xml b/stuff/profiles/layouts/fxs/STD_iwa_TextFx.xml index aab4c54..528a508 100644 --- a/stuff/profiles/layouts/fxs/STD_iwa_TextFx.xml +++ b/stuff/profiles/layouts/fxs/STD_iwa_TextFx.xml @@ -2,8 +2,12 @@ targetType - columnIndex - text + + columnIndex + + + text + hAlign center width diff --git a/stuff/profiles/layouts/fxs/STD_iwa_TimeCodeFx.xml b/stuff/profiles/layouts/fxs/STD_iwa_TimeCodeFx.xml index 87d3662..803470d 100644 --- a/stuff/profiles/layouts/fxs/STD_iwa_TimeCodeFx.xml +++ b/stuff/profiles/layouts/fxs/STD_iwa_TimeCodeFx.xml @@ -2,13 +2,17 @@ displayType - frameRate + + frameRate + startFrame position size textColor showBox - boxColor + + boxColor + diff --git a/toonz/sources/include/toonzqt/paramfield.h b/toonz/sources/include/toonzqt/paramfield.h index 5de4fb3..01ad39e 100644 --- a/toonz/sources/include/toonzqt/paramfield.h +++ b/toonz/sources/include/toonzqt/paramfield.h @@ -426,10 +426,36 @@ protected slots: }; //============================================================================= +// Mode Sensitive Box +//----------------------------------------------------------------------------- + +class ModeChangerParamField : public ParamField { + Q_OBJECT +public: + ModeChangerParamField(QWidget *parent, QString paramName, + const TParamP ¶m, bool addEmptyLabel = true) + : ParamField(parent, paramName, param, addEmptyLabel) {} +signals: + void modeChanged(int); +}; + +class DVAPI ModeSensitiveBox final : public QWidget { + Q_OBJECT + QList m_modes; + +public: + ModeSensitiveBox(QWidget *parent, ModeChangerParamField *modeChanger, + QList modes); + QList modes() { return m_modes; } +protected slots: + void onModeChanged(int mode); +}; + +//============================================================================= // EnumParamField //----------------------------------------------------------------------------- -class EnumParamField final : public ParamField { +class EnumParamField final : public ModeChangerParamField { Q_OBJECT TIntEnumParamP m_currentParam, m_actualParam; @@ -452,7 +478,7 @@ protected slots: // BoolParamField //----------------------------------------------------------------------------- -class DVAPI BoolParamField final : public ParamField { +class DVAPI BoolParamField final : public ModeChangerParamField { Q_OBJECT TBoolParamP m_currentParam, m_actualParam; diff --git a/toonz/sources/toonzqt/fxsettings.cpp b/toonz/sources/toonzqt/fxsettings.cpp index 241b39b..e311e87 100644 --- a/toonz/sources/toonzqt/fxsettings.cpp +++ b/toonz/sources/toonzqt/fxsettings.cpp @@ -243,41 +243,67 @@ void ParamsPage::setPageField(TIStream &is, const TFxP &fx, bool isVertical) { setPageField(is, fx, false); m_mainLayout->addLayout(m_horizontalLayout, currentRow, 1, 1, 2); } else if (tagName == "vbox") { - int shrink = 0; - std::string shrinkStr = is.getTagAttribute("shrink"); - if (shrinkStr != "") { - shrink = QString::fromStdString(shrinkStr).toInt(); - std::string label = is.getTagAttribute("label"); - QCheckBox *checkBox = new QCheckBox(this); - QHBoxLayout *sepLay = new QHBoxLayout(); - sepLay->setMargin(0); - sepLay->setSpacing(5); - sepLay->addWidget(checkBox, 0); - sepLay->addWidget(new Separator(QString::fromStdString(label), this), - 1); - int currentRow = m_mainLayout->rowCount(); - m_mainLayout->addLayout(sepLay, currentRow, 0, 1, 2); - m_mainLayout->setRowStretch(currentRow, 0); + int shrink = 0; + std::string shrinkStr = is.getTagAttribute("shrink"); + std::string modeSensitiveStr = is.getTagAttribute("modeSensitive"); + if (shrinkStr != "" || modeSensitiveStr != "") { + QWidget *tmpWidget; + if (shrinkStr != "") { + tmpWidget = new QWidget(this); + shrink = QString::fromStdString(shrinkStr).toInt(); + std::string label = is.getTagAttribute("label"); + QCheckBox *checkBox = new QCheckBox(this); + QHBoxLayout *sepLay = new QHBoxLayout(); + sepLay->setMargin(0); + sepLay->setSpacing(5); + sepLay->addWidget(checkBox, 0); + sepLay->addWidget(new Separator(QString::fromStdString(label), this), + 1); + int currentRow = m_mainLayout->rowCount(); + m_mainLayout->addLayout(sepLay, currentRow, 0, 1, 2); + m_mainLayout->setRowStretch(currentRow, 0); + //--- signal-slot connection + connect(checkBox, SIGNAL(toggled(bool)), tmpWidget, + SLOT(setVisible(bool))); + checkBox->setChecked(shrink == 1); + tmpWidget->setVisible(shrink == 1); + } else { // modeSensitiveStr != "" + QList modes; + QStringList modeListStr = + QString::fromStdString(is.getTagAttribute("mode")) + .split(',', QString::SkipEmptyParts); + for (QString modeNum : modeListStr) modes.push_back(modeNum.toInt()); + // find the mode combobox + ModeChangerParamField *modeChanger = nullptr; + for (int r = 0; r < m_mainLayout->rowCount(); r++) { + QLayoutItem *li = m_mainLayout->itemAtPosition(r, 1); + if (!li || !li->widget()) continue; + ModeChangerParamField *field = + dynamic_cast(li->widget()); + if (!field || + field->getParamName().toStdString() != modeSensitiveStr) + continue; + modeChanger = field; + break; + } + assert(modeChanger); + tmpWidget = new ModeSensitiveBox(this, modeChanger, modes); + } + + int currentRow = m_mainLayout->rowCount(); QGridLayout *keepMainLay = m_mainLayout; - /*-- レイアウトを一時的に差し替え --*/ - m_mainLayout = new QGridLayout(this); - m_mainLayout->setMargin(12); + // temporary switch the layout + m_mainLayout = new QGridLayout(); + m_mainLayout->setMargin(0); m_mainLayout->setVerticalSpacing(10); m_mainLayout->setHorizontalSpacing(5); m_mainLayout->setColumnStretch(0, 0); m_mainLayout->setColumnStretch(1, 1); setPageField(is, fx, true); - - QWidget *tmpWidget = new QWidget(this); tmpWidget->setLayout(m_mainLayout); - /*-- レイアウト戻し --*/ + // turn back the layout m_mainLayout = keepMainLay; - m_mainLayout->addWidget(tmpWidget, currentRow + 1, 0, 1, 2); - //--- signal-slot connection - connect(checkBox, SIGNAL(toggled(bool)), tmpWidget, - SLOT(setVisible(bool))); - checkBox->setChecked(shrink == 1); - tmpWidget->setVisible(shrink == 1); + m_mainLayout->addWidget(tmpWidget, currentRow, 0, 1, 2); } else setPageField(is, fx, true); } @@ -611,6 +637,8 @@ void updateMaximumPageSize(QGridLayout *layout, int &maxLabelWidth, } /*-- Widget側の最適な縦サイズおよび横幅の最大値を得る --*/ + QMap heightsByMode; + int maxModeHeight = 0; for (int r = 0; r < layout->rowCount(); r++) { /*-- Column1にある可能性のあるもの:ParamField, Histogram, Layout, * RgbLinkButtons --*/ @@ -618,10 +646,28 @@ void updateMaximumPageSize(QGridLayout *layout, int &maxLabelWidth, QLayoutItem *item = layout->itemAtPosition(r, 1); if (!item) continue; + ModeSensitiveBox *box = dynamic_cast(item->widget()); + if (box) { + // if (box->isHidden()) continue; + QGridLayout *innerLay = dynamic_cast(box->layout()); + if (!innerLay) continue; + int tmpHeight = 0; + updateMaximumPageSize(innerLay, maxLabelWidth, maxWidgetWidth, tmpHeight); + for (int mode : box->modes()) { + heightsByMode[mode] += tmpHeight; + maxModeHeight = std::max(maxModeHeight, heightsByMode[mode]); + } + + // attempt to align the label column + innerLay->setColumnMinimumWidth(0, maxLabelWidth); + continue; + } + QSize itemSize = getItemSize(item); if (maxWidgetWidth < itemSize.width()) maxWidgetWidth = itemSize.width(); fieldsHeight += itemSize.height(); } + if (maxModeHeight > 0) fieldsHeight += maxModeHeight; if (layout->rowCount() > 1) fieldsHeight += (layout->rowCount() - 1) * 10; } diff --git a/toonz/sources/toonzqt/paramfield.cpp b/toonz/sources/toonzqt/paramfield.cpp index 3af0729..fc826bf 100644 --- a/toonz/sources/toonzqt/paramfield.cpp +++ b/toonz/sources/toonzqt/paramfield.cpp @@ -1243,12 +1243,30 @@ void SpectrumParamField::onKeyRemoved(int keyIndex) { } //============================================================================= +// Mode Sensitive Box +//----------------------------------------------------------------------------- + +ModeSensitiveBox::ModeSensitiveBox(QWidget *parent, + ModeChangerParamField *modeChanger, + QList modes) + : QWidget(parent), m_modes(modes) { + connect(modeChanger, SIGNAL(modeChanged(int)), this, + SLOT(onModeChanged(int))); +} + +//----------------------------------------------------------------------------- + +void ModeSensitiveBox::onModeChanged(int modeValue) { + setVisible(m_modes.contains(modeValue)); +} + +//============================================================================= // EnumParamField //----------------------------------------------------------------------------- EnumParamField::EnumParamField(QWidget *parent, QString name, const TIntEnumParamP ¶m) - : ParamField(parent, name, param) { + : ModeChangerParamField(parent, name, param) { QString str; m_paramName = str.fromStdString(param->getName()); m_om = new QComboBox(this); @@ -1300,6 +1318,8 @@ void EnumParamField::onChange(const QString &str) { emit currentParamChanged(); emit actualParamChanged(); + emit modeChanged(m_actualParam->getValue()); + if (undo) TUndoManager::manager()->add(undo); } @@ -1312,6 +1332,7 @@ void EnumParamField::setParam(const TParamP ¤t, const TParamP &actual, assert(m_currentParam); assert(m_actualParam); update(frame); + emit modeChanged(m_actualParam->getValue()); } //----------------------------------------------------------------------------- @@ -1336,7 +1357,7 @@ void EnumParamField::update(int frame) { BoolParamField::BoolParamField(QWidget *parent, QString name, const TBoolParamP ¶m) - : ParamField(parent, name, param) { + : ModeChangerParamField(parent, name, param) { QString str; m_paramName = str.fromStdString(param->getName()); if (!param->hasUILabel()) m_interfaceName = name; @@ -1362,6 +1383,8 @@ void BoolParamField::onToggled(bool checked) { emit currentParamChanged(); emit actualParamChanged(); + emit modeChanged((checked) ? 1 : 0); + TBoolParamP boolParam = m_actualParam; if (boolParam) TUndoManager::manager()->add(new BoolParamFieldUndo( @@ -1377,6 +1400,7 @@ void BoolParamField::setParam(const TParamP ¤t, const TParamP &actual, assert(m_currentParam); assert(m_actualParam); update(frame); + emit modeChanged((m_actualParam->getValue()) ? 1 : 0); } //-----------------------------------------------------------------------------