国产系统设置界面sane与twain同步

This commit is contained in:
yangjiaxuan 2023-07-14 17:04:27 +08:00
parent 21ce2efb8e
commit 64876ffdfb
14 changed files with 3120 additions and 2376 deletions

View File

@ -63,6 +63,8 @@ unix {
../../../modules/saneui/HGSaneUI.cpp \ ../../../modules/saneui/HGSaneUI.cpp \
../../../modules/saneui/cfg/cJSON.c \ ../../../modules/saneui/cfg/cJSON.c \
../../../modules/saneui/cfg/gb_json.cpp \ ../../../modules/saneui/cfg/gb_json.cpp \
../../../modules/saneui/app_cfg.cpp \
../../../modules/saneui/HGUIGlobal.cpp \
../../../modules/saneui/cutdialog.cpp \ ../../../modules/saneui/cutdialog.cpp \
../../../modules/saneui/cutpapertool.cpp \ ../../../modules/saneui/cutpapertool.cpp \
../../../modules/saneui/device_menu.cpp \ ../../../modules/saneui/device_menu.cpp \
@ -81,6 +83,8 @@ unix {
../../../modules/saneui/HGSaneUI.h \ ../../../modules/saneui/HGSaneUI.h \
../../../modules/saneui/cfg/cJSON.h \ ../../../modules/saneui/cfg/cJSON.h \
../../../modules/saneui/cfg/gb_json.h \ ../../../modules/saneui/cfg/gb_json.h \
../../../modules/saneui/app_cfg.h \
../../../modules/saneui/HGUIGlobal.h \
../../../modules/saneui/cutdialog.h \ ../../../modules/saneui/cutdialog.h \
../../../modules/saneui/cutpapertool.h \ ../../../modules/saneui/cutpapertool.h \
../../../modules/saneui/device_menu.h \ ../../../modules/saneui/device_menu.h \

View File

@ -0,0 +1,20 @@
#include "HGUIGlobal.h"
#include "base/HGDef.h"
#include "base/HGInc.h"
#include "base/HGUtility.h"
QString getStdFileName(const QString &fileName)
{
char result[512] = {0};
HGBase_StandardiseFileName(fileName.toStdString().c_str(), result, 512);
return result;
}
std::string getStdString(const QString &str)
{
#ifdef HG_CMP_MSC
return str.toLocal8Bit().data();
#else
return str.toStdString();
#endif
}

View File

@ -0,0 +1,10 @@
#ifndef __HGUIGLOBAL_H__
#define __HGUIGLOBAL_H__
#include <QString>
QString getStdFileName(const QString &fileName);
std::string getStdString(const QString &str);
#endif /* __HGUIGLOBAL_H__ */

120
modules/saneui/app_cfg.cpp Normal file
View File

@ -0,0 +1,120 @@
#include "app_cfg.h"
#include "base/HGInc.h"
#include "base/HGUtility.h"
#include "base/HGIni.h"
#include "HGUIGlobal.h"
#include "HGString.h"
#ifdef HG_CMP_MSC
#include <shlobj.h>
#endif
QString getCfgValue(const char *appName, const char *key, const QString &def)
{
HGChar cfgPath[512];
HGBase_GetConfigPath(cfgPath, 512);
strcat(cfgPath, "config.ini");
HGChar value[512] = {0};
HGBase_GetProfileString(cfgPath, appName, key, getStdString(def).c_str(), value, 512);
return StdStringToUtf8(value).c_str();
}
int getCfgValue(const char *appName, const char *key, int def)
{
HGChar cfgPath[512];
HGBase_GetConfigPath(cfgPath, 512);
strcat(cfgPath, "config.ini");
HGInt value = 0;
HGBase_GetProfileInt(cfgPath, appName, key, def, &value);
return value;
}
bool getCfgValue(const char *appName, const char *key, bool def)
{
HGChar cfgPath[512];
HGBase_GetConfigPath(cfgPath, 512);
strcat(cfgPath, "config.ini");
HGInt value = 0;
HGBase_GetProfileInt(cfgPath, appName, key, (HGInt)def, &value);
return (bool)value;
}
void saveCfgValue(const char *appName, const char *key, const QString &value)
{
HGChar cfgPath[512];
HGBase_GetConfigPath(cfgPath, 512);
HGBase_CreateDir(cfgPath);
strcat(cfgPath, "config.ini");
HGBase_SetProfileString(cfgPath, appName, key, getStdString(value).c_str());
}
void saveCfgValue(const char *appName, const char *key, int value)
{
HGChar cfgPath[512];
HGBase_GetConfigPath(cfgPath, 512);
HGBase_CreateDir(cfgPath);
strcat(cfgPath, "config.ini");
HGBase_SetProfileInt(cfgPath, appName, key, value);
}
void saveCfgValue(const char *appName, const char *key, bool value)
{
HGChar cfgPath[512];
HGBase_GetConfigPath(cfgPath, 512);
HGBase_CreateDir(cfgPath);
strcat(cfgPath, "config.ini");
HGBase_SetProfileInt(cfgPath, appName, key, (HGInt)value);
}
HGResult GetConfigPath(HGChar* configPath, HGUInt maxLen)
{
if (NULL == configPath || 0 == maxLen)
{
return HGBASE_ERR_INVALIDARG;
}
const char* appName = "HuaGoScan";
#if defined(OEM_HANWANG)
appName = "HanvonScan";
#elif defined(OEM_LISICHENG)
appName = "LanxumScan";
#elif defined(OEM_CANGTIAN)
appName = "CumtennScan";
#elif defined(OEM_ZHONGJING)
appName = "MicrotekScan";
#elif defined(OEM_ZIGUANG)
appName = "UniScan";
#endif
#if defined(HG_CMP_MSC)
CHAR cfgPath[MAX_PATH] = { 0 };
BOOL ret = SHGetSpecialFolderPathA(NULL, cfgPath, CSIDL_APPDATA, FALSE);
if (!ret)
return HGBASE_ERR_FAIL;
if (cfgPath[strlen(cfgPath) - 1] != '\\')
strcat(cfgPath, "\\");
strcat(cfgPath, appName);
strcat(cfgPath, "\\Cfg\\");
#else
char cfgPath[512] = { 0 };
struct passwd* pw = getpwuid(getuid());
strcpy(cfgPath, pw->pw_dir);
if (cfgPath[strlen(cfgPath) - 1] != '/')
strcat(cfgPath, "/");
strcat(cfgPath, ".");
strcat(cfgPath, appName);
strcat(cfgPath, "/Cfg/");
#endif
if (maxLen < strlen(cfgPath) + 1)
return HGBASE_ERR_FAIL;
strcpy(configPath, cfgPath);
return HGBASE_ERR_OK;
}

16
modules/saneui/app_cfg.h Normal file
View File

@ -0,0 +1,16 @@
#ifndef __APP_CFG_H__
#define __APP_CFG_H__
#include <QString>
#include "base/HGDef.h"
QString getCfgValue(const char *appName, const char *key, const QString &def);
int getCfgValue(const char *appName, const char *key, int def);
bool getCfgValue(const char *appName, const char *key, bool def);
void saveCfgValue(const char *appName, const char *key, const QString &value);
void saveCfgValue(const char *appName, const char *key, int value);
void saveCfgValue(const char *appName, const char *key, bool value);
HGResult GetConfigPath(HGChar* configPath, HGUInt maxLen);
#endif /* __APP_CFG_H__ */

View File

@ -1,4 +1,4 @@

#include "gb_json.h" #include "gb_json.h"
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
@ -1376,7 +1376,15 @@ namespace gb
void sane_config_schm::remove_config(const char* name) void sane_config_schm::remove_config(const char* name)
{ {
if (jsn_) if (jsn_)
jsn_->remove(name); {
if (name)
jsn_->remove(name);
else
{
jsn_->clear();
jsn_->create_empty();
}
}
} }
void sane_config_schm::set_value(const char* name, const char* val, size_t bytes, bool extra) void sane_config_schm::set_value(const char* name, const char* val, size_t bytes, bool extra)
{ {
@ -1422,6 +1430,33 @@ namespace gb
return old.size() > 0; return old.size() > 0;
} }
bool sane_config_schm::is_equal(sane_config_schm* r)
{
std::map<std::string, std::string> old;
std::string n(""), v("");
if (r->jsn_->first_child(v, &n))
{
do
{
old[n] = v;
} while (r->jsn_->next_child(v, &n));
}
if (jsn_->first_child(v, &n))
{
do
{
if (old.count(n) == 0)
return false;
if (old[n] != v)
return false;
old.erase(n);
} while (jsn_->next_child(v, &n));
}
return old.size() == 0;
}
void sane_config_schm::end_setting(bool cancel) void sane_config_schm::end_setting(bool cancel)
{ {
if (in_setting_) if (in_setting_)
@ -1557,6 +1592,9 @@ namespace gb
scanner_cfg::scanner_cfg() : path_(""), scanner_name_(""), global_(new json()) scanner_cfg::scanner_cfg() : path_(""), scanner_name_(""), global_(new json())
{ {
default_setting_name_ = QObject::tr("default_setting").toStdString(); default_setting_name_ = QObject::tr("default_setting").toStdString();
user_default_ = new gb::sane_config_schm(this);
user_default_->set_scheme_name(scanner_cfg::default_setting_name_.c_str());
init_version(); init_version();
init_select(); init_select();
} }
@ -1605,6 +1643,11 @@ namespace gb
return true; return true;
} }
std::string scanner_cfg::user_default_scheme_name(void)
{
return scanner_cfg::default_setting_name_;
}
void scanner_cfg::clear(void) void scanner_cfg::clear(void)
{ {
global_->set_value("ver", ""); global_->set_value("ver", "");
@ -1684,10 +1727,15 @@ namespace gb
return ret; return ret;
} }
int scanner_cfg::load_mem(const char* mem) int scanner_cfg::load_mem(const char* mem, bool in_base64)
{ {
base64 b64; std::string text(mem);
std::string text(b64.decode(mem, strlen(mem))); if (in_base64)
{
base64 b64;
text = b64.decode(mem, strlen(mem));
}
cJSON* root = cJSON_Parse(text.c_str()); cJSON* root = cJSON_Parse(text.c_str());
if (!root) if (!root)
@ -1702,6 +1750,23 @@ namespace gb
walk_sibling_schemes(root->child); walk_sibling_schemes(root->child);
cJSON_Delete(root); cJSON_Delete(root);
user_default_->release();
user_default_ = nullptr;
for (int i = 0; i < schemes_.size(); ++i)
{
if (schemes_[i].name == scanner_cfg::default_setting_name_)
{
user_default_ = schemes_[i].schm;
schemes_.erase(schemes_.begin() + i);
break;
}
}
if (!user_default_)
{
user_default_ = new gb::sane_config_schm(this);
}
user_default_->set_scheme_name(scanner_cfg::default_setting_name_.c_str());
return 0; return 0;
} }
int scanner_cfg::save(const char* file) int scanner_cfg::save(const char* file)
@ -1709,35 +1774,51 @@ namespace gb
if (!file && path_.empty() && scanner_name_.empty()) if (!file && path_.empty() && scanner_name_.empty())
return EINVAL; return EINVAL;
std::string cont("{\"" + scanner_cfg::global_name_ + "\":"), std::string cont(to_text(true)),
f(file ? file : path_ + scanner_name_ + ".cfg"), f(file ? file : path_ + scanner_name_ + ".cfg"),
v(""); v("");
FILE* dst = fopen(f.c_str(), "wb");
if (!dst)
return errno;
fwrite(cont.c_str(), 1, cont.length(), dst);
fclose(dst);
return 0;
}
std::string scanner_cfg::to_text(bool in_base64)
{
std::string cont("{\"" + scanner_cfg::global_name_ + "\":"),
v("");
int sel = -1; int sel = -1;
base64 b64;
if (!global_->get_value("ver", v) || v.empty()) if (!global_->get_value("ver", v) || v.empty())
init_version(); init_version();
if (!global_->get_value(scanner_cfg::cur_sel_.c_str(), sel) || sel >= schemes_.size()) if (!global_->get_value(scanner_cfg::cur_sel_.c_str(), sel) || sel >= schemes_.size())
init_select(); init_select();
// global at first ...
cont += global_->to_string(false); cont += global_->to_string(false);
for (auto& v: schemes_)
// user fixed schemes ...
for (auto& v : schemes_)
{ {
cont += ",\"" + sane_config_schm::to_hex_letter(v.name.c_str(), v.name.length()) + "\":"; cont += ",\"" + sane_config_schm::to_hex_letter(v.name.c_str(), v.name.length()) + "\":";
cont += v.schm->to_text_stream(false, false); cont += v.schm->to_text_stream(false, false);
} }
// default setting at last ...
cont += ",\"" + sane_config_schm::to_hex_letter(scanner_cfg::default_setting_name_.c_str(), scanner_cfg::default_setting_name_.length()) + "\":";
cont += user_default_->to_text_stream(false, false);
// final ...
cont += "}"; cont += "}";
base64 b64; return std::move(in_base64 ? b64.encode(cont.c_str(), cont.length()) : cont);
FILE* dst = fopen(f.c_str(), "wb");
if (!dst)
return errno;
f = b64.encode(cont.c_str(), cont.length());
fwrite(f.c_str(), 1, f.length(), dst);
fclose(dst);
return 0;
} }
void scanner_cfg::get_all_schemes(std::vector<std::string>& schemes) void scanner_cfg::get_all_schemes(std::vector<std::string>& schemes)
@ -1752,9 +1833,14 @@ namespace gb
if (scheme_name && *scheme_name) if (scheme_name && *scheme_name)
{ {
std::vector<CFGSCHM>::iterator it = std::find(schemes_.begin(), schemes_.end(), scheme_name); if (scanner_cfg::default_setting_name_ == scheme_name)
if (it != schemes_.end()) found = user_default_;
found = it->schm; else
{
std::vector<CFGSCHM>::iterator it = std::find(schemes_.begin(), schemes_.end(), scheme_name);
if (it != schemes_.end())
found = it->schm;
}
} }
else else
{ {
@ -1763,6 +1849,8 @@ namespace gb
global_->get_value(scanner_cfg::cur_sel_.c_str(), ind); global_->get_value(scanner_cfg::cur_sel_.c_str(), ind);
if (ind >= 0 && ind < schemes_.size()) if (ind >= 0 && ind < schemes_.size())
found = schemes_[ind].schm; found = schemes_[ind].schm;
else
found = user_default_;
} }
if (found) if (found)
@ -1808,6 +1896,7 @@ namespace gb
v.schm->release(); v.schm->release();
schemes_.clear(); schemes_.clear();
user_default_->remove_config(nullptr);
} }
bool scanner_cfg::select_scheme(const char* scheme_name) bool scanner_cfg::select_scheme(const char* scheme_name)
{ {
@ -1825,15 +1914,22 @@ namespace gb
{ {
if (!cp_from_name) if (!cp_from_name)
return nullptr; return nullptr;
else if (scanner_cfg::default_setting_name_ == cp_from_name)
return new sane_config_schm();
else else
{ {
std::vector<CFGSCHM>::iterator it = std::find(schemes_.begin(), schemes_.end(), cp_from_name); std::string cont("");
if (it == schemes_.end()) if (scanner_cfg::default_setting_name_ == cp_from_name)
{
cont = std::move(user_default_->to_text_stream());
}
else
{
std::vector<CFGSCHM>::iterator it = std::find(schemes_.begin(), schemes_.end(), cp_from_name);
if (it != schemes_.end())
cont = std::move(it->schm->to_text_stream());
}
if (cont.empty())
return nullptr; return nullptr;
std::string cont(it->schm->to_text_stream());
sane_config_schm* schm = new sane_config_schm(); sane_config_schm* schm = new sane_config_schm();
schm->load_from_mem(cont.c_str()); schm->load_from_mem(cont.c_str());

View File

@ -1,4 +1,4 @@
#pragma once #pragma once
#if defined(WIN32) || defined(_WIN64) #if defined(WIN32) || defined(_WIN64)
#include <Windows.h> #include <Windows.h>
@ -147,9 +147,10 @@ namespace gb
void begin_setting(bool restore = false); void begin_setting(bool restore = false);
void config_changed(const char* name, const char* val, size_t bytes, bool extra = false); void config_changed(const char* name, const char* val, size_t bytes, bool extra = false);
void config_changed(int sn, const char* val, size_t bytes, bool extra = false); void config_changed(int sn, const char* val, size_t bytes, bool extra = false);
void remove_config(const char* name); void remove_config(const char* name/*nullptr for clear*/);
void set_value(const char* name, const char* val, size_t bytes, bool extra = false); void set_value(const char* name, const char* val, size_t bytes, bool extra = false);
bool has_changed(int* items = nullptr); bool has_changed(int* items = nullptr);
bool is_equal(sane_config_schm* r);
void end_setting(bool cancel); void end_setting(bool cancel);
int id_from_name(const char* name); int id_from_name(const char* name);
std::string to_text_stream(bool b64 = true, bool with_ver = true); std::string to_text_stream(bool b64 = true, bool with_ver = true);
@ -189,6 +190,7 @@ namespace gb
} }
}CFGSCHM; }CFGSCHM;
std::vector<CFGSCHM> schemes_; std::vector<CFGSCHM> schemes_;
sane_config_schm* user_default_;
static std::string global_name_; static std::string global_name_;
static std::string cur_sel_; static std::string cur_sel_;
@ -213,11 +215,13 @@ namespace gb
void* func_param; void* func_param;
}UDF, *LPUDF; }UDF, *LPUDF;
static bool update(const char* file, LPUDF func); static bool update(const char* file, LPUDF func);
static std::string user_default_scheme_name(void);
public: public:
int load_file(const char* file); int load_file(const char* file);
int load_mem(const char* mem); int load_mem(const char* mem, bool in_base64 = true);
int save(const char* file = nullptr); int save(const char* file = nullptr);
std::string to_text(bool in_base64);
void get_all_schemes(std::vector<std::string>& schemes); // return all schemes name queue, the first is always be 'Default settings' void get_all_schemes(std::vector<std::string>& schemes); // return all schemes name queue, the first is always be 'Default settings'
sane_config_schm* get_scheme(const char* scheme_name = nullptr/*return current scheme if was null*/); // call sane_config_schm::release() if not use anymore sane_config_schm* get_scheme(const char* scheme_name = nullptr/*return current scheme if was null*/); // call sane_config_schm::release() if not use anymore

View File

@ -192,6 +192,7 @@ void cutDialog::setCutRectPixel(QRectF &rect)
m_startPoint.setY(scaleRec.height()*rect.y()/(paperHeight*realRate*0.03937*dpi)); m_startPoint.setY(scaleRec.height()*rect.y()/(paperHeight*realRate*0.03937*dpi));
m_endPoint.setX(m_startPoint.x()+scaleRec.width()*rect.width()/(paperWidth*realRate*0.03937*dpi)); m_endPoint.setX(m_startPoint.x()+scaleRec.width()*rect.width()/(paperWidth*realRate*0.03937*dpi));
m_endPoint.setY(m_startPoint.y()+scaleRec.height()*rect.height()/(paperHeight*realRate*0.03937*dpi)); m_endPoint.setY(m_startPoint.y()+scaleRec.height()*rect.height()/(paperHeight*realRate*0.03937*dpi));
m_rect = QRectF(m_startPoint,m_endPoint);
update(); update();
} }
@ -434,7 +435,7 @@ void cutDialog::mousePosition(const QPoint& e)
void cutDialog::refreshView() void cutDialog::refreshView()
{ {
if(sizeType == INCH){ if(MILLIM == sizeType || sizeType == INCH){
emit cutRectX(QString::number(getCutRectStartPos().x(),'f',2).toDouble()); emit cutRectX(QString::number(getCutRectStartPos().x(),'f',2).toDouble());
emit cutRectY(QString::number(getCutRectStartPos().y(),'f',2).toDouble()); emit cutRectY(QString::number(getCutRectStartPos().y(),'f',2).toDouble());
emit cutRectWidth(QString::number(getCutRectSize().width(),'f',2).toDouble()); emit cutRectWidth(QString::number(getCutRectSize().width(),'f',2).toDouble());

View File

@ -3,7 +3,7 @@
#include <QDebug> #include <QDebug>
#include <QValidator> #include <QValidator>
CutPaperTool::CutPaperTool(QWidget *parent) : CutPaperTool::CutPaperTool(int d, const QString& t, int w, int unit, QWidget *parent) :
QDialog(parent), QDialog(parent),
ui(new Ui::CutPaperTool) ui(new Ui::CutPaperTool)
{ {
@ -14,12 +14,19 @@ CutPaperTool::CutPaperTool(QWidget *parent) :
connect(ui->widget,SIGNAL(cutRectWidth(double)),this,SLOT(cutRectWidthSlot(double))); connect(ui->widget,SIGNAL(cutRectWidth(double)),this,SLOT(cutRectWidthSlot(double)));
connect(ui->widget,SIGNAL(cutRectHeight(double)),this,SLOT(cutRectHeightSlot(double))); connect(ui->widget,SIGNAL(cutRectHeight(double)),this,SLOT(cutRectHeightSlot(double)));
connect(ui->widget,SIGNAL(lineEditEnable(bool)),this,SLOT(lineEditEnableSlot(bool))); connect(ui->widget,SIGNAL(lineEditEnable(bool)),this,SLOT(lineEditEnableSlot(bool)));
//setDpi(200);
//setPaperType(200,"A4",400);
ui->widget->setSizeType(MILLIM); ui->widget->setSizeType(MILLIM);
dpi = d;
ui->dpiLab->setText(QString::number(dpi));
ui->widget->setDpiValue(dpi);
paperType = t;
ui->paperLab->setText(paperType);
ui->widget->setPaperSize(paperType, w);
setSizeLabel(); setSizeLabel();
//ui->pbtn_init->setFixedWidth(160);
this->setFixedWidth(ui->widget->width()+40); this->setFixedWidth(ui->widget->width()+40);
setSizeInit();
ui->comboBox_2->setCurrentIndex(unit);
} }
CutPaperTool::~CutPaperTool() CutPaperTool::~CutPaperTool()
@ -32,32 +39,27 @@ void CutPaperTool::paintEvent(QPaintEvent *)
} }
void CutPaperTool::setPaperType(const int d, const QString &t, const int& w)
{
dpi = d;
ui->dpiLab->setText(QString::number(dpi));
ui->widget->setDpiValue(dpi);
paperType = t;
ui->paperLab->setText(paperType);
ui->widget->setPaperSize(paperType,w);
//ui->widget->refreshView();
setSizeLabel();
this->setFixedWidth(ui->widget->width()+40);
setSizeInit();
}
QRectF CutPaperTool::getCutRectPixel() QRectF CutPaperTool::getCutRectPixel()
{ {
return QRectF(ui->widget->getCutRectPixel()); return QRectF(ui->widget->getCutRectPixel());
} }
void CutPaperTool::setCutRect(QRectF &rect) void CutPaperTool::setCutRectPixel(QRectF &rect)
{ {
ui->widget->setCutRectPixel(rect); ui->widget->setCutRectPixel(rect);
ui->startXEdt->setText(QString::number(rect.x()/dpi/0.03937)); ui->startXEdt->setText(QString::number(rect.x()/dpi/0.03937));
ui->startYEdt->setText(QString::number(rect.y()/dpi/0.03937)); ui->startYEdt->setText(QString::number(rect.y()/dpi/0.03937));
ui->rectWidth->setText(QString::number(rect.width()/dpi/0.03937)); ui->rectWidth->setText(QString::number(rect.width()/dpi/0.03937));
ui->rectHeight->setText(QString::number(rect.height()/dpi/0.03937)); ui->rectHeight->setText(QString::number(rect.height()/dpi/0.03937));
update();
setSizeLabel();
ui->widget->refreshView();
}
int CutPaperTool::getUnit()
{
return ui->comboBox_2->currentIndex();
} }
void CutPaperTool::setSizeLabel() void CutPaperTool::setSizeLabel()
@ -87,12 +89,6 @@ void CutPaperTool::setSizeInit()
ui->rectHeight->setText(QString::number(int(ui->widget->getPaperSize().height()))); ui->rectHeight->setText(QString::number(int(ui->widget->getPaperSize().height())));
} }
void CutPaperTool::setSizeInit(QRectF& rect){
setSizeInit();
if(rect != QRectF(0,0,0,0))
setCutRect(rect);
}
void CutPaperTool::cutRectXSlot(double x) void CutPaperTool::cutRectXSlot(double x)
{ {
ui->startXEdt->setText(QString::number(x)); ui->startXEdt->setText(QString::number(x));
@ -174,7 +170,8 @@ void CutPaperTool::on_rectHeight_textEdited(QString arg1)
void CutPaperTool::on_comboBox_2_currentIndexChanged(int index) void CutPaperTool::on_comboBox_2_currentIndexChanged(int index)
{ {
switch(index){ switch(index)
{
case 0: case 0:
ui->xLabel->setText("mm"); ui->xLabel->setText("mm");
ui->yLabel->setText("mm"); ui->yLabel->setText("mm");
@ -197,6 +194,7 @@ void CutPaperTool::on_comboBox_2_currentIndexChanged(int index)
ui->widget->setSizeType(PIXEL); ui->widget->setSizeType(PIXEL);
break; break;
} }
update(); update();
setSizeLabel(); setSizeLabel();
ui->widget->refreshView(); ui->widget->refreshView();

View File

@ -13,18 +13,16 @@ class CutPaperTool : public QDialog
Q_OBJECT Q_OBJECT
public: public:
explicit CutPaperTool(QWidget *parent = nullptr); explicit CutPaperTool(int d, const QString& t, int w, int unit, QWidget *parent = nullptr);
~CutPaperTool(); ~CutPaperTool();
void setPaperType(const int dpi, const QString& t,const int& w=200);
QRectF getCutRectPixel(); QRectF getCutRectPixel();
void setCutRect(QRectF& rect); void setCutRectPixel(QRectF& rect);
void setSizeInit(); int getUnit();
void setSizeInit(QRectF& rect);
private: private:
void paintEvent(QPaintEvent *); void paintEvent(QPaintEvent *);
void setSizeLabel(); void setSizeLabel();
void setSizeInit();
private slots: private slots:
void cutRectXSlot(double x); void cutRectXSlot(double x);

File diff suppressed because it is too large Load Diff

View File

@ -1,146 +1,171 @@
#ifndef HG_SETTING_DIALOG_H #ifndef HG_SETTING_DIALOG_H
#define HG_SETTING_DIALOG_H #define HG_SETTING_DIALOG_H
#include <QtWidgets> #include <QtWidgets>
#include <QSettings> #include <QSettings>
#include <algorithm> #include <algorithm>
#include "cfg/gb_json.h" #include "cfg/gb_json.h"
#include "device_menu.h" #include "device_menu.h"
class hg_settingdialog : public QDialog class hg_settingdialog : public QDialog
{ {
Q_OBJECT Q_OBJECT
int changed_count_; int changed_count_;
bool save_; bool save_;
bool clicked_gamma_; bool clicked_gamma_;
bool quit_ = false; bool quit_ = false;
dev_que dev_que_; // dev_que dev_que_;
gb::scanner_cfg *cur_cfg_; gb::scanner_cfg *cur_cfg_;
gb::sane_config_schm *cur_scheme_; gb::sane_config_schm *cur_scheme_;
gb::sane_config_schm *def_value_;
void refresh_control_value(int op_id);
void on_select_scheme(bool apply_to_dev = true); void refresh_control_value(int op_id);
QString gen_gamma_file_path(void); void on_select_scheme(bool apply_to_dev = true);
QString gen_gamma_file_path(void);
QMenu *top_menu_;
QLineEdit *edit_name_; QMenu *top_menu_;
QPushButton *m_pbtn_addNew; QLineEdit *edit_name_;
QPushButton *del_this_; QPushButton *m_pbtn_addNew;
QPushButton *del_all_; QPushButton* m_pbtn_Save;
QLabel *custom_area_lable_; QPushButton *m_deleteCur;
QPushButton *btn_cut_area_; QPushButton *m_deleteAll;
QPushButton *btn_gamma_; QLabel * m_label_restore;
QTextEdit *sketch_; QPushButton* m_pbtn_restore;
QLineEdit *m_lineEdit_name; QLabel *custom_area_lable_;
void create_scheme_management_ui(QVBoxLayout* layout); QPushButton *btn_cut_area_;
QString find_current_scheme_menu(int *scheme_id = nullptr); QPushButton *btn_gamma_;
QTextEdit *sketch_;
static std::string property_combox_data_type_; QLineEdit *m_lineEdit_name;
enum _cbox_type void create_scheme_management_ui(QVBoxLayout* layout);
{ QString find_current_scheme_menu(int *scheme_id = nullptr);
COMBO_VAL_STRING = 0,
COMBO_VAL_INT, static std::string property_combox_data_type_;
COMBO_VAL_FLOAT, enum _cbox_type
}; {
COMBO_VAL_STRING = 0,
public: COMBO_VAL_INT,
explicit hg_settingdialog(const SANEAPI* saneApi, SANE_Handle handle, const char *devName, QWidget *parent = nullptr); COMBO_VAL_FLOAT,
~hg_settingdialog(); };
public: public:
void initUi(); explicit hg_settingdialog(const SANEAPI* saneApi, SANE_Handle handle, const char *devName, QWidget *parent = nullptr);
void updateOpt(); ~hg_settingdialog();
void createUI();
void updateUIStatus(); static void apply_scheme(SANE_Handle dev, LPSANEAPI api, gb::sane_config_schm* schm);
QVector<QWidget*> find_control(int opt_num);
void keyPressEvent(QKeyEvent *e); public:
int get_changed_items(void); void initUi();
gb::sane_config_schm *getCurScheme(); void update_opt_value_from_driver();
void createUI();
private: void updateUIStatus();
static hg_settingdialog *hg_setting_ui_; QVector<QWidget*> find_control(int opt_num);
SANEAPI m_saneAPI; void keyPressEvent(QKeyEvent *e);
SANE_Handle m_devHandle; int get_changed_items(void);
std::string m_devName; int getCloseButtonCliked();
QTranslator m_translator; gb::sane_config_schm *getCurScheme();
QTranslator m_translator_qt;
int m_langCode; public:
enum closeButtonClicked
private: {
QString m_qstrFileName; closeButtonOk = 0,
QSettings *m_configIniWrite; closeButtonCancel,
QSettings *m_configIniRead; closeButtonNormal,
closeButtonScan,
private: };
QString md5(QString key);
const void* find_option_description(int id); // return const SANE_Option_Descriptor* pointer int m_closeButton;
const void* find_option_description(const std::string& title, int* id); // return const SANE_Option_Descriptor* pointer
private:
virtual void closeEvent(QCloseEvent* e); static hg_settingdialog *hg_setting_ui_;
virtual bool eventFilter(QObject *target, QEvent *event) override; SANEAPI m_saneAPI;
bool createMsgBoxUi(bool add, std::string &name); SANE_Handle m_devHandle;
std::string getCurUiShemeName(std::string name); std::string m_devName;
void save_scheme(void);
void cancel_setting(void); private:
std::string getAppVersion(); QString m_qstrFileName;
void apply_current_scheme(void); QSettings *m_configIniWrite;
QSettings *m_configIniRead;
private:
QVector<QPair<QPair<int, QVariant>, QString>> m_list_IdValueTitle; private:
QVector<QPair<const void*, QVariant>> m_list_defaultOptions; // default values of device QString md5(QString key);
QVector<QPair<QObject*, QObject*>> m_list_sliderSpinbox; const void* find_option_description(int id); // return const SANE_Option_Descriptor* pointer
QVector<QPair<int, const void*>> m_list_getOpt; const void* find_option_description(const std::string& title, int* id); // return const SANE_Option_Descriptor* pointer
QVector<std::string> m_list_deviceNames;
QVector<QWidget*> m_list_widgets; virtual void closeEvent(QCloseEvent* e);
virtual bool eventFilter(QObject *target, QEvent *event) override;
private slots:
void slot_checkedClicked(); void save_to_default_if_ui_not_equal_scheme(gb::sane_config_schm* cur, bool save);
void slot_sliderClicked(int value); bool createMsgBoxUi(bool add, std::string &name);
void slot_spinBoxClicked(int value); std::string getCurUiShemeName(std::string name);
void slot_doubleSpinboxClicked(double value); void save_scheme(void);
void slot_string_list_comboBoxClicked(); void cancel_setting(void);
void slot_pushButtonClicked(); std::string getAppVersion();
void slot_cutButtonClicked(); void apply_current_scheme(void);
void slot_gammaButtonClicked(); void setIcon();
void slot_word_list_comboBoxClicked(int value); void cancelScheme();
void slot_lineEditInput(); void updateSchemeFromUi(gb::sane_config_schm* schm = nullptr);
void slot_buttonAboutClicked(); void updateSchemeManagerUi();
void slot_buttonOkClicked(); void updateRestorePushButton();
void slot_buttonCancelClicked();
void slot_pushButton_scheme_management(void); private:
void on_current_scheme_changed(void); QVector<QPair<QPair<int, QVariant>, QString>> m_list_IdValueTitle;
void restore_2_default_settings(void); QVector<QPair<const void*, QVariant>> m_list_defaultOptions; // default values of device
QVector<QPair<const void*, QVariant>> m_list_originDeviceScheme;
private: QVector<QPair<QObject*, QObject*>> m_list_sliderSpinbox;
int m_dpiId; QVector<QPair<int, const void*>> m_list_getOpt;
int m_dpiValue; QVector<std::string> m_list_deviceNames;
int m_paperSizeId; QVector<QWidget*> m_list_widgets;
QString m_paperSizeValue;
int m_cutLeftId; private slots:
int m_cutTopId; void slot_checkedClicked();
int m_cutRightId; void slot_sliderClicked(int value);
int m_cutBottomId; void slot_spinBoxClicked(int value);
double m_cutWidth; // 单位是毫米 void slot_doubleSpinboxClicked(double value);
double m_cutHeight; // 单位是毫米 void slot_string_list_comboBoxClicked();
double m_cutLeftValue; // 单位是毫米 void slot_pushButtonClicked();
double m_cutTopValue; // 单位是毫米 void slot_cutButtonClicked();
double m_cutRightValue; // 单位是毫米 void slot_gammaButtonClicked();
double m_cutBottomValue; // 单位是毫米 void slot_word_list_comboBoxClicked(int value);
void slot_lineEditInput();
int m_colorModeId; void slot_buttonAboutClicked();
QString m_colorModeValue; void slot_buttonOkClicked();
SANE_Gamma m_gammaData; void slot_buttonCancelClicked();
QComboBox *comb_; void slot_pushButton_scheme_management(void);
}; void on_current_scheme_changed(void);
void restore_2_default_settings(void);
#endif // HG_SETTING_DIALOG_H
private:
int m_dpiId;
int m_dpiValue;
int m_paperSizeId;
QString m_paperSizeValue;
int m_cutLeftId;
int m_cutTopId;
int m_cutRightId;
int m_cutBottomId;
double m_cutWidth; // 单位是毫米
double m_cutHeight; // 单位是毫米
double m_cutLeftValue; // 单位是毫米
double m_cutTopValue; // 单位是毫米
double m_cutRightValue; // 单位是毫米
double m_cutBottomValue; // 单位是毫米
int m_colorModeId;
QString m_colorModeValue;
SANE_Gamma m_gammaData;
QComboBox *comb_;
bool m_isRefreshUi;
};
#endif // HG_SETTING_DIALOG_H

View File

@ -1,4 +1,4 @@
#include "setpicclrtool.h" #include "setpicclrtool.h"
#include "ui_setpicclrtool.h" #include "ui_setpicclrtool.h"
#include "widget.h" #include "widget.h"
#include <QDebug> #include <QDebug>
@ -126,6 +126,21 @@ void setPicClrTool::setGrayKeyTable(QList<QPoint> &plv)
setGrayKeyPoint(plv); setGrayKeyPoint(plv);
} }
QVector<int> setPicClrTool::getRgbAndColorType()
{
QVector<int> info;
info.clear();
info.push_back(ui->comboBox->currentIndex());
info.push_back(ui->colorSetCmb->currentIndex());
return info;
}
void setPicClrTool::setRgbAndColorType(int rgbTypeIndex, int colorTypeIndex)
{
ui->comboBox->setCurrentIndex(rgbTypeIndex);
ui->colorSetCmb->setCurrentIndex(colorTypeIndex);
}
QVector<int> setPicClrTool::getRgbALLPoint() QVector<int> setPicClrTool::getRgbALLPoint()
{ {
return ui->widget->getRgbALLPoint(); return ui->widget->getRgbALLPoint();
@ -222,7 +237,8 @@ void setPicClrTool::lineChangeSlot()
void setPicClrTool::on_colorSetCmb_currentIndexChanged(int index) void setPicClrTool::on_colorSetCmb_currentIndexChanged(int index)
{ {
(void)index; ui->widget->updateCurLinePnt(index);
//(void)index;
/* switch(index){ /* switch(index){
case RED: case RED:
ui->widget->updateCurLinePnt(RED); ui->widget->updateCurLinePnt(RED);

View File

@ -1,4 +1,4 @@
#ifndef SETPICCLRTOOL_H #ifndef SETPICCLRTOOL_H
#define SETPICCLRTOOL_H #define SETPICCLRTOOL_H
//#include "colorlinesetdef.h" //#include "colorlinesetdef.h"
@ -31,6 +31,8 @@ public:
QList<QPoint> getGrayKeyTable(); QList<QPoint> getGrayKeyTable();
void setGrayKeyTable(QList<QPoint> &plv); void setGrayKeyTable(QList<QPoint> &plv);
QVector<int> getRgbAndColorType();
void setRgbAndColorType(int rgbTypeIndex, int colorTypeIndex);
private: private:
QVector<int> getRgbALLPoint(); QVector<int> getRgbALLPoint();