HGGitLab

Commit dbd24150 authored by luoliangyi's avatar luoliangyi

增加应用配置功能

parent de7bd5d0
#include "app_cfg.h"
#include "base/HGDef.h"
#include "base/HGInc.h"
#include "base/HGUtility.h"
#include "HGUIGlobal.h"
QString getCfgValue(const char *appName, const char *key, const QString &def)
{
HGChar cfgPath[512];
HGBase_GetConfigPath(cfgPath, 512);
strcat(cfgPath, "HGScanner.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, "HGScanner.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, "HGScanner.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);
strcat(cfgPath, "HGScanner.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);
strcat(cfgPath, "HGScanner.ini");
HGBase_SetProfileInt(cfgPath, appName, key, value);
}
void saveCfgValue(const char *appName, const char *key, bool value)
{
HGChar cfgPath[512];
HGBase_GetConfigPath(cfgPath, 512);
strcat(cfgPath, "HGScanner.ini");
HGBase_SetProfileInt(cfgPath, appName, key, (HGInt)value);
}
#ifndef __APP_CFG_H__
#define __APP_CFG_H__
#include <QString>
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);
#endif /* __APP_CFG_H__ */
......@@ -9,11 +9,11 @@
#include "base/HGInc.h"
#include "base/HGUtility.h"
#include "HGUIGlobal.h"
#include "app_cfg.h"
Dialog_AquireInto::Dialog_AquireInto(QWidget* parent) :
QDialog(parent),
ui(new Ui::Dialog_AquireInto),
m_saveQuality(0)
ui(new Ui::Dialog_AquireInto)
{
ui->setupUi(this);
......@@ -25,16 +25,17 @@ Dialog_AquireInto::Dialog_AquireInto(QWidget* parent) :
strcat(aquireIntoPath, "Huago/ScannerApp/AquireInto/");
QString filePath = getStdFileName(StdStringToUtf8(aquireIntoPath).c_str());
ui->lineEdit_directory->setText(filePath);
ui->cbtn_subFolder->setChecked(false);
m_saveQuality = getCfgValue("aquire", "quality", 0);
ui->lineEdit_directory->setText(getCfgValue("aquire", "aquireIntoPath", filePath));
ui->cbtn_subFolder->setChecked(getCfgValue("aquire", "subFolderByTime", false));
ui->cbtn_subFolderByBlank->setChecked(false);
ui->cbtn_subFolderByColor->setChecked(false);
ui->lineEdit_fileName->setText("HGScan");
ui->spin_index->setValue(1);
ui->cbox_digit->setCurrentIndex(2);
ui->lineEdit_fileName->setText(getCfgValue("aquire", "namePrefix", QString("HGScan")));
ui->spin_index->setValue(getCfgValue("aquire", "startIndex", 1));
ui->cbox_digit->setCurrentIndex(getCfgValue("aquire", "digit", 2));
ui->cbox_evenOdd->setCurrentIndex(0);
ui->cbox_format->setCurrentIndex(0);
ui->cbtn_multiFile->setChecked(false);
ui->cbox_format->setCurrentIndex(getCfgValue("aquire", "format", 0));
ui->cbtn_multiFile->setChecked(getCfgValue("aquire", "multiFile", false));
ui->radio_multiAll->setChecked(true);
ui->spinBox_multiPages->setValue(1);
......@@ -139,7 +140,14 @@ void Dialog_AquireInto::on_lineEdit_directory_textChanged(const QString& arg1)
void Dialog_AquireInto::on_buttonBox_accepted()
{
// 保存到配置文件
saveCfgValue("aquire", "quality", m_saveQuality);
saveCfgValue("aquire", "aquireIntoPath", ui->lineEdit_directory->text());
saveCfgValue("aquire", "namePrefix", ui->lineEdit_fileName->text());
saveCfgValue("aquire", "subFolderByTime", ui->cbtn_subFolder->isChecked());
saveCfgValue("aquire", "startIndex", ui->spin_index->value());
saveCfgValue("aquire", "digit", ui->cbox_digit->currentIndex());
saveCfgValue("aquire", "format", ui->cbox_format->currentIndex());
saveCfgValue("aquire", "multiFile", ui->cbtn_multiFile->isChecked());
}
void Dialog_AquireInto::on_cbox_digit_currentIndexChanged(int index)
......
......@@ -116,6 +116,12 @@
</item>
<item>
<widget class="QSpinBox" name="spin_index">
<property name="minimumSize">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
<property name="maximum">
<number>99999</number>
</property>
......
This diff is collapsed.
#include "dialog_fullscreen.h"
#include "dialog_fullscreen.h"
#include "ui_dialog_fullscreen.h"
#include "mainwindow.h"
#include "imgfmt/HGPdf.h"
......
......@@ -2,12 +2,12 @@
#include "ui_dialog_insertindex.h"
#include <QButtonGroup>
#include <QPushButton>
#include "app_cfg.h"
Dialog_InsertIndex::Dialog_InsertIndex(QWidget *parent) :
QDialog(parent),
ui(new Ui::Dialog_InsertIndex),
button_group(new QButtonGroup),
m_index(afterLast)
button_group(new QButtonGroup)
{
ui->setupUi(this);
button_group->addButton(ui->rbtn_first, 0);
......@@ -17,8 +17,17 @@ Dialog_InsertIndex::Dialog_InsertIndex(QWidget *parent) :
ui->buttonBox->button(QDialogButtonBox::Ok)->setText(tr("ok"));
ui->buttonBox->button(QDialogButtonBox::Cancel)->setText(tr("cancel"));
connect(button_group, SIGNAL(buttonClicked(int)), this, SLOT(on_rbtn_clicked(int)));
m_index = getCfgValue("insertScan", "insertType", 3);
if (0 == m_index)
ui->rbtn_first->setChecked(true);
else if (1 == m_index)
ui->rbtn_beforeCurr->setChecked(true);
else if (2 == m_index)
ui->rbtn_afterCurr->setChecked(true);
else
ui->rbtn_last->setChecked(true);
}
Dialog_InsertIndex::~Dialog_InsertIndex()
......@@ -31,3 +40,8 @@ void Dialog_InsertIndex::on_rbtn_clicked(int id)
{
m_index = id;
}
void Dialog_InsertIndex::on_buttonBox_accepted()
{
saveCfgValue("insertScan", "insertType", m_index);
}
......@@ -12,14 +12,6 @@ class Dialog_InsertIndex : public QDialog
{
Q_OBJECT
public:
enum IndexPosition{
beforeFirst,
beforeCurrent,
afterCurrent,
afterLast
};
public:
explicit Dialog_InsertIndex(QWidget *parent = nullptr);
~Dialog_InsertIndex();
......@@ -29,6 +21,8 @@ public:
private slots:
void on_rbtn_clicked(int id);
void on_buttonBox_accepted();
private:
Ui::Dialog_InsertIndex *ui;
QButtonGroup *button_group;
......
......@@ -7,6 +7,7 @@ Dialog_MoveTo::Dialog_MoveTo(int count, int pos, QWidget *parent) :
{
ui->setupUi(this);
ui->spinBox->setFixedWidth(120);
ui->spinBox->setMaximum(count);
ui->spinBox->setMinimum(0);
ui->spinBox->setValue(pos);
......
......@@ -29,28 +29,27 @@
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
<widget class="QSpinBox" name="spinBox">
<widget class="QWidget" name="">
<property name="geometry">
<rect>
<x>150</x>
<x>10</x>
<y>50</y>
<width>91</width>
<height>22</height>
</rect>
</property>
</widget>
<widget class="QLabel" name="label">
<property name="geometry">
<rect>
<x>80</x>
<y>50</y>
<width>61</width>
<width>231</width>
<height>21</height>
</rect>
</property>
<property name="text">
<string>insert pos: </string>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>insert pos: </string>
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="spinBox"/>
</item>
</layout>
</widget>
</widget>
<resources/>
......
......@@ -2,12 +2,11 @@
#include "ui_dialog_saveas.h"
#include "dialog_savequality.h"
#include "HGUIGlobal.h"
#include "app_cfg.h"
Dialog_SaveAs::Dialog_SaveAs(QWidget *parent) :
QDialog(parent)
, ui(new Ui::Dialog_SaveAs)
, m_saveQuality(0)
, m_suffix(0)
{
ui->setupUi(this);
......@@ -26,6 +25,10 @@ Dialog_SaveAs::Dialog_SaveAs(QWidget *parent) :
connect(ui->fileDialog, SIGNAL(accepted()), this, SLOT(on_dialog_accepted()));
connect(ui->fileDialog, SIGNAL(rejected()), this, SLOT(close()));
connect(ui->fileDialog, SIGNAL(filterSelected(const QString&)), this, SLOT(on_filterSelected(const QString&)));
m_saveQuality = getCfgValue("saveAs", "quality", 0);
m_suffix = getCfgValue("saveAs", "suffix", 0);
ui->fileDialog->selectNameFilter(ui->fileDialog->nameFilters().at(m_suffix));
}
Dialog_SaveAs::~Dialog_SaveAs()
......@@ -83,6 +86,8 @@ void Dialog_SaveAs::on_dialog_accepted()
m_savePath = getStdFileName(path + name + extName);
}
saveCfgValue("saveAs", "quality", m_saveQuality);
saveCfgValue("saveAs", "suffix", m_suffix);
accept();
}
......
......@@ -8,6 +8,7 @@ Dialog_SaveQuality::Dialog_SaveQuality(int quality, QWidget *parent) :
{
ui->setupUi(this);
ui->spinBox->setFixedWidth(120);
ui->spinBox->setValue(quality);
ui->buttonBox->button(QDialogButtonBox::Ok)->setText(tr("ok"));
......
......@@ -34,11 +34,11 @@
#include "imgproc/HGImgProc.h"
#include "base/HGUtility.h"
#include "HGUIGlobal.h"
#include "app_cfg.h"
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
, m_password("123456")
, m_admin_loggedIn(false)
, m_currFilePath("")
, m_currIndex(-1)
......@@ -222,7 +222,7 @@ MainWindow::MainWindow(QWidget *parent)
m_saneDeviceAction = nullptr;
m_saneDeviceHandle = nullptr;
//
m_password = getCfgValue("login", "password", "123456");
m_config.load();
SANE_Int v = 0;
......@@ -1967,6 +1967,7 @@ void MainWindow::on_act_passwordChange_triggered()
if (dlg.exec())
{
m_password = dlg.getNewPassword();
saveCfgValue("login", "password", m_password);
}
}
......
#ifndef MAINWINDOW_H
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
......
......@@ -42,6 +42,7 @@ INCLUDEPATH += $$PWD/../../../release/include/
INCLUDEPATH += $$PWD/../../../third_party/sane/
SOURCES += \
../../../app/scanner/app_cfg.cpp \
../../../app/scanner/dialog_aquireinto.cpp \
../../../app/scanner/dialog_clrcache.cpp \
../../../app/scanner/dialog_export.cpp \
......@@ -74,6 +75,7 @@ SOURCES += \
../../../ui/HGUIGlobal.cpp
HEADERS += \
../../../app/scanner/app_cfg.h \
../../../app/scanner/dialog_aquireinto.h \
../../../app/scanner/dialog_clrcache.h \
../../../app/scanner/dialog_export.h \
......
#include "HGImgThumb.h"
#include "HGImgThumb.h"
#include <QMouseEvent>
#include <QPainter>
#include <QKeyEvent>
......
#ifndef __HGIMGTHUMB_H__
#ifndef __HGIMGTHUMB_H__
#define __HGIMGTHUMB_H__
#include "base/HGDef.h"
......
#include "HGImgView.h"
#include "HGImgView.h"
#include <QMouseEvent>
#include <QPainter>
#include <QToolTip>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment