From 2d88fb76fe78c1c19d963e70d173208724a646ab Mon Sep 17 00:00:00 2001 From: luoliangyi <87842688@qq.com> Date: Fri, 13 May 2022 15:40:05 +0800 Subject: [PATCH] =?UTF-8?q?1=EF=BC=89=E7=BC=93=E5=AD=98=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E4=BF=9D=E5=AD=98=E6=97=B6=EF=BC=8C=E5=BC=B9=E5=87=BA=E5=8F=A6?= =?UTF-8?q?=E5=AD=98=E9=97=AE=E5=AF=B9=E8=AF=9D=E6=A1=86=202=EF=BC=89?= =?UTF-8?q?=E6=9C=89=E6=96=87=E4=BB=B6=E6=9C=AA=E4=BF=9D=E5=AD=98=EF=BC=8C?= =?UTF-8?q?=E5=85=B3=E9=97=AD=E6=97=B6=E8=BF=9B=E8=A1=8C=E6=8F=90=E7=A4=BA?= =?UTF-8?q?=203=EF=BC=89=E6=89=93=E5=BC=80=E5=B7=B2=E7=BB=8F=E5=AD=98?= =?UTF-8?q?=E5=9C=A8=E7=9A=84=E6=96=87=E4=BB=B6=E6=97=B6=EF=BC=8C=E6=8F=90?= =?UTF-8?q?=E7=A4=BA=E6=98=AF=E5=90=A6=E7=A7=BB=E5=8A=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/scanner/dialog_exportimagefile.cpp | 4 +- app/scanner/dialog_multirotateimagefile.cpp | 2 +- app/scanner/mainwindow.cpp | 96 ++++++++++++++--- imgfmt/HGImgFmt.cpp | 8 ++ ui/HGImgThumb.cpp | 112 +++++++++++++++----- ui/HGImgView.cpp | 6 ++ 6 files changed, 188 insertions(+), 40 deletions(-) diff --git a/app/scanner/dialog_exportimagefile.cpp b/app/scanner/dialog_exportimagefile.cpp index 7003f7bd..57288647 100644 --- a/app/scanner/dialog_exportimagefile.cpp +++ b/app/scanner/dialog_exportimagefile.cpp @@ -78,7 +78,7 @@ void Dialog_ExportImageFile::ThreadFunc(HGThread thread, HGPointer param) HGImgFmt_LoadImageFromReader(imgFmtReader, j, nullptr, HGBASE_IMGTYPE_RGB, HGBASE_IMGORIGIN_TOP, &img); if (nullptr != img) { - HGImgFmt_SaveImageToWriter(imgFmtWriter, img, nullptr, (HGUInt)p->m_saveQuality); + HGImgFmt_SaveImageToWriter(imgFmtWriter, img, nullptr); HGBase_DestroyImage(img); } } @@ -126,7 +126,7 @@ void Dialog_ExportImageFile::ThreadFunc(HGThread thread, HGPointer param) QString saveFileName = p->m_destPath + QString(StdStringToUtf8(fileName).c_str()) + p->m_destExt; - HGImgFmt_SaveImage(img, 0, nullptr, (HGUInt)p->m_saveQuality, getStdString(saveFileName).c_str()); + HGImgFmt_SaveImage(img, 0, nullptr, getStdString(saveFileName).c_str()); HGBase_DestroyImage(img); } } diff --git a/app/scanner/dialog_multirotateimagefile.cpp b/app/scanner/dialog_multirotateimagefile.cpp index 1b9026a1..c195db50 100644 --- a/app/scanner/dialog_multirotateimagefile.cpp +++ b/app/scanner/dialog_multirotateimagefile.cpp @@ -84,7 +84,7 @@ void Dialog_MultiRotateImageFile::ThreadFunc(HGThread thread, HGPointer param) img = img2; } - if (HGBASE_ERR_OK == HGImgFmt_SaveImage(img, 0, nullptr, 0, getStdString(p->m_fileList[i]).c_str())) + if (HGBASE_ERR_OK == HGImgFmt_SaveImage(img, 0, nullptr, getStdString(p->m_fileList[i]).c_str())) { emit p->updateImageFile(p->m_fileList[i]); } diff --git a/app/scanner/mainwindow.cpp b/app/scanner/mainwindow.cpp index d8ee0645..91b2dac5 100644 --- a/app/scanner/mainwindow.cpp +++ b/app/scanner/mainwindow.cpp @@ -711,13 +711,13 @@ void MainWindow::on_new_image(void *img) if (-1 == m_scanInsertPos) { QString fileName = getCacheFileName(); - HGImgFmt_SaveImage(image, 0, nullptr, 0, getStdString(fileName).c_str()); + HGImgFmt_SaveImage(image, 0, nullptr, getStdString(fileName).c_str()); m_thumb->addItem(fileName); } else { QString fileName = getCacheFileName(); - HGImgFmt_SaveImage(image, 0, nullptr, 0, getStdString(fileName).c_str()); + HGImgFmt_SaveImage(image, 0, nullptr, getStdString(fileName).c_str()); m_thumb->insertItem(fileName, m_scanInsertPos); ++m_scanInsertPos; } @@ -755,7 +755,7 @@ void MainWindow::on_new_image(void *img) } if (nullptr != m_scanImgFmtWriter) - HGImgFmt_SaveImageToWriter(m_scanImgFmtWriter, image, nullptr, (HGUInt)m_aquireIntoSaveParam.m_saveQuality); + HGImgFmt_SaveImageToWriter(m_scanImgFmtWriter, image, nullptr); } else { @@ -781,7 +781,7 @@ void MainWindow::on_new_image(void *img) } } - HGImgFmt_SaveImage(image, 0, nullptr, 0, getStdString(getStdFileName(scanFileName)).c_str()); + HGImgFmt_SaveImage(image, 0, nullptr, getStdString(getStdFileName(scanFileName)).c_str()); m_thumb->addItem(scanFileName); ++m_aquireIntoSaveParam.m_fileNameStartIndex; } @@ -1045,8 +1045,8 @@ void MainWindow::updateActionStatus() } ui->act_open->setEnabled(!cur_dev_.is_online() || !m_isScanning); - ui->act_insert->setEnabled(0 != count && (!cur_dev_.is_online() || !m_isScanning)); - ui->act_save->setEnabled(nullptr != img && m_modify && -1 != m_currIndex && m_multiPageCount == 1 + ui->act_insert->setEnabled(!cur_dev_.is_online() || !m_isScanning); + ui->act_save->setEnabled(nullptr != img && -1 != m_currIndex && m_multiPageCount == 1 && (!cur_dev_.is_online() || !m_isScanning)); ui->act_saveAs->setEnabled(nullptr != img); ui->act_Export->setEnabled(0 != count && (!cur_dev_.is_online() || !m_isScanning)); @@ -1102,7 +1102,7 @@ void MainWindow::updateActionStatus() ui->act_acquireSingle->setEnabled(cur_dev_.is_online() && !m_isScanning); ui->act_acquire->setEnabled(cur_dev_.is_online() && !m_isScanning); ui->act_scannerSettings->setEnabled(cur_dev_.is_online() && !m_isScanning); - ui->act_insertFromScanner->setEnabled(0 != count && cur_dev_.is_online() && !m_isScanning); + ui->act_insertFromScanner->setEnabled(cur_dev_.is_online() && !m_isScanning); ui->menu_scan->setEnabled(cur_dev_.is_online() && !m_isScanning); ui->menu_device->setEnabled(!cur_dev_.is_online() || !m_isScanning); @@ -1443,13 +1443,59 @@ void MainWindow::on_act_save_triggered() { HGImage img = nullptr; m_view->getImage(&img); - if (nullptr == img || !m_modify || -1 == m_currIndex || 1 != m_multiPageCount) + if (nullptr == img || -1 == m_currIndex || 1 != m_multiPageCount) { return; } assert(!m_currFilePath.isEmpty()); - if (HGBASE_ERR_OK == HGImgFmt_SaveImage(img, 0, nullptr, 0, getStdString(m_currFilePath).c_str())) + if (0 == m_currFilePath.indexOf(Dialog_ClrCache::getCachePath())) + { + Dialog_SaveAs dlg(this); + if (dlg.exec()) + { + QString savePath = dlg.getSavePath(); + + bool find = false; + int count = 0; + m_thumb->getItemCount(&count); + for (int i = 0; i < count; ++i) + { + QString fileName; + m_thumb->getItemFileName(i, fileName); + assert(!fileName.isEmpty()); + + if (fileName == savePath) + { + find = true; + break; + } + } + + if (!find) + { + int saveQuality = dlg.getSaveQuality(); + if (HGBASE_ERR_OK == HGImgFmt_SaveImage(img, 0, nullptr, getStdString(savePath).c_str())) + { + m_thumb->updateItem(m_currIndex, savePath); + m_currFilePath = savePath; + m_modify = false; + } + else + { + QMessageBox::information(this, tr("info"), tr("save failed")); + } + } + else + { + QMessageBox::information(this, tr("info"), tr("find savePath in thumbnail")); + } + } + + return; + } + + if (HGBASE_ERR_OK == HGImgFmt_SaveImage(img, 0, nullptr, getStdString(m_currFilePath).c_str())) { m_thumb->refreshItem(m_currFilePath); m_modify = false; @@ -1494,7 +1540,7 @@ void MainWindow::on_act_saveAs_triggered() if (!find) { int saveQuality = dlg.getSaveQuality(); - if (HGBASE_ERR_OK == HGImgFmt_SaveImage(img, 0, nullptr, (HGUInt)saveQuality, getStdString(savePath).c_str())) + if (HGBASE_ERR_OK == HGImgFmt_SaveImage(img, 0, nullptr, getStdString(savePath).c_str())) { } @@ -1655,12 +1701,38 @@ void MainWindow::closeEvent(QCloseEvent *e) return; } + bool cache_saved = true; int count = 0; m_thumb->getItemCount(&count); - if(count != 0) + for (int i = 0; i < count; ++i) + { + QString fileName; + m_thumb->getItemFileName(i, fileName); + if (0 == fileName.indexOf(Dialog_ClrCache::getCachePath())) + { + cache_saved = false; + break; + } + } + + if (!cache_saved || m_modify) { QMessageBox msg(QMessageBox::Question, tr("Question"), - tr("Application is about to close.Make sure all needed files are saved.\nContinue to close?"), + tr("There are pictures that have not been saved.\nAre you sure to close?"), + 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)) + { + e->ignore(); + return; + } + } + else + { + QMessageBox msg(QMessageBox::Question, tr("tips"), + tr("Are you sure to close?"), QMessageBox::Yes | QMessageBox::No, this); msg.setButtonText(QMessageBox::Yes, tr("yes")); msg.setButtonText(QMessageBox::No, tr("no")); diff --git a/imgfmt/HGImgFmt.cpp b/imgfmt/HGImgFmt.cpp index efa2d472..b1a51985 100644 --- a/imgfmt/HGImgFmt.cpp +++ b/imgfmt/HGImgFmt.cpp @@ -533,6 +533,7 @@ HGResult HGAPI HGImgFmt_SaveImage(HGImage image, HGUInt fmtType, const HGImgFmtS if (NULL != info) { + jpegInfo.quality = 80; jpegInfo.densityUnit = HGIMGFMT_JPEGDENUNIT_INCH; jpegInfo.xDensity = info->xDpi; jpegInfo.yDensity = info->yDpi; @@ -584,6 +585,7 @@ HGResult HGAPI HGImgFmt_SaveImage(HGImage image, HGUInt fmtType, const HGImgFmtS if (NULL != info) { + tiffInfo.compression = HGIMGFMT_TIFFCOMP_LZW; tiffInfo.resolutionUnit = HGIMGFMT_TIFFRESUNIT_INCH; tiffInfo.xResolution = (float)info->xDpi; tiffInfo.yResolution = (float)info->yDpi; @@ -608,6 +610,7 @@ HGResult HGAPI HGImgFmt_SaveImage(HGImage image, HGUInt fmtType, const HGImgFmtS if (NULL != info) { + jpegInfo.quality = 80; jpegInfo.densityUnit = HGIMGFMT_JPEGDENUNIT_INCH; jpegInfo.xDensity = info->xDpi; jpegInfo.yDensity = info->yDpi; @@ -633,6 +636,7 @@ HGResult HGAPI HGImgFmt_SaveImage(HGImage image, HGUInt fmtType, const HGImgFmtS if (NULL != info) { + jpegInfo.quality = 80; jpegInfo.densityUnit = HGIMGFMT_JPEGDENUNIT_INCH; jpegInfo.xDensity = info->xDpi; jpegInfo.yDensity = info->yDpi; @@ -1113,6 +1117,7 @@ HGResult HGAPI HGImgFmt_SaveImageToWriter(HGImgFmtWriter writer, HGImage image, if (NULL != info) { + jpegInfo.quality = 80; jpegInfo.densityUnit = HGIMGFMT_JPEGDENUNIT_INCH; jpegInfo.xDensity = info->xDpi; jpegInfo.yDensity = info->yDpi; @@ -1185,6 +1190,7 @@ HGResult HGAPI HGImgFmt_SaveImageToWriter(HGImgFmtWriter writer, HGImage image, if (NULL != info) { + tiffInfo.compression = HGIMGFMT_TIFFCOMP_LZW; tiffInfo.resolutionUnit = HGIMGFMT_TIFFRESUNIT_INCH; tiffInfo.xResolution = (float)info->xDpi; tiffInfo.yResolution = (float)info->yDpi; @@ -1200,6 +1206,7 @@ HGResult HGAPI HGImgFmt_SaveImageToWriter(HGImgFmtWriter writer, HGImage image, if (NULL != info) { + jpegInfo.quality = 80; jpegInfo.densityUnit = HGIMGFMT_JPEGDENUNIT_INCH; jpegInfo.xDensity = info->xDpi; jpegInfo.yDensity = info->yDpi; @@ -1216,6 +1223,7 @@ HGResult HGAPI HGImgFmt_SaveImageToWriter(HGImgFmtWriter writer, HGImage image, if (NULL != info) { + jpegInfo.quality = 80; jpegInfo.densityUnit = HGIMGFMT_JPEGDENUNIT_INCH; jpegInfo.xDensity = info->xDpi; jpegInfo.yDensity = info->yDpi; diff --git a/ui/HGImgThumb.cpp b/ui/HGImgThumb.cpp index 210613d5..0aadff5c 100644 --- a/ui/HGImgThumb.cpp +++ b/ui/HGImgThumb.cpp @@ -1163,6 +1163,7 @@ HGResult HGImgThumb::insertItems(const QStringList &fileNames, int pos) return HGBASE_ERR_INVALIDARG; } + bool findInThumb = false; std::vector stdFileNames; for (int i = 0; i < (int)fileNames.size(); ++i) { @@ -1183,22 +1184,24 @@ HGResult HGImgThumb::insertItems(const QStringList &fileNames, int pos) } } - bool findInThumb = false; - for (int j = 0; j < (int)m_frontItems.size(); ++j) - { - if (m_frontItems[j]->fileName == stdFileName) - { - findInThumb = true; - break; - } - } - - if (!find && !findInThumb) + if (!find) { HGUInt fmtType = 0; HGImgFmt_GetImgFmtTypeFromFileName(getStdString(stdFileName).c_str(), &fmtType); if (0 != fmtType) { + if (!findInThumb) + { + for (int i = 0; i < (int)m_frontItems.size(); ++i) + { + if (m_frontItems[i]->fileName == stdFileName) + { + findInThumb = true; + break; + } + } + } + stdFileNames.push_back(stdFileName); } } @@ -1206,9 +1209,29 @@ HGResult HGImgThumb::insertItems(const QStringList &fileNames, int pos) if (stdFileNames.empty()) { + if (!fileNames.empty()) + { + QMessageBox::information(this, tr("tips"), tr("unsupported file format")); + } + return HGBASE_ERR_INVALIDARG; } + bool isMove = false; + if (findInThumb) + { + QMessageBox msg(QMessageBox::Question, tr("Question"), + tr("some files have been loaded, do you want to move?"), + 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)) + { + isMove = true; + } + } + reset(); int oldItemCount = (int)m_frontItems.size(); @@ -1230,25 +1253,64 @@ HGResult HGImgThumb::insertItems(const QStringList &fileNames, int pos) for (int i = 0; i < (int)stdFileNames.size(); ++i) { const QString &stdFileName = stdFileNames[i]; + int oldIndex = findIndex(stdFileName); + if (-1 == oldIndex) + { + HGImgThumbItem *item = new HGImgThumbItem; + item->fileName = stdFileName; + item->selected = true; - HGImgThumbItem *item = new HGImgThumbItem; - item->fileName = stdFileName; - item->selected = true; + HGBase_EnterLock(m_lockFront); + item->selected = true; + if (posEx != (int)m_frontItems.size()) + m_frontItems.insert(m_frontItems.begin() + posEx, item); + else + m_frontItems.push_back(item); + HGBase_LeaveLock(m_lockFront); - HGBase_EnterLock(m_lockFront); - item->selected = true; - if (posEx != (int)m_frontItems.size()) - m_frontItems.insert(m_frontItems.begin() + posEx, item); + HGBase_EnterLock(m_lockBack); + m_backList.push_back(stdFileName); + HGBase_LeaveLock(m_lockBack); + HGBase_SetEvent(m_event); + + ++posEx; + } else - m_frontItems.push_back(item); - HGBase_LeaveLock(m_lockFront); + { + if (isMove) + { + HGImgThumbItem *item = m_frontItems[oldIndex]; + item->selected = true; - HGBase_EnterLock(m_lockBack); - m_backList.push_back(stdFileName); - HGBase_LeaveLock(m_lockBack); - HGBase_SetEvent(m_event); + if (oldIndex < posEx) + { + if (pos == posEx) + { + --pos; + } - ++posEx; + --posEx; + } + + HGBase_EnterLock(m_lockFront); + m_frontItems.erase(m_frontItems.begin() + oldIndex); + if (posEx != (int)m_frontItems.size()) + m_frontItems.insert(m_frontItems.begin() + posEx, item); + else + m_frontItems.push_back(item); + HGBase_LeaveLock(m_lockFront); + + ++posEx; + } + else + { + m_frontItems[oldIndex]->selected = true; + m_curItemIndex = oldIndex; + m_signItemIndex = oldIndex; + locateItem(oldIndex); + recalcShowRect(this->width(), this->height(), m_scrollSize, m_type, m_hScroll, m_vScroll, m_showThumb, m_thumbRect); + } + } } if (pos != posEx) diff --git a/ui/HGImgView.cpp b/ui/HGImgView.cpp index 95db9a16..723e273e 100644 --- a/ui/HGImgView.cpp +++ b/ui/HGImgView.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include "base/HGInc.h" #include "imgfmt/HGImgFmt.h" #include "HGUIGlobal.h" @@ -1721,6 +1722,11 @@ void HGImgView::dropEvent(QDropEvent *e) for (QUrl url : urls) { QString fileName = getStdFileName(url.toLocalFile()); + QFileInfo fileInfo(fileName); + if (!fileInfo.isFile()) + { + continue; + } HGUInt fmtType = 0; HGImgFmt_GetImgFmtTypeFromFileName(getStdString(fileName).c_str(), &fmtType);