Skip to content

Commit f8af847

Browse files
authored
Merge pull request #3397 from shun-iwasawa/g/mode_sensitive_fx_settings
Mode Sensitive Tag for Fx Settings Layout
2 parents 852949f + 6e910bc commit f8af847

File tree

5 files changed

+139
-35
lines changed

5 files changed

+139
-35
lines changed

stuff/profiles/layouts/fxs/STD_iwa_TextFx.xml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,12 @@
22
<page name="Text Iwa">
33
<vbox>
44
<control>targetType</control>
5-
<control>columnIndex</control>
6-
<control>text</control>
5+
<vbox modeSensitive="targetType" mode="1">
6+
<control>columnIndex</control>
7+
</vbox>
8+
<vbox modeSensitive="targetType" mode="2">
9+
<control>text</control>
10+
</vbox>
711
<control>hAlign</control>
812
<control>center</control>
913
<control>width</control>

stuff/profiles/layouts/fxs/STD_iwa_TimeCodeFx.xml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,17 @@
22
<page name="TimeCode Iwa">
33
<vbox>
44
<control>displayType</control>
5-
<control>frameRate</control>
5+
<vbox modeSensitive="displayType" mode="0,2">
6+
<control>frameRate</control>
7+
</vbox>
68
<control>startFrame</control>
79
<control>position</control>
810
<control>size</control>
911
<control>textColor</control>
1012
<control>showBox</control>
11-
<control>boxColor</control>
13+
<vbox modeSensitive="showBox" mode="1">
14+
<control>boxColor</control>
15+
</vbox>
1216
</vbox>
1317
</page>
1418
</fxlayout>

toonz/sources/include/toonzqt/paramfield.h

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -425,11 +425,37 @@ protected slots:
425425
void onKeyRemoved(int keyIndex);
426426
};
427427

428+
//=============================================================================
429+
// Mode Sensitive Box
430+
//-----------------------------------------------------------------------------
431+
432+
class ModeChangerParamField : public ParamField {
433+
Q_OBJECT
434+
public:
435+
ModeChangerParamField(QWidget *parent, QString paramName,
436+
const TParamP &param, bool addEmptyLabel = true)
437+
: ParamField(parent, paramName, param, addEmptyLabel) {}
438+
signals:
439+
void modeChanged(int);
440+
};
441+
442+
class DVAPI ModeSensitiveBox final : public QWidget {
443+
Q_OBJECT
444+
QList<int> m_modes;
445+
446+
public:
447+
ModeSensitiveBox(QWidget *parent, ModeChangerParamField *modeChanger,
448+
QList<int> modes);
449+
QList<int> modes() { return m_modes; }
450+
protected slots:
451+
void onModeChanged(int mode);
452+
};
453+
428454
//=============================================================================
429455
// EnumParamField
430456
//-----------------------------------------------------------------------------
431457

432-
class EnumParamField final : public ParamField {
458+
class EnumParamField final : public ModeChangerParamField {
433459
Q_OBJECT
434460

435461
TIntEnumParamP m_currentParam, m_actualParam;
@@ -452,7 +478,7 @@ protected slots:
452478
// BoolParamField
453479
//-----------------------------------------------------------------------------
454480

455-
class DVAPI BoolParamField final : public ParamField {
481+
class DVAPI BoolParamField final : public ModeChangerParamField {
456482
Q_OBJECT
457483

458484
TBoolParamP m_currentParam, m_actualParam;

toonz/sources/toonzqt/fxsettings.cpp

Lines changed: 73 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -243,41 +243,67 @@ void ParamsPage::setPageField(TIStream &is, const TFxP &fx, bool isVertical) {
243243
setPageField(is, fx, false);
244244
m_mainLayout->addLayout(m_horizontalLayout, currentRow, 1, 1, 2);
245245
} else if (tagName == "vbox") {
246-
int shrink = 0;
247-
std::string shrinkStr = is.getTagAttribute("shrink");
248-
if (shrinkStr != "") {
249-
shrink = QString::fromStdString(shrinkStr).toInt();
250-
std::string label = is.getTagAttribute("label");
251-
QCheckBox *checkBox = new QCheckBox(this);
252-
QHBoxLayout *sepLay = new QHBoxLayout();
253-
sepLay->setMargin(0);
254-
sepLay->setSpacing(5);
255-
sepLay->addWidget(checkBox, 0);
256-
sepLay->addWidget(new Separator(QString::fromStdString(label), this),
257-
1);
258-
int currentRow = m_mainLayout->rowCount();
259-
m_mainLayout->addLayout(sepLay, currentRow, 0, 1, 2);
260-
m_mainLayout->setRowStretch(currentRow, 0);
246+
int shrink = 0;
247+
std::string shrinkStr = is.getTagAttribute("shrink");
248+
std::string modeSensitiveStr = is.getTagAttribute("modeSensitive");
249+
if (shrinkStr != "" || modeSensitiveStr != "") {
250+
QWidget *tmpWidget;
251+
if (shrinkStr != "") {
252+
tmpWidget = new QWidget(this);
253+
shrink = QString::fromStdString(shrinkStr).toInt();
254+
std::string label = is.getTagAttribute("label");
255+
QCheckBox *checkBox = new QCheckBox(this);
256+
QHBoxLayout *sepLay = new QHBoxLayout();
257+
sepLay->setMargin(0);
258+
sepLay->setSpacing(5);
259+
sepLay->addWidget(checkBox, 0);
260+
sepLay->addWidget(new Separator(QString::fromStdString(label), this),
261+
1);
262+
int currentRow = m_mainLayout->rowCount();
263+
m_mainLayout->addLayout(sepLay, currentRow, 0, 1, 2);
264+
m_mainLayout->setRowStretch(currentRow, 0);
265+
//--- signal-slot connection
266+
connect(checkBox, SIGNAL(toggled(bool)), tmpWidget,
267+
SLOT(setVisible(bool)));
268+
checkBox->setChecked(shrink == 1);
269+
tmpWidget->setVisible(shrink == 1);
270+
} else { // modeSensitiveStr != ""
271+
QList<int> modes;
272+
QStringList modeListStr =
273+
QString::fromStdString(is.getTagAttribute("mode"))
274+
.split(',', QString::SkipEmptyParts);
275+
for (QString modeNum : modeListStr) modes.push_back(modeNum.toInt());
276+
// find the mode combobox
277+
ModeChangerParamField *modeChanger = nullptr;
278+
for (int r = 0; r < m_mainLayout->rowCount(); r++) {
279+
QLayoutItem *li = m_mainLayout->itemAtPosition(r, 1);
280+
if (!li || !li->widget()) continue;
281+
ModeChangerParamField *field =
282+
dynamic_cast<ModeChangerParamField *>(li->widget());
283+
if (!field ||
284+
field->getParamName().toStdString() != modeSensitiveStr)
285+
continue;
286+
modeChanger = field;
287+
break;
288+
}
289+
assert(modeChanger);
290+
tmpWidget = new ModeSensitiveBox(this, modeChanger, modes);
291+
}
292+
293+
int currentRow = m_mainLayout->rowCount();
261294
QGridLayout *keepMainLay = m_mainLayout;
262-
/*-- レイアウトを一時的に差し替え --*/
263-
m_mainLayout = new QGridLayout(this);
264-
m_mainLayout->setMargin(12);
295+
// temporary switch the layout
296+
m_mainLayout = new QGridLayout();
297+
m_mainLayout->setMargin(0);
265298
m_mainLayout->setVerticalSpacing(10);
266299
m_mainLayout->setHorizontalSpacing(5);
267300
m_mainLayout->setColumnStretch(0, 0);
268301
m_mainLayout->setColumnStretch(1, 1);
269302
setPageField(is, fx, true);
270-
271-
QWidget *tmpWidget = new QWidget(this);
272303
tmpWidget->setLayout(m_mainLayout);
273-
/*-- レイアウト戻し --*/
304+
// turn back the layout
274305
m_mainLayout = keepMainLay;
275-
m_mainLayout->addWidget(tmpWidget, currentRow + 1, 0, 1, 2);
276-
//--- signal-slot connection
277-
connect(checkBox, SIGNAL(toggled(bool)), tmpWidget,
278-
SLOT(setVisible(bool)));
279-
checkBox->setChecked(shrink == 1);
280-
tmpWidget->setVisible(shrink == 1);
306+
m_mainLayout->addWidget(tmpWidget, currentRow, 0, 1, 2);
281307
} else
282308
setPageField(is, fx, true);
283309
}
@@ -611,17 +637,37 @@ void updateMaximumPageSize(QGridLayout *layout, int &maxLabelWidth,
611637
}
612638

613639
/*-- Widget側の最適な縦サイズおよび横幅の最大値を得る --*/
640+
QMap<int, int> heightsByMode;
641+
int maxModeHeight = 0;
614642
for (int r = 0; r < layout->rowCount(); r++) {
615643
/*-- Column1にある可能性のあるもの:ParamField, Histogram, Layout,
616644
* RgbLinkButtons --*/
617645

618646
QLayoutItem *item = layout->itemAtPosition(r, 1);
619647
if (!item) continue;
620648

649+
ModeSensitiveBox *box = dynamic_cast<ModeSensitiveBox *>(item->widget());
650+
if (box) {
651+
// if (box->isHidden()) continue;
652+
QGridLayout *innerLay = dynamic_cast<QGridLayout *>(box->layout());
653+
if (!innerLay) continue;
654+
int tmpHeight = 0;
655+
updateMaximumPageSize(innerLay, maxLabelWidth, maxWidgetWidth, tmpHeight);
656+
for (int mode : box->modes()) {
657+
heightsByMode[mode] += tmpHeight;
658+
maxModeHeight = std::max(maxModeHeight, heightsByMode[mode]);
659+
}
660+
661+
// attempt to align the label column
662+
innerLay->setColumnMinimumWidth(0, maxLabelWidth);
663+
continue;
664+
}
665+
621666
QSize itemSize = getItemSize(item);
622667
if (maxWidgetWidth < itemSize.width()) maxWidgetWidth = itemSize.width();
623668
fieldsHeight += itemSize.height();
624669
}
670+
if (maxModeHeight > 0) fieldsHeight += maxModeHeight;
625671

626672
if (layout->rowCount() > 1) fieldsHeight += (layout->rowCount() - 1) * 10;
627673
}

toonz/sources/toonzqt/paramfield.cpp

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1242,13 +1242,31 @@ void SpectrumParamField::onKeyRemoved(int keyIndex) {
12421242
if (undo) TUndoManager::manager()->add(undo);
12431243
}
12441244

1245+
//=============================================================================
1246+
// Mode Sensitive Box
1247+
//-----------------------------------------------------------------------------
1248+
1249+
ModeSensitiveBox::ModeSensitiveBox(QWidget *parent,
1250+
ModeChangerParamField *modeChanger,
1251+
QList<int> modes)
1252+
: QWidget(parent), m_modes(modes) {
1253+
connect(modeChanger, SIGNAL(modeChanged(int)), this,
1254+
SLOT(onModeChanged(int)));
1255+
}
1256+
1257+
//-----------------------------------------------------------------------------
1258+
1259+
void ModeSensitiveBox::onModeChanged(int modeValue) {
1260+
setVisible(m_modes.contains(modeValue));
1261+
}
1262+
12451263
//=============================================================================
12461264
// EnumParamField
12471265
//-----------------------------------------------------------------------------
12481266

12491267
EnumParamField::EnumParamField(QWidget *parent, QString name,
12501268
const TIntEnumParamP &param)
1251-
: ParamField(parent, name, param) {
1269+
: ModeChangerParamField(parent, name, param) {
12521270
QString str;
12531271
m_paramName = str.fromStdString(param->getName());
12541272
m_om = new QComboBox(this);
@@ -1300,6 +1318,8 @@ void EnumParamField::onChange(const QString &str) {
13001318
emit currentParamChanged();
13011319
emit actualParamChanged();
13021320

1321+
emit modeChanged(m_actualParam->getValue());
1322+
13031323
if (undo) TUndoManager::manager()->add(undo);
13041324
}
13051325

@@ -1312,6 +1332,7 @@ void EnumParamField::setParam(const TParamP &current, const TParamP &actual,
13121332
assert(m_currentParam);
13131333
assert(m_actualParam);
13141334
update(frame);
1335+
emit modeChanged(m_actualParam->getValue());
13151336
}
13161337

13171338
//-----------------------------------------------------------------------------
@@ -1336,7 +1357,7 @@ void EnumParamField::update(int frame) {
13361357

13371358
BoolParamField::BoolParamField(QWidget *parent, QString name,
13381359
const TBoolParamP &param)
1339-
: ParamField(parent, name, param) {
1360+
: ModeChangerParamField(parent, name, param) {
13401361
QString str;
13411362
m_paramName = str.fromStdString(param->getName());
13421363
if (!param->hasUILabel()) m_interfaceName = name;
@@ -1362,6 +1383,8 @@ void BoolParamField::onToggled(bool checked) {
13621383
emit currentParamChanged();
13631384
emit actualParamChanged();
13641385

1386+
emit modeChanged((checked) ? 1 : 0);
1387+
13651388
TBoolParamP boolParam = m_actualParam;
13661389
if (boolParam)
13671390
TUndoManager::manager()->add(new BoolParamFieldUndo(
@@ -1377,6 +1400,7 @@ void BoolParamField::setParam(const TParamP &current, const TParamP &actual,
13771400
assert(m_currentParam);
13781401
assert(m_actualParam);
13791402
update(frame);
1403+
emit modeChanged((m_actualParam->getValue()) ? 1 : 0);
13801404
}
13811405

13821406
//-----------------------------------------------------------------------------

0 commit comments

Comments
 (0)