This commit is contained in:
luoliangyi 2024-04-28 11:46:44 +08:00
parent e659e3c2c6
commit f42d57228a
1 changed files with 23 additions and 56 deletions

View File

@ -371,7 +371,6 @@ void Form_DeviceConfig::Init(SANE_Handle devHandle)
QComboBox *comboBox = new QComboBox;
for (int k = 0; k < (int)deviceConfig.stringValueList.size(); ++k)
comboBox->addItem(QString::fromStdString(deviceConfig.stringValueList[k]));
//comboBox->setCurrentText(QString::fromStdString(deviceConfig.stringValue));
comboBox->installEventFilter(this);
ctrl = comboBox;
ctrlWidget = comboBox;
@ -382,7 +381,6 @@ void Form_DeviceConfig::Init(SANE_Handle devHandle)
QComboBox *comboBox = new QComboBox;
for (int k = 0; k < (int)deviceConfig.intValueList.size(); ++k)
comboBox->addItem(QString::number(deviceConfig.intValueList[k]));
//comboBox->setCurrentText(QString::number(deviceConfig.intValue));
comboBox->installEventFilter(this);
ctrl = comboBox;
ctrlWidget = comboBox;
@ -393,7 +391,6 @@ void Form_DeviceConfig::Init(SANE_Handle devHandle)
QComboBox *comboBox = new QComboBox;
for (int k = 0; k < (int)deviceConfig.doubleValueList.size(); ++k)
comboBox->addItem(QString::number(deviceConfig.doubleValueList[k]));
//comboBox->setCurrentText(QString::number(deviceConfig.doubleValue));
comboBox->installEventFilter(this);
ctrl = comboBox;
ctrlWidget = comboBox;
@ -404,7 +401,6 @@ void Form_DeviceConfig::Init(SANE_Handle devHandle)
QSlider *slider = new QSlider;
slider->setOrientation(Qt::Horizontal);
slider->setRange(deviceConfig.intValueMin, deviceConfig.intValueMax);
//slider->setValue(deviceConfig.intValue);
slider->installEventFilter(this);
connect(slider, SIGNAL(valueChanged(int)), this, SLOT(on_sliderClicked(int)));
@ -412,13 +408,15 @@ void Form_DeviceConfig::Init(SANE_Handle devHandle)
spinBox->setMinimumWidth(75);
spinBox->setMaximumWidth(75);
spinBox->setRange(deviceConfig.intValueMin, deviceConfig.intValueMax);
spinBox->setProperty("config_name", QString::fromStdString(deviceConfig.name));
spinBox->installEventFilter(this);
connect(spinBox, SIGNAL(valueChanged(int)), this, SLOT(on_spinBoxClicked(int)));
slider->setProperty("relate_ctrl", QVariant::fromValue(spinBox));
spinBox->setProperty("relate_ctrl", QVariant::fromValue(slider));
ctrl = slider;
QHBoxLayout* hLayout = new QHBoxLayout;
hLayout->addWidget(ctrl);
hLayout->addWidget(slider);
hLayout->addWidget(spinBox);
QWidget* sliderSpinWidget = new QWidget;
sliderSpinWidget->setLayout(hLayout);
@ -430,7 +428,6 @@ void Form_DeviceConfig::Init(SANE_Handle devHandle)
QSlider *slider = new QSlider;
slider->setOrientation(Qt::Horizontal);
slider->setRange(round(deviceConfig.doubleValueMin * 100), round(deviceConfig.doubleValueMax * 100));
//slider->setValue(round(deviceConfig.doubleValue * 100));
slider->installEventFilter(this);
connect(slider, SIGNAL(valueChanged(int)), this, SLOT(on_sliderClicked(int)));
@ -440,13 +437,15 @@ void Form_DeviceConfig::Init(SANE_Handle devHandle)
doubleSpinBox->setRange(deviceConfig.doubleValueMin, deviceConfig.doubleValueMax);
doubleSpinBox->setDecimals(2);
doubleSpinBox->setSingleStep(0.01);
doubleSpinBox->setProperty("config_name", QString::fromStdString(deviceConfig.name));
doubleSpinBox->installEventFilter(this);
connect(doubleSpinBox, SIGNAL(valueChanged(double)), this, SLOT(on_doubleSpinboxClicked(double)));
slider->setProperty("relate_ctrl", QVariant::fromValue(doubleSpinBox));
doubleSpinBox->setProperty("relate_ctrl", QVariant::fromValue(slider));
ctrl = slider;
QHBoxLayout* hLayout = new QHBoxLayout;
hLayout->addWidget(ctrl);
hLayout->addWidget(slider);
hLayout->addWidget(doubleSpinBox);
QWidget* sliderSpinWidget = new QWidget;
sliderSpinWidget->setLayout(hLayout);
@ -464,7 +463,6 @@ void Form_DeviceConfig::Init(SANE_Handle devHandle)
spinBox->setMinimumWidth(75);
spinBox->setMaximumWidth(75);
spinBox->setRange(-1, 1000);
//spinBox->setValue(deviceConfig.intValue);
spinBox->installEventFilter(this);
ctrl = spinBox;
ctrlWidget = spinBox;
@ -476,7 +474,6 @@ void Form_DeviceConfig::Init(SANE_Handle devHandle)
else if (4 == deviceConfig.valueType)
{
QCheckBox *checkBox = new QCheckBox;
//checkBox->setChecked(deviceConfig.boolValue);
ctrl = checkBox;
ctrlWidget = checkBox;
}
@ -582,60 +579,30 @@ void Form_DeviceConfig::on_defaultBtn_clicked()
void Form_DeviceConfig::on_sliderClicked(int value)
{
QSlider *slider = qobject_cast<QSlider*>(sender());
QString sliderProverty = slider->property("config_name").toString();
QList<QAbstractSpinBox*> buttons = this->findChildren<QAbstractSpinBox*>();
foreach (QAbstractSpinBox* abstractSpinBox, buttons)
QWidget* ctrl = qvariant_cast<QWidget*>(slider->property("relate_ctrl"));
if (typeid(*ctrl) == typeid(QSpinBox))
{
QString spinBoxProverty = abstractSpinBox->property("config_name").toString();
if (spinBoxProverty == sliderProverty)
{
if (typeid(*abstractSpinBox) == typeid(QSpinBox))
{
QSpinBox* spinBox = reinterpret_cast<QSpinBox*>(abstractSpinBox);
QSpinBox* spinBox = reinterpret_cast<QSpinBox*>(ctrl);
spinBox->setValue(value);
}
else
{
QDoubleSpinBox* doubleSpinBox = reinterpret_cast<QDoubleSpinBox*>(abstractSpinBox);
assert(typeid(*ctrl) == typeid(QDoubleSpinBox));
QDoubleSpinBox* doubleSpinBox = reinterpret_cast<QDoubleSpinBox*>(ctrl);
doubleSpinBox->setValue(value / 100.0);
}
break;
}
}
}
void Form_DeviceConfig::on_spinBoxClicked(int value)
{
QSpinBox* spinBox = qobject_cast<QSpinBox*>(sender());
QString spinBoxProverty = spinBox->property("config_name").toString();
QList<QSlider*> buttons = this->findChildren<QSlider*>();
foreach (QSlider* slider, buttons)
{
QString sliderProverty = slider->property("config_name").toString();
if (sliderProverty == spinBoxProverty)
{
QSlider* slider = qvariant_cast<QSlider*>(spinBox->property("relate_ctrl"));
slider->setValue(value);
break;
}
}
}
void Form_DeviceConfig::on_doubleSpinboxClicked(double value)
{
QDoubleSpinBox* spinBox = qobject_cast<QDoubleSpinBox*>(sender());
QString spinBoxProverty = spinBox->property("config_name").toString();
QList<QSlider*> buttons = this->findChildren<QSlider*>();
foreach (QSlider* slider, buttons)
{
QString sliderProverty = slider->property("config_name").toString();
if (sliderProverty == spinBoxProverty)
{
QDoubleSpinBox* doubleSpinBox = qobject_cast<QDoubleSpinBox*>(sender());
QSlider* slider = qvariant_cast<QSlider*>(doubleSpinBox->property("relate_ctrl"));
slider->setValue(round(value * 100));
break;
}
}
}