Qt: add filter/scale to shader window

This commit is contained in:
Brad Parker 2018-08-18 00:33:52 -04:00
parent b76f3abfbc
commit 16459bfa91
7 changed files with 674 additions and 340 deletions

View File

@ -503,8 +503,8 @@ bool video_shader_resolve_parameters(config_file_t *conf,
char *line = NULL;
const char *path = shader->pass[i].source.path;
if (string_is_empty(path))
continue;
if (string_is_empty(path))
continue;
#if defined(HAVE_SLANG) && defined(HAVE_SPIRV_CROSS)
/* First try to use the more robust slang
@ -529,6 +529,9 @@ bool video_shader_resolve_parameters(config_file_t *conf,
line = (char*)malloc(4096 * sizeof(char));
line[0] = '\0';
/* even though the pass is set in the loop too, not all passes have parameters */
param->pass = i;
while (shader->num_parameters < ARRAY_SIZE(shader->parameters)
&& intfstream_gets(file, line, line_size))
{

View File

@ -559,7 +559,7 @@ void MainWindow::onPlaylistWidgetContextMenuRequested(const QPoint&)
strlcpy(settings->arrays.playlist_cores,
new_playlist_cores, sizeof(settings->arrays.playlist_cores));
}
else if (selectedAction == deletePlaylistAction.data())
else if (selectedItem && selectedAction == deletePlaylistAction.data())
{
if (currentPlaylistFile.exists())
{
@ -583,7 +583,7 @@ void MainWindow::onPlaylistWidgetContextMenuRequested(const QPoint&)
reloadPlaylists();
}
else if (selectedAction == hideAction.data())
else if (selectedItem && selectedAction == hideAction.data())
{
int row = m_listWidget->row(selectedItem);

View File

@ -1,10 +1,46 @@
#include <QCloseEvent>
#include <QResizeEvent>
#include <QScrollArea>
#include <QVBoxLayout>
#include <QGroupBox>
#include <QFileInfo>
#include <QFormLayout>
#include <QSpinBox>
#include <QDoubleSpinBox>
#include <QCheckBox>
#include <QComboBox>
#include "shaderparamsdialog.h"
#include "../ui_qt.h"
extern "C" {
#include "../../../command.h"
#ifdef HAVE_MENU
#include "../../../menu/menu_shader.h"
#endif
}
ShaderParamsDialog::ShaderParamsDialog(QWidget *parent) :
QDialog(parent)
,m_layout(NULL)
{
QScrollArea *scrollArea = NULL;
QWidget *widget = NULL;
setWindowTitle(msg_hash_to_str(MENU_ENUM_LABEL_VALUE_SHADER_OPTIONS));
setObjectName("shaderParamsDialog");
m_layout = new QVBoxLayout();
widget = new QWidget();
widget->setLayout(m_layout);
widget->setObjectName("shaderParamsWidget");
scrollArea = new QScrollArea(this);
scrollArea->setWidgetResizable(true);
scrollArea->setWidget(widget);
scrollArea->setObjectName("shaderParamsScrollArea");
setProperty("scrollArea", QVariant::fromValue(scrollArea));
}
ShaderParamsDialog::~ShaderParamsDialog()
@ -13,9 +49,20 @@ ShaderParamsDialog::~ShaderParamsDialog()
void ShaderParamsDialog::resizeEvent(QResizeEvent *event)
{
QVariant scrollAreaVariant = property("scrollArea");
QScrollArea *scrollArea = NULL;
QDialog::resizeEvent(event);
emit resized(event->size());
if (!scrollAreaVariant.isValid())
return;
scrollArea = scrollAreaVariant.value<QScrollArea*>();
if (!scrollArea)
return;
scrollArea->resize(event->size());
}
void ShaderParamsDialog::closeEvent(QCloseEvent *event)
@ -25,3 +72,590 @@ void ShaderParamsDialog::closeEvent(QCloseEvent *event)
emit closed();
}
QString ShaderParamsDialog::getFilterLabel(unsigned filter)
{
QString filterString;
switch (filter)
{
case 0:
filterString = msg_hash_to_str(MENU_ENUM_LABEL_VALUE_DONT_CARE);
break;
case 1:
filterString = msg_hash_to_str(MENU_ENUM_LABEL_VALUE_LINEAR);
break;
case 2:
filterString = msg_hash_to_str(MENU_ENUM_LABEL_VALUE_NEAREST);
break;
default:
break;
}
return filterString;
}
void ShaderParamsDialog::clearLayout(QLayout *layout)
{
QLayoutItem *child = NULL;
while (layout->count() && ((child = layout->takeAt(0)) != 0))
{
QWidget *widget = child->widget();
QLayout *childLayout = child->layout();
if (widget)
{
QLayout *widgetLayout = widget->layout();
if (widgetLayout)
clearLayout(widgetLayout);
/* deleteLater() doesn't work right for some reason here,
* so just disconnect any signals in case there are pending events,
* and delete the widget immediately.
*/
widget->disconnect();
delete widget;
}
if (childLayout)
clearLayout(childLayout);
delete child;
}
}
void ShaderParamsDialog::getShaders(struct video_shader **menu_shader, struct video_shader **video_shader)
{
video_shader_ctx_t shader_info = {0};
#ifdef HAVE_MENU
struct video_shader *shader = menu_shader_get();
if (menu_shader)
{
if (shader)
{
*menu_shader = shader;
}
else
{
*menu_shader = NULL;
}
}
if (video_shader)
{
if (shader)
{
*video_shader = shader_info.data;
}
else
{
*video_shader = NULL;
}
}
#endif
if (video_shader)
{
if (!video_shader_driver_get_current_shader(&shader_info))
{
*video_shader = NULL;
return;
}
if (!shader_info.data || shader_info.data->num_parameters > GFX_MAX_PARAMETERS)
{
*video_shader = NULL;
return;
}
if (shader_info.data)
{
*video_shader = shader_info.data;
}
else
{
*video_shader = NULL;
}
}
}
void ShaderParamsDialog::onFilterComboBoxIndexChanged(int)
{
QComboBox *comboBox = qobject_cast<QComboBox*>(sender());
QVariant passVariant;
int pass = 0;
bool ok = false;
struct video_shader *menu_shader = NULL;
struct video_shader *video_shader = NULL;
getShaders(&menu_shader, &video_shader);
if (!comboBox)
return;
passVariant = comboBox->property("pass");
if (!passVariant.isValid())
return;
pass = passVariant.toInt(&ok);
if (!ok)
return;
if (menu_shader && pass >= 0 && pass < static_cast<int>(menu_shader->passes))
{
QVariant data = comboBox->currentData();
if (data.isValid())
{
unsigned filter = data.toUInt(&ok);
if (ok)
{
if (menu_shader)
menu_shader->pass[pass].filter = filter;
if (video_shader)
video_shader->pass[pass].filter = filter;
command_event(CMD_EVENT_SHADERS_APPLY_CHANGES, NULL);
}
}
}
}
void ShaderParamsDialog::onScaleComboBoxIndexChanged(int)
{
QComboBox *comboBox = qobject_cast<QComboBox*>(sender());
QVariant passVariant;
int pass = 0;
bool ok = false;
struct video_shader *menu_shader = NULL;
struct video_shader *video_shader = NULL;
getShaders(&menu_shader, &video_shader);
if (!comboBox)
return;
passVariant = comboBox->property("pass");
if (!passVariant.isValid())
return;
pass = passVariant.toInt(&ok);
if (!ok)
return;
if (menu_shader && pass >= 0 && pass < static_cast<int>(menu_shader->passes))
{
QVariant data = comboBox->currentData();
if (data.isValid())
{
unsigned scale = data.toUInt(&ok);
if (ok)
{
if (menu_shader)
{
menu_shader->pass[pass].fbo.scale_x = scale;
menu_shader->pass[pass].fbo.scale_y = scale;
menu_shader->pass[pass].fbo.valid = scale;
}
if (video_shader)
{
video_shader->pass[pass].fbo.scale_x = scale;
video_shader->pass[pass].fbo.scale_y = scale;
video_shader->pass[pass].fbo.valid = scale;
}
command_event(CMD_EVENT_SHADERS_APPLY_CHANGES, NULL);
}
}
}
}
void ShaderParamsDialog::reload()
{
struct video_shader *menu_shader = NULL;
struct video_shader *video_shader = NULL;
int i;
unsigned j;
getShaders(&menu_shader, &video_shader);
/* NOTE: For some reason, menu_shader_get() returns a COPY of what get_current_shader() gives us.
* And if you want to be able to change shader settings/parameters from both the raster menu and
* Qt at the same time... you must change BOTH or one will overwrite the other.
*/
if ((video_shader && video_shader->passes == 0) || !video_shader)
goto end;
clearLayout(m_layout);
/* NOTE: We assume that parameters are always grouped in order by the pass number, e.g., all parameters for pass 0 come first, then params for pass 1, etc. */
for (i = 0; i < static_cast<int>(video_shader->passes); i++)
{
QFormLayout *form = NULL;
QGroupBox *groupBox = NULL;
QFileInfo fileInfo(video_shader->pass[i].source.path);
QString shaderBasename = fileInfo.completeBaseName();
QHBoxLayout *filterScaleHBoxLayout = NULL;
QComboBox *filterComboBox = new QComboBox();
QComboBox *scaleComboBox = new QComboBox();
unsigned j = 0;
filterComboBox->setProperty("pass", i);
scaleComboBox->setProperty("pass", i);
for (;;)
{
QString filterLabel = getFilterLabel(j);
if (filterLabel.isEmpty())
break;
if (j == 0)
filterLabel = msg_hash_to_str(MENU_ENUM_LABEL_VALUE_DONT_CARE);
filterComboBox->addItem(filterLabel, j);
j++;
}
for (j = 0; j < 7; j++)
{
QString label;
if (j == 0)
label = msg_hash_to_str(MENU_ENUM_LABEL_VALUE_DONT_CARE);
else
label = QString::number(j) + "x";
scaleComboBox->addItem(label, j);
}
filterComboBox->setCurrentIndex(static_cast<int>(video_shader->pass[i].filter));
scaleComboBox->setCurrentIndex(static_cast<int>(video_shader->pass[i].fbo.scale_x));
/* connect the signals only after the initial index is set */
connect(filterComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(onFilterComboBoxIndexChanged(int)));
connect(scaleComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(onScaleComboBoxIndexChanged(int)));
form = new QFormLayout();
groupBox = new QGroupBox(shaderBasename);
groupBox->setLayout(form);
m_layout->addWidget(groupBox);
filterScaleHBoxLayout = new QHBoxLayout();
filterScaleHBoxLayout->addWidget(new QLabel(msg_hash_to_str(MENU_ENUM_LABEL_VALUE_FILTER)));
filterScaleHBoxLayout->addWidget(filterComboBox);
filterScaleHBoxLayout->addWidget(new QLabel(msg_hash_to_str(MENU_ENUM_LABEL_VALUE_SCALE)));
filterScaleHBoxLayout->addWidget(scaleComboBox);
form->addRow("", filterScaleHBoxLayout);
for (j = 0; j < video_shader->num_parameters; j++)
{
struct video_shader_parameter *param = &video_shader->parameters[j];
if (param->pass != i)
continue;
addShaderParam(param, j, form);
}
}
m_layout->addItem(new QSpacerItem(20, 20, QSizePolicy::Minimum, QSizePolicy::Expanding));
end:
resize(720, 480);
show();
}
void ShaderParamsDialog::addShaderParam(struct video_shader_parameter *param, int parameter, QFormLayout *form)
{
QString desc = param->desc;
if ((param->minimum == 0.0)
&& (param->maximum
== (param->minimum
+ param->step)))
{
/* option is basically a bool, so use a checkbox */
QCheckBox *checkBox = new QCheckBox(this);
checkBox->setChecked(param->current == param->maximum ? true : false);
checkBox->setProperty("pass", param->pass);
connect(checkBox, SIGNAL(clicked()), this, SLOT(onShaderParamCheckBoxClicked()));
form->addRow(desc, checkBox);
}
else
{
QDoubleSpinBox *doubleSpinBox = NULL;
QSpinBox *spinBox = NULL;
QHBoxLayout *box = new QHBoxLayout();
QSlider *slider = new QSlider(Qt::Horizontal, this);
double value = MainWindow::lerp(param->minimum, param->maximum, 0, 100, param->current);
double intpart = 0;
bool stepIsFractional = modf(param->step, &intpart);
slider->setRange(0, 100);
slider->setSingleStep(1);
slider->setValue(value);
slider->setProperty("param", parameter);
connect(slider, SIGNAL(valueChanged(int)), this, SLOT(onShaderParamSliderValueChanged(int)));
box->addWidget(slider);
if (stepIsFractional)
{
doubleSpinBox = new QDoubleSpinBox(this);
doubleSpinBox->setRange(param->minimum, param->maximum);
doubleSpinBox->setSingleStep(param->step);
doubleSpinBox->setValue(param->current);
doubleSpinBox->setProperty("slider", QVariant::fromValue(slider));
slider->setProperty("doubleSpinBox", QVariant::fromValue(doubleSpinBox));
connect(doubleSpinBox, SIGNAL(valueChanged(double)), this, SLOT(onShaderParamDoubleSpinBoxValueChanged(double)));
box->addWidget(doubleSpinBox);
}
else
{
spinBox = new QSpinBox(this);
spinBox->setRange(param->minimum, param->maximum);
spinBox->setSingleStep(param->step);
spinBox->setValue(param->current);
spinBox->setProperty("slider", QVariant::fromValue(slider));
slider->setProperty("spinBox", QVariant::fromValue(spinBox));
connect(spinBox, SIGNAL(valueChanged(int)), this, SLOT(onShaderParamSpinBoxValueChanged(int)));
box->addWidget(spinBox);
}
form->addRow(desc, box);
}
}
void ShaderParamsDialog::onShaderParamCheckBoxClicked()
{
QCheckBox *checkBox = qobject_cast<QCheckBox*>(sender());
QVariant paramVariant;
struct video_shader *menu_shader = NULL;
struct video_shader *video_shader = NULL;
getShaders(&menu_shader, &video_shader);
if (!checkBox)
return;
if (menu_shader && menu_shader->passes == 0)
return;
paramVariant = checkBox->property("parameter");
if (paramVariant.isValid())
{
bool ok = false;
int parameter = paramVariant.toInt(&ok);
if (!ok)
return;
if (menu_shader)
{
struct video_shader_parameter *param = NULL;
param = &menu_shader->parameters[parameter];
if (param)
param->current = (checkBox->isChecked() ? param->maximum : param->minimum);
}
if (video_shader)
{
struct video_shader_parameter *param = NULL;
param = &video_shader->parameters[parameter];
if (param)
param->current = (checkBox->isChecked() ? param->maximum : param->minimum);
}
}
}
void ShaderParamsDialog::onShaderParamSliderValueChanged(int)
{
QVariant spinBoxVariant;
QVariant paramVariant;
QSlider *slider = qobject_cast<QSlider*>(sender());
struct video_shader *menu_shader = NULL;
struct video_shader *video_shader = NULL;
double newValue = 0.0;
getShaders(&menu_shader, &video_shader);
if (!slider)
return;
spinBoxVariant = slider->property("spinBox");
paramVariant = slider->property("param");
if (paramVariant.isValid())
{
bool ok = false;
int parameter = paramVariant.toInt(&ok);
if (ok)
{
if (menu_shader)
{
struct video_shader_parameter *param = &menu_shader->parameters[parameter];
newValue = MainWindow::lerp(0, 100, param->minimum, param->maximum, slider->value());
param->current = newValue;
}
if (video_shader)
{
struct video_shader_parameter *param = &video_shader->parameters[parameter];
newValue = MainWindow::lerp(0, 100, param->minimum, param->maximum, slider->value());
param->current = newValue;
}
}
}
if (spinBoxVariant.isValid())
{
QSpinBox *spinBox = spinBoxVariant.value<QSpinBox*>();
if (!spinBox)
return;
spinBox->blockSignals(true);
spinBox->setValue(newValue);
spinBox->blockSignals(false);
}
else
{
QVariant doubleSpinBoxVariant = slider->property("doubleSpinBox");
QDoubleSpinBox *doubleSpinBox = doubleSpinBoxVariant.value<QDoubleSpinBox*>();
if (!doubleSpinBox)
return;
doubleSpinBox->blockSignals(true);
doubleSpinBox->setValue(newValue);
doubleSpinBox->blockSignals(false);
}
}
void ShaderParamsDialog::onShaderParamSpinBoxValueChanged(int value)
{
QSpinBox *spinBox = qobject_cast<QSpinBox*>(sender());
QVariant sliderVariant;
QVariant paramVariant;
QSlider *slider = NULL;
struct video_shader *menu_shader = NULL;
struct video_shader *video_shader = NULL;
double newValue = 0.0;
getShaders(&menu_shader, &video_shader);
if (!spinBox)
return;
sliderVariant = spinBox->property("slider");
if (!sliderVariant.isValid())
return;
slider = sliderVariant.value<QSlider*>();
if (!slider)
return;
paramVariant = slider->property("param");
if (paramVariant.isValid())
{
bool ok = false;
int parameter = paramVariant.toInt(&ok);
if (ok)
{
if (menu_shader)
{
struct video_shader_parameter *param = &menu_shader->parameters[parameter];
param->current = value;
newValue = MainWindow::lerp(param->minimum, param->maximum, 0, 100, param->current);
slider->blockSignals(true);
slider->setValue(newValue);
slider->blockSignals(false);
}
if (video_shader)
{
struct video_shader_parameter *param = &video_shader->parameters[parameter];
param->current = value;
newValue = MainWindow::lerp(param->minimum, param->maximum, 0, 100, param->current);
slider->blockSignals(true);
slider->setValue(newValue);
slider->blockSignals(false);
}
}
}
}
void ShaderParamsDialog::onShaderParamDoubleSpinBoxValueChanged(double value)
{
QDoubleSpinBox *doubleSpinBox = qobject_cast<QDoubleSpinBox*>(sender());
QVariant sliderVariant;
QVariant paramVariant;
QSlider *slider = NULL;
struct video_shader_parameter *param = NULL;
double newValue = 0.0;
if (!doubleSpinBox)
return;
sliderVariant = doubleSpinBox->property("slider");
if (!sliderVariant.isValid())
return;
slider = sliderVariant.value<QSlider*>();
if (!slider)
return;
paramVariant = slider->property("param");
if (paramVariant.isValid())
{
param = paramVariant.value<struct video_shader_parameter*>();
if (param)
{
param->current = value;
newValue = MainWindow::lerp(param->minimum, param->maximum, 0, 100, param->current);
slider->blockSignals(true);
slider->setValue(newValue);
slider->blockSignals(false);
}
}
}

View File

@ -5,6 +5,9 @@
class QCloseEvent;
class QResizeEvent;
class QVBoxLayout;
class QFormLayout;
class QLayout;
class ShaderParamsDialog : public QDialog
{
@ -15,6 +18,22 @@ public:
signals:
void closed();
void resized(QSize size);
public slots:
void reload();
private slots:
void onShaderParamCheckBoxClicked();
void onShaderParamSliderValueChanged(int value);
void onShaderParamSpinBoxValueChanged(int value);
void onShaderParamDoubleSpinBoxValueChanged(double value);
void onFilterComboBoxIndexChanged(int index);
void onScaleComboBoxIndexChanged(int index);
private:
QString getFilterLabel(unsigned filter);
void addShaderParam(struct video_shader_parameter *param, int parameter, QFormLayout *form);
void clearLayout(QLayout *layout);
void getShaders(struct video_shader **menu_shader, struct video_shader **video_shader);
QVBoxLayout *m_layout;
protected:
void closeEvent(QCloseEvent *event);
void resizeEvent(QResizeEvent *event);

View File

@ -314,7 +314,7 @@ MainWindow::MainWindow(QWidget *parent) :
,m_allPlaylistsGridMaxCount(0)
,m_playlistEntryDialog(NULL)
,m_statusMessageElapsedTimer()
,m_shaderParamsDialog()
,m_shaderParamsDialog(new ShaderParamsDialog())
,m_networkManager(new QNetworkAccessManager(this))
,m_updateProgressDialog(new QProgressDialog())
,m_updateFile()
@ -585,312 +585,6 @@ double MainWindow::lerp(double x, double y, double a, double b, double d) {
return a + (b - a) * ((double)(d - x) / (double)(y - x));
}
void MainWindow::onShaderParamsDialogResized(QSize size)
{
QVariant scrollAreaVariant = m_shaderParamsDialog->property("scrollArea");
QScrollArea *scrollArea = NULL;
if (!scrollAreaVariant.isValid())
return;
scrollArea = scrollAreaVariant.value<QScrollArea*>();
if (!scrollArea)
return;
scrollArea->resize(size);
}
void MainWindow::onShaderParamsClicked()
{
video_shader_ctx_t shader_info = {0};
unsigned i;
int last_pass = -1;
QFormLayout *last_form = NULL;
QGroupBox *last_group = NULL;
QScrollArea *scrollArea = NULL;
QWidget *widget = NULL;
QVBoxLayout *layout = NULL;
if (!video_shader_driver_get_current_shader(&shader_info))
return;
if (!shader_info.data || shader_info.data->num_parameters > GFX_MAX_PARAMETERS)
return;
/* shader might have changed, so re-create the entire window */
if (m_shaderParamsDialog)
delete m_shaderParamsDialog;
m_shaderParamsDialog = new ShaderParamsDialog();
m_shaderParamsDialog->setWindowTitle(msg_hash_to_str(MENU_ENUM_LABEL_VALUE_VIDEO_SHADER_PARAMETERS));
m_shaderParamsDialog->setObjectName("shaderParamsDialog");
layout = new QVBoxLayout();
widget = new QWidget();
widget->setLayout(layout);
widget->setObjectName("shaderParamsWidget");
scrollArea = new QScrollArea(m_shaderParamsDialog);
scrollArea->setWidgetResizable(true);
scrollArea->setWidget(widget);
scrollArea->setObjectName("shaderParamsScrollArea");
m_shaderParamsDialog->setProperty("scrollArea", QVariant::fromValue(scrollArea));
connect(m_shaderParamsDialog, SIGNAL(closed()), m_shaderParamsDialog, SLOT(deleteLater()));
connect(m_shaderParamsDialog, SIGNAL(resized(QSize)), this, SLOT(onShaderParamsDialogResized(QSize)));
if (shader_info.data->num_parameters == 0)
{
QLabel *label = new QLabel(msg_hash_to_str(MENU_ENUM_LABEL_VALUE_NO_SHADER_PARAMETERS), m_shaderParamsDialog);
label->setAlignment(Qt::AlignCenter);
layout->addWidget(label);
}
else
{
/* NOTE: We assume that parameters are always grouped in order by the pass number, e.g., all parameters for pass 0 come first, then params for pass 1, etc. */
for (i = 0; i < shader_info.data->num_parameters; i++)
{
struct video_shader_parameter *param = &shader_info.data->parameters[i];
QString desc = param->desc;
QFormLayout *form = last_form;
if (param->pass > last_pass)
{
QGroupBox *groupBox = NULL;
QFileInfo fileInfo(shader_info.data->pass[param->pass].source.path);
QString shaderBasename = fileInfo.completeBaseName();
form = new QFormLayout();
groupBox = new QGroupBox(shaderBasename);
groupBox->setLayout(form);
layout->addWidget(groupBox);
last_form = form;
last_pass = param->pass;
}
if ((param->minimum == 0.0)
&& (param->maximum
== (param->minimum
+ param->step)))
{
/* option is basically a bool, so use a checkbox */
QCheckBox *checkBox = new QCheckBox(m_shaderParamsDialog);
checkBox->setChecked(param->current == param->maximum ? true : false);
checkBox->setProperty("param", QVariant::fromValue(param));
connect(checkBox, SIGNAL(clicked()), this, SLOT(onShaderParamCheckBoxClicked()));
form->addRow(desc, checkBox);
}
else
{
QDoubleSpinBox *doubleSpinBox = NULL;
QSpinBox *spinBox = NULL;
QHBoxLayout *box = new QHBoxLayout();
QSlider *slider = new QSlider(Qt::Horizontal, m_shaderParamsDialog);
double value = lerp(param->minimum, param->maximum, 0, 100, param->current);
double intpart = 0;
bool stepIsFractional = modf(param->step, &intpart);
slider->setRange(0, 100);
slider->setSingleStep(1);
slider->setValue(value);
slider->setProperty("param", QVariant::fromValue(param));
connect(slider, SIGNAL(valueChanged(int)), this, SLOT(onShaderParamSliderValueChanged(int)));
box->addWidget(slider);
if (stepIsFractional)
{
doubleSpinBox = new QDoubleSpinBox(m_shaderParamsDialog);
doubleSpinBox->setRange(param->minimum, param->maximum);
doubleSpinBox->setSingleStep(param->step);
doubleSpinBox->setValue(param->current);
doubleSpinBox->setProperty("slider", QVariant::fromValue(slider));
slider->setProperty("doubleSpinBox", QVariant::fromValue(doubleSpinBox));
connect(doubleSpinBox, SIGNAL(valueChanged(double)), this, SLOT(onShaderParamDoubleSpinBoxValueChanged(double)));
box->addWidget(doubleSpinBox);
}
else
{
spinBox = new QSpinBox(m_shaderParamsDialog);
spinBox->setRange(param->minimum, param->maximum);
spinBox->setSingleStep(param->step);
spinBox->setValue(param->current);
spinBox->setProperty("slider", QVariant::fromValue(slider));
slider->setProperty("spinBox", QVariant::fromValue(spinBox));
connect(spinBox, SIGNAL(valueChanged(int)), this, SLOT(onShaderParamSpinBoxValueChanged(int)));
box->addWidget(spinBox);
}
form->addRow(desc, box);
}
}
layout->addItem(new QSpacerItem(20, 20, QSizePolicy::Minimum, QSizePolicy::Expanding));
}
m_shaderParamsDialog->resize(720, 480);
m_shaderParamsDialog->show();
}
void MainWindow::onShaderParamCheckBoxClicked()
{
QCheckBox *checkBox = qobject_cast<QCheckBox*>(sender());
QVariant paramVariant;
struct video_shader_parameter *param = NULL;
if (!checkBox)
return;
paramVariant = checkBox->property("param");
if (paramVariant.isValid())
{
param = paramVariant.value<struct video_shader_parameter*>();
if (param)
param->current = (checkBox->isChecked() ? param->maximum : param->minimum);
}
}
void MainWindow::onShaderParamSliderValueChanged(int value)
{
QVariant spinBoxVariant;
QVariant paramVariant;
QSlider *slider = qobject_cast<QSlider*>(sender());
struct video_shader_parameter *param = NULL;
double newValue = 0.0;
if (!slider)
return;
spinBoxVariant = slider->property("spinBox");
paramVariant = slider->property("param");
if (paramVariant.isValid())
{
param = paramVariant.value<struct video_shader_parameter*>();
if (param)
{
newValue = lerp(0, 100, param->minimum, param->maximum, slider->value());
param->current = newValue;
}
}
if (spinBoxVariant.isValid())
{
QSpinBox *spinBox = spinBoxVariant.value<QSpinBox*>();
if (!spinBox)
return;
spinBox->blockSignals(true);
spinBox->setValue(newValue);
spinBox->blockSignals(false);
}
else
{
QVariant doubleSpinBoxVariant = slider->property("doubleSpinBox");
QDoubleSpinBox *doubleSpinBox = doubleSpinBoxVariant.value<QDoubleSpinBox*>();
if (!doubleSpinBox)
return;
doubleSpinBox->blockSignals(true);
doubleSpinBox->setValue(newValue);
doubleSpinBox->blockSignals(false);
}
}
void MainWindow::onShaderParamSpinBoxValueChanged(int value)
{
QSpinBox *spinBox = qobject_cast<QSpinBox*>(sender());
QVariant sliderVariant;
QVariant paramVariant;
QSlider *slider = NULL;
struct video_shader_parameter *param = NULL;
double newValue = 0.0;
if (!spinBox)
return;
sliderVariant = spinBox->property("slider");
if (!sliderVariant.isValid())
return;
slider = sliderVariant.value<QSlider*>();
if (!slider)
return;
paramVariant = slider->property("param");
if (paramVariant.isValid())
{
param = paramVariant.value<struct video_shader_parameter*>();
if (param)
{
param->current = value;
newValue = lerp(param->minimum, param->maximum, 0, 100, param->current);
slider->blockSignals(true);
slider->setValue(newValue);
slider->blockSignals(false);
}
}
}
void MainWindow::onShaderParamDoubleSpinBoxValueChanged(double value)
{
QDoubleSpinBox *doubleSpinBox = qobject_cast<QDoubleSpinBox*>(sender());
QVariant sliderVariant;
QVariant paramVariant;
QSlider *slider = NULL;
struct video_shader_parameter *param = NULL;
double newValue = 0.0;
if (!doubleSpinBox)
return;
sliderVariant = doubleSpinBox->property("slider");
if (!sliderVariant.isValid())
return;
slider = sliderVariant.value<QSlider*>();
if (!slider)
return;
paramVariant = slider->property("param");
if (paramVariant.isValid())
{
param = paramVariant.value<struct video_shader_parameter*>();
if (param)
{
param->current = value;
newValue = lerp(param->minimum, param->maximum, 0, 100, param->current);
slider->blockSignals(true);
slider->setValue(newValue);
slider->blockSignals(false);
}
}
}
void MainWindow::onGridItemClicked(ThumbnailWidget *widget)
{
QHash<QString, QString> hash;
@ -1225,10 +919,20 @@ void MainWindow::deferReloadShaderParams()
emit gotReloadShaderParams();
}
void MainWindow::onShaderParamsClicked()
{
if (!m_shaderParamsDialog)
return;
m_shaderParamsDialog->show();
onGotReloadShaderParams();
}
void MainWindow::onGotReloadShaderParams()
{
if (m_shaderParamsDialog && m_shaderParamsDialog->isVisible())
onShaderParamsClicked();
m_shaderParamsDialog->reload();
}
void MainWindow::appendLogMessage(const QString &msg)
@ -1736,7 +1440,6 @@ void MainWindow::onTableWidgetDeletePressed()
QHash<QString, QString> MainWindow::getCurrentContentHash()
{
QTableWidgetItem *contentItem = m_tableWidget->currentItem();
QListWidgetItem *playlistItem = m_listWidget->currentItem();
QHash<QString, QString> contentHash;
ViewType viewType = getCurrentViewType();

View File

@ -324,7 +324,7 @@ static void* ui_companion_qt_init(void)
QObject::connect(viewClosedDocksMenu, SIGNAL(aboutToShow()), mainwindow, SLOT(onViewClosedDocksAboutToShow()));
viewMenu->addAction(msg_hash_to_str(MENU_ENUM_LABEL_VALUE_QT_MENU_VIEW_SHADER_PARAMS), mainwindow, SLOT(onShaderParamsClicked()));
viewMenu->addAction(msg_hash_to_str(MENU_ENUM_LABEL_VALUE_SHADER_OPTIONS), mainwindow, SLOT(onShaderParamsClicked()));
viewMenu->addSeparator();
viewMenu->addAction(msg_hash_to_str(MENU_ENUM_LABEL_VALUE_QT_VIEW_TYPE_ICONS), mainwindow, SLOT(onIconViewClicked()));
@ -634,26 +634,6 @@ static void ui_companion_qt_event_command(void *data, enum event_command cmd)
switch (cmd)
{
case CMD_EVENT_SHADERS_APPLY_CHANGES:
{
/* If shader was turned off, reload the params window manually because PRESET_LOADED won't be fired */
video_shader_ctx_t shader_info = {0};
if (!video_shader_driver_get_current_shader(&shader_info))
break;
/* Isn't there a better way to do this? */
if (shader_info.data && shader_info.data->num_parameters == 0)
{
if (shader_info.data->passes == 1 && string_is_empty(shader_info.data->pass[0].source.path))
{
RARCH_LOG("[Qt]: Clearing shader parameters.\n");
win_handle->qtWindow->deferReloadShaderParams();
}
}
/* Otherwise, PRESET_LOADED fires in more situations than APPLY_CHANGES, so use that for reloading the params window */
break;
}
case CMD_EVENT_SHADER_PRESET_LOADED:
RARCH_LOG("[Qt]: Reloading shader parameters.\n");
win_handle->qtWindow->deferReloadShaderParams();

View File

@ -368,11 +368,6 @@ private slots:
void onShowErrorMessage(QString msg);
void onShowInfoMessage(QString msg);
void onContributorsClicked();
void onShaderParamCheckBoxClicked();
void onShaderParamSliderValueChanged(int value);
void onShaderParamSpinBoxValueChanged(int value);
void onShaderParamDoubleSpinBoxValueChanged(double value);
void onShaderParamsDialogResized(QSize size);
int onExtractArchive(QString path);
private: