This commit is contained in:
luoliangyi 2022-05-12 16:55:42 +08:00
commit f0b8f35a21
7 changed files with 308 additions and 144 deletions

View File

@ -0,0 +1,60 @@
#include "dialog_input.h"
#include "ui_dialog_input.h"
#include <qmessagebox.h>
Dialog_Input::Dialog_Input(QWidget *parent) :
QDialog(parent),
ui(new Ui::Dialog_Input)
{
ui->setupUi(this);
}
Dialog_Input::~Dialog_Input()
{
delete ui;
}
void Dialog_Input::on_pushButton_clicked()
{
std::string str(ui->lineEdit->text().toStdString());
int pos = 0;
while(pos < str.length() && str[pos++] == ' ');
if(--pos > 0)
str.erase(0, pos);
pos = str.length() - 1;
while(pos >= 0)
{
if(str[pos] != ' ')
break;
}
str.erase(pos + 1);
if(str.empty())
{
QString title(QString::fromStdString("\351\224\231\350\257\257")),
text(QString::fromStdString("\350\276\223\345\205\245\351\235\236\346\263\225"));
QMessageBox::warning(this, title, text);
return;
}
val_ = QString::fromStdString(str);
done(1);
}
void Dialog_Input::on_pushButton_2_clicked()
{
done(0);
}
void Dialog_Input::init_value(const QString& str)
{
val_ = str;
ui->lineEdit->setText(str);
ui->lineEdit->setSelection(0, str.length());
}
QString Dialog_Input::get_inputting_value(void)
{
return val_;
}

View File

@ -0,0 +1,33 @@
#ifndef DIALOG_INPUT_H
#define DIALOG_INPUT_H
#include <QDialog>
namespace Ui {
class Dialog_Input;
}
class Dialog_Input : public QDialog
{
Q_OBJECT
QString val_;
public:
explicit Dialog_Input(QWidget *parent = nullptr);
~Dialog_Input();
public:
void init_value(const QString& str);
QString get_inputting_value(void);
private slots:
void on_pushButton_clicked();
void on_pushButton_2_clicked();
private:
Ui::Dialog_Input *ui;
};
#endif // DIALOG_INPUT_H

View File

@ -0,0 +1,74 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Dialog_Input</class>
<widget class="QDialog" name="Dialog_Input">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>320</width>
<height>89</height>
</rect>
</property>
<property name="windowTitle">
<string>Dialog</string>
</property>
<widget class="QLabel" name="label">
<property name="geometry">
<rect>
<x>20</x>
<y>10</y>
<width>51</width>
<height>22</height>
</rect>
</property>
<property name="midLineWidth">
<number>-1</number>
</property>
<property name="text">
<string>输入:</string>
</property>
<property name="margin">
<number>0</number>
</property>
</widget>
<widget class="QLineEdit" name="lineEdit">
<property name="geometry">
<rect>
<x>80</x>
<y>10</y>
<width>221</width>
<height>31</height>
</rect>
</property>
</widget>
<widget class="QPushButton" name="pushButton">
<property name="geometry">
<rect>
<x>185</x>
<y>50</y>
<width>61</width>
<height>36</height>
</rect>
</property>
<property name="text">
<string>Ok</string>
</property>
</widget>
<widget class="QPushButton" name="pushButton_2">
<property name="geometry">
<rect>
<x>250</x>
<y>50</y>
<width>61</width>
<height>36</height>
</rect>
</property>
<property name="text">
<string>Cancel</string>
</property>
</widget>
</widget>
<resources/>
<connections/>
</ui>

View File

@ -7,6 +7,7 @@
#include "base/HGDef.h"
#include "../../utility/HGString.h"
#include "sane/sane_option_definitions.h"
#include "dialog_input.h"
std::string hg_settingdialog::property_combox_data_type_ = "combox_value_type";
@ -15,7 +16,7 @@ hg_settingdialog::hg_settingdialog(void *handle, QWidget *parent
: QDialog(parent)
, schemes_(cfg), cur_ind_(cfg->cur_scheme), changed_count_(0), save_(false)
, btn_cut_area_(nullptr), btn_gamma_(nullptr), cfg_file_(nullptr), clicked_gamma_(false)
, custom_area_lable_(nullptr)
, custom_area_lable_(nullptr), comb_(nullptr)
{
m_dpiId = -1;
m_dpiValue = 200;
@ -52,6 +53,7 @@ void hg_settingdialog::initUi()
updateOpt();
createUI();
setWindowTitle(schemes_ ? QString::fromStdString(schemes_->name) : tr("set"));
resize(690, height());
}
void hg_settingdialog::updateOpt()
@ -161,114 +163,92 @@ void hg_settingdialog::updateOpt()
}
}
QAction* hg_settingdialog::find_current_scheme_menu(int *scheme_id)
QString hg_settingdialog::find_current_scheme_menu(int *scheme_id)
{
QList<QAction*> acts = top_menu_->actions();
for(size_t i = 0; i < (size_t)acts.size(); ++i)
QString text(comb_->currentText());
if(scheme_id)
{
if(!acts[i]->isChecked())
continue;
if(scheme_id)
{
if(comb_->currentIndex() >= 0 && comb_->currentIndex() < comb_->count())
*scheme_id = comb_->currentIndex();
else {
*scheme_id = -1;
for(size_t j = 1; j < schemes_->schemes.size(); ++j)
{
if(schemes_->schemes[j].name != acts[i]->text().toStdString())
continue;
*scheme_id = j - 1;
break;
}
}
return acts[i];
}
return NULL;
return text;
}
void hg_settingdialog::create_scheme_management_ui(QVBoxLayout* layout)
{
QLabel *title = new QLabel(this);
QMenuBar *mb = new QMenuBar(this);
QActionGroup *group = new QActionGroup(this);
bool enabled = false;
QAction *acts = NULL;
QHBoxLayout *hbox = new QHBoxLayout();
int width = 180;
top_menu_ = new QMenu(this);
top_menu_->setTitle(tr("configuration management"));
layout->setMenuBar(mb);
mb->addMenu(top_menu_);
edit_name_ = new QLineEdit(tr("No configuration selected"), this);
comb_ = new QComboBox(this);
layout->addSpacing(30);
for(int i = 1; i < (int)schemes_->schemes.size(); ++i)
{
QAction *item = group->addAction(QString::fromStdString(schemes_->schemes[i].name));
top_menu_->addAction(item);
item->setCheckable(true);
comb_->addItem(QString::fromStdString(schemes_->schemes[i].name));
if(schemes_->cur_scheme == i - 1)
{
acts = item;
edit_name_->setText(QString::fromStdString(schemes_->schemes[i].name));
item->setChecked(true);
enabled = true;
comb_->setCurrentText(QString::fromStdString(schemes_->schemes[i].name));
}
}
connect(group, SIGNAL(triggered(QAction*)), this, SLOT(on_scheme_triggered(QAction*)));
if(schemes_->schemes.size() <= 1)
{
acts = top_menu_->addAction(tr("No custom configuration was found"));
acts->setEnabled(false);
}
title->setFixedWidth(100);
layout->addWidget(title);
layout->addSpacing(30);
title->setFixedWidth(width);
comb_->setFixedWidth(width);
title = new QLabel(this);
title->setText(tr("configuration name: "));
title->setText(QString::fromStdString("\347\216\260\346\234\211\351\205\215\347\275\256\346\226\271\346\241\210\357\274\232"));
layout->addWidget(title);
edit_name_->setEnabled(enabled);
edit_name_->setFixedWidth(title->width());
layout->addWidget(edit_name_);
layout->addWidget(comb_);
rename_ = new QPushButton(this);
rename_->setText(tr("configuration change name"));
rename_->setText(QString::fromStdString("\346\224\271\345\220\215"));
rename_->setEnabled(enabled);
rename_->setFixedWidth(title->width());
layout->addWidget(rename_);
rename_->setFixedWidth(width/3);
hbox->addWidget(rename_);
connect(rename_, SIGNAL(clicked(bool)), this, SLOT(slot_pushButton_scheme_management()));
apply_ = new QPushButton(this);
apply_->setText(tr("apply configuration-->"));
apply_->setEnabled(enabled);
apply_->setFixedWidth(title->width());
layout->addWidget(apply_);
connect(apply_, SIGNAL(clicked(bool)), this, SLOT(slot_pushButton_scheme_management()));
layout->addSpacing(10);
del_this_ = new QPushButton(this);
del_this_->setText(tr("delete configuration"));
del_this_->setText(QString::fromStdString("\345\210\240\351\231\244"));
del_this_->setEnabled(enabled);
del_this_->setFixedWidth(title->width());
layout->addWidget(del_this_);
del_this_->setFixedWidth(width / 3);
hbox->addWidget(del_this_);
connect(del_this_, SIGNAL(clicked(bool)), this, SLOT(slot_pushButton_scheme_management()));
apply_ = new QPushButton(this);
apply_->setText(QString::fromStdString("\345\272\224\347\224\250"));
apply_->setEnabled(enabled);
apply_->setFixedWidth(width / 3);
hbox->addWidget(apply_);
connect(apply_, SIGNAL(clicked(bool)), this, SLOT(slot_pushButton_scheme_management()));
hbox->setSizeConstraint(QLayout::SetFixedSize);
layout->addLayout(hbox);
layout->addSpacing(10);
del_all_ = new QPushButton(this);
del_all_->setText(tr("delete all configurations"));
del_all_->setEnabled(enabled);
del_all_->setFixedWidth(title->width());
del_all_->setFixedWidth(width);
layout->addWidget(del_all_);
connect(del_all_, SIGNAL(clicked(bool)), this, SLOT(slot_pushButton_scheme_management()));
sketch_ = new QTextEdit(this);
sketch_->setReadOnly(true);
sketch_->setFixedSize(title->width(), 200);
layout->addWidget(sketch_);
layout->addStretch();
on_scheme_triggered(acts);
title = new QLabel(this);
title->setText(QString::fromStdString("\351\205\215\347\275\256\344\277\241\346\201\257\357\274\232"));
layout->addWidget(title);
sketch_ = new QTextEdit(this);
sketch_->setReadOnly(true);
sketch_->setFixedSize(width, 200);
layout->addWidget(sketch_);
connect(comb_, SIGNAL(currentTextChanged(const QString)), this, SLOT(on_current_scheme_changed()));
on_current_scheme_changed();
}
void hg_settingdialog::createUI()
{
@ -293,11 +273,16 @@ void hg_settingdialog::createUI()
*v2 = new QVBoxLayout();
create_scheme_management_ui(v1);
v2->addWidget(tabWidgetCreation);
h->addItem(v1);
h->addItem(v2);
QGroupBox *grp = new QGroupBox(QString::fromStdString("\351\205\215\347\275\256\346\226\271\346\241\210\347\256\241\347\220\206"), this);
grp->setLayout(v1);
grp->setFixedSize(195, 500);
h->addWidget(grp);
h->addLayout(v2);
QVBoxLayout* mainVerticalLayout = new QVBoxLayout(this);
mainVerticalLayout->addItem(h);
mainVerticalLayout->addLayout(h);
// mainVerticalLayout->addWidget(tabWidgetCreation);
mainVerticalLayout->addWidget(widgetOkAndCancel);
this->setLayout(mainVerticalLayout);
@ -1799,6 +1784,9 @@ void hg_settingdialog::save_scheme(void)
if(!opt)
continue;
if(opt->cap & SANE_CAP_INACTIVE) // fixed for bug-126
continue;
if(is_equal_default_value(changed_opts_[i], opt->type))
continue;
@ -2115,28 +2103,19 @@ void hg_settingdialog::record_changed_option(int opt, const QVariant& var)
it->val = var;
}
void hg_settingdialog::on_scheme_triggered(QAction* act)
void hg_settingdialog::on_current_scheme_changed()
{
bool enabled = false;
QString scheme(comb_->currentText());
std::vector<OPTSCHEME>::iterator it = std::find(schemes_->schemes.begin(), schemes_->schemes.end(), scheme.toStdString());
bool enabled = scheme.isEmpty() ? false : it != schemes_->schemes.end();
edit_name_->setText(tr(""));
if(act)
{
std::vector<OPTSCHEME>::iterator it = std::find(schemes_->schemes.begin(), schemes_->schemes.end(), act->text().toStdString());
enabled = it != schemes_->schemes.end();
edit_name_->setText(act->text());
}
edit_name_->setCursorPosition(0);
edit_name_->setEnabled(enabled);
rename_->setEnabled(enabled);
apply_->setEnabled(enabled);
del_this_->setEnabled(enabled);
del_all_->setEnabled(enabled);
int id = -1;
int id = enabled ? it - schemes_->schemes.begin() - 1 : -1;
QString info(tr(""));
find_current_scheme_menu(&id);
if(id >= 0 && id + 1 < (int)schemes_->schemes.size())
{
const std::vector<OPTVAL>& opts = schemes_->schemes[id + 1].opts;
@ -2156,13 +2135,27 @@ void hg_settingdialog::slot_pushButton_scheme_management(void)
if(btn == rename_)
{
int id = 0;
QAction *act = find_current_scheme_menu(&id);
QString text(find_current_scheme_menu(&id));
if(!text.isEmpty() && id >= 0 && id + 1 < schemes_->schemes.size())
{
Dialog_Input dlg;
if(act)
act->setText(edit_name_->text());
if(id >= 0)
schemes_->schemes[id + 1].name = edit_name_->text().toStdString();
changed_count_++;
dlg.init_value(text);
dlg.setWindowTitle(QString::fromStdString("\351\205\215\347\275\256\346\226\271\346\241\210\346\224\271\345\220\215"));
if(dlg.exec())
{
text = dlg.get_inputting_value();
disconnect(comb_, SIGNAL(currentTextChanged(const QString)), this, SLOT(on_current_scheme_changed()));
comb_->removeItem(id);
comb_->insertItem(id, text);
comb_->setCurrentIndex(id);
connect(comb_, SIGNAL(currentTextChanged(const QString)), this, SLOT(on_current_scheme_changed()));
schemes_->schemes[id + 1].name = text.toStdString();
changed_count_++;
}
}
}
else if(btn == apply_)
{
@ -2172,52 +2165,44 @@ void hg_settingdialog::slot_pushButton_scheme_management(void)
}
else if(btn == del_this_)
{
int id = 0;
QAction *act = find_current_scheme_menu(&id);
int id = -1;
QString text(find_current_scheme_menu(&id));
if(!act)
if(id < 0 || id + 1 >= schemes_->schemes.size())
{
on_current_scheme_changed();
return;
}
if(text.isEmpty())
return;
QMessageBox msg(QMessageBox::Question, tr("be sure to delete the configuration"),
tr("Are you sure you want to delete the configuration \"") + act->text() + tr("\" ?"), QMessageBox::Yes | QMessageBox::No, this);
tr("Are you sure you want to delete the configuration \"") + text + tr("\" ?"), QMessageBox::Yes | QMessageBox::No, this);
msg.setButtonText(QMessageBox::Yes, tr("yes"));
msg.setButtonText(QMessageBox::No, tr("no"));
msg.exec();
if (msg.clickedButton() != msg.button(QMessageBox::Yes))
return;
if(id >= 0)
OPTSCHEME* s = &schemes_->schemes[id + 1];
for(size_t i = 0; i < s->opts.size(); ++i)
{
QList<QAction*> acts = top_menu_->actions();
for(size_t i = 0; i < (size_t)acts.size(); ++i)
if(s->opts[i].name == OPTION_TITLE_QYSDQX)
{
if(acts[i]->text().toStdString() == schemes_->schemes[id + 1].name)
{
top_menu_->removeAction(acts[i]);
break;
}
}
OPTSCHEME* s = &schemes_->schemes[id + 1];
for(size_t i = 0; i < s->opts.size(); ++i)
{
if(s->opts[i].name == OPTION_TITLE_QYSDQX)
{
SANE_Gamma gmma;
if(config::load_custom_gamma(s->opts[i].extra.c_str(), &gmma))
remove(s->opts[i].extra.c_str());
}
}
schemes_->schemes.erase(schemes_->schemes.begin() + id + 1);
if(top_menu_->actions().size() == 0)
{
QAction* acts = top_menu_->addAction(tr("No custom configuration was found"));
acts->setEnabled(false);
SANE_Gamma gmma;
if(config::load_custom_gamma(s->opts[i].extra.c_str(), &gmma))
remove(s->opts[i].extra.c_str());
}
}
comb_->removeItem(id);
schemes_->schemes.erase(schemes_->schemes.begin() + id + 1);
if(cur_ind_ == id)
{
cur_ind_ = -1;
on_select_scheme(-1);
}
on_scheme_triggered(NULL);
on_current_scheme_changed();
changed_count_++;
}
else if(btn == del_all_)
@ -2244,12 +2229,10 @@ void hg_settingdialog::slot_pushButton_scheme_management(void)
}
}
schemes_->schemes.erase(schemes_->schemes.begin() + 1, schemes_->schemes.end());
QAction* acts = top_menu_->addAction(tr("No custom configuration was found"));
acts->setEnabled(false);
comb_->clear();
cur_ind_ = -1;
on_select_scheme(-1);
top_menu_->clear();
on_scheme_triggered(NULL);
on_current_scheme_changed();
changed_count_++;
}
}

View File

@ -48,7 +48,7 @@ class hg_settingdialog : public QDialog
QPushButton *btn_gamma_;
QTextEdit *sketch_;
void create_scheme_management_ui(QVBoxLayout* layout);
QAction* find_current_scheme_menu(int *scheme_id = NULL);
QString find_current_scheme_menu(int *scheme_id = nullptr);
static std::string property_combox_data_type_;
enum _cbox_type
@ -121,8 +121,8 @@ private slots:
void slot_lineEditInput();
void slot_buttonOkClicked();
void slot_buttonCancelClicked();
void on_scheme_triggered(QAction*);
void slot_pushButton_scheme_management(void);
void on_current_scheme_changed(void);
private:
int m_dpiId;
@ -143,6 +143,7 @@ private:
int m_colorModeId;
QString m_colorModeValue;
SANE_Gamma m_gammaData;
QComboBox *comb_;
};
#endif // HG_SETTING_DIALOG_H

View File

@ -2061,6 +2061,11 @@ void MainWindow::on_act_clearRoller_triggered()
return;
}
if(QMessageBox::question(this, QString::fromStdString("\347\241\256\350\256\244\346\223\215\344\275\234")
, QString::fromStdString("\346\202\250\347\241\256\345\256\232\350\246\201\346\270\205\351\231\244\346\273\232\350\275\264\350\256\241\346\225\260\345\220\227\357\274\237"))
!= QMessageBox::Yes)
return;
unsigned int count = 0;
int ret = sane_io_control(cur_dev_.handle(), IO_CTRL_CODE_CLEAR_ROLLER_COUNT, nullptr, &count);
@ -2091,21 +2096,26 @@ void MainWindow::my_url_handler(const QUrl& url)
if(to.find("://clear-roller") != std::string::npos)
{
unsigned int count = 0;
int ret = sane_io_control(cur_dev_.handle(), IO_CTRL_CODE_CLEAR_ROLLER_COUNT, nullptr, &count);
QString info;
if(ret == SANE_STATUS_GOOD)
if(QMessageBox::question(this, QString::fromStdString("\347\241\256\350\256\244\346\223\215\344\275\234")
, QString::fromStdString("\346\202\250\347\241\256\345\256\232\350\246\201\346\270\205\351\231\244\346\273\232\350\275\264\350\256\241\346\225\260\345\220\227\357\274\237"))
== QMessageBox::Yes)
{
info = tr("Roller scanned count has been set to 0.");
unsigned int count = 0;
int ret = sane_io_control(cur_dev_.handle(), IO_CTRL_CODE_CLEAR_ROLLER_COUNT, nullptr, &count);
// +请重新进入关于界面以获取最新值
info += QString::fromStdString("\350\257\267\351\207\215\346\226\260\350\277\233\345\205\245\345\205\263\344\272\216\347\225\214\351\235\242\344\273\245\350\216\267\345\217\226\346\234\200\346\226\260\345\200\274");
QString info;
if(ret == SANE_STATUS_GOOD)
{
info = tr("Roller scanned count has been set to 0.");
// +请重新进入关于界面以获取最新值
info += QString::fromStdString("\350\257\267\351\207\215\346\226\260\350\277\233\345\205\245\345\205\263\344\272\216\347\225\214\351\235\242\344\273\245\350\216\267\345\217\226\346\234\200\346\226\260\345\200\274");
}
else
info = tr("Roller scanned count reset failed.");
QMessageBox::information(this, tr("hint"), info);
}
else
info = tr("Roller scanned count reset failed.");
QMessageBox::information(this, tr("hint"), info);
}
}
void MainWindow::on_act_about_triggered()

View File

@ -124,7 +124,8 @@ SOURCES += \
../../ui/HGImgThumb.cpp \
../../ui/HGImgView.cpp \
../../ui/HGUIGlobal.cpp \
../../utility/HGString.cpp
../../utility/HGString.cpp \
../../app/scanner/dialog_input.cpp
HEADERS += \
../../app/scanner/app_cfg.h \
@ -166,7 +167,8 @@ HEADERS += \
../../ui/HGImgThumb.h \
../../ui/HGImgView.h \
../../ui/HGUIGlobal.h \
../../utility/HGString.h
../../utility/HGString.h \
../../app/scanner/dialog_input.h
FORMS += \
../../app/scanner/cutdialog.ui \
@ -195,7 +197,8 @@ FORMS += \
../../app/scanner/widget.ui \
../../app/scanner/widget_imgproc_base.ui \
../../app/scanner/widget_statusbar.ui \
../../app/scanner/dialog_log.ui
../../app/scanner/dialog_log.ui \
../../app/scanner/dialog_input.ui
TRANSLATIONS += \
../../app/scanner/Scanner_zh_CN.ts \