scantool配置界面禁用滚轮,增加滑块与spinbox关联
This commit is contained in:
parent
4b62a7bba0
commit
0db6f10642
|
@ -11,6 +11,7 @@
|
||||||
#include <QSpinBox>
|
#include <QSpinBox>
|
||||||
#include <QSpacerItem>
|
#include <QSpacerItem>
|
||||||
#include <QPushButton>
|
#include <QPushButton>
|
||||||
|
#include <QEvent>
|
||||||
|
|
||||||
Form_DeviceConfig::Form_DeviceConfig(SANE_Handle devHandle, const std::vector<DeviceConfig>& deviceConfigs, QWidget *parent)
|
Form_DeviceConfig::Form_DeviceConfig(SANE_Handle devHandle, const std::vector<DeviceConfig>& deviceConfigs, QWidget *parent)
|
||||||
: QWidget(parent)
|
: QWidget(parent)
|
||||||
|
@ -164,6 +165,19 @@ std::vector<DeviceConfig> Form_DeviceConfig::GetDeviceConfigs()
|
||||||
return deviceConfigs;
|
return deviceConfigs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Form_DeviceConfig::eventFilter(QObject *target, QEvent *event)
|
||||||
|
{
|
||||||
|
if (typeid(*target) == typeid(QSlider) || typeid(*target) == typeid(QComboBox) || typeid(*target) == typeid(QSpinBox))
|
||||||
|
{
|
||||||
|
if (event->type() == QEvent::Wheel)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return QWidget::eventFilter(target, event);
|
||||||
|
}
|
||||||
|
|
||||||
void Form_DeviceConfig::Init(SANE_Handle devHandle)
|
void Form_DeviceConfig::Init(SANE_Handle devHandle)
|
||||||
{
|
{
|
||||||
// 1.重置设备
|
// 1.重置设备
|
||||||
|
@ -347,6 +361,9 @@ void Form_DeviceConfig::Init(SANE_Handle devHandle)
|
||||||
|
|
||||||
// 创建控件
|
// 创建控件
|
||||||
QWidget *ctrl = nullptr;
|
QWidget *ctrl = nullptr;
|
||||||
|
QWidget *extraCtrl = nullptr;
|
||||||
|
QWidget* sliderSpinWidget = new QWidget(scrollArea);
|
||||||
|
|
||||||
if (1 == deviceConfig.rangeType)
|
if (1 == deviceConfig.rangeType)
|
||||||
{
|
{
|
||||||
assert(1 == deviceConfig.valueType);
|
assert(1 == deviceConfig.valueType);
|
||||||
|
@ -354,6 +371,7 @@ void Form_DeviceConfig::Init(SANE_Handle devHandle)
|
||||||
for (int k = 0; k < (int)deviceConfig.stringValueList.size(); ++k)
|
for (int k = 0; k < (int)deviceConfig.stringValueList.size(); ++k)
|
||||||
comboBox->addItem(QString::fromStdString(deviceConfig.stringValueList[k]));
|
comboBox->addItem(QString::fromStdString(deviceConfig.stringValueList[k]));
|
||||||
//comboBox->setCurrentText(QString::fromStdString(deviceConfig.stringValue));
|
//comboBox->setCurrentText(QString::fromStdString(deviceConfig.stringValue));
|
||||||
|
comboBox->installEventFilter(this);
|
||||||
ctrl = comboBox;
|
ctrl = comboBox;
|
||||||
}
|
}
|
||||||
else if (2 == deviceConfig.rangeType)
|
else if (2 == deviceConfig.rangeType)
|
||||||
|
@ -363,6 +381,7 @@ void Form_DeviceConfig::Init(SANE_Handle devHandle)
|
||||||
for (int k = 0; k < (int)deviceConfig.intValueList.size(); ++k)
|
for (int k = 0; k < (int)deviceConfig.intValueList.size(); ++k)
|
||||||
comboBox->addItem(QString::number(deviceConfig.intValueList[k]));
|
comboBox->addItem(QString::number(deviceConfig.intValueList[k]));
|
||||||
//comboBox->setCurrentText(QString::number(deviceConfig.intValue));
|
//comboBox->setCurrentText(QString::number(deviceConfig.intValue));
|
||||||
|
comboBox->installEventFilter(this);
|
||||||
ctrl = comboBox;
|
ctrl = comboBox;
|
||||||
}
|
}
|
||||||
else if (3 == deviceConfig.rangeType)
|
else if (3 == deviceConfig.rangeType)
|
||||||
|
@ -372,6 +391,7 @@ void Form_DeviceConfig::Init(SANE_Handle devHandle)
|
||||||
for (int k = 0; k < (int)deviceConfig.doubleValueList.size(); ++k)
|
for (int k = 0; k < (int)deviceConfig.doubleValueList.size(); ++k)
|
||||||
comboBox->addItem(QString::number(deviceConfig.doubleValueList[k]));
|
comboBox->addItem(QString::number(deviceConfig.doubleValueList[k]));
|
||||||
//comboBox->setCurrentText(QString::number(deviceConfig.doubleValue));
|
//comboBox->setCurrentText(QString::number(deviceConfig.doubleValue));
|
||||||
|
comboBox->installEventFilter(this);
|
||||||
ctrl = comboBox;
|
ctrl = comboBox;
|
||||||
}
|
}
|
||||||
else if (4 == deviceConfig.rangeType)
|
else if (4 == deviceConfig.rangeType)
|
||||||
|
@ -381,7 +401,23 @@ void Form_DeviceConfig::Init(SANE_Handle devHandle)
|
||||||
slider->setOrientation(Qt::Horizontal);
|
slider->setOrientation(Qt::Horizontal);
|
||||||
slider->setRange(deviceConfig.intValueMin, deviceConfig.intValueMax);
|
slider->setRange(deviceConfig.intValueMin, deviceConfig.intValueMax);
|
||||||
//slider->setValue(deviceConfig.intValue);
|
//slider->setValue(deviceConfig.intValue);
|
||||||
|
slider->installEventFilter(this);
|
||||||
|
connect(slider, SIGNAL(valueChanged(int)), this, SLOT(on_sliderClicked(int)));
|
||||||
|
|
||||||
|
QSpinBox* spinBox = new QSpinBox;
|
||||||
|
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)));
|
||||||
|
|
||||||
ctrl = slider;
|
ctrl = slider;
|
||||||
|
extraCtrl = spinBox;
|
||||||
|
QHBoxLayout* hLayout = new QHBoxLayout;
|
||||||
|
hLayout->addWidget(ctrl);
|
||||||
|
hLayout->addWidget(extraCtrl);
|
||||||
|
sliderSpinWidget->setLayout(hLayout);
|
||||||
}
|
}
|
||||||
else if (5 == deviceConfig.rangeType)
|
else if (5 == deviceConfig.rangeType)
|
||||||
{
|
{
|
||||||
|
@ -390,7 +426,25 @@ void Form_DeviceConfig::Init(SANE_Handle devHandle)
|
||||||
slider->setOrientation(Qt::Horizontal);
|
slider->setOrientation(Qt::Horizontal);
|
||||||
slider->setRange(round(deviceConfig.doubleValueMin * 100), round(deviceConfig.doubleValueMax * 100));
|
slider->setRange(round(deviceConfig.doubleValueMin * 100), round(deviceConfig.doubleValueMax * 100));
|
||||||
//slider->setValue(round(deviceConfig.doubleValue * 100));
|
//slider->setValue(round(deviceConfig.doubleValue * 100));
|
||||||
|
slider->installEventFilter(this);
|
||||||
|
connect(slider, SIGNAL(valueChanged(int)), this, SLOT(on_sliderClicked(int)));
|
||||||
|
|
||||||
|
QDoubleSpinBox* doubleSpinBox = new QDoubleSpinBox;
|
||||||
|
doubleSpinBox->setMinimumWidth(75);
|
||||||
|
doubleSpinBox->setMaximumWidth(75);
|
||||||
|
doubleSpinBox->setRange(round(deviceConfig.doubleValueMin * 100), round(deviceConfig.doubleValueMax * 100));
|
||||||
|
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)));
|
||||||
|
|
||||||
ctrl = slider;
|
ctrl = slider;
|
||||||
|
extraCtrl = doubleSpinBox;
|
||||||
|
QHBoxLayout* hLayout = new QHBoxLayout;
|
||||||
|
hLayout->addWidget(ctrl);
|
||||||
|
hLayout->addWidget(extraCtrl);
|
||||||
|
sliderSpinWidget->setLayout(hLayout);
|
||||||
}
|
}
|
||||||
else if (0 == deviceConfig.rangeType)
|
else if (0 == deviceConfig.rangeType)
|
||||||
{
|
{
|
||||||
|
@ -401,13 +455,11 @@ void Form_DeviceConfig::Init(SANE_Handle devHandle)
|
||||||
else if (2 == deviceConfig.valueType)
|
else if (2 == deviceConfig.valueType)
|
||||||
{
|
{
|
||||||
QSpinBox* spinBox = new QSpinBox;
|
QSpinBox* spinBox = new QSpinBox;
|
||||||
#ifdef HG_CMP_MSC
|
|
||||||
spinBox->setMinimumWidth(75);
|
spinBox->setMinimumWidth(75);
|
||||||
#else
|
spinBox->setMaximumWidth(75);
|
||||||
spinBox->setMinimumWidth(150);
|
|
||||||
#endif
|
|
||||||
spinBox->setRange(-1, 1000);
|
spinBox->setRange(-1, 1000);
|
||||||
//spinBox->setValue(deviceConfig.intValue);
|
//spinBox->setValue(deviceConfig.intValue);
|
||||||
|
spinBox->installEventFilter(this);
|
||||||
ctrl = spinBox;
|
ctrl = spinBox;
|
||||||
}
|
}
|
||||||
else if (3 == deviceConfig.valueType)
|
else if (3 == deviceConfig.valueType)
|
||||||
|
@ -428,8 +480,15 @@ void Form_DeviceConfig::Init(SANE_Handle devHandle)
|
||||||
m_ctrlList.push_back(ctrl);
|
m_ctrlList.push_back(ctrl);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (nullptr != extraCtrl)
|
||||||
|
{
|
||||||
|
layout->addRow(label, sliderSpinWidget);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
layout->addRow(label, ctrl);
|
layout->addRow(label, ctrl);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
tabWidget->addTab(scrollArea, QString::fromStdString(m_baseDeviceConfigsGroups[i].groupTitle));
|
tabWidget->addTab(scrollArea, QString::fromStdString(m_baseDeviceConfigsGroups[i].groupTitle));
|
||||||
}
|
}
|
||||||
|
@ -515,3 +574,67 @@ void Form_DeviceConfig::on_defaultBtn_clicked()
|
||||||
{
|
{
|
||||||
Update(m_baseDeviceConfigsGroups);
|
Update(m_baseDeviceConfigsGroups);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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)
|
||||||
|
{
|
||||||
|
QString spinBoxProverty = abstractSpinBox->property("config_name").toString();
|
||||||
|
if (spinBoxProverty == sliderProverty)
|
||||||
|
{
|
||||||
|
if (typeid(*abstractSpinBox) == typeid(QSpinBox))
|
||||||
|
{
|
||||||
|
QSpinBox* spinBox = reinterpret_cast<QSpinBox*>(abstractSpinBox);
|
||||||
|
spinBox->setValue(value);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
QDoubleSpinBox* doubleSpinBox = reinterpret_cast<QDoubleSpinBox*>(abstractSpinBox);
|
||||||
|
double temp = value * doubleSpinBox->singleStep();
|
||||||
|
doubleSpinBox->setValue(temp);
|
||||||
|
}
|
||||||
|
|
||||||
|
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)
|
||||||
|
{
|
||||||
|
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)
|
||||||
|
{
|
||||||
|
int temp = value / spinBox->singleStep() + 0.5;
|
||||||
|
slider->setValue(temp);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -81,12 +81,18 @@ public:
|
||||||
std::vector<DeviceConfig> GetDeviceConfigs();
|
std::vector<DeviceConfig> GetDeviceConfigs();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
virtual bool eventFilter(QObject *target, QEvent *event) override;
|
||||||
|
|
||||||
void Init(SANE_Handle devHandle);
|
void Init(SANE_Handle devHandle);
|
||||||
void Update(std::vector<DeviceConfigsGroup> &deviceConfigsGroups);
|
void Update(std::vector<DeviceConfigsGroup> &deviceConfigsGroups);
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void on_defaultBtn_clicked();
|
void on_defaultBtn_clicked();
|
||||||
|
|
||||||
|
void on_sliderClicked(int value);
|
||||||
|
void on_spinBoxClicked(int value);
|
||||||
|
void on_doubleSpinboxClicked(double value);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::vector<DeviceConfigsGroup> m_baseDeviceConfigsGroups;
|
std::vector<DeviceConfigsGroup> m_baseDeviceConfigsGroups;
|
||||||
std::vector<QWidget*> m_ctrlList;
|
std::vector<QWidget*> m_ctrlList;
|
||||||
|
|
Loading…
Reference in New Issue