拖拽到窗口和缩略图的功能一致化

This commit is contained in:
luoliangyi 2022-05-12 19:21:43 +08:00
parent a37cba98fc
commit 3d9e00a367
8 changed files with 7700 additions and 5714 deletions

Binary file not shown.

File diff suppressed because it is too large Load Diff

View File

@ -49,7 +49,6 @@ MainWindow::MainWindow(QWidget *parent)
, m_currIndex(-1)
, m_multiPageCount(0)
, m_multiIndex(-1)
, m_relation(false)
, m_modify(false)
, m_singleScan(false)
, m_scanType(0)
@ -111,7 +110,7 @@ MainWindow::MainWindow(QWidget *parent)
connect(m_view, SIGNAL(scaleChanged(double)), this, SLOT(on_viewerScale(double)));
connect(m_view, SIGNAL(mousePos(int, int)), this, SLOT(on_viewerMousePos(int, int)));
connect(m_view, SIGNAL(drop(const QString &)), this, SLOT(on_viewerDrop(const QString &)));
connect(m_view, SIGNAL(drop(const QStringList &)), this, SLOT(on_viewerDrop(const QStringList &)));
connect(m_view, SIGNAL(doubleClicked()), this, SLOT(on_viewerDblClick()));
connect(m_thumb, SIGNAL(itemCountChanged(int)), this, SLOT(on_itemCountChanged(int)));
connect(m_thumb, SIGNAL(itemSelectingChanged()), this, SLOT(on_itemSelectingChanged()));
@ -370,7 +369,7 @@ void MainWindow::on_currItemChanged(int index)
{
HGImage img = nullptr;
m_view->getImage(&img);
if (nullptr != img && m_relation && m_modify && -1 != m_currIndex && m_multiPageCount == 1)
if (nullptr != img && m_modify && -1 != m_currIndex && m_multiPageCount == 1)
{
assert(!m_currFilePath.isEmpty());
@ -414,14 +413,12 @@ void MainWindow::on_currItemChanged(int index)
{
m_view->addImage(img2);
HGBase_DestroyImage(img2);
m_relation = true;
m_modify = false;
}
else
{
m_view->clearImage();
m_wndStatusBar->setMousePosInfo(0, 0);
m_relation = false;
m_modify = false;
QFileInfo info(m_currFilePath);
@ -450,7 +447,6 @@ void MainWindow::on_currItemChanged(int index)
m_view->clearImage();
m_wndStatusBar->setMousePosInfo(0, 0);
m_relation = false;
m_modify = false;
}
@ -485,73 +481,9 @@ void MainWindow::on_viewerMousePos(int x, int y)
m_wndStatusBar->setMousePosInfo(x, y);
}
void MainWindow::on_viewerDrop(const QString &fileName)
void MainWindow::on_viewerDrop(const QStringList &fileNames)
{
int index = -1;
int count = 0;
m_thumb->getItemCount(&count);
for (int i = 0; i < count; ++i)
{
QString fName;
m_thumb->getItemFileName(i, fName);
assert(!fName.isEmpty());
if (fName == fileName)
{
index = i;
break;
}
}
if (-1 != index)
{
m_thumb->setCurrItem(index);
}
else
{
m_thumb->resetCurrItem();
m_thumb->addItem(fileName);
int cnt = 0;
m_thumb->getItemCount(&cnt);
m_thumb->selectItem(cnt - 1, true);
return;
HGImage img = nullptr;
HGPdfReader pdfReader = nullptr;
HGImgFmt_OpenPdfReader(getStdString(fileName).c_str(), &pdfReader);
if (nullptr != pdfReader)
{
HGPdfPageInfo pageInfo = {0, 0};
if (HGBASE_ERR_OK == HGImgFmt_GetPdfPageInfo(pdfReader, 0, &pageInfo))
{
float scale = 1.0f;
if (pageInfo.width < 1600)
scale = 1600.0f / pageInfo.width;
HGImgFmt_LoadImageFromPdfReader(pdfReader, 0, scale, scale, HGBASE_IMGTYPE_RGB, HGBASE_IMGORIGIN_TOP, &img);
}
HGImgFmt_ClosePdfReader(pdfReader);
}
else
{
HGImgFmt_LoadImage(getStdString(fileName).c_str(), 0, nullptr, HGBASE_IMGTYPE_RGB, HGBASE_IMGORIGIN_TOP, &img);
}
if (nullptr == img)
{
return;
}
m_view->addImage(img);
HGBase_DestroyImage(img);
m_relation = false;
m_modify = false;
updateStatusBarPixelInfo();
updateActionStatus();
}
m_thumb->addItems(fileNames);
}
void MainWindow::on_viewerDblClick()
@ -618,14 +550,12 @@ void MainWindow::on_multiPageLineEditFinished()
{
m_view->addImage(img);
HGBase_DestroyImage(img);
m_relation = true;
m_modify = false;
}
else
{
m_view->clearImage();
m_wndStatusBar->setMousePosInfo(0, 0);
m_relation = false;
m_modify = false;
}
@ -1116,7 +1046,7 @@ void MainWindow::updateActionStatus()
ui->act_open->setEnabled(!cur_dev_.is_online() || !m_isScanning);
ui->act_insert->setEnabled(!cur_dev_.is_online() || !m_isScanning);
ui->act_save->setEnabled(nullptr != img && m_relation && m_modify && -1 != m_currIndex && m_multiPageCount == 1
ui->act_save->setEnabled(nullptr != img && m_modify && -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));
@ -1183,7 +1113,7 @@ void MainWindow::startSaveMessageBox(QWidget* parent)
{
HGImage img = nullptr;
m_view->getImage(&img);
if (nullptr != img && m_relation && m_modify && -1 != m_currIndex && m_multiPageCount == 1)
if (nullptr != img && m_modify && -1 != m_currIndex && m_multiPageCount == 1)
{
QMessageBox msg(QMessageBox::Question, tr("Question"),
tr("modified, save it?"),
@ -1309,14 +1239,12 @@ void MainWindow::on_act_previousPage_triggered()
{
m_view->addImage(img);
HGBase_DestroyImage(img);
m_relation = true;
m_modify = false;
}
else
{
m_view->clearImage();
m_wndStatusBar->setMousePosInfo(0, 0);
m_relation = false;
m_modify = false;
}
@ -1336,14 +1264,12 @@ void MainWindow::on_act_nextPage_triggered()
{
m_view->addImage(img);
HGBase_DestroyImage(img);
m_relation = true;
m_modify = false;
}
else
{
m_view->clearImage();
m_wndStatusBar->setMousePosInfo(0, 0);
m_relation = false;
m_modify = false;
}
@ -1363,14 +1289,12 @@ void MainWindow::on_act_firstPage_triggered()
{
m_view->addImage(img);
HGBase_DestroyImage(img);
m_relation = true;
m_modify = false;
}
else
{
m_view->clearImage();
m_wndStatusBar->setMousePosInfo(0, 0);
m_relation = false;
m_modify = false;
}
@ -1390,14 +1314,12 @@ void MainWindow::on_act_lastPage_triggered()
{
m_view->addImage(img);
HGBase_DestroyImage(img);
m_relation = true;
m_modify = false;
}
else
{
m_view->clearImage();
m_wndStatusBar->setMousePosInfo(0, 0);
m_relation = false;
m_modify = false;
}
@ -1521,7 +1443,7 @@ void MainWindow::on_act_save_triggered()
{
HGImage img = nullptr;
m_view->getImage(&img);
if (nullptr == img || !m_relation || !m_modify || -1 == m_currIndex || 1 != m_multiPageCount)
if (nullptr == img || !m_modify || -1 == m_currIndex || 1 != m_multiPageCount)
{
return;
}

View File

@ -98,7 +98,7 @@ private slots:
void on_thumbContextMenu(int index);
void on_viewerScale(double scale);
void on_viewerMousePos(int x, int y);
void on_viewerDrop(const QString &fileName);
void on_viewerDrop(const QStringList &fileNames);
void on_viewerDblClick();
void on_act_moveTo_triggered();
void on_act_thumbGrid_triggered(bool checked);
@ -230,7 +230,6 @@ private:
int m_currIndex;
int m_multiPageCount;
int m_multiIndex;
bool m_relation; // m_view上的图像是否关联到m_thumb
bool m_modify; // m_view上面的图像是否改变
bool m_singleScan; // 是否单张扫描
int m_scanType; // 1-扫描到缓存目录2-扫描到本地目录

File diff suppressed because it is too large Load Diff

View File

@ -8,11 +8,11 @@
#include <QDrag>
#include <QMimeData>
#include <QFileInfo>
#include <QMessageBox>
#include "base/HGInc.h"
#include "base/HGUtility.h"
#include "imgfmt/HGImgFmt.h"
#include "HGUIGlobal.h"
#include "HGImgView.h" // for drop files type check
HGImgThumb::HGImgThumb(QWidget* parent)
@ -1185,7 +1185,12 @@ HGResult HGImgThumb::insertItems(const QStringList &fileNames, int pos)
if (!find)
{
stdFileNames.push_back(stdFileName);
HGUInt fmtType = 0;
HGImgFmt_GetImgFmtTypeFromFileName(getStdString(stdFileName).c_str(), &fmtType);
if (0 != fmtType)
{
stdFileNames.push_back(stdFileName);
}
}
}
@ -3060,14 +3065,12 @@ void HGImgThumb::dropEvent(QDropEvent *e)
continue;
}
std::string stdf(stdFileName.toStdString());
if(HGImgView::is_acceptable_image_file(stdf))
HGUInt fmtType = 0;
HGImgFmt_GetImgFmtTypeFromFileName(getStdString(stdFileName).c_str(), &fmtType);
if (0 != fmtType)
{
stdFileNames.push_back(stdFileName);
}
if(stdFileNames.empty() && urls.size())
{
HGImgView::show_no_image_in_drop_files_msgbox(this);
return;
}
}
if (-1 != m_curInsertPos && !stdFileNames.empty())
@ -3175,6 +3178,11 @@ void HGImgThumb::dropEvent(QDropEvent *e)
emit currItemChanged(m_curItemIndex);
if (newSelectedIndexs != oldSelectedIndexs)
emit itemSelectingChanged();
if (stdFileNames.empty() && urls.size() > 0)
{
QMessageBox::information(this, tr("tips"), tr("unsupported file format"));
}
}
void HGImgThumb::mouseDoubleClickEvent(QMouseEvent *e)

View File

@ -3,9 +3,10 @@
#include <QPainter>
#include <QToolTip>
#include <QMimeData>
#include "base/HGInc.h"
#include "HGUIGlobal.h"
#include <QMessageBox>
#include "base/HGInc.h"
#include "imgfmt/HGImgFmt.h"
#include "HGUIGlobal.h"
HGImgView::HGImgView(QWidget* parent)
: QWidget(parent)
@ -1238,32 +1239,6 @@ HGResult HGImgView::showColorInfo(bool show)
return HGBASE_ERR_OK;
}
bool HGImgView::is_acceptable_image_file(const std::string& path_file)
{
size_t pos = path_file.rfind('.');
if(pos++ == std::string::npos)
return false;
std::string ext(path_file.substr(pos));
std::transform(ext.begin(), ext.end(), ext.begin(), tolower);
return ext == "bmp" ||
ext == "png" ||
ext == "tif" ||
ext == "tiff" ||
ext == "pdf" ||
ext == "jpg" ||
ext == "jpeg" ||
ext == "webp" ||
ext == "svg";
}
void HGImgView::show_no_image_in_drop_files_msgbox(QWidget* parent)
{
QMessageBox::information(parent, QString::fromStdString("\344\270\215\346\216\245\345\217\227\347\232\204\346\226\207\344\273\266\347\261\273\345\236\213")
, QString::fromStdString("\346\213\226\346\233\263\346\226\207\344\273\266\345\217\252\346\216\245\345\217\227\346\211\251\345\261\225\345\220\215\344\270\272bmp\343\200\201png\343\200\201jpg\343\200\201jpeg\343\200\201tif\343\200\201tiff\343\200\201pdf \347\232\204\345\233\276\347\211\207\346\226\207\344\273\266"));
}
void HGImgView::mousePressEvent(QMouseEvent* e)
{
if (e->button() != Qt::LeftButton)
@ -1741,21 +1716,31 @@ void HGImgView::dropEvent(QDropEvent *e)
Q_UNUSED(e);
QList<QUrl> urls = e->mimeData()->urls();
bool has_img = false;
for (size_t i = 0; i < urls.size(); ++i)
QStringList fileNames;
for (QUrl url : urls)
{
std::string file(urls[i].toLocalFile().toStdString());
if(HGImgView::is_acceptable_image_file(file))
QString fileName = getStdFileName(url.toLocalFile());
HGUInt fmtType = 0;
HGImgFmt_GetImgFmtTypeFromFileName(getStdString(fileName).c_str(), &fmtType);
if (0 != fmtType)
{
has_img = true;
emit drop(QString::fromStdString(file));
fileNames.append(fileName);
}
}
if(!has_img && urls.size())
HGImgView::show_no_image_in_drop_files_msgbox(this);
m_draging = false;
if (!fileNames.empty())
{
emit drop(fileNames);
}
if (fileNames.empty() && urls.size() > 0)
{
QMessageBox::information(this, tr("tips"), tr("unsupported file format"));
}
}
void HGImgView::mouseDoubleClickEvent(QMouseEvent* e)

View File

@ -44,15 +44,12 @@ public:
HGResult showColorInfo(bool show);
static bool is_acceptable_image_file(const std::string& path_file);
static void show_no_image_in_drop_files_msgbox(QWidget* parent);
signals:
void escape();
void doubleClicked();
void mousePos(int x, int y);
void scaleChanged(double scale);
void drop(const QString &fileName);
void drop(const QStringList &fileNames);
private: