From ff09503ac10247caec91f0f6e5745f1f240059db Mon Sep 17 00:00:00 2001 From: Brad Parker Date: Mon, 20 Aug 2018 21:48:59 -0400 Subject: [PATCH] Qt: add right-click options to reset shader parameters back to defaults --- intl/msg_hash_ja.h | 6 + intl/msg_hash_us.h | 6 + msg_hash.h | 3 + ui/drivers/qt/shaderparamsdialog.cpp | 187 ++++++++++++++++++++++++++- ui/drivers/qt/shaderparamsdialog.h | 5 + 5 files changed, 202 insertions(+), 5 deletions(-) diff --git a/intl/msg_hash_ja.h b/intl/msg_hash_ja.h index 88adc933c0..e13ceb1c71 100644 --- a/intl/msg_hash_ja.h +++ b/intl/msg_hash_ja.h @@ -3774,3 +3774,9 @@ MSG_HASH(MENU_ENUM_LABEL_VALUE_QT_SHADER_CLEAR_ALL_PASSES, "すべてのパスを取り除く") MSG_HASH(MENU_ENUM_LABEL_VALUE_QT_SHADER_NO_PASSES, "シェーダーパスはありません。") +MSG_HASH(MENU_ENUM_LABEL_VALUE_QT_RESET_PASS, + "このパスをリセット") +MSG_HASH(MENU_ENUM_LABEL_VALUE_QT_RESET_ALL_PASSES, + "すべてのパスをリセット") +MSG_HASH(MENU_ENUM_LABEL_VALUE_QT_RESET_PARAMETER, + "パラメータをリセット") diff --git a/intl/msg_hash_us.h b/intl/msg_hash_us.h index 8bb57653c9..6fa7aca4cf 100644 --- a/intl/msg_hash_us.h +++ b/intl/msg_hash_us.h @@ -4284,3 +4284,9 @@ MSG_HASH(MENU_ENUM_LABEL_VALUE_QT_SHADER_CLEAR_ALL_PASSES, "Clear All Passes") MSG_HASH(MENU_ENUM_LABEL_VALUE_QT_SHADER_NO_PASSES, "No shader passes.") +MSG_HASH(MENU_ENUM_LABEL_VALUE_QT_RESET_PASS, + "Reset Pass") +MSG_HASH(MENU_ENUM_LABEL_VALUE_QT_RESET_ALL_PASSES, + "Reset All Passes") +MSG_HASH(MENU_ENUM_LABEL_VALUE_QT_RESET_PARAMETER, + "Reset Parameter") diff --git a/msg_hash.h b/msg_hash.h index 5ea9620d1c..483178f62c 100644 --- a/msg_hash.h +++ b/msg_hash.h @@ -1992,6 +1992,9 @@ enum msg_hash_enums MENU_ENUM_LABEL_VALUE_QT_SHADER_ADD_PASS, MENU_ENUM_LABEL_VALUE_QT_SHADER_CLEAR_ALL_PASSES, MENU_ENUM_LABEL_VALUE_QT_SHADER_NO_PASSES, + MENU_ENUM_LABEL_VALUE_QT_RESET_PASS, + MENU_ENUM_LABEL_VALUE_QT_RESET_ALL_PASSES, + MENU_ENUM_LABEL_VALUE_QT_RESET_PARAMETER, MENU_LABEL(MIDI_INPUT), MENU_LABEL(MIDI_OUTPUT), diff --git a/ui/drivers/qt/shaderparamsdialog.cpp b/ui/drivers/qt/shaderparamsdialog.cpp index 960aba8ec6..5ce8a387be 100644 --- a/ui/drivers/qt/shaderparamsdialog.cpp +++ b/ui/drivers/qt/shaderparamsdialog.cpp @@ -114,9 +114,10 @@ void ShaderParamsDialog::clearLayout() if (m_scrollArea) { - //qDeleteAll(children()); foreach (QObject *obj, children()) + { obj->deleteLater(); + } } m_layout = new QVBoxLayout(); @@ -436,6 +437,85 @@ void ShaderParamsDialog::onShaderLoadPresetClicked() #endif } +void ShaderParamsDialog::onShaderResetPass(int pass) +{ + struct video_shader *menu_shader = NULL; + struct video_shader *video_shader = NULL; + unsigned i; + + getShaders(&menu_shader, &video_shader); + + if (menu_shader) + { + for (i = 0; i < menu_shader->num_parameters; i++) + { + struct video_shader_parameter *param = &menu_shader->parameters[i]; + + /* if pass < 0, reset all params, otherwise only reset the selected pass */ + if (pass >= 0 && param->pass != pass) + continue; + + param->current = param->initial; + } + } + + if (video_shader) + { + for (i = 0; i < video_shader->num_parameters; i++) + { + struct video_shader_parameter *param = &video_shader->parameters[i]; + + /* if pass < 0, reset all params, otherwise only reset the selected pass */ + if (pass >= 0 && param->pass != pass) + continue; + + param->current = param->initial; + } + } + + emit reload(); +} + +void ShaderParamsDialog::onShaderResetParameter(int parameter) +{ + struct video_shader *menu_shader = NULL; + struct video_shader *video_shader = NULL; + unsigned i; + + getShaders(&menu_shader, &video_shader); + + if (menu_shader) + { + struct video_shader_parameter *param = NULL; + + if (parameter < 0 || parameter >= static_cast(menu_shader->num_parameters)) + return; + + param = &menu_shader->parameters[parameter]; + + param->current = param->initial; + } + + if (video_shader) + { + struct video_shader_parameter *param = NULL; + + if (parameter < 0 || parameter >= static_cast(video_shader->num_parameters)) + return; + + param = &video_shader->parameters[parameter]; + + param->current = param->initial; + } + + emit reload(); +} + +void ShaderParamsDialog::onShaderResetAllPasses() +{ + emit onShaderResetPass(-1); +} + void ShaderParamsDialog::onShaderAddPassClicked() { #ifdef HAVE_MENU @@ -670,7 +750,7 @@ void ShaderParamsDialog::onShaderApplyClicked() void ShaderParamsDialog::reload() { - buildLayout(); + emit buildLayout(); } void ShaderParamsDialog::buildLayout() @@ -703,7 +783,7 @@ void ShaderParamsDialog::buildLayout() goto end; } - clearLayout(); + emit clearLayout(); /* Only check video_shader for the path, menu_shader seems stale... e.g. if you remove all the shader passes, * it still has the old path in it, but video_shader does not @@ -846,6 +926,10 @@ void ShaderParamsDialog::buildLayout() form = new QFormLayout(); groupBox = new QGroupBox(shaderBasename); groupBox->setLayout(form); + groupBox->setProperty("pass", i); + groupBox->setContextMenuPolicy(Qt::CustomContextMenu); + + connect(groupBox, SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(onGroupBoxContextMenuRequested(const QPoint&))); m_layout->addWidget(groupBox); @@ -893,9 +977,102 @@ end: resize(720, 480); } +void ShaderParamsDialog::onParameterLabelContextMenuRequested(const QPoint&) +{ + QLabel *label = NULL; + QPointer action; + QList actions; + QScopedPointer resetParamAction; + QVariant paramVariant; + int parameter = 0; + bool ok = false; + + label = qobject_cast(sender()); + + if (!label) + return; + + paramVariant = label->property("parameter"); + + if (!paramVariant.isValid()) + return; + + parameter = paramVariant.toInt(&ok); + + if (!ok) + return; + + resetParamAction.reset(new QAction(msg_hash_to_str(MENU_ENUM_LABEL_VALUE_QT_RESET_PARAMETER), 0)); + + actions.append(resetParamAction.data()); + + action = QMenu::exec(actions, QCursor::pos(), NULL, label); + + if (!action) + return; + + if (action == resetParamAction.data()) + { + emit onShaderResetParameter(parameter); + } +} + +void ShaderParamsDialog::onGroupBoxContextMenuRequested(const QPoint&) +{ + QGroupBox *groupBox = NULL; + QPointer action; + QList actions; + QScopedPointer resetPassAction; + QScopedPointer resetAllPassesAction; + QVariant passVariant; + int pass = 0; + bool ok = false; + + groupBox = qobject_cast(sender()); + + if (!groupBox) + return; + + passVariant = groupBox->property("pass"); + + if (!passVariant.isValid()) + return; + + pass = passVariant.toInt(&ok); + + if (!ok) + return; + + resetPassAction.reset(new QAction(msg_hash_to_str(MENU_ENUM_LABEL_VALUE_QT_RESET_PASS), 0)); + resetAllPassesAction.reset(new QAction(msg_hash_to_str(MENU_ENUM_LABEL_VALUE_QT_RESET_ALL_PASSES), 0)); + + actions.append(resetPassAction.data()); + actions.append(resetAllPassesAction.data()); + + action = QMenu::exec(actions, QCursor::pos(), NULL, groupBox); + + if (!action) + return; + + if (action == resetPassAction.data()) + { + emit onShaderResetPass(pass); + } + else if (action == resetAllPassesAction.data()) + { + emit onShaderResetAllPasses(); + } +} + void ShaderParamsDialog::addShaderParam(struct video_shader_parameter *param, int parameter, QFormLayout *form) { QString desc = param->desc; + QLabel *label = new QLabel(desc); + + label->setProperty("parameter", parameter); + label->setContextMenuPolicy(Qt::CustomContextMenu); + + connect(label, SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(onParameterLabelContextMenuRequested(const QPoint&))); if ((param->minimum == 0.0) && (param->maximum @@ -909,7 +1086,7 @@ void ShaderParamsDialog::addShaderParam(struct video_shader_parameter *param, in connect(checkBox, SIGNAL(clicked()), this, SLOT(onShaderParamCheckBoxClicked())); - form->addRow(desc, checkBox); + form->addRow(label, checkBox); } else { @@ -957,7 +1134,7 @@ void ShaderParamsDialog::addShaderParam(struct video_shader_parameter *param, in box->addWidget(spinBox); } - form->addRow(desc, box); + form->addRow(label, box); } } diff --git a/ui/drivers/qt/shaderparamsdialog.h b/ui/drivers/qt/shaderparamsdialog.h index 398ff283b1..309e785234 100644 --- a/ui/drivers/qt/shaderparamsdialog.h +++ b/ui/drivers/qt/shaderparamsdialog.h @@ -28,9 +28,14 @@ private slots: void onShaderParamSpinBoxValueChanged(int value); void onShaderParamDoubleSpinBoxValueChanged(double value); void onFilterComboBoxIndexChanged(int index); + void onGroupBoxContextMenuRequested(const QPoint &pos); + void onParameterLabelContextMenuRequested(const QPoint &pos); void onScaleComboBoxIndexChanged(int index); void onShaderPassMoveDownClicked(); void onShaderPassMoveUpClicked(); + void onShaderResetPass(int pass); + void onShaderResetAllPasses(); + void onShaderResetParameter(int parameter); void onShaderLoadPresetClicked(); void onShaderAddPassClicked(); void onShaderSavePresetAsClicked();