增加整数下拉框类型控件,保存自定义扫描区域数据
This commit is contained in:
parent
5e9351532a
commit
537750b6dc
|
@ -6,6 +6,9 @@
|
||||||
#include "setpicclrtool.h"
|
#include "setpicclrtool.h"
|
||||||
#include "base/HGDef.h"
|
#include "base/HGDef.h"
|
||||||
#include "../../utility/HGString.h"
|
#include "../../utility/HGString.h"
|
||||||
|
#include "sane/sane_option_definitions.h"
|
||||||
|
|
||||||
|
std::string hg_settingdialog::property_combox_data_type_ = "combox_value_type";
|
||||||
|
|
||||||
hg_settingdialog::hg_settingdialog(void *handle, QWidget *parent
|
hg_settingdialog::hg_settingdialog(void *handle, QWidget *parent
|
||||||
, DEVCFG* cfg)
|
, DEVCFG* cfg)
|
||||||
|
@ -417,7 +420,30 @@ void hg_settingdialog::createUI()
|
||||||
|
|
||||||
case SANE_CONSTRAINT_WORD_LIST:
|
case SANE_CONSTRAINT_WORD_LIST:
|
||||||
{
|
{
|
||||||
|
QComboBox* comboBoxCreation = new QComboBox(scrollArea);
|
||||||
|
comboBoxCreation->setToolTip(opt->desc);
|
||||||
|
int id = i + 1;
|
||||||
|
comboBoxCreation->setProperty("controls_id", id);
|
||||||
|
reinterpret_cast<QFormLayout*>(widget->layout())->addRow(opt->title + QString(" : "), comboBoxCreation);
|
||||||
|
|
||||||
|
auto p_str = opt->constraint.word_list;
|
||||||
|
char buf[20];
|
||||||
|
for(SANE_Int i = 0; i < p_str[0]; ++i)
|
||||||
|
{
|
||||||
|
sprintf(buf, "%d", p_str[i + 1]);
|
||||||
|
comboBoxCreation->addItem(QString::fromStdString(buf));
|
||||||
|
}
|
||||||
|
sprintf(buf, "%d", m_list_defaultOptions.at(i).second.toInt());
|
||||||
|
comboBoxCreation->setProperty(hg_settingdialog::property_combox_data_type_.c_str(), COMBO_VAL_INT);
|
||||||
|
m_list_widgets.append(comboBoxCreation);
|
||||||
|
m_list_getOpt.append(QPair<int, const void*>(id, opt));
|
||||||
|
|
||||||
|
if(ind == -1)
|
||||||
|
init.val = m_list_defaultOptions.at(i).second;
|
||||||
|
else
|
||||||
|
init.val = QVariant(QString::fromStdString(schemes_->schemes[scheme].opts[ind].val));
|
||||||
|
comboBoxCreation->setCurrentText(init.val.toString());
|
||||||
|
connect(comboBoxCreation, SIGNAL(currentTextChanged(const QString)), this, SLOT(slot_string_list_comboBoxClicked()));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -528,6 +554,7 @@ void hg_settingdialog::createUI()
|
||||||
comboBoxCreation->addItem(stringList.at(i));
|
comboBoxCreation->addItem(stringList.at(i));
|
||||||
}
|
}
|
||||||
comboBoxCreation->setCurrentText(m_list_defaultOptions.at(i).second.toString());
|
comboBoxCreation->setCurrentText(m_list_defaultOptions.at(i).second.toString());
|
||||||
|
comboBoxCreation->setProperty(hg_settingdialog::property_combox_data_type_.c_str(), COMBO_VAL_STRING);
|
||||||
//printf("Option %02d default value is: %s\n", i + 1, m_list_defaultOptions.at(i).second.toString().data());
|
//printf("Option %02d default value is: %s\n", i + 1, m_list_defaultOptions.at(i).second.toString().data());
|
||||||
|
|
||||||
m_list_widgets.append(comboBoxCreation);
|
m_list_widgets.append(comboBoxCreation);
|
||||||
|
@ -584,44 +611,46 @@ void hg_settingdialog::createUI()
|
||||||
}
|
}
|
||||||
} //switch(opt->type)
|
} //switch(opt->type)
|
||||||
|
|
||||||
if (Utf8ToStdString(opt->title) == "分辨率")
|
// if (Utf8ToStdString(opt->title) == "分辨率")
|
||||||
|
if (strcmp(opt->title, OPTION_TITLE_FBL) == 0)
|
||||||
{
|
{
|
||||||
m_dpiId = i + 1;
|
m_dpiId = i + 1;
|
||||||
m_dpiValue = m_list_defaultOptions.at(i).second.toInt();
|
m_dpiValue = m_list_defaultOptions.at(i).second.toInt();
|
||||||
}
|
}
|
||||||
|
// else if (Utf8ToStdString(opt->title) == "纸张尺寸")
|
||||||
if (Utf8ToStdString(opt->title) == "纸张尺寸")
|
else if (strcmp(opt->title, OPTION_TITLE_ZZCC) == 0)
|
||||||
{
|
{
|
||||||
m_paperSizeId = i + 1;
|
m_paperSizeId = i + 1;
|
||||||
m_paperSizeValue = m_list_defaultOptions.at(i).second.toString();
|
m_paperSizeValue = m_list_defaultOptions.at(i).second.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (0 == strcmp(opt->name, "tl-x"))
|
if (0 == strcmp(opt->name, KNOWN_OPT_NAME_CUSTOM_AREA_LEFT))
|
||||||
{
|
{
|
||||||
m_cutLeftId = i + 1;
|
m_cutLeftId = i + 1;
|
||||||
m_cutLeftValue = SANE_UNFIX(m_list_defaultOptions.at(i).second.toInt());
|
m_cutLeftValue = SANE_UNFIX(m_list_defaultOptions.at(i).second.toInt());
|
||||||
if (opt->constraint_type == SANE_CONSTRAINT_RANGE)
|
if (opt->constraint_type == SANE_CONSTRAINT_RANGE)
|
||||||
m_cutWidth = SANE_UNFIX(opt->constraint.range->max);
|
m_cutWidth = SANE_UNFIX(opt->constraint.range->max);
|
||||||
}
|
}
|
||||||
else if (0 == strcmp(opt->name, "tl-y"))
|
else if (0 == strcmp(opt->name, KNOWN_OPT_NAME_CUSTOM_AREA_TOP))
|
||||||
{
|
{
|
||||||
m_cutTopId = i + 1;
|
m_cutTopId = i + 1;
|
||||||
m_cutTopValue = SANE_UNFIX(m_list_defaultOptions.at(i).second.toInt());
|
m_cutTopValue = SANE_UNFIX(m_list_defaultOptions.at(i).second.toInt());
|
||||||
if (opt->constraint_type == SANE_CONSTRAINT_RANGE)
|
if (opt->constraint_type == SANE_CONSTRAINT_RANGE)
|
||||||
m_cutHeight = SANE_UNFIX(opt->constraint.range->max);
|
m_cutHeight = SANE_UNFIX(opt->constraint.range->max);
|
||||||
}
|
}
|
||||||
else if (0 == strcmp(opt->name, "br-x"))
|
else if (0 == strcmp(opt->name, KNOWN_OPT_NAME_CUSTOM_AREA_RIGHT))
|
||||||
{
|
{
|
||||||
m_cutRightId = i + 1;
|
m_cutRightId = i + 1;
|
||||||
m_cutRightValue = SANE_UNFIX(m_list_defaultOptions.at(i).second.toInt());
|
m_cutRightValue = SANE_UNFIX(m_list_defaultOptions.at(i).second.toInt());
|
||||||
}
|
}
|
||||||
else if (0 == strcmp(opt->name, "br-y"))
|
else if (0 == strcmp(opt->name, KNOWN_OPT_NAME_CUSTOM_AREA_BOTTOM))
|
||||||
{
|
{
|
||||||
m_cutBottomId = i + 1;
|
m_cutBottomId = i + 1;
|
||||||
m_cutBottomValue = SANE_UNFIX(m_list_defaultOptions.at(i).second.toInt());
|
m_cutBottomValue = SANE_UNFIX(m_list_defaultOptions.at(i).second.toInt());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Utf8ToStdString(opt->title) == "分辨率")
|
// if (Utf8ToStdString(opt->title) == "分辨率")
|
||||||
|
if (strcmp(opt->title, OPTION_TITLE_FBL) == 0)
|
||||||
{
|
{
|
||||||
QPushButton* pushButton = new QPushButton(this);
|
QPushButton* pushButton = new QPushButton(this);
|
||||||
pushButton->setText(StdStringToUtf8("区域裁剪").c_str());
|
pushButton->setText(StdStringToUtf8("区域裁剪").c_str());
|
||||||
|
@ -630,14 +659,14 @@ void hg_settingdialog::createUI()
|
||||||
|
|
||||||
connect(pushButton, SIGNAL(clicked(bool)), this, SLOT(slot_cutButtonClicked()));
|
connect(pushButton, SIGNAL(clicked(bool)), this, SLOT(slot_cutButtonClicked()));
|
||||||
}
|
}
|
||||||
|
// else if (Utf8ToStdString(opt->title) == "颜色模式")
|
||||||
if (Utf8ToStdString(opt->title) == "颜色模式")
|
else if (strcmp(opt->title, OPTION_TITLE_YSMS) == 0)
|
||||||
{
|
{
|
||||||
m_colorModeId = i + 1;
|
m_colorModeId = i + 1;
|
||||||
m_colorModeValue = m_list_defaultOptions.at(i).second.toString();
|
m_colorModeValue = m_list_defaultOptions.at(i).second.toString();
|
||||||
}
|
}
|
||||||
|
// else if (Utf8ToStdString(opt->title) == "伽玛" || Utf8ToStdString(opt->title) == "伽玛值")
|
||||||
if (Utf8ToStdString(opt->title) == "伽玛" || Utf8ToStdString(opt->title) == "伽玛值")
|
else if (strcmp(opt->title, OPTION_TITLE_GMZ) == 0)
|
||||||
{
|
{
|
||||||
unsigned int len = sizeof(SANE_Gamma);
|
unsigned int len = sizeof(SANE_Gamma);
|
||||||
sane_io_control(m_handle, IO_CTRL_CODE_GET_CUSTOM_GAMMA, &m_gammaData, &len);
|
sane_io_control(m_handle, IO_CTRL_CODE_GET_CUSTOM_GAMMA, &m_gammaData, &len);
|
||||||
|
@ -686,21 +715,33 @@ void hg_settingdialog::refresh_control_value(int op_id)
|
||||||
{
|
{
|
||||||
for(size_t i = 0; i < (size_t)ctrls.size(); ++i)
|
for(size_t i = 0; i < (size_t)ctrls.size(); ++i)
|
||||||
{
|
{
|
||||||
QSlider* slider = qobject_cast<QSlider*>(ctrls[i]);
|
QComboBox* comb = qobject_cast<QComboBox*>(ctrls[i]);
|
||||||
if(slider)
|
if(comb)
|
||||||
{
|
{
|
||||||
disconnect(slider, SIGNAL(valueChanged(int)), this, SLOT(slot_sliderClicked(int)));
|
char buf[40] = {0};
|
||||||
slider->setValue(m_list_defaultOptions.at(op_id - 1).second.toInt());
|
sprintf(buf, "%d", m_list_defaultOptions.at(op_id - 1).second.toInt());
|
||||||
connect(slider, SIGNAL(valueChanged(int)), this, SLOT(slot_sliderClicked(int)));
|
comb->disconnect(comb, SIGNAL(currentTextChanged(const QString)), this, SLOT(slot_string_list_comboBoxClicked()));
|
||||||
|
comb->setCurrentText(QString::fromStdString(buf));
|
||||||
|
connect(comb, SIGNAL(currentTextChanged(const QString)), this, SLOT(slot_string_list_comboBoxClicked()));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
QSpinBox* spin = qobject_cast<QSpinBox*>(ctrls[i]);
|
QSlider* slider = qobject_cast<QSlider*>(ctrls[i]);
|
||||||
if(spin)
|
if(slider)
|
||||||
{
|
{
|
||||||
disconnect(spin, SIGNAL(valueChanged(int)), this, SLOT(slot_spinBoxClicked(int)));
|
disconnect(slider, SIGNAL(valueChanged(int)), this, SLOT(slot_sliderClicked(int)));
|
||||||
spin->setValue(m_list_defaultOptions.at(op_id - 1).second.toInt());
|
slider->setValue(m_list_defaultOptions.at(op_id - 1).second.toInt());
|
||||||
connect(spin, SIGNAL(valueChanged(int)), this, SLOT(slot_spinBoxClicked(int)));
|
connect(slider, SIGNAL(valueChanged(int)), this, SLOT(slot_sliderClicked(int)));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
QSpinBox* spin = qobject_cast<QSpinBox*>(ctrls[i]);
|
||||||
|
if(spin)
|
||||||
|
{
|
||||||
|
disconnect(spin, SIGNAL(valueChanged(int)), this, SLOT(slot_spinBoxClicked(int)));
|
||||||
|
spin->setValue(m_list_defaultOptions.at(op_id - 1).second.toInt());
|
||||||
|
connect(spin, SIGNAL(valueChanged(int)), this, SLOT(slot_spinBoxClicked(int)));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -712,13 +753,22 @@ void hg_settingdialog::refresh_control_value(int op_id)
|
||||||
QDoubleSpinBox* spin = NULL;
|
QDoubleSpinBox* spin = NULL;
|
||||||
for(size_t i = 0; i < (size_t)ctrls.size(); ++i)
|
for(size_t i = 0; i < (size_t)ctrls.size(); ++i)
|
||||||
{
|
{
|
||||||
if(!slider)
|
QComboBox* comb = qobject_cast<QComboBox*>(ctrls[i]);
|
||||||
|
if(comb)
|
||||||
|
{
|
||||||
|
char buf[40] = {0};
|
||||||
|
sprintf(buf, "%f", val);
|
||||||
|
comb->disconnect(comb, SIGNAL(currentTextChanged(const QString)), this, SLOT(slot_string_list_comboBoxClicked()));
|
||||||
|
comb->setCurrentText(QString::fromStdString(buf));
|
||||||
|
connect(comb, SIGNAL(currentTextChanged(const QString)), this, SLOT(slot_string_list_comboBoxClicked()));
|
||||||
|
}
|
||||||
|
else if(!slider)
|
||||||
{
|
{
|
||||||
slider = qobject_cast<QSlider*>(ctrls[i]);
|
slider = qobject_cast<QSlider*>(ctrls[i]);
|
||||||
if(slider)
|
if(slider)
|
||||||
disconnect(slider, SIGNAL(valueChanged(int)), this, SLOT(slot_sliderClicked(int)));
|
disconnect(slider, SIGNAL(valueChanged(int)), this, SLOT(slot_sliderClicked(int)));
|
||||||
}
|
}
|
||||||
if(!spin)
|
else if(!spin)
|
||||||
{
|
{
|
||||||
spin = qobject_cast<QDoubleSpinBox*>(ctrls[i]);
|
spin = qobject_cast<QDoubleSpinBox*>(ctrls[i]);
|
||||||
if(spin)
|
if(spin)
|
||||||
|
@ -743,6 +793,7 @@ void hg_settingdialog::refresh_control_value(int op_id)
|
||||||
{
|
{
|
||||||
disconnect(comb, SIGNAL(currentTextChanged(const QString)), this, SLOT(slot_string_list_comboBoxClicked()));
|
disconnect(comb, SIGNAL(currentTextChanged(const QString)), this, SLOT(slot_string_list_comboBoxClicked()));
|
||||||
comb->setCurrentText(m_list_defaultOptions.at(op_id - 1).second.toString());
|
comb->setCurrentText(m_list_defaultOptions.at(op_id - 1).second.toString());
|
||||||
|
// comb->setProperty(hg_settingdialog::property_combox_data_type_.c_str(), COMBO_VAL_STRING);
|
||||||
connect(comb, SIGNAL(currentTextChanged(const QString)), this, SLOT(slot_string_list_comboBoxClicked()));
|
connect(comb, SIGNAL(currentTextChanged(const QString)), this, SLOT(slot_string_list_comboBoxClicked()));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -889,6 +940,7 @@ void hg_settingdialog::slot_string_list_comboBoxClicked()
|
||||||
QComboBox *comboBox = qobject_cast<QComboBox*>(sender());
|
QComboBox *comboBox = qobject_cast<QComboBox*>(sender());
|
||||||
SANE_Int id = comboBox->property("controls_id").toInt();
|
SANE_Int id = comboBox->property("controls_id").toInt();
|
||||||
std::string comboBoxcurrentItem(comboBox->currentText().toUtf8());
|
std::string comboBoxcurrentItem(comboBox->currentText().toUtf8());
|
||||||
|
int type = comboBox->property(hg_settingdialog::property_combox_data_type_.c_str()).toInt();
|
||||||
|
|
||||||
if (id == m_paperSizeId)
|
if (id == m_paperSizeId)
|
||||||
{
|
{
|
||||||
|
@ -911,25 +963,24 @@ void hg_settingdialog::slot_string_list_comboBoxClicked()
|
||||||
|
|
||||||
SANE_Int method = 0;
|
SANE_Int method = 0;
|
||||||
SANE_String buf = (SANE_String)malloc(opt->size * 2 + 4);
|
SANE_String buf = (SANE_String)malloc(opt->size * 2 + 4);
|
||||||
strcpy(buf, comboBoxcurrentItem.c_str());
|
if(type == COMBO_VAL_INT)
|
||||||
|
*((SANE_Int*)buf) = atoi(comboBoxcurrentItem.c_str());
|
||||||
|
else if(type == COMBO_VAL_FLOAT)
|
||||||
|
*((SANE_Fixed*)buf) = SANE_FIX(atof(comboBoxcurrentItem.c_str()));
|
||||||
|
else
|
||||||
|
strcpy(buf, comboBoxcurrentItem.c_str());
|
||||||
sane_control_option(m_handle, id, SANE_ACTION_SET_VALUE, buf, &method);
|
sane_control_option(m_handle, id, SANE_ACTION_SET_VALUE, buf, &method);
|
||||||
if((method & SANE_INFO_RELOAD_OPTIONS) == SANE_INFO_RELOAD_OPTIONS)
|
if((method & SANE_INFO_RELOAD_OPTIONS) == SANE_INFO_RELOAD_OPTIONS)
|
||||||
updateUIStatus();
|
updateUIStatus();
|
||||||
else if(method & SANE_INFO_INEXACT)
|
else if(method & SANE_INFO_INEXACT)
|
||||||
comboBox->setCurrentText(QString::fromStdString(buf));
|
comboBox->setCurrentText(QString::fromStdString(buf));
|
||||||
|
|
||||||
std::vector<CHANGEDOPT>::iterator it =
|
if(type == COMBO_VAL_INT)
|
||||||
std::find(changed_opts_.begin(), changed_opts_.end(), (int)id);
|
record_changed_option((int)id, *((SANE_Int*)buf));
|
||||||
if(it == changed_opts_.end())
|
else if(type == COMBO_VAL_FLOAT)
|
||||||
{
|
record_changed_option((int)id, SANE_UNFIX(*(SANE_Fixed*)buf));
|
||||||
CHANGEDOPT co;
|
else
|
||||||
co.opt = id;
|
record_changed_option((int)id, buf);
|
||||||
co.val = QVariant(buf);
|
|
||||||
changed_opts_.push_back(co);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
it->val = QVariant(buf);
|
|
||||||
}
|
|
||||||
free(buf);
|
free(buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -975,6 +1026,12 @@ void hg_settingdialog::slot_cutButtonClicked()
|
||||||
sane_control_option(m_handle, m_cutRightId, SANE_ACTION_SET_VALUE, &value, &info);
|
sane_control_option(m_handle, m_cutRightId, SANE_ACTION_SET_VALUE, &value, &info);
|
||||||
value = SANE_FIX(m_cutBottomValue);
|
value = SANE_FIX(m_cutBottomValue);
|
||||||
sane_control_option(m_handle, m_cutBottomId, SANE_ACTION_SET_VALUE, &value, &info);
|
sane_control_option(m_handle, m_cutBottomId, SANE_ACTION_SET_VALUE, &value, &info);
|
||||||
|
|
||||||
|
// write-down changes ...
|
||||||
|
record_changed_option(m_cutLeftId, m_cutLeftValue);
|
||||||
|
record_changed_option(m_cutRightId, m_cutRightValue);
|
||||||
|
record_changed_option(m_cutTopId, m_cutTopValue);
|
||||||
|
record_changed_option(m_cutBottomId, m_cutBottomValue);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1928,6 +1985,21 @@ int hg_settingdialog::apply_settings(OPTSCHEME* scheme)
|
||||||
|
|
||||||
return none;
|
return none;
|
||||||
}
|
}
|
||||||
|
void hg_settingdialog::record_changed_option(int opt, const QVariant& var)
|
||||||
|
{
|
||||||
|
std::vector<CHANGEDOPT>::iterator it =
|
||||||
|
std::find(changed_opts_.begin(), changed_opts_.end(), opt);
|
||||||
|
|
||||||
|
if(it == changed_opts_.end())
|
||||||
|
{
|
||||||
|
CHANGEDOPT chg;
|
||||||
|
chg.opt = opt;
|
||||||
|
chg.val = var;
|
||||||
|
changed_opts_.push_back(chg);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
it->val = var;
|
||||||
|
}
|
||||||
|
|
||||||
void hg_settingdialog::on_scheme_triggered(QAction* act)
|
void hg_settingdialog::on_scheme_triggered(QAction* act)
|
||||||
{
|
{
|
||||||
|
|
|
@ -44,6 +44,14 @@ class hg_settingdialog : public QDialog
|
||||||
void create_scheme_management_ui(QVBoxLayout* layout);
|
void create_scheme_management_ui(QVBoxLayout* layout);
|
||||||
QAction* find_current_scheme_menu(int *scheme_id = NULL);
|
QAction* find_current_scheme_menu(int *scheme_id = NULL);
|
||||||
|
|
||||||
|
static std::string property_combox_data_type_;
|
||||||
|
enum _cbox_type
|
||||||
|
{
|
||||||
|
COMBO_VAL_STRING = 0,
|
||||||
|
COMBO_VAL_INT,
|
||||||
|
COMBO_VAL_FLOAT,
|
||||||
|
};
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit hg_settingdialog(void *handle, QWidget *parent = nullptr,
|
explicit hg_settingdialog(void *handle, QWidget *parent = nullptr,
|
||||||
DEVCFG* cfg = nullptr);
|
DEVCFG* cfg = nullptr);
|
||||||
|
@ -83,6 +91,7 @@ private:
|
||||||
static int find_opt_setting(const char* name, const std::vector<OPTVAL>& opts);
|
static int find_opt_setting(const char* name, const std::vector<OPTVAL>& opts);
|
||||||
int apply_setting(const SANE_Option_Descriptor* desc, int opt_ind, OPTVAL* val);
|
int apply_setting(const SANE_Option_Descriptor* desc, int opt_ind, OPTVAL* val);
|
||||||
int apply_settings(OPTSCHEME* scheme);
|
int apply_settings(OPTSCHEME* scheme);
|
||||||
|
void record_changed_option(int opt, const QVariant& var);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QVector<QPair<QPair<int, QVariant>, QString>> m_list_IdValueTitle;
|
QVector<QPair<QPair<int, QVariant>, QString>> m_list_IdValueTitle;
|
||||||
|
|
Loading…
Reference in New Issue