2024-04-24 03:57:56 +00:00
|
|
|
#include "form_deviceconfig.h"
|
2024-04-25 08:06:21 +00:00
|
|
|
#include <QTabWidget>
|
|
|
|
#include <QScrollArea>
|
|
|
|
#include <QFormLayout>
|
|
|
|
#include <QHBoxLayout>
|
|
|
|
#include <QVBoxLayout>
|
|
|
|
#include <QLabel>
|
|
|
|
#include <QComboBox>
|
|
|
|
#include <QSlider>
|
|
|
|
#include <QCheckBox>
|
|
|
|
#include <QSpinBox>
|
|
|
|
#include <QSpacerItem>
|
|
|
|
#include <QPushButton>
|
2024-04-26 06:11:33 +00:00
|
|
|
#include <QEvent>
|
2024-04-28 10:15:51 +00:00
|
|
|
#include <QMessageBox>
|
2024-04-24 03:57:56 +00:00
|
|
|
|
2024-04-25 03:06:28 +00:00
|
|
|
Form_DeviceConfig::Form_DeviceConfig(SANE_Handle devHandle, const std::vector<DeviceConfig>& deviceConfigs, QWidget *parent)
|
2024-04-24 03:57:56 +00:00
|
|
|
: QWidget(parent)
|
2024-04-28 10:15:51 +00:00
|
|
|
, m_devHandle(devHandle)
|
2024-05-05 03:29:13 +00:00
|
|
|
, m_defButtonId(-1)
|
2024-04-24 03:57:56 +00:00
|
|
|
{
|
2024-04-29 09:29:39 +00:00
|
|
|
Init(deviceConfigs);
|
2024-04-24 03:57:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Form_DeviceConfig::~Form_DeviceConfig()
|
|
|
|
{
|
2024-04-25 01:54:44 +00:00
|
|
|
|
2024-04-24 03:57:56 +00:00
|
|
|
}
|
|
|
|
|
2024-04-25 03:06:28 +00:00
|
|
|
std::vector<DeviceConfig> Form_DeviceConfig::GetDeviceConfigs()
|
2024-04-24 03:57:56 +00:00
|
|
|
{
|
2024-04-25 03:06:28 +00:00
|
|
|
std::vector<DeviceConfig> deviceConfigs;
|
2024-04-24 03:57:56 +00:00
|
|
|
|
2024-04-29 09:29:39 +00:00
|
|
|
for (int i = 0; i < (int)m_deviceConfigsGroups.size(); ++i)
|
2024-04-25 08:06:21 +00:00
|
|
|
{
|
2024-04-29 09:29:39 +00:00
|
|
|
for (int j = 0; j < (int)m_deviceConfigsGroups[i].deviceConfigs.size(); ++j)
|
2024-04-25 08:06:21 +00:00
|
|
|
{
|
2024-04-29 09:29:39 +00:00
|
|
|
const DeviceConfigEx &deviceConfigEx = m_deviceConfigsGroups[i].deviceConfigs[j];
|
2024-04-25 08:06:21 +00:00
|
|
|
|
2024-05-05 03:29:13 +00:00
|
|
|
DeviceConfig deviceConfig;
|
|
|
|
deviceConfig.name = deviceConfigEx.name;
|
|
|
|
deviceConfig.valueType = deviceConfigEx.valueType;
|
2024-04-25 08:06:21 +00:00
|
|
|
|
2024-05-05 03:29:13 +00:00
|
|
|
if (1 == deviceConfigEx.valueType && deviceConfigEx.stringValue != deviceConfigEx.defStringValue)
|
2024-04-25 08:06:21 +00:00
|
|
|
{
|
2024-04-29 09:29:39 +00:00
|
|
|
deviceConfig.stringValue = deviceConfigEx.stringValue;
|
2024-05-05 03:29:13 +00:00
|
|
|
deviceConfigs.push_back(deviceConfig);
|
|
|
|
}
|
|
|
|
else if (2 == deviceConfigEx.valueType && deviceConfigEx.intValue != deviceConfigEx.defIntValue)
|
|
|
|
{
|
2024-04-29 09:29:39 +00:00
|
|
|
deviceConfig.intValue = deviceConfigEx.intValue;
|
2024-05-05 03:29:13 +00:00
|
|
|
deviceConfigs.push_back(deviceConfig);
|
|
|
|
}
|
|
|
|
else if (3 == deviceConfigEx.valueType && deviceConfigEx.doubleValue != deviceConfigEx.defDoubleValue)
|
|
|
|
{
|
2024-04-29 09:29:39 +00:00
|
|
|
deviceConfig.doubleValue = deviceConfigEx.doubleValue;
|
2024-05-05 03:29:13 +00:00
|
|
|
deviceConfigs.push_back(deviceConfig);
|
|
|
|
}
|
|
|
|
else if (4 == deviceConfigEx.valueType && deviceConfigEx.boolValue != deviceConfigEx.defBoolValue)
|
|
|
|
{
|
2024-04-29 09:29:39 +00:00
|
|
|
deviceConfig.boolValue = deviceConfigEx.boolValue;
|
|
|
|
deviceConfigs.push_back(deviceConfig);
|
2024-04-25 08:06:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2024-04-24 03:57:56 +00:00
|
|
|
|
2024-04-25 03:06:28 +00:00
|
|
|
return deviceConfigs;
|
2024-04-24 03:57:56 +00:00
|
|
|
}
|
2024-04-24 10:08:14 +00:00
|
|
|
|
2024-04-29 09:29:39 +00:00
|
|
|
void Form_DeviceConfig::Init(const std::vector<DeviceConfig>& deviceConfigs)
|
2024-04-26 06:11:33 +00:00
|
|
|
{
|
2024-05-05 03:29:13 +00:00
|
|
|
// 1.获取默认ID
|
|
|
|
m_defButtonId = -1;
|
2024-04-25 03:06:28 +00:00
|
|
|
SANE_Int num_dev_options = 0;
|
2024-04-28 10:15:51 +00:00
|
|
|
sane_control_option(m_devHandle, 0, SANE_ACTION_GET_VALUE, &num_dev_options, NULL);
|
2024-04-25 03:06:28 +00:00
|
|
|
for (int i = 1; i < num_dev_options; ++i)
|
|
|
|
{
|
2024-04-28 10:15:51 +00:00
|
|
|
const SANE_Option_Descriptor* desp = sane_get_option_descriptor(m_devHandle, i);
|
2024-04-25 03:06:28 +00:00
|
|
|
if (NULL == desp)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
const char* name = desp->name;
|
|
|
|
while (' ' == *name)
|
|
|
|
++name;
|
|
|
|
|
|
|
|
if (0 == strcmp(SANE_STD_OPT_NAME_RESTORE, name) && SANE_TYPE_BUTTON == desp->type)
|
|
|
|
{
|
2024-05-05 03:29:13 +00:00
|
|
|
m_defButtonId = i;
|
2024-04-25 03:06:28 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-05-05 03:29:13 +00:00
|
|
|
// 2.恢复默认
|
|
|
|
assert(-1 != m_defButtonId);
|
|
|
|
sane_control_option(m_devHandle, m_defButtonId, SANE_ACTION_SET_VALUE, NULL, NULL);
|
2024-04-29 09:29:39 +00:00
|
|
|
|
2024-05-05 03:29:13 +00:00
|
|
|
// 3.更新当前配置信息
|
2024-04-29 09:29:39 +00:00
|
|
|
m_deviceConfigsGroups.clear();
|
2024-04-25 03:06:28 +00:00
|
|
|
for (int i = 1; i < num_dev_options; ++i)
|
|
|
|
{
|
2024-04-28 10:15:51 +00:00
|
|
|
const SANE_Option_Descriptor* desp = sane_get_option_descriptor(m_devHandle, i);
|
2024-04-25 03:06:28 +00:00
|
|
|
if (NULL == desp)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
const char* name = desp->name;
|
|
|
|
while (' ' == *name)
|
|
|
|
++name;
|
|
|
|
|
2024-04-29 10:02:18 +00:00
|
|
|
if (0 == strcmp(SANE_STD_OPT_NAME_IS_CUSTOM_GAMMA, name))
|
|
|
|
continue;
|
|
|
|
|
2024-04-25 03:06:28 +00:00
|
|
|
const char* title = desp->title;
|
|
|
|
while (' ' == *title)
|
|
|
|
++title;
|
|
|
|
|
|
|
|
if (SANE_TYPE_GROUP == desp->type)
|
|
|
|
{
|
|
|
|
DeviceConfigsGroup group;
|
|
|
|
group.groupTitle = title;
|
2024-04-29 09:29:39 +00:00
|
|
|
m_deviceConfigsGroups.push_back(group);
|
2024-04-25 03:06:28 +00:00
|
|
|
}
|
|
|
|
else if (SANE_TYPE_STRING == desp->type)
|
|
|
|
{
|
|
|
|
char value[256] = { 0 };
|
2024-04-28 10:15:51 +00:00
|
|
|
sane_control_option(m_devHandle, i, SANE_ACTION_GET_VALUE, value, NULL);
|
2024-04-25 03:06:28 +00:00
|
|
|
|
2024-04-29 09:29:39 +00:00
|
|
|
DeviceConfigEx devConfigEx;
|
|
|
|
devConfigEx.id = i;
|
|
|
|
devConfigEx.name = name;
|
|
|
|
devConfigEx.title = title;
|
|
|
|
devConfigEx.valueType = 1;
|
|
|
|
devConfigEx.stringValue = value;
|
2024-05-05 03:29:13 +00:00
|
|
|
devConfigEx.defStringValue = value;
|
2024-04-30 02:39:08 +00:00
|
|
|
devConfigEx.hide = ((desp->cap & SANE_CAP_INACTIVE) == SANE_CAP_INACTIVE);
|
2024-04-30 03:53:18 +00:00
|
|
|
devConfigEx.readOnly = IS_CAP_READONLY(desp->cap);
|
2024-04-25 03:06:28 +00:00
|
|
|
|
|
|
|
if (SANE_CONSTRAINT_STRING_LIST == desp->constraint_type)
|
|
|
|
{
|
2024-04-29 09:29:39 +00:00
|
|
|
devConfigEx.rangeType = 1;
|
2024-04-25 03:06:28 +00:00
|
|
|
const SANE_String_Const* p = desp->constraint.string_list;
|
|
|
|
while (NULL != *p)
|
|
|
|
{
|
2024-04-29 09:29:39 +00:00
|
|
|
devConfigEx.stringValueList.push_back(*p);
|
2024-04-25 03:06:28 +00:00
|
|
|
++p;
|
|
|
|
}
|
|
|
|
}
|
2024-04-29 09:29:39 +00:00
|
|
|
|
|
|
|
assert(!m_deviceConfigsGroups.empty());
|
|
|
|
m_deviceConfigsGroups[m_deviceConfigsGroups.size() - 1].deviceConfigs.push_back(devConfigEx);
|
2024-04-25 03:06:28 +00:00
|
|
|
}
|
|
|
|
else if (SANE_TYPE_INT == desp->type)
|
|
|
|
{
|
|
|
|
SANE_Int value = 0;
|
2024-04-28 10:15:51 +00:00
|
|
|
sane_control_option(m_devHandle, i, SANE_ACTION_GET_VALUE, &value, NULL);
|
2024-04-25 03:06:28 +00:00
|
|
|
|
2024-04-29 09:29:39 +00:00
|
|
|
DeviceConfigEx devConfigEx;
|
|
|
|
devConfigEx.id = i;
|
|
|
|
devConfigEx.name = name;
|
|
|
|
devConfigEx.title = title;
|
|
|
|
devConfigEx.valueType = 2;
|
|
|
|
devConfigEx.intValue = (int)value;
|
2024-05-05 03:29:13 +00:00
|
|
|
devConfigEx.defIntValue = (int)value;
|
2024-04-30 02:39:08 +00:00
|
|
|
devConfigEx.hide = ((desp->cap & SANE_CAP_INACTIVE) == SANE_CAP_INACTIVE);
|
2024-04-30 03:53:18 +00:00
|
|
|
devConfigEx.readOnly = IS_CAP_READONLY(desp->cap);
|
2024-04-25 03:06:28 +00:00
|
|
|
|
|
|
|
if (SANE_CONSTRAINT_WORD_LIST == desp->constraint_type)
|
|
|
|
{
|
2024-04-29 09:29:39 +00:00
|
|
|
devConfigEx.rangeType = 2;
|
2024-04-25 03:06:28 +00:00
|
|
|
const SANE_Word* p = desp->constraint.word_list;
|
|
|
|
for (SANE_Int i = 0; i < p[0]; ++i)
|
|
|
|
{
|
2024-04-29 09:29:39 +00:00
|
|
|
devConfigEx.intValueList.push_back(p[i + 1]);
|
2024-04-25 03:06:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (SANE_CONSTRAINT_RANGE == desp->constraint_type)
|
|
|
|
{
|
2024-04-29 09:29:39 +00:00
|
|
|
devConfigEx.rangeType = 4;
|
|
|
|
devConfigEx.intValueMin = desp->constraint.range->min;
|
|
|
|
devConfigEx.intValueMax = desp->constraint.range->max;
|
2024-04-25 03:06:28 +00:00
|
|
|
}
|
|
|
|
|
2024-04-29 09:29:39 +00:00
|
|
|
assert(!m_deviceConfigsGroups.empty());
|
|
|
|
m_deviceConfigsGroups[m_deviceConfigsGroups.size() - 1].deviceConfigs.push_back(devConfigEx);
|
2024-04-25 03:06:28 +00:00
|
|
|
}
|
|
|
|
else if (SANE_TYPE_FIXED == desp->type)
|
|
|
|
{
|
|
|
|
SANE_Word value = 0;
|
2024-04-28 10:15:51 +00:00
|
|
|
sane_control_option(m_devHandle, i, SANE_ACTION_GET_VALUE, &value, NULL);
|
2024-04-25 03:06:28 +00:00
|
|
|
|
2024-04-29 09:29:39 +00:00
|
|
|
DeviceConfigEx devConfigEx;
|
|
|
|
devConfigEx.id = i;
|
|
|
|
devConfigEx.name = name;
|
|
|
|
devConfigEx.title = title;
|
|
|
|
devConfigEx.valueType = 3;
|
|
|
|
devConfigEx.doubleValue = SANE_UNFIX(value);
|
2024-05-05 03:29:13 +00:00
|
|
|
devConfigEx.defDoubleValue = SANE_UNFIX(value);
|
2024-04-30 02:39:08 +00:00
|
|
|
devConfigEx.hide = ((desp->cap & SANE_CAP_INACTIVE) == SANE_CAP_INACTIVE);
|
2024-04-30 03:53:18 +00:00
|
|
|
devConfigEx.readOnly = IS_CAP_READONLY(desp->cap);
|
2024-04-25 03:06:28 +00:00
|
|
|
|
|
|
|
if (SANE_CONSTRAINT_WORD_LIST == desp->constraint_type)
|
|
|
|
{
|
2024-04-29 09:29:39 +00:00
|
|
|
devConfigEx.rangeType = 3;
|
2024-04-25 03:06:28 +00:00
|
|
|
const SANE_Word* p = desp->constraint.word_list;
|
|
|
|
for (SANE_Int i = 0; i < p[0]; ++i)
|
|
|
|
{
|
2024-04-29 09:29:39 +00:00
|
|
|
devConfigEx.doubleValueList.push_back(SANE_UNFIX(p[i + 1]));
|
2024-04-25 03:06:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (SANE_CONSTRAINT_RANGE == desp->constraint_type)
|
|
|
|
{
|
2024-04-29 09:29:39 +00:00
|
|
|
devConfigEx.rangeType = 5;
|
|
|
|
devConfigEx.doubleValueMin = SANE_UNFIX(desp->constraint.range->min);
|
|
|
|
devConfigEx.doubleValueMax = SANE_UNFIX(desp->constraint.range->max);
|
2024-04-25 03:06:28 +00:00
|
|
|
}
|
|
|
|
|
2024-04-29 09:29:39 +00:00
|
|
|
assert(!m_deviceConfigsGroups.empty());
|
|
|
|
m_deviceConfigsGroups[m_deviceConfigsGroups.size() - 1].deviceConfigs.push_back(devConfigEx);
|
2024-04-25 03:06:28 +00:00
|
|
|
}
|
|
|
|
else if (SANE_TYPE_BOOL == desp->type)
|
|
|
|
{
|
|
|
|
SANE_Bool value = 0;
|
2024-04-28 10:15:51 +00:00
|
|
|
sane_control_option(m_devHandle, i, SANE_ACTION_GET_VALUE, &value, NULL);
|
2024-04-25 03:06:28 +00:00
|
|
|
|
2024-04-29 09:29:39 +00:00
|
|
|
DeviceConfigEx devConfigEx;
|
|
|
|
devConfigEx.id = i;
|
|
|
|
devConfigEx.name = name;
|
|
|
|
devConfigEx.title = title;
|
|
|
|
devConfigEx.valueType = 4;
|
|
|
|
devConfigEx.boolValue = (bool)value;
|
2024-05-05 03:29:13 +00:00
|
|
|
devConfigEx.defBoolValue = (bool)value;
|
2024-04-30 02:39:08 +00:00
|
|
|
devConfigEx.hide = ((desp->cap & SANE_CAP_INACTIVE) == SANE_CAP_INACTIVE);
|
2024-04-30 03:53:18 +00:00
|
|
|
devConfigEx.readOnly = IS_CAP_READONLY(desp->cap);
|
2024-04-25 03:06:28 +00:00
|
|
|
|
2024-04-29 09:29:39 +00:00
|
|
|
assert(!m_deviceConfigsGroups.empty());
|
|
|
|
m_deviceConfigsGroups[m_deviceConfigsGroups.size() - 1].deviceConfigs.push_back(devConfigEx);
|
2024-04-25 08:06:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-05-05 03:29:13 +00:00
|
|
|
// 4.创建UI
|
2024-04-25 08:06:21 +00:00
|
|
|
QPushButton *defaultBtn = new QPushButton(tr("Default"));
|
|
|
|
connect(defaultBtn, &QPushButton::clicked, this, &Form_DeviceConfig::on_defaultBtn_clicked);
|
|
|
|
QHBoxLayout *hLayout = new QHBoxLayout;
|
|
|
|
hLayout->addSpacerItem(new QSpacerItem(20, 20, QSizePolicy::Expanding));
|
|
|
|
hLayout->addWidget(defaultBtn);
|
|
|
|
QTabWidget *tabWidget = new QTabWidget(this);
|
|
|
|
tabWidget->setTabPosition(QTabWidget::North);
|
|
|
|
QVBoxLayout *mainLayout = new QVBoxLayout(this);
|
|
|
|
mainLayout->addLayout(hLayout);
|
|
|
|
mainLayout->addWidget(tabWidget);
|
|
|
|
this->setLayout(mainLayout);
|
|
|
|
|
2024-04-29 09:29:39 +00:00
|
|
|
for (int i = 0; i < (int)m_deviceConfigsGroups.size(); ++i)
|
2024-04-25 08:06:21 +00:00
|
|
|
{
|
|
|
|
QWidget *widget = new QWidget;
|
|
|
|
QFormLayout* layout = new QFormLayout;
|
|
|
|
widget->setLayout(layout);
|
|
|
|
|
|
|
|
QScrollArea* scrollArea = new QScrollArea(this);
|
|
|
|
scrollArea->setWidgetResizable(true);
|
|
|
|
scrollArea->setAlignment(Qt::AlignCenter);
|
2024-04-29 09:29:39 +00:00
|
|
|
scrollArea->setWindowTitle(QString::fromStdString(m_deviceConfigsGroups[i].groupTitle));
|
2024-04-25 08:06:21 +00:00
|
|
|
scrollArea->setWidget(widget);
|
|
|
|
|
2024-04-29 09:29:39 +00:00
|
|
|
for (int j = 0; j < (int)m_deviceConfigsGroups[i].deviceConfigs.size(); ++j)
|
2024-04-25 08:06:21 +00:00
|
|
|
{
|
2024-04-29 09:29:39 +00:00
|
|
|
DeviceConfigEx &deviceConfigEx = m_deviceConfigsGroups[i].deviceConfigs[j];
|
2024-04-25 08:06:21 +00:00
|
|
|
|
|
|
|
// 创建Label
|
|
|
|
QLabel *label = new QLabel;
|
2024-04-29 09:29:39 +00:00
|
|
|
label->setText(QString::fromStdString(deviceConfigEx.title) + QString(" : "));
|
2024-04-25 08:06:21 +00:00
|
|
|
|
|
|
|
// 创建控件
|
|
|
|
QWidget *ctrl = nullptr;
|
2024-04-26 06:35:27 +00:00
|
|
|
QWidget *ctrlWidget = nullptr;
|
2024-04-26 06:11:33 +00:00
|
|
|
|
2024-04-29 09:29:39 +00:00
|
|
|
if (1 == deviceConfigEx.rangeType)
|
2024-04-25 08:06:21 +00:00
|
|
|
{
|
2024-04-29 09:29:39 +00:00
|
|
|
assert(1 == deviceConfigEx.valueType);
|
2024-04-25 08:06:21 +00:00
|
|
|
QComboBox *comboBox = new QComboBox;
|
2024-04-29 09:29:39 +00:00
|
|
|
for (int k = 0; k < (int)deviceConfigEx.stringValueList.size(); ++k)
|
|
|
|
comboBox->addItem(QString::fromStdString(deviceConfigEx.stringValueList[k]));
|
|
|
|
comboBox->setCurrentText(QString::fromStdString(deviceConfigEx.stringValue));
|
2024-04-26 06:11:33 +00:00
|
|
|
comboBox->installEventFilter(this);
|
2024-04-29 09:29:39 +00:00
|
|
|
connect(comboBox, SIGNAL(currentTextChanged(const QString)), this, SLOT(on_string_list_comboBoxClicked()));
|
|
|
|
|
2024-04-25 08:06:21 +00:00
|
|
|
ctrl = comboBox;
|
2024-04-26 06:35:27 +00:00
|
|
|
ctrlWidget = comboBox;
|
2024-04-25 08:06:21 +00:00
|
|
|
}
|
2024-04-29 09:29:39 +00:00
|
|
|
else if (2 == deviceConfigEx.rangeType)
|
2024-04-25 08:06:21 +00:00
|
|
|
{
|
2024-04-29 09:29:39 +00:00
|
|
|
assert(2 == deviceConfigEx.valueType);
|
2024-04-25 08:06:21 +00:00
|
|
|
QComboBox *comboBox = new QComboBox;
|
2024-04-29 09:29:39 +00:00
|
|
|
for (int k = 0; k < (int)deviceConfigEx.intValueList.size(); ++k)
|
|
|
|
comboBox->addItem(QString::number(deviceConfigEx.intValueList[k]));
|
|
|
|
comboBox->setCurrentText(QString::number(deviceConfigEx.intValue));
|
2024-04-26 06:11:33 +00:00
|
|
|
comboBox->installEventFilter(this);
|
2024-04-29 09:29:39 +00:00
|
|
|
connect(comboBox, SIGNAL(currentTextChanged(const QString)), this, SLOT(on_int_list_comboBoxClicked()));
|
|
|
|
|
2024-04-25 08:06:21 +00:00
|
|
|
ctrl = comboBox;
|
2024-04-26 06:35:27 +00:00
|
|
|
ctrlWidget = comboBox;
|
2024-04-25 08:06:21 +00:00
|
|
|
}
|
2024-04-29 09:29:39 +00:00
|
|
|
else if (3 == deviceConfigEx.rangeType)
|
2024-04-25 08:06:21 +00:00
|
|
|
{
|
2024-04-29 09:29:39 +00:00
|
|
|
assert(3 == deviceConfigEx.valueType);
|
2024-04-25 08:06:21 +00:00
|
|
|
QComboBox *comboBox = new QComboBox;
|
2024-04-29 09:29:39 +00:00
|
|
|
for (int k = 0; k < (int)deviceConfigEx.doubleValueList.size(); ++k)
|
|
|
|
comboBox->addItem(QString::number(deviceConfigEx.doubleValueList[k]));
|
|
|
|
comboBox->setCurrentText(QString::number(deviceConfigEx.doubleValue));
|
2024-04-26 06:11:33 +00:00
|
|
|
comboBox->installEventFilter(this);
|
2024-04-29 09:29:39 +00:00
|
|
|
connect(comboBox, SIGNAL(currentTextChanged(const QString)), this, SLOT(on_double_list_comboBoxClicked()));
|
|
|
|
|
2024-04-25 08:06:21 +00:00
|
|
|
ctrl = comboBox;
|
2024-04-26 06:35:27 +00:00
|
|
|
ctrlWidget = comboBox;
|
2024-04-25 08:06:21 +00:00
|
|
|
}
|
2024-04-29 09:29:39 +00:00
|
|
|
else if (4 == deviceConfigEx.rangeType)
|
2024-04-25 08:06:21 +00:00
|
|
|
{
|
2024-04-29 09:29:39 +00:00
|
|
|
assert(2 == deviceConfigEx.valueType);
|
2024-04-25 08:06:21 +00:00
|
|
|
QSlider *slider = new QSlider;
|
|
|
|
slider->setOrientation(Qt::Horizontal);
|
2024-04-29 09:29:39 +00:00
|
|
|
slider->setRange(deviceConfigEx.intValueMin, deviceConfigEx.intValueMax);
|
|
|
|
slider->setValue(deviceConfigEx.intValue);
|
2024-04-26 06:11:33 +00:00
|
|
|
slider->installEventFilter(this);
|
2024-04-29 09:29:39 +00:00
|
|
|
connect(slider, SIGNAL(valueChanged(int)), this, SLOT(on_int_sliderClicked(int)));
|
2024-04-26 06:11:33 +00:00
|
|
|
|
|
|
|
QSpinBox* spinBox = new QSpinBox;
|
|
|
|
spinBox->setMinimumWidth(75);
|
|
|
|
spinBox->setMaximumWidth(75);
|
2024-04-29 09:29:39 +00:00
|
|
|
spinBox->setRange(deviceConfigEx.intValueMin, deviceConfigEx.intValueMax);
|
|
|
|
spinBox->setValue(deviceConfigEx.intValue);
|
2024-04-26 06:11:33 +00:00
|
|
|
spinBox->installEventFilter(this);
|
2024-04-29 09:29:39 +00:00
|
|
|
connect(spinBox, SIGNAL(valueChanged(int)), this, SLOT(on_relate_spinBoxClicked(int)));
|
2024-04-26 06:11:33 +00:00
|
|
|
|
2024-04-28 03:46:44 +00:00
|
|
|
slider->setProperty("relate_ctrl", QVariant::fromValue(spinBox));
|
|
|
|
spinBox->setProperty("relate_ctrl", QVariant::fromValue(slider));
|
|
|
|
|
2024-04-26 06:11:33 +00:00
|
|
|
QHBoxLayout* hLayout = new QHBoxLayout;
|
2024-04-28 03:46:44 +00:00
|
|
|
hLayout->addWidget(slider);
|
2024-04-26 06:35:27 +00:00
|
|
|
hLayout->addWidget(spinBox);
|
2024-04-26 09:39:37 +00:00
|
|
|
QWidget* sliderSpinWidget = new QWidget;
|
2024-04-26 06:11:33 +00:00
|
|
|
sliderSpinWidget->setLayout(hLayout);
|
2024-04-28 10:15:51 +00:00
|
|
|
|
|
|
|
ctrl = slider;
|
2024-04-26 06:35:27 +00:00
|
|
|
ctrlWidget = sliderSpinWidget;
|
2024-04-25 08:06:21 +00:00
|
|
|
}
|
2024-04-29 09:29:39 +00:00
|
|
|
else if (5 == deviceConfigEx.rangeType)
|
2024-04-25 08:06:21 +00:00
|
|
|
{
|
2024-04-29 09:29:39 +00:00
|
|
|
assert(3 == deviceConfigEx.valueType);
|
2024-04-25 08:06:21 +00:00
|
|
|
QSlider *slider = new QSlider;
|
|
|
|
slider->setOrientation(Qt::Horizontal);
|
2024-04-29 09:29:39 +00:00
|
|
|
slider->setRange(round(deviceConfigEx.doubleValueMin * 100), round(deviceConfigEx.doubleValueMax * 100));
|
|
|
|
slider->setValue(round(deviceConfigEx.doubleValue * 100));
|
2024-04-26 06:11:33 +00:00
|
|
|
slider->installEventFilter(this);
|
2024-04-29 09:29:39 +00:00
|
|
|
connect(slider, SIGNAL(valueChanged(int)), this, SLOT(on_double_sliderClicked(int)));
|
2024-04-26 06:11:33 +00:00
|
|
|
|
|
|
|
QDoubleSpinBox* doubleSpinBox = new QDoubleSpinBox;
|
|
|
|
doubleSpinBox->setMinimumWidth(75);
|
|
|
|
doubleSpinBox->setMaximumWidth(75);
|
2024-04-29 09:29:39 +00:00
|
|
|
doubleSpinBox->setRange(deviceConfigEx.doubleValueMin, deviceConfigEx.doubleValueMax);
|
2024-04-26 06:11:33 +00:00
|
|
|
doubleSpinBox->setDecimals(2);
|
|
|
|
doubleSpinBox->setSingleStep(0.01);
|
2024-04-29 09:29:39 +00:00
|
|
|
doubleSpinBox->setValue(deviceConfigEx.doubleValue);
|
2024-04-26 06:11:33 +00:00
|
|
|
doubleSpinBox->installEventFilter(this);
|
2024-04-29 09:29:39 +00:00
|
|
|
connect(doubleSpinBox, SIGNAL(valueChanged(double)), this, SLOT(on_relate_doubleSpinboxClicked(double)));
|
2024-04-26 06:11:33 +00:00
|
|
|
|
2024-04-28 03:46:44 +00:00
|
|
|
slider->setProperty("relate_ctrl", QVariant::fromValue(doubleSpinBox));
|
|
|
|
doubleSpinBox->setProperty("relate_ctrl", QVariant::fromValue(slider));
|
|
|
|
|
2024-04-26 06:11:33 +00:00
|
|
|
QHBoxLayout* hLayout = new QHBoxLayout;
|
2024-04-28 03:46:44 +00:00
|
|
|
hLayout->addWidget(slider);
|
2024-04-26 06:35:27 +00:00
|
|
|
hLayout->addWidget(doubleSpinBox);
|
2024-04-26 09:39:37 +00:00
|
|
|
QWidget* sliderSpinWidget = new QWidget;
|
2024-04-26 06:11:33 +00:00
|
|
|
sliderSpinWidget->setLayout(hLayout);
|
2024-04-28 10:15:51 +00:00
|
|
|
|
|
|
|
ctrl = slider;
|
2024-04-26 06:35:27 +00:00
|
|
|
ctrlWidget = sliderSpinWidget;
|
2024-04-25 08:06:21 +00:00
|
|
|
}
|
2024-04-29 09:29:39 +00:00
|
|
|
else if (0 == deviceConfigEx.rangeType)
|
2024-04-25 08:06:21 +00:00
|
|
|
{
|
2024-04-29 09:29:39 +00:00
|
|
|
if (1 == deviceConfigEx.valueType)
|
2024-04-25 08:06:21 +00:00
|
|
|
{
|
2024-04-29 09:29:39 +00:00
|
|
|
QComboBox *comboBox = new QComboBox;
|
|
|
|
comboBox->addItem(QString::fromStdString(deviceConfigEx.stringValue));
|
|
|
|
comboBox->setCurrentText(QString::fromStdString(deviceConfigEx.stringValue));
|
|
|
|
comboBox->installEventFilter(this);
|
|
|
|
connect(comboBox, SIGNAL(currentTextChanged(const QString)), this, SLOT(on_string_comboBoxClicked()));
|
|
|
|
|
|
|
|
ctrl = comboBox;
|
|
|
|
ctrlWidget = comboBox;
|
2024-04-25 08:06:21 +00:00
|
|
|
}
|
2024-04-29 09:29:39 +00:00
|
|
|
else if (2 == deviceConfigEx.valueType)
|
2024-04-25 08:06:21 +00:00
|
|
|
{
|
|
|
|
QSpinBox* spinBox = new QSpinBox;
|
|
|
|
spinBox->setMinimumWidth(75);
|
2024-04-26 06:11:33 +00:00
|
|
|
spinBox->setMaximumWidth(75);
|
2024-04-30 09:35:45 +00:00
|
|
|
spinBox->setRange(-1, 1000);
|
2024-04-29 09:29:39 +00:00
|
|
|
spinBox->setValue(deviceConfigEx.intValue);
|
2024-04-26 06:11:33 +00:00
|
|
|
spinBox->installEventFilter(this);
|
2024-04-29 09:29:39 +00:00
|
|
|
connect(spinBox, SIGNAL(valueChanged(int)), this, SLOT(on_spinBoxClicked(int)));
|
|
|
|
|
2024-04-25 08:06:21 +00:00
|
|
|
ctrl = spinBox;
|
2024-04-26 06:35:27 +00:00
|
|
|
ctrlWidget = spinBox;
|
2024-04-25 08:06:21 +00:00
|
|
|
}
|
2024-04-29 09:29:39 +00:00
|
|
|
else if (4 == deviceConfigEx.valueType)
|
2024-04-25 08:06:21 +00:00
|
|
|
{
|
|
|
|
QCheckBox *checkBox = new QCheckBox;
|
2024-04-29 09:29:39 +00:00
|
|
|
checkBox->setChecked(deviceConfigEx.boolValue);
|
2024-04-28 10:15:51 +00:00
|
|
|
connect(checkBox, SIGNAL(stateChanged(int)), this, SLOT(on_checkedClicked()));
|
2024-04-29 09:29:39 +00:00
|
|
|
|
2024-04-25 08:06:21 +00:00
|
|
|
ctrl = checkBox;
|
2024-04-26 06:50:18 +00:00
|
|
|
ctrlWidget = checkBox;
|
2024-04-25 08:06:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-04-29 09:29:39 +00:00
|
|
|
ctrl->setProperty("config_id", deviceConfigEx.id);
|
2024-05-05 03:29:13 +00:00
|
|
|
ctrl->setProperty("configex_ptr", QVariant::fromValue(&deviceConfigEx));
|
2024-04-29 09:29:39 +00:00
|
|
|
deviceConfigEx.label = label;
|
|
|
|
deviceConfigEx.ctrl = ctrl;
|
|
|
|
deviceConfigEx.ctrlWidget = ctrlWidget;
|
|
|
|
layout->addRow(label, ctrlWidget);
|
2024-04-30 02:39:08 +00:00
|
|
|
|
|
|
|
label->setVisible(!deviceConfigEx.hide);
|
|
|
|
ctrlWidget->setVisible(!deviceConfigEx.hide);
|
2024-04-30 03:53:18 +00:00
|
|
|
ctrl->setEnabled(!deviceConfigEx.readOnly);
|
2024-04-25 03:06:28 +00:00
|
|
|
}
|
2024-04-25 08:06:21 +00:00
|
|
|
|
2024-04-29 09:29:39 +00:00
|
|
|
tabWidget->addTab(scrollArea, QString::fromStdString(m_deviceConfigsGroups[i].groupTitle));
|
|
|
|
}
|
2024-05-05 03:29:13 +00:00
|
|
|
|
|
|
|
// 5.设置新配置
|
2024-05-05 08:48:54 +00:00
|
|
|
bool update = false;
|
2024-05-05 03:29:13 +00:00
|
|
|
for (int i = 0; i < (int)deviceConfigs.size(); ++i)
|
|
|
|
{
|
|
|
|
for (int j = 1; j < num_dev_options; ++j)
|
|
|
|
{
|
|
|
|
const SANE_Option_Descriptor* desp = sane_get_option_descriptor(m_devHandle, j);
|
|
|
|
if (NULL == desp)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
const char* name = desp->name;
|
|
|
|
while (' ' == *name)
|
|
|
|
++name;
|
|
|
|
|
|
|
|
if (0 == strcmp(deviceConfigs[i].name.c_str(), name))
|
|
|
|
{
|
2024-05-05 08:48:54 +00:00
|
|
|
SANE_Int method = 0;
|
2024-05-05 03:29:13 +00:00
|
|
|
if (SANE_TYPE_STRING == desp->type)
|
|
|
|
{
|
2024-05-05 08:48:54 +00:00
|
|
|
sane_control_option(m_devHandle, j, SANE_ACTION_SET_VALUE, (void*)deviceConfigs[i].stringValue.c_str(), &method);
|
2024-05-05 03:29:13 +00:00
|
|
|
}
|
|
|
|
else if (SANE_TYPE_INT == desp->type)
|
|
|
|
{
|
|
|
|
SANE_Int value = deviceConfigs[i].intValue;
|
2024-05-05 08:48:54 +00:00
|
|
|
sane_control_option(m_devHandle, j, SANE_ACTION_SET_VALUE, &value, &method);
|
2024-05-05 03:29:13 +00:00
|
|
|
}
|
|
|
|
else if (SANE_TYPE_FIXED == desp->type)
|
|
|
|
{
|
|
|
|
SANE_Fixed value = SANE_FIX(deviceConfigs[i].doubleValue);
|
2024-05-05 08:48:54 +00:00
|
|
|
sane_control_option(m_devHandle, j, SANE_ACTION_SET_VALUE, &value, &method);
|
2024-05-05 03:29:13 +00:00
|
|
|
}
|
|
|
|
else if (SANE_TYPE_BOOL == desp->type)
|
|
|
|
{
|
|
|
|
SANE_Bool value = (SANE_Bool)deviceConfigs[i].boolValue;
|
2024-05-05 08:48:54 +00:00
|
|
|
sane_control_option(m_devHandle, j, SANE_ACTION_SET_VALUE, &value, &method);
|
2024-05-05 03:29:13 +00:00
|
|
|
}
|
|
|
|
|
2024-05-05 08:48:54 +00:00
|
|
|
if ((method & SANE_INFO_RELOAD_OPTIONS) == SANE_INFO_RELOAD_OPTIONS)
|
|
|
|
update = true;
|
2024-05-05 03:29:13 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 6.更新UI
|
2024-05-05 08:48:54 +00:00
|
|
|
if (update)
|
|
|
|
{
|
|
|
|
Update(-1);
|
|
|
|
}
|
2024-04-25 03:06:28 +00:00
|
|
|
}
|
|
|
|
|
2024-04-29 09:29:39 +00:00
|
|
|
void Form_DeviceConfig::Update(int ignoreId)
|
2024-04-25 03:06:28 +00:00
|
|
|
{
|
2024-04-29 09:29:39 +00:00
|
|
|
// 1.更新当前配置信息
|
|
|
|
SANE_Int num_dev_options = 0;
|
|
|
|
sane_control_option(m_devHandle, 0, SANE_ACTION_GET_VALUE, &num_dev_options, NULL);
|
|
|
|
for (int k = 1; k < num_dev_options; ++k)
|
2024-04-28 10:15:51 +00:00
|
|
|
{
|
2024-04-30 02:39:08 +00:00
|
|
|
if (k == ignoreId)
|
2024-04-29 09:29:39 +00:00
|
|
|
continue;
|
|
|
|
|
2024-04-30 02:39:08 +00:00
|
|
|
const SANE_Option_Descriptor* desp = sane_get_option_descriptor(m_devHandle, k);
|
|
|
|
if (NULL == desp)
|
2024-04-29 09:29:39 +00:00
|
|
|
continue;
|
|
|
|
|
2024-04-29 10:02:18 +00:00
|
|
|
const char* name = desp->name;
|
|
|
|
while (' ' == *name)
|
|
|
|
++name;
|
|
|
|
|
|
|
|
if (0 == strcmp(SANE_STD_OPT_NAME_IS_CUSTOM_GAMMA, name))
|
|
|
|
continue;
|
|
|
|
|
2024-04-30 02:39:08 +00:00
|
|
|
const char* title = desp->title;
|
|
|
|
while (' ' == *title)
|
|
|
|
++title;
|
|
|
|
|
2024-04-29 09:29:39 +00:00
|
|
|
DeviceConfigEx *pDeviceConfigEx = nullptr;
|
|
|
|
for (int i = 0; i < (int)m_deviceConfigsGroups.size(); ++i)
|
2024-04-28 10:15:51 +00:00
|
|
|
{
|
2024-04-29 09:29:39 +00:00
|
|
|
for (int j = 0; j < (int)m_deviceConfigsGroups[i].deviceConfigs.size(); ++j)
|
2024-04-28 10:15:51 +00:00
|
|
|
{
|
2024-04-29 09:29:39 +00:00
|
|
|
if (m_deviceConfigsGroups[i].deviceConfigs[j].id == k)
|
2024-04-28 10:15:51 +00:00
|
|
|
{
|
2024-04-29 09:29:39 +00:00
|
|
|
pDeviceConfigEx = &m_deviceConfigsGroups[i].deviceConfigs[j];
|
2024-04-28 10:15:51 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2024-04-29 09:29:39 +00:00
|
|
|
}
|
2024-04-28 10:15:51 +00:00
|
|
|
|
2024-04-29 09:29:39 +00:00
|
|
|
if (nullptr != pDeviceConfigEx)
|
|
|
|
{
|
2024-04-30 02:39:08 +00:00
|
|
|
assert(pDeviceConfigEx->id == k);
|
|
|
|
assert(pDeviceConfigEx->name == name);
|
|
|
|
assert(pDeviceConfigEx->title == title);
|
|
|
|
pDeviceConfigEx->hide = ((desp->cap & SANE_CAP_INACTIVE) == SANE_CAP_INACTIVE);
|
2024-04-30 03:53:18 +00:00
|
|
|
pDeviceConfigEx->readOnly = IS_CAP_READONLY(desp->cap);
|
2024-04-30 02:39:08 +00:00
|
|
|
|
2024-04-29 09:29:39 +00:00
|
|
|
pDeviceConfigEx->valueType = 0;
|
|
|
|
pDeviceConfigEx->stringValue.clear();
|
|
|
|
pDeviceConfigEx->intValue = 0;
|
|
|
|
pDeviceConfigEx->doubleValue = 0;
|
|
|
|
pDeviceConfigEx->boolValue = false;
|
|
|
|
|
|
|
|
pDeviceConfigEx->rangeType = 0;
|
|
|
|
pDeviceConfigEx->stringValueList.clear();
|
|
|
|
pDeviceConfigEx->intValueList.clear();
|
|
|
|
pDeviceConfigEx->doubleValueList.clear();
|
|
|
|
pDeviceConfigEx->intValueMin = 0;
|
|
|
|
pDeviceConfigEx->intValueMax = 0;
|
|
|
|
pDeviceConfigEx->doubleValueMin = 0;
|
|
|
|
pDeviceConfigEx->doubleValueMax = 0;
|
2024-04-28 10:15:51 +00:00
|
|
|
}
|
|
|
|
|
2024-04-29 09:29:39 +00:00
|
|
|
if (SANE_TYPE_STRING == desp->type)
|
2024-04-25 08:06:21 +00:00
|
|
|
{
|
2024-04-29 09:29:39 +00:00
|
|
|
char value[256] = { 0 };
|
|
|
|
sane_control_option(m_devHandle, k, SANE_ACTION_GET_VALUE, value, NULL);
|
2024-04-25 03:06:28 +00:00
|
|
|
|
2024-04-29 09:29:39 +00:00
|
|
|
assert(nullptr != pDeviceConfigEx);
|
|
|
|
pDeviceConfigEx->valueType = 1;
|
|
|
|
pDeviceConfigEx->stringValue = value;
|
|
|
|
|
|
|
|
if (SANE_CONSTRAINT_STRING_LIST == desp->constraint_type)
|
2024-04-25 08:06:21 +00:00
|
|
|
{
|
2024-04-29 09:29:39 +00:00
|
|
|
pDeviceConfigEx->rangeType = 1;
|
|
|
|
const SANE_String_Const* p = desp->constraint.string_list;
|
|
|
|
while (NULL != *p)
|
2024-04-25 08:06:21 +00:00
|
|
|
{
|
2024-04-29 09:29:39 +00:00
|
|
|
pDeviceConfigEx->stringValueList.push_back(*p);
|
|
|
|
++p;
|
2024-04-25 08:06:21 +00:00
|
|
|
}
|
|
|
|
}
|
2024-04-29 09:29:39 +00:00
|
|
|
}
|
|
|
|
else if (SANE_TYPE_INT == desp->type)
|
|
|
|
{
|
|
|
|
SANE_Int value = 0;
|
|
|
|
sane_control_option(m_devHandle, k, SANE_ACTION_GET_VALUE, &value, NULL);
|
2024-04-25 08:06:21 +00:00
|
|
|
|
2024-04-29 09:29:39 +00:00
|
|
|
assert(nullptr != pDeviceConfigEx);
|
|
|
|
pDeviceConfigEx->valueType = 2;
|
|
|
|
pDeviceConfigEx->intValue = (int)value;
|
|
|
|
|
|
|
|
if (SANE_CONSTRAINT_WORD_LIST == desp->constraint_type)
|
2024-04-25 08:06:21 +00:00
|
|
|
{
|
2024-04-29 09:29:39 +00:00
|
|
|
pDeviceConfigEx->rangeType = 2;
|
|
|
|
const SANE_Word* p = desp->constraint.word_list;
|
|
|
|
for (SANE_Int i = 0; i < p[0]; ++i)
|
2024-04-25 08:06:21 +00:00
|
|
|
{
|
2024-04-29 09:29:39 +00:00
|
|
|
pDeviceConfigEx->intValueList.push_back(p[i + 1]);
|
2024-04-25 08:06:21 +00:00
|
|
|
}
|
2024-04-29 09:29:39 +00:00
|
|
|
}
|
|
|
|
else if (SANE_CONSTRAINT_RANGE == desp->constraint_type)
|
|
|
|
{
|
|
|
|
pDeviceConfigEx->rangeType = 4;
|
|
|
|
pDeviceConfigEx->intValueMin = desp->constraint.range->min;
|
|
|
|
pDeviceConfigEx->intValueMax = desp->constraint.range->max;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (SANE_TYPE_FIXED == desp->type)
|
|
|
|
{
|
|
|
|
SANE_Word value = 0;
|
|
|
|
sane_control_option(m_devHandle, k, SANE_ACTION_GET_VALUE, &value, NULL);
|
|
|
|
|
|
|
|
assert(nullptr != pDeviceConfigEx);
|
|
|
|
pDeviceConfigEx->valueType = 3;
|
|
|
|
pDeviceConfigEx->doubleValue = SANE_UNFIX(value);
|
|
|
|
|
|
|
|
if (SANE_CONSTRAINT_WORD_LIST == desp->constraint_type)
|
|
|
|
{
|
|
|
|
pDeviceConfigEx->rangeType = 3;
|
|
|
|
const SANE_Word* p = desp->constraint.word_list;
|
|
|
|
for (SANE_Int i = 0; i < p[0]; ++i)
|
2024-04-25 08:06:21 +00:00
|
|
|
{
|
2024-04-29 09:29:39 +00:00
|
|
|
pDeviceConfigEx->doubleValueList.push_back(SANE_UNFIX(p[i + 1]));
|
2024-04-25 08:06:21 +00:00
|
|
|
}
|
2024-04-29 09:29:39 +00:00
|
|
|
}
|
|
|
|
else if (SANE_CONSTRAINT_RANGE == desp->constraint_type)
|
|
|
|
{
|
|
|
|
pDeviceConfigEx->rangeType = 5;
|
|
|
|
pDeviceConfigEx->doubleValueMin = SANE_UNFIX(desp->constraint.range->min);
|
|
|
|
pDeviceConfigEx->doubleValueMax = SANE_UNFIX(desp->constraint.range->max);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (SANE_TYPE_BOOL == desp->type)
|
|
|
|
{
|
|
|
|
SANE_Bool value = 0;
|
|
|
|
sane_control_option(m_devHandle, k, SANE_ACTION_GET_VALUE, &value, NULL);
|
|
|
|
|
|
|
|
assert(nullptr != pDeviceConfigEx);
|
|
|
|
pDeviceConfigEx->valueType = 4;
|
|
|
|
pDeviceConfigEx->boolValue = (bool)value;
|
|
|
|
|
|
|
|
assert(SANE_CONSTRAINT_NONE == desp->constraint_type);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 2.更新UI
|
|
|
|
for (int i = 0; i < (int)m_deviceConfigsGroups.size(); ++i)
|
|
|
|
{
|
|
|
|
for (int j = 0; j < (int)m_deviceConfigsGroups[i].deviceConfigs.size(); ++j)
|
|
|
|
{
|
|
|
|
const DeviceConfigEx &deviceConfigEx = m_deviceConfigsGroups[i].deviceConfigs[j];
|
|
|
|
if (deviceConfigEx.id == ignoreId)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (1 == deviceConfigEx.rangeType)
|
|
|
|
{
|
|
|
|
assert(1 == deviceConfigEx.valueType);
|
|
|
|
QComboBox *comboBox = (QComboBox *)deviceConfigEx.ctrl;
|
|
|
|
disconnect(comboBox, SIGNAL(currentTextChanged(const QString)), this, SLOT(on_string_list_comboBoxClicked()));
|
|
|
|
comboBox->clear();
|
|
|
|
for (int k = 0; k < (int)deviceConfigEx.stringValueList.size(); ++k)
|
|
|
|
comboBox->addItem(QString::fromStdString(deviceConfigEx.stringValueList[k]));
|
|
|
|
comboBox->setCurrentText(QString::fromStdString(deviceConfigEx.stringValue));
|
|
|
|
connect(comboBox, SIGNAL(currentTextChanged(const QString)), this, SLOT(on_string_list_comboBoxClicked()));
|
|
|
|
}
|
|
|
|
else if (2 == deviceConfigEx.rangeType)
|
|
|
|
{
|
|
|
|
assert(2 == deviceConfigEx.valueType);
|
|
|
|
QComboBox *comboBox = (QComboBox *)deviceConfigEx.ctrl;
|
|
|
|
disconnect(comboBox, SIGNAL(currentTextChanged(const QString)), this, SLOT(on_int_list_comboBoxClicked()));
|
|
|
|
comboBox->clear();
|
|
|
|
for (int k = 0; k < (int)deviceConfigEx.intValueList.size(); ++k)
|
|
|
|
comboBox->addItem(QString::number(deviceConfigEx.intValueList[k]));
|
|
|
|
comboBox->setCurrentText(QString::number(deviceConfigEx.intValue));
|
|
|
|
connect(comboBox, SIGNAL(currentTextChanged(const QString)), this, SLOT(on_int_list_comboBoxClicked()));
|
|
|
|
}
|
|
|
|
else if (3 == deviceConfigEx.rangeType)
|
|
|
|
{
|
|
|
|
assert(3 == deviceConfigEx.valueType);
|
|
|
|
QComboBox *comboBox = (QComboBox *)deviceConfigEx.ctrl;
|
|
|
|
disconnect(comboBox, SIGNAL(currentTextChanged(const QString)), this, SLOT(on_double_list_comboBoxClicked()));
|
|
|
|
comboBox->clear();
|
|
|
|
for (int k = 0; k < (int)deviceConfigEx.doubleValueList.size(); ++k)
|
|
|
|
comboBox->addItem(QString::number(deviceConfigEx.doubleValueList[k]));
|
|
|
|
comboBox->setCurrentText(QString::number(deviceConfigEx.doubleValue));
|
|
|
|
connect(comboBox, SIGNAL(currentTextChanged(const QString)), this, SLOT(on_double_list_comboBoxClicked()));
|
|
|
|
}
|
|
|
|
else if (4 == deviceConfigEx.rangeType)
|
|
|
|
{
|
|
|
|
assert(2 == deviceConfigEx.valueType);
|
|
|
|
QSlider *slider = (QSlider*)deviceConfigEx.ctrl;
|
|
|
|
QSpinBox* spinBox = qvariant_cast<QSpinBox*>(slider->property("relate_ctrl"));
|
|
|
|
disconnect(slider, SIGNAL(valueChanged(int)), this, SLOT(on_int_sliderClicked(int)));
|
|
|
|
disconnect(spinBox, SIGNAL(valueChanged(int)), this, SLOT(on_relate_spinBoxClicked(int)));
|
|
|
|
slider->setRange(deviceConfigEx.intValueMin, deviceConfigEx.intValueMax);
|
|
|
|
slider->setValue(deviceConfigEx.intValue);
|
|
|
|
spinBox->setRange(deviceConfigEx.intValueMin, deviceConfigEx.intValueMax);
|
|
|
|
spinBox->setValue(deviceConfigEx.intValue);
|
|
|
|
connect(slider, SIGNAL(valueChanged(int)), this, SLOT(on_int_sliderClicked(int)));
|
|
|
|
connect(spinBox, SIGNAL(valueChanged(int)), this, SLOT(on_relate_spinBoxClicked(int)));
|
|
|
|
}
|
|
|
|
else if (5 == deviceConfigEx.rangeType)
|
|
|
|
{
|
|
|
|
assert(3 == deviceConfigEx.valueType);
|
|
|
|
QSlider *slider = (QSlider*)deviceConfigEx.ctrl;
|
|
|
|
QDoubleSpinBox* doubleSpinBox = qvariant_cast<QDoubleSpinBox*>(slider->property("relate_ctrl"));
|
|
|
|
disconnect(slider, SIGNAL(valueChanged(int)), this, SLOT(on_double_sliderClicked(int)));
|
|
|
|
disconnect(doubleSpinBox, SIGNAL(valueChanged(double)), this, SLOT(on_relate_doubleSpinboxClicked(double)));
|
|
|
|
slider->setRange(round(deviceConfigEx.doubleValueMin * 100), round(deviceConfigEx.doubleValueMax * 100));
|
|
|
|
slider->setValue(round(deviceConfigEx.doubleValue * 100));
|
|
|
|
doubleSpinBox->setRange(deviceConfigEx.doubleValueMin, deviceConfigEx.doubleValueMax);
|
|
|
|
doubleSpinBox->setValue(deviceConfigEx.doubleValue);
|
|
|
|
connect(slider, SIGNAL(valueChanged(int)), this, SLOT(on_double_sliderClicked(int)));
|
|
|
|
connect(doubleSpinBox, SIGNAL(valueChanged(double)), this, SLOT(on_relate_doubleSpinboxClicked(double)));
|
|
|
|
}
|
|
|
|
else if (0 == deviceConfigEx.rangeType)
|
|
|
|
{
|
|
|
|
if (1 == deviceConfigEx.valueType)
|
2024-04-25 08:06:21 +00:00
|
|
|
{
|
2024-04-29 09:29:39 +00:00
|
|
|
QComboBox *comboBox = (QComboBox*)deviceConfigEx.ctrl;
|
|
|
|
disconnect(comboBox, SIGNAL(currentTextChanged(const QString)), this, SLOT(on_string_comboBoxClicked()));
|
|
|
|
comboBox->clear();
|
|
|
|
comboBox->addItem(QString::fromStdString(deviceConfigEx.stringValue));
|
|
|
|
comboBox->setCurrentText(QString::fromStdString(deviceConfigEx.stringValue));
|
|
|
|
connect(comboBox, SIGNAL(currentTextChanged(const QString)), this, SLOT(on_string_comboBoxClicked()));
|
2024-04-25 08:06:21 +00:00
|
|
|
}
|
2024-04-29 09:29:39 +00:00
|
|
|
else if (2 == deviceConfigEx.valueType)
|
2024-04-25 08:06:21 +00:00
|
|
|
{
|
2024-04-29 09:29:39 +00:00
|
|
|
QSpinBox* spinBox = (QSpinBox*)deviceConfigEx.ctrl;
|
|
|
|
disconnect(spinBox, SIGNAL(valueChanged(int)), this, SLOT(on_spinBoxClicked(int)));
|
|
|
|
spinBox->setValue(deviceConfigEx.intValue);
|
|
|
|
connect(spinBox, SIGNAL(valueChanged(int)), this, SLOT(on_spinBoxClicked(int)));
|
2024-04-25 08:06:21 +00:00
|
|
|
}
|
2024-04-29 09:29:39 +00:00
|
|
|
else if (4 == deviceConfigEx.valueType)
|
2024-04-25 08:06:21 +00:00
|
|
|
{
|
2024-04-29 09:29:39 +00:00
|
|
|
QCheckBox *checkBox = (QCheckBox*)deviceConfigEx.ctrl;
|
|
|
|
disconnect(checkBox, SIGNAL(stateChanged(int)), this, SLOT(on_checkedClicked()));
|
|
|
|
checkBox->setChecked(deviceConfigEx.boolValue);
|
|
|
|
connect(checkBox, SIGNAL(stateChanged(int)), this, SLOT(on_checkedClicked()));
|
2024-04-25 08:06:21 +00:00
|
|
|
}
|
|
|
|
}
|
2024-04-29 09:29:39 +00:00
|
|
|
|
2024-04-30 02:39:08 +00:00
|
|
|
deviceConfigEx.label->setVisible(!deviceConfigEx.hide);
|
|
|
|
deviceConfigEx.ctrlWidget->setVisible(!deviceConfigEx.hide);
|
2024-04-30 03:53:18 +00:00
|
|
|
deviceConfigEx.ctrl->setEnabled(!deviceConfigEx.readOnly);
|
2024-04-29 09:29:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Form_DeviceConfig::eventFilter(QObject *target, QEvent *event)
|
|
|
|
{
|
|
|
|
if (typeid(*target) == typeid(QSlider) || typeid(*target) == typeid(QComboBox) || typeid(*target) == typeid(QSpinBox) ||
|
|
|
|
typeid(*target) == typeid(QDoubleSpinBox))
|
|
|
|
{
|
|
|
|
if (event->type() == QEvent::Wheel)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return QWidget::eventFilter(target, event);
|
|
|
|
}
|
2024-04-28 10:15:51 +00:00
|
|
|
|
2024-04-29 09:29:39 +00:00
|
|
|
void Form_DeviceConfig::on_defaultBtn_clicked()
|
|
|
|
{
|
|
|
|
// 1.恢复默认
|
2024-05-05 03:29:13 +00:00
|
|
|
assert(-1 != m_defButtonId);
|
|
|
|
sane_control_option(m_devHandle, m_defButtonId, SANE_ACTION_SET_VALUE, NULL, NULL);
|
2024-04-28 10:15:51 +00:00
|
|
|
|
2024-04-29 09:29:39 +00:00
|
|
|
// 2.更新UI
|
|
|
|
Update(-1);
|
|
|
|
}
|
2024-04-28 10:15:51 +00:00
|
|
|
|
2024-04-29 09:29:39 +00:00
|
|
|
void Form_DeviceConfig::on_string_list_comboBoxClicked()
|
|
|
|
{
|
|
|
|
QComboBox *comboBox = qobject_cast<QComboBox*>(sender());
|
|
|
|
std::string currentText = comboBox->currentText().toUtf8();
|
|
|
|
SANE_Int id = comboBox->property("config_id").toInt();
|
2024-05-05 03:29:13 +00:00
|
|
|
DeviceConfigEx *deviceConfigEx = qvariant_cast<DeviceConfigEx*>(comboBox->property("configex_ptr"));
|
2024-04-29 09:29:39 +00:00
|
|
|
|
|
|
|
SANE_Int method = 0;
|
|
|
|
SANE_Status ret = sane_control_option(m_devHandle, id, SANE_ACTION_SET_VALUE, (void *)currentText.c_str(), &method);
|
|
|
|
if (ret == SANE_STATUS_UNSUPPORTED)
|
2024-04-28 10:15:51 +00:00
|
|
|
{
|
2024-04-29 09:29:39 +00:00
|
|
|
SANE_Char v[256] = {0};
|
|
|
|
sane_control_option(m_devHandle, id, SANE_ACTION_GET_VALUE, &v, &method);
|
|
|
|
disconnect(comboBox, SIGNAL(currentTextChanged(const QString)), this, SLOT(on_string_list_comboBoxClicked()));
|
|
|
|
comboBox->setCurrentText(QString::fromUtf8(v));
|
|
|
|
connect(comboBox, SIGNAL(currentTextChanged(const QString)), this, SLOT(on_string_list_comboBoxClicked()));
|
|
|
|
QMessageBox::information(this, tr("Prompt"), tr("The funtion is unsupported"));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2024-05-05 03:29:13 +00:00
|
|
|
deviceConfigEx->stringValue = currentText;
|
2024-04-29 09:29:39 +00:00
|
|
|
if ((method & SANE_INFO_RELOAD_OPTIONS) == SANE_INFO_RELOAD_OPTIONS)
|
|
|
|
{
|
|
|
|
Update(id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Form_DeviceConfig::on_int_list_comboBoxClicked()
|
|
|
|
{
|
|
|
|
QComboBox *comboBox = qobject_cast<QComboBox*>(sender());
|
|
|
|
SANE_Int currentValue = comboBox->currentText().toInt();
|
|
|
|
SANE_Int id = comboBox->property("config_id").toInt();
|
2024-05-05 03:29:13 +00:00
|
|
|
DeviceConfigEx *deviceConfigEx = qvariant_cast<DeviceConfigEx*>(comboBox->property("configex_ptr"));
|
2024-04-28 10:15:51 +00:00
|
|
|
|
2024-04-29 09:29:39 +00:00
|
|
|
SANE_Int method = 0;
|
|
|
|
SANE_Status ret = sane_control_option(m_devHandle, id, SANE_ACTION_SET_VALUE, ¤tValue, &method);
|
|
|
|
if (ret == SANE_STATUS_UNSUPPORTED)
|
|
|
|
{
|
|
|
|
SANE_Int v = 0;
|
|
|
|
sane_control_option(m_devHandle, id, SANE_ACTION_GET_VALUE, &v, &method);
|
|
|
|
disconnect(comboBox, SIGNAL(currentTextChanged(const QString)), this, SLOT(on_int_list_comboBoxClicked()));
|
|
|
|
comboBox->setCurrentText(QString::number(v));
|
|
|
|
connect(comboBox, SIGNAL(currentTextChanged(const QString)), this, SLOT(on_int_list_comboBoxClicked()));
|
|
|
|
QMessageBox::information(this, tr("Prompt"), tr("The funtion is unsupported"));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2024-05-05 03:29:13 +00:00
|
|
|
deviceConfigEx->intValue = currentValue;
|
2024-04-29 09:29:39 +00:00
|
|
|
if ((method & SANE_INFO_RELOAD_OPTIONS) == SANE_INFO_RELOAD_OPTIONS)
|
|
|
|
{
|
|
|
|
Update(id);
|
|
|
|
}
|
2024-04-28 10:15:51 +00:00
|
|
|
}
|
|
|
|
|
2024-04-29 09:29:39 +00:00
|
|
|
void Form_DeviceConfig::on_double_list_comboBoxClicked()
|
2024-04-28 10:15:51 +00:00
|
|
|
{
|
2024-04-29 09:29:39 +00:00
|
|
|
QComboBox *comboBox = qobject_cast<QComboBox*>(sender());
|
|
|
|
SANE_Word currentValue = SANE_FIX(comboBox->currentText().toDouble());
|
|
|
|
SANE_Int id = comboBox->property("config_id").toInt();
|
2024-05-05 03:29:13 +00:00
|
|
|
DeviceConfigEx *deviceConfigEx = qvariant_cast<DeviceConfigEx*>(comboBox->property("configex_ptr"));
|
2024-04-28 10:15:51 +00:00
|
|
|
|
2024-04-29 09:29:39 +00:00
|
|
|
SANE_Int method = 0;
|
|
|
|
SANE_Status ret = sane_control_option(m_devHandle, id, SANE_ACTION_SET_VALUE, ¤tValue, &method);
|
|
|
|
if (ret == SANE_STATUS_UNSUPPORTED)
|
|
|
|
{
|
|
|
|
SANE_Word v = 0;
|
|
|
|
sane_control_option(m_devHandle, id, SANE_ACTION_GET_VALUE, &v, &method);
|
|
|
|
disconnect(comboBox, SIGNAL(currentTextChanged(const QString)), this, SLOT(on_double_list_comboBoxClicked()));
|
|
|
|
comboBox->setCurrentText(QString::number(SANE_UNFIX(v)));
|
|
|
|
connect(comboBox, SIGNAL(currentTextChanged(const QString)), this, SLOT(on_double_list_comboBoxClicked()));
|
|
|
|
QMessageBox::information(this, tr("Prompt"), tr("The funtion is unsupported"));
|
|
|
|
return;
|
|
|
|
}
|
2024-04-28 10:15:51 +00:00
|
|
|
|
2024-05-05 03:29:13 +00:00
|
|
|
deviceConfigEx->doubleValue = comboBox->currentText().toDouble();
|
2024-04-29 09:29:39 +00:00
|
|
|
if ((method & SANE_INFO_RELOAD_OPTIONS) == SANE_INFO_RELOAD_OPTIONS)
|
|
|
|
{
|
|
|
|
Update(id);
|
2024-04-28 10:15:51 +00:00
|
|
|
}
|
2024-04-25 08:06:21 +00:00
|
|
|
}
|
|
|
|
|
2024-04-29 09:29:39 +00:00
|
|
|
void Form_DeviceConfig::on_int_sliderClicked(int value)
|
2024-04-25 08:06:21 +00:00
|
|
|
{
|
2024-04-29 09:29:39 +00:00
|
|
|
QSlider *slider = qobject_cast<QSlider*>(sender());
|
|
|
|
SANE_Int currentValue = value;
|
|
|
|
SANE_Int id = slider->property("config_id").toInt();
|
2024-05-05 03:29:13 +00:00
|
|
|
DeviceConfigEx *deviceConfigEx = qvariant_cast<DeviceConfigEx*>(slider->property("configex_ptr"));
|
|
|
|
|
2024-04-29 09:29:39 +00:00
|
|
|
QSpinBox* spinBox = qvariant_cast<QSpinBox*>(slider->property("relate_ctrl"));
|
|
|
|
disconnect(spinBox, SIGNAL(valueChanged(int)), this, SLOT(on_relate_spinBoxClicked(int)));
|
|
|
|
spinBox->setValue(value);
|
|
|
|
connect(spinBox, SIGNAL(valueChanged(int)), this, SLOT(on_relate_spinBoxClicked(int)));
|
|
|
|
|
|
|
|
SANE_Int method = 0;
|
|
|
|
SANE_Status ret = sane_control_option(m_devHandle, id, SANE_ACTION_SET_VALUE, ¤tValue, &method);
|
|
|
|
if (ret == SANE_STATUS_UNSUPPORTED)
|
|
|
|
{
|
|
|
|
SANE_Int v = 0;
|
|
|
|
sane_control_option(m_devHandle, id, SANE_ACTION_GET_VALUE, &v, &method);
|
|
|
|
disconnect(slider, SIGNAL(valueChanged(int)), this, SLOT(on_int_sliderClicked(int)));
|
|
|
|
disconnect(spinBox, SIGNAL(valueChanged(int)), this, SLOT(on_relate_spinBoxClicked(int)));
|
|
|
|
slider->setValue(v);
|
|
|
|
spinBox->setValue(v);
|
|
|
|
connect(slider, SIGNAL(valueChanged(int)), this, SLOT(on_int_sliderClicked(int)));
|
|
|
|
connect(spinBox, SIGNAL(valueChanged(int)), this, SLOT(on_relate_spinBoxClicked(int)));
|
|
|
|
QMessageBox::information(this, tr("Prompt"), tr("The funtion is unsupported"));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2024-05-05 03:29:13 +00:00
|
|
|
deviceConfigEx->intValue = currentValue;
|
2024-04-29 09:29:39 +00:00
|
|
|
if ((method & SANE_INFO_RELOAD_OPTIONS) == SANE_INFO_RELOAD_OPTIONS)
|
|
|
|
{
|
|
|
|
Update(id);
|
|
|
|
}
|
2024-04-24 10:08:14 +00:00
|
|
|
}
|
2024-04-26 06:11:33 +00:00
|
|
|
|
2024-04-29 09:29:39 +00:00
|
|
|
void Form_DeviceConfig::on_double_sliderClicked(int value)
|
2024-04-26 06:11:33 +00:00
|
|
|
{
|
|
|
|
QSlider *slider = qobject_cast<QSlider*>(sender());
|
2024-04-29 09:29:39 +00:00
|
|
|
SANE_Word currentValue = SANE_FIX(value / 100.0);
|
|
|
|
SANE_Int id = slider->property("config_id").toInt();
|
2024-05-05 03:29:13 +00:00
|
|
|
DeviceConfigEx *deviceConfigEx = qvariant_cast<DeviceConfigEx*>(slider->property("configex_ptr"));
|
|
|
|
|
2024-04-29 09:29:39 +00:00
|
|
|
QDoubleSpinBox* doubleSpinBox = qvariant_cast<QDoubleSpinBox*>(slider->property("relate_ctrl"));
|
|
|
|
disconnect(doubleSpinBox, SIGNAL(valueChanged(double)), this, SLOT(on_relate_doubleSpinboxClicked(double)));
|
|
|
|
doubleSpinBox->setValue(value / 100.0);
|
|
|
|
connect(doubleSpinBox, SIGNAL(valueChanged(double)), this, SLOT(on_relate_doubleSpinboxClicked(double)));
|
|
|
|
|
|
|
|
SANE_Int method = 0;
|
|
|
|
SANE_Status ret = sane_control_option(m_devHandle, id, SANE_ACTION_SET_VALUE, ¤tValue, &method);
|
|
|
|
if (ret == SANE_STATUS_UNSUPPORTED)
|
2024-04-26 06:11:33 +00:00
|
|
|
{
|
2024-04-29 09:29:39 +00:00
|
|
|
SANE_Word v = 0;
|
|
|
|
sane_control_option(m_devHandle, id, SANE_ACTION_GET_VALUE, &v, &method);
|
|
|
|
disconnect(slider, SIGNAL(valueChanged(int)), this, SLOT(on_double_sliderClicked(int)));
|
|
|
|
disconnect(doubleSpinBox, SIGNAL(valueChanged(double)), this, SLOT(on_relate_doubleSpinboxClicked(double)));
|
|
|
|
slider->setValue(round(SANE_UNFIX(v) * 100));
|
|
|
|
doubleSpinBox->setValue(SANE_UNFIX(v));
|
|
|
|
connect(slider, SIGNAL(valueChanged(int)), this, SLOT(on_double_sliderClicked(int)));
|
|
|
|
connect(doubleSpinBox, SIGNAL(valueChanged(double)), this, SLOT(on_relate_doubleSpinboxClicked(double)));
|
|
|
|
QMessageBox::information(this, tr("Prompt"), tr("The funtion is unsupported"));
|
|
|
|
return;
|
2024-04-28 03:46:44 +00:00
|
|
|
}
|
2024-04-29 09:29:39 +00:00
|
|
|
|
2024-05-05 03:29:13 +00:00
|
|
|
deviceConfigEx->doubleValue = value / 100.0;
|
2024-04-29 09:29:39 +00:00
|
|
|
if ((method & SANE_INFO_RELOAD_OPTIONS) == SANE_INFO_RELOAD_OPTIONS)
|
2024-04-28 03:46:44 +00:00
|
|
|
{
|
2024-04-29 09:29:39 +00:00
|
|
|
Update(id);
|
2024-04-26 06:11:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-04-29 09:29:39 +00:00
|
|
|
void Form_DeviceConfig::on_relate_spinBoxClicked(int value)
|
2024-04-26 06:11:33 +00:00
|
|
|
{
|
|
|
|
QSpinBox* spinBox = qobject_cast<QSpinBox*>(sender());
|
2024-04-28 03:46:44 +00:00
|
|
|
QSlider* slider = qvariant_cast<QSlider*>(spinBox->property("relate_ctrl"));
|
|
|
|
slider->setValue(value);
|
2024-04-26 06:11:33 +00:00
|
|
|
}
|
|
|
|
|
2024-04-29 09:29:39 +00:00
|
|
|
void Form_DeviceConfig::on_relate_doubleSpinboxClicked(double value)
|
2024-04-26 06:11:33 +00:00
|
|
|
{
|
2024-04-28 03:46:44 +00:00
|
|
|
QDoubleSpinBox* doubleSpinBox = qobject_cast<QDoubleSpinBox*>(sender());
|
|
|
|
QSlider* slider = qvariant_cast<QSlider*>(doubleSpinBox->property("relate_ctrl"));
|
|
|
|
slider->setValue(round(value * 100));
|
2024-04-26 06:11:33 +00:00
|
|
|
}
|
2024-04-28 10:15:51 +00:00
|
|
|
|
2024-04-29 09:29:39 +00:00
|
|
|
void Form_DeviceConfig::on_string_comboBoxClicked()
|
|
|
|
{
|
|
|
|
QComboBox *comboBox = qobject_cast<QComboBox*>(sender());
|
|
|
|
std::string currentText = comboBox->currentText().toUtf8();
|
|
|
|
SANE_Int id = comboBox->property("config_id").toInt();
|
2024-05-05 03:29:13 +00:00
|
|
|
DeviceConfigEx *deviceConfigEx = qvariant_cast<DeviceConfigEx*>(comboBox->property("configex_ptr"));
|
2024-04-29 09:29:39 +00:00
|
|
|
|
|
|
|
SANE_Int method = 0;
|
|
|
|
SANE_Status ret = sane_control_option(m_devHandle, id, SANE_ACTION_SET_VALUE, (void *)currentText.c_str(), &method);
|
|
|
|
if (ret == SANE_STATUS_UNSUPPORTED)
|
|
|
|
{
|
|
|
|
SANE_Char v[256] = {0};
|
|
|
|
sane_control_option(m_devHandle, id, SANE_ACTION_GET_VALUE, &v, &method);
|
|
|
|
disconnect(comboBox, SIGNAL(currentTextChanged(const QString)), this, SLOT(on_string_comboBoxClicked()));
|
|
|
|
comboBox->setCurrentText(QString::fromUtf8(v));
|
|
|
|
connect(comboBox, SIGNAL(currentTextChanged(const QString)), this, SLOT(on_string_comboBoxClicked()));
|
|
|
|
QMessageBox::information(this, tr("Prompt"), tr("The funtion is unsupported"));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2024-05-05 03:29:13 +00:00
|
|
|
deviceConfigEx->stringValue = currentText;
|
2024-04-29 09:29:39 +00:00
|
|
|
if ((method & SANE_INFO_RELOAD_OPTIONS) == SANE_INFO_RELOAD_OPTIONS)
|
|
|
|
{
|
|
|
|
Update(id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Form_DeviceConfig::on_spinBoxClicked(int value)
|
|
|
|
{
|
|
|
|
QSpinBox* spinBox = qobject_cast<QSpinBox*>(sender());
|
|
|
|
SANE_Int currentValue = value;
|
|
|
|
SANE_Int id = spinBox->property("config_id").toInt();
|
2024-05-05 03:29:13 +00:00
|
|
|
DeviceConfigEx *deviceConfigEx = qvariant_cast<DeviceConfigEx*>(spinBox->property("configex_ptr"));
|
2024-04-29 09:29:39 +00:00
|
|
|
|
|
|
|
SANE_Int method = 0;
|
|
|
|
SANE_Status ret = sane_control_option(m_devHandle, id, SANE_ACTION_SET_VALUE, ¤tValue, &method);
|
|
|
|
if (ret == SANE_STATUS_UNSUPPORTED)
|
|
|
|
{
|
|
|
|
SANE_Int v = 0;
|
|
|
|
sane_control_option(m_devHandle, id, SANE_ACTION_GET_VALUE, &v, &method);
|
|
|
|
disconnect(spinBox, SIGNAL(valueChanged(int)), this, SLOT(on_spinBoxClicked(int)));
|
|
|
|
spinBox->setValue(v);
|
|
|
|
connect(spinBox, SIGNAL(valueChanged(int)), this, SLOT(on_spinBoxClicked(int)));
|
|
|
|
QMessageBox::information(this, tr("Prompt"), tr("The funtion is unsupported"));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2024-05-05 03:29:13 +00:00
|
|
|
deviceConfigEx->intValue = currentValue;
|
2024-04-29 09:29:39 +00:00
|
|
|
if ((method & SANE_INFO_RELOAD_OPTIONS) == SANE_INFO_RELOAD_OPTIONS)
|
|
|
|
{
|
|
|
|
Update(id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-04-28 10:15:51 +00:00
|
|
|
void Form_DeviceConfig::on_checkedClicked()
|
|
|
|
{
|
|
|
|
QCheckBox *checkBox = qobject_cast<QCheckBox*>(sender());
|
|
|
|
SANE_Bool currentState = checkBox->isChecked();
|
|
|
|
int id = checkBox->property("config_id").toInt();
|
2024-05-05 03:29:13 +00:00
|
|
|
DeviceConfigEx *deviceConfigEx = qvariant_cast<DeviceConfigEx*>(checkBox->property("configex_ptr"));
|
2024-04-28 10:15:51 +00:00
|
|
|
|
|
|
|
SANE_Int method = 0;
|
|
|
|
SANE_Status ret = sane_control_option(m_devHandle, id, SANE_ACTION_SET_VALUE, ¤tState, &method);
|
|
|
|
if (ret == SANE_STATUS_UNSUPPORTED)
|
|
|
|
{
|
|
|
|
SANE_Bool value = false;
|
2024-04-29 09:29:39 +00:00
|
|
|
sane_control_option(m_devHandle, id, SANE_ACTION_GET_VALUE, &value, &method);
|
2024-04-28 10:15:51 +00:00
|
|
|
disconnect(checkBox, SIGNAL(stateChanged(int)), this, SLOT(on_checkedClicked()));
|
|
|
|
checkBox->setCheckState(value ? Qt::Checked : Qt::Unchecked);
|
|
|
|
connect(checkBox, SIGNAL(stateChanged(int)), this, SLOT(on_checkedClicked()));
|
|
|
|
QMessageBox::information(this, tr("Prompt"), tr("The funtion is unsupported"));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2024-05-05 03:29:13 +00:00
|
|
|
deviceConfigEx->boolValue = currentState;
|
2024-04-28 10:15:51 +00:00
|
|
|
if ((method & SANE_INFO_RELOAD_OPTIONS) == SANE_INFO_RELOAD_OPTIONS)
|
|
|
|
{
|
2024-04-29 09:29:39 +00:00
|
|
|
Update(id);
|
2024-04-28 10:15:51 +00:00
|
|
|
}
|
|
|
|
}
|