From 7d4de68e185b46b0f064e7b4a1ea7e2f74bc8447 Mon Sep 17 00:00:00 2001 From: gb <741021719@qq.com> Date: Wed, 25 May 2022 16:52:03 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E5=AF=BC=E5=87=BA=E5=AF=B9=E8=AF=9D?= =?UTF-8?q?=E6=A1=86=EF=BC=8C=E5=B1=8F=E8=94=BD=E6=96=87=E4=BB=B6=E5=90=8D?= =?UTF-8?q?=E8=BE=93=E5=85=A5=E6=A1=86=E8=81=94=E6=83=B3=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/scanner/custom_file_dialog.h | 241 +++++++++++++++++++++++++++++++ 1 file changed, 241 insertions(+) create mode 100644 app/scanner/custom_file_dialog.h diff --git a/app/scanner/custom_file_dialog.h b/app/scanner/custom_file_dialog.h new file mode 100644 index 00000000..1ec1e711 --- /dev/null +++ b/app/scanner/custom_file_dialog.h @@ -0,0 +1,241 @@ +#ifndef CUSTOM_FILE_DIALOG_H +#define CUSTOM_FILE_DIALOG_H + +#include +#include +#include +#include +#include +#include +#include + +#define USE_FILE_DLG_WITHOUT_PROMPT + +template +class custom_file_dlg +{ + QLineEdit* edit_; + QLineEdit* new_; + QPushButton *save_; + QFileDialog *fdlg_; + QListView *list_; + + enum find_cls + { + FIND_BUTTON = 1, + FIND_LINE_EDIT, + FIND_LIST, + }; + typedef struct _find_ctrl + { + int cls; + std::string title; + QObject *found; + }FINDCTRL, *LPFINDCTRL; + + static bool find_ctrls(QObject* obj, LPFINDCTRL ret) + { + if(ret->cls == FIND_BUTTON) + { + QPushButton* btn = dynamic_cast(obj); + if(btn) + { + std::string t(btn->text().toStdString()); + if(ret->title.empty() || t == ret->title) // "\344\277\235\345\255\230(&S)") + { + ret->found = obj; + return true; + } + } + + QButtonGroup* grp = dynamic_cast(obj); + if(grp) + { + printf("Found button-group with %d buttons\n", grp->buttons().size()); + QList btns = grp->buttons(); + for(auto& b : btns) + { + btn = dynamic_cast(b); + if(btn) + { + std::string t(btn->text().toStdString()); + if(ret->title.empty() || t == ret->title) // "\344\277\235\345\255\230(&S)") + { + ret->found = obj; + return true; + } + } + } + } + } + else if(ret->cls == FIND_LINE_EDIT) + { + QLineEdit* edit = dynamic_cast(obj); + if(edit) + { + std::string t(edit->text().toStdString()); + if(ret->title.empty() || t == ret->title) // "\344\277\235\345\255\230(&S)") + { + ret->found = obj; + return true; + } + } + } + else if(ret->cls == FIND_LIST) + { + QListView *v = dynamic_cast(obj); + if(v) + { + std::string t(v->objectName().toStdString()); + if(ret->title.empty() && ret->title.empty()) // || t == ret->title) + { + ret->found = obj; + return true; + } + } + } + + + QListWidget *l = dynamic_cast(obj); + if(l) + { + printf("Found list widget\n"); + } + else { + QListView *v = dynamic_cast(obj); + if(v) + printf("Found list view: %s\n", v->objectName().toStdString().c_str()); + } + QObjectList objs(obj->children()); + for(auto& o : objs) + { + if(find_ctrls(o, ret)) + return true; + } + + return false; + } + QPushButton* save_button(void){return save_;} + QLineEdit* input_edit(bool org){return org ? edit_ : new_;} + QListView* file_list(void){return list_;} + void replace_input(QLineEdit* from, QLineEdit* tobe) + { + fdlg_->layout()->replaceWidget(from, tobe); + from->hide(); + tobe->show(); + } + +protected slots: + virtual void on_file_dialog_textChanged(const QString &path) = 0; + virtual void on_file_dialog_returnPressed() = 0; + +protected: + custom_file_dlg() : edit_(nullptr), new_(nullptr), save_(nullptr), fdlg_(nullptr), list_(nullptr) + { + } + ~custom_file_dlg() + { + } + +public: + static QLineEdit* find_input_box(QFileDialog* host) + { + FINDCTRL fc; + QObjectList objs(host->children()); + + fc.cls = FIND_LINE_EDIT; + fc.found = nullptr; + for(auto& o : objs) + { + if(custom_file_dlg::find_ctrls(o, &fc)) + break; + } + + return dynamic_cast(fc.found); + } + static QPushButton* find_button(QFileDialog* host, const char* title) + { + FINDCTRL fc; + QObjectList objs(host->children()); + + fc.cls = FIND_BUTTON; + fc.title = (title && *title) ? title : ""; + fc.found = nullptr; + for(auto& o : objs) + { + if(custom_file_dlg::find_ctrls(o, &fc)) + break; + } + + return dynamic_cast(fc.found); + } + static QListView* find_list(QFileDialog* host, const char* title) + { + FINDCTRL fc; + QObjectList objs(host->children()); + + fc.cls = FIND_LIST; + fc.title = (title && *title) ? title : ""; + fc.found = nullptr; + for(auto& o : objs) + { + if(custom_file_dlg::find_ctrls(o, &fc)) + break; + } + + return dynamic_cast(fc.found); + } + + +protected: + bool init_custom_file_dlg(QFileDialog* fdlg) + { + new_ = new QLineEdit(((T*)this)); + fdlg_ = fdlg; + edit_ = custom_file_dlg::find_input_box(fdlg); + save_ = custom_file_dlg::find_button(fdlg, "\344\277\235\345\255\230(&S)"); + list_ = custom_file_dlg::find_list(fdlg, ""); + enable_prompt(false); + ((T*)this)->connect(new_, SIGNAL(textChanged(const QString&)), (T*)this, SLOT(on_file_dialog_textChanged(const QString))); + ((T*)this)->connect(new_, SIGNAL(returnPressed()), (T*)this, SLOT(on_file_dialog_returnPressed())); + ((T*)this)->connect(fdlg, SIGNAL(currentChanged(const QString&)), (T*)this, SLOT(on_file_dialog_textChanged(const QString))); + + return edit_ && save_; + } + void enable_prompt(bool enable) + { + if(enable) + replace_input(new_, edit_); + else + replace_input(edit_, new_); + } + void on_file_name_changed(const QLineEdit* ctrl, const QString& text) + { + if(ctrl == nullptr) // send by QFileDialog + { + std::string name(text.toStdString()); + size_t pos = name.rfind('/'); + if(pos++ != std::string::npos) + name.erase(0, pos); + new_->setText(QString::fromStdString(name)); + } + else if(ctrl == edit_ && new_) + new_->setText(text); + else if(edit_) + { + list_->clearSelection(); + edit_->setText(text); + edit_->setSelection(0, text.length()); + } + + if(save_) + save_->setEnabled(!text.isEmpty()); + } + void on_file_name_press_return(void) + { + emit save_->clicked(); + } +}; + + +#endif // CUSTOM_FILE_DIALOG_H From 5dd5b2ba1903eb46dcd7417b0dc25d359fbf4fe2 Mon Sep 17 00:00:00 2001 From: gb <741021719@qq.com> Date: Wed, 25 May 2022 16:52:55 +0800 Subject: [PATCH 2/4] =?UTF-8?q?=E5=AF=BC=E5=87=BA=E5=AF=B9=E8=AF=9D?= =?UTF-8?q?=E6=A1=86=EF=BC=8C=E5=B1=8F=E8=94=BD=E6=96=87=E4=BB=B6=E5=90=8D?= =?UTF-8?q?=E8=BE=93=E5=85=A5=E6=A1=86=E8=81=94=E6=83=B3=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/scanner/dialog_export.cpp | 17 ++++ app/scanner/dialog_export.h | 13 +++ app/scanner/dialog_export.ui | 150 +++++++++++++++++++++------------- 3 files changed, 125 insertions(+), 55 deletions(-) diff --git a/app/scanner/dialog_export.cpp b/app/scanner/dialog_export.cpp index 6b815ba6..7ca08ec9 100644 --- a/app/scanner/dialog_export.cpp +++ b/app/scanner/dialog_export.cpp @@ -35,6 +35,10 @@ Dialog_Export::Dialog_Export(int total, const std::vector &selectedIndexs, connect(ui->fileDialog, SIGNAL(rejected()), this, SLOT(close())); connect(ui->fileDialog, SIGNAL(filterSelected(const QString&)), this, SLOT(on_filterSelected(const QString&))); +#ifdef USE_FILE_DLG_WITHOUT_PROMPT + init_custom_file_dlg(ui->fileDialog); +#endif + QButtonGroup* btn_group = new QButtonGroup(this); btn_group->addButton(ui->radio_chosenPages, 0); btn_group->addButton(ui->radio_allPages, 1); @@ -237,6 +241,19 @@ void Dialog_Export::on_lineEdit_nominatePages_textChanged(const QString& arg1) ui->lab_warning->setText(tr("Input is not valid.\nPage range will be 'Chosen Pages'.")); } +#ifdef USE_FILE_DLG_WITHOUT_PROMPT +void Dialog_Export::on_file_dialog_textChanged(const QString &path) +{ + QLineEdit* edit = dynamic_cast(sender()); + + on_file_name_changed(edit, path); +} +void Dialog_Export::on_file_dialog_returnPressed() +{ + on_file_name_press_return(); +} +#endif + bool Dialog_Export::isNominatedPagesLegal(const QString& page) { if (page.isEmpty()) diff --git a/app/scanner/dialog_export.h b/app/scanner/dialog_export.h index d30425a5..5bfa40e2 100644 --- a/app/scanner/dialog_export.h +++ b/app/scanner/dialog_export.h @@ -3,14 +3,22 @@ #include +// u can ONLY comment following line if u want to use filedialog as system present ! +#include "custom_file_dialog.h" + namespace Ui { class Dialog_Export; } + class Dialog_Export : public QDialog +#ifdef USE_FILE_DLG_WITHOUT_PROMPT + , public custom_file_dlg +#endif { Q_OBJECT + public: explicit Dialog_Export(int total, const std::vector &selectedIndexs, QWidget *parent = nullptr); ~Dialog_Export(); @@ -33,6 +41,11 @@ private slots: void on_radio_nominatedPages_toggled(bool checked); void on_lineEdit_nominatePages_textChanged(const QString& arg1); +#ifdef USE_FILE_DLG_WITHOUT_PROMPT + void on_file_dialog_textChanged(const QString &path) override; + void on_file_dialog_returnPressed() override; +#endif + private: bool isNominatedPagesLegal(const QString& page); void makeSaveIndexs(); diff --git a/app/scanner/dialog_export.ui b/app/scanner/dialog_export.ui index 5e196f56..b9b3594d 100644 --- a/app/scanner/dialog_export.ui +++ b/app/scanner/dialog_export.ui @@ -6,8 +6,8 @@ 0 0 - 546 - 414 + 650 + 530 @@ -17,30 +17,6 @@ - - - - - - Compression Option - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - @@ -50,25 +26,55 @@ - - - Chosen Pages - - - - - - - All Pages - - - - - - - Nominate Pages(example:1,3,6 or 3-6) - - + + + + + Nominate Pages(example:1,3,6 or 3-6) + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Chosen Pages + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + All Pages + + + + @@ -91,8 +97,10 @@ color: rgb(216, 0, 0); - Input is not valid. -Page range will be "Chosen Pages". + +Input is not valid. +Page range will be "Chosen Pages". + true @@ -114,28 +122,60 @@ Page range will be "Chosen Pages". - - - - Save as multipages (TIFF/PDF/OFD) - - - + + + + + + Save as multipages (TIFF/PDF/OFD) + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Compression Option + + + + + QFileDialog QWidget -
qfiledialog.h
+
qfiledialog.h
1
+ + radio_chosenPages + radio_nominatedPages + radio_allPages + lineEdit_nominatePages + check_saveAsMulti + btn_option + From 1f2690f15bed36aae368a2da39f9f017a846ae24 Mon Sep 17 00:00:00 2001 From: gb <741021719@qq.com> Date: Thu, 26 May 2022 09:00:58 +0800 Subject: [PATCH 3/4] =?UTF-8?q?=E5=AF=BC=E5=87=BA=E5=AF=B9=E8=AF=9D?= =?UTF-8?q?=E6=A1=86=E5=BC=B9=E5=87=BA=E6=97=B6=E5=B0=86=E7=84=A6=E7=82=B9?= =?UTF-8?q?=E8=AE=BE=E7=BD=AE=E5=88=B0=E6=96=87=E4=BB=B6=E5=90=8D=E8=BE=93?= =?UTF-8?q?=E5=85=A5=E6=A1=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/scanner/custom_file_dialog.h | 25 ++++++++++++++++--------- build-qt/HGSolution/HGScanner.pro | 3 ++- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/app/scanner/custom_file_dialog.h b/app/scanner/custom_file_dialog.h index 1ec1e711..9ab4a589 100644 --- a/app/scanner/custom_file_dialog.h +++ b/app/scanner/custom_file_dialog.h @@ -195,19 +195,26 @@ protected: edit_ = custom_file_dlg::find_input_box(fdlg); save_ = custom_file_dlg::find_button(fdlg, "\344\277\235\345\255\230(&S)"); list_ = custom_file_dlg::find_list(fdlg, ""); - enable_prompt(false); - ((T*)this)->connect(new_, SIGNAL(textChanged(const QString&)), (T*)this, SLOT(on_file_dialog_textChanged(const QString))); - ((T*)this)->connect(new_, SIGNAL(returnPressed()), (T*)this, SLOT(on_file_dialog_returnPressed())); - ((T*)this)->connect(fdlg, SIGNAL(currentChanged(const QString&)), (T*)this, SLOT(on_file_dialog_textChanged(const QString))); - + if(edit_ && save_ && list_) + { + enable_prompt(false); + ((T*)this)->connect(new_, SIGNAL(textChanged(const QString&)), (T*)this, SLOT(on_file_dialog_textChanged(const QString))); + ((T*)this)->connect(new_, SIGNAL(returnPressed()), (T*)this, SLOT(on_file_dialog_returnPressed())); + ((T*)this)->connect(fdlg, SIGNAL(currentChanged(const QString&)), (T*)this, SLOT(on_file_dialog_textChanged(const QString))); + fdlg->setFocus(); + new_->setFocus(); + } return edit_ && save_; } void enable_prompt(bool enable) { - if(enable) - replace_input(new_, edit_); - else - replace_input(edit_, new_); + if(edit_) + { + if(enable) + replace_input(new_, edit_); + else + replace_input(edit_, new_); + } } void on_file_name_changed(const QLineEdit* ctrl, const QString& text) { diff --git a/build-qt/HGSolution/HGScanner.pro b/build-qt/HGSolution/HGScanner.pro index 3fa0ca29..f1078fb7 100644 --- a/build-qt/HGSolution/HGScanner.pro +++ b/build-qt/HGSolution/HGScanner.pro @@ -202,7 +202,8 @@ HEADERS += \ ../../app/scanner/HGImgView.h \ ../../app/scanner/HGUIGlobal.h \ ../../utility/HGString.h \ - ../../app/scanner/dialog_input.h + ../../app/scanner/dialog_input.h \ + ../../app/scanner/custom_file_dialog.h FORMS += \ ../../app/scanner/cutdialog.ui \ From 272fab710b7b466c4163cbcd4ec3841cbdee53d3 Mon Sep 17 00:00:00 2001 From: 13038267101 Date: Thu, 26 May 2022 11:12:18 +0800 Subject: [PATCH 4/4] =?UTF-8?q?=E8=B0=83=E6=95=B4=E5=BA=94=E7=94=A8?= =?UTF-8?q?=E7=A8=8B=E5=BA=8F=E5=91=BD=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build-qt/HGSolution/HGScanner.pro | 2 +- build.sh | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/build-qt/HGSolution/HGScanner.pro b/build-qt/HGSolution/HGScanner.pro index f1078fb7..b4f5ca89 100644 --- a/build-qt/HGSolution/HGScanner.pro +++ b/build-qt/HGSolution/HGScanner.pro @@ -20,7 +20,7 @@ RC_ICONS = ../../app/scanner/image_rsc/logo/logo.ico # You can also select to disable deprecated APIs only up to a certain version of Qt. #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 -TARGET = HGScanner +TARGET = HuaGoScan win32 { DEFINES += _CRT_SECURE_NO_WARNINGS diff --git a/build.sh b/build.sh index 0863a296..750456b3 100755 --- a/build.sh +++ b/build.sh @@ -81,7 +81,7 @@ if [ "${1}" == "hw" ]; then sed -i "s/OEM_HUAGAO/OEM_HANWANG/g" HGScannerTmp.pro sed -i "s/hgsane/hwsane/g" HGScannerTmp.pro sed -i "s/hgdriver/hwdriver/g" HGScannerTmp.pro - sed -i "s/HGScanner/HwScanner/g" HGScannerTmp.pro + sed -i "s/HuaGoScan/HanvonScan/g" HGScannerTmp.pro sed -i "s/HGBase/HwBase/g" HGScannerTmp.pro sed -i "s/HGImgFmt/HwImgFmt/g" HGScannerTmp.pro sed -i "s/HGImgProc/HwImgProc/g" HGScannerTmp.pro @@ -90,7 +90,7 @@ elif [ "${1}" == "lsc" ]; then sed -i "s/OEM_HUAGAO/OEM_LISICHENG/g" HGScannerTmp.pro sed -i "s/hgsane/lscsane/g" HGScannerTmp.pro sed -i "s/hgdriver/lscdriver/g" HGScannerTmp.pro - sed -i "s/HGScanner/LscScanner/g" HGScannerTmp.pro + sed -i "s/HuaGoScan/LanxumScan/g" HGScannerTmp.pro sed -i "s/HGBase/LscBase/g" HGScannerTmp.pro sed -i "s/HGImgFmt/LscImgFmt/g" HGScannerTmp.pro sed -i "s/HGImgProc/LscImgProc/g" HGScannerTmp.pro