HGGitLab

Commit 4c1ae170 authored by luoliangyi's avatar luoliangyi

1)Scanner减少不必要的图像加载,提高使用体验

2)HGImgThumb减少不必要的CurrItemChanged信号
parent 9dd1a588
......@@ -9,8 +9,6 @@ Dialog_ExportImageFile::Dialog_ExportImageFile(const QString &destFile, int save
, m_destFile(destFile)
, m_saveQuality(saveQuality)
, m_srcFiles(srcFiles)
, m_stopThread(false)
, m_thread(nullptr)
{
ui->setupUi(this);
......@@ -21,24 +19,21 @@ Dialog_ExportImageFile::Dialog_ExportImageFile(const QString &destFile, int save
connect(this, SIGNAL(updateProgress(int)), this, SLOT(on_updateProgress(int)), Qt::QueuedConnection);
connect(this, SIGNAL(finish()), this, SLOT(on_finish()), Qt::QueuedConnection);
start();
m_stopThread = false;
HGBase_OpenThread(ThreadFunc, this, &m_thread);
}
Dialog_ExportImageFile::~Dialog_ExportImageFile()
{
HGBase_CloseThread(m_thread);
m_thread = nullptr;
if (nullptr != m_thread)
{
HGBase_CloseThread(m_thread);
m_thread = nullptr;
}
delete ui;
}
void Dialog_ExportImageFile::start()
{
assert(NULL == m_thread);
m_stopThread = false;
HGBase_OpenThread(ThreadFunc, this, &m_thread);
}
void Dialog_ExportImageFile::ThreadFunc(HGThread thread, HGPointer param)
{
(void)thread;
......@@ -102,10 +97,14 @@ void Dialog_ExportImageFile::on_finish()
void Dialog_ExportImageFile::on_pushButton_clicked()
{
m_stopThread = true;
HGBase_CloseThread(m_thread);
m_thread = nullptr;
}
void Dialog_ExportImageFile::closeEvent(QCloseEvent *e)
{
(void)e;
m_stopThread = true;
HGBase_CloseThread(m_thread);
m_thread = nullptr;
}
......@@ -16,8 +16,6 @@ public:
explicit Dialog_ExportImageFile(const QString &destFile, int saveQuality, const QStringList &srcFiles, QWidget *parent = nullptr);
~Dialog_ExportImageFile();
void start();
private:
static void ThreadFunc(HGThread thread, HGPointer param);
......
......@@ -197,6 +197,8 @@ void Dialog_FullScreen::on_escape()
void Dialog_FullScreen::on_mouseMove(int x, int y)
{
(void)x;
(void)y;
setBtnOpacity(0.7);
}
......
......@@ -358,7 +358,7 @@
<customwidget>
<class>HGImgView</class>
<extends>QWidget</extends>
<header>hgimgview.h</header>
<header>HGImgView.h</header>
<container>1</container>
</customwidget>
</customwidgets>
......
......@@ -17,9 +17,11 @@
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
, m_currFilePath("")
, m_currIndex(-1)
, m_multiPageCount(0)
, m_multiIndex(-1)
, m_relation(false)
, m_modify(false)
{
ui->setupUi(this);
......@@ -128,6 +130,12 @@ MainWindow::MainWindow(QWidget *parent)
MainWindow::~MainWindow()
{
if (nullptr != m_dlgFullScreen)
{
delete m_dlgFullScreen;
m_dlgFullScreen = nullptr;
}
delete ui;
}
......@@ -220,17 +228,27 @@ void MainWindow::on_currItemChanged(int index)
{
HGImage img = nullptr;
m_view->getImage(&img);
if (nullptr != img && m_modify && -1 != m_currIndex && m_multiPageCount == 1)
if (nullptr != img && m_relation && m_modify && -1 != m_currIndex && m_multiPageCount == 1)
{
int ret = QMessageBox::question(this, tr("Question"), tr("modified, save it?"));
if (ret == QMessageBox::Yes)
assert(!m_currFilePath.isEmpty());
QString newCurrFilePath;
if (-1 != index)
m_thumb->getItemFileName(index, newCurrFilePath);
if (m_currFilePath != newCurrFilePath)
{
on_act_save_triggered();
int ret = QMessageBox::question(this, tr("Question"), tr("modified, save it?"));
if (ret == QMessageBox::Yes)
{
on_act_save_triggered();
}
}
}
m_currIndex = index;
QString oldCurrFilePath = m_currFilePath;
m_currFilePath.clear();
m_currIndex = index;
m_multiIndex = (-1 != m_currIndex) ? 0 : -1;
m_multiPageCount = 0;
......@@ -240,23 +258,30 @@ void MainWindow::on_currItemChanged(int index)
assert(!m_currFilePath.isEmpty());
m_multiPageCount = getMultiPageCount();
HGImage img2 = createImage();
if (nullptr != img2)
{
m_view->addImage(img2);
HGBase_DestroyImage(img2);
}
else
if (oldCurrFilePath != m_currFilePath)
{
m_view->clearImage();
HGImage img2 = createImage();
if (nullptr != img2)
{
m_view->addImage(img2);
HGBase_DestroyImage(img2);
m_relation = true;
m_modify = false;
}
else
{
m_view->clearImage();
m_relation = false;
m_modify = false;
}
}
}
else
{
m_view->clearImage();
m_relation = false;
m_modify = false;
}
m_modify = false;
}
void MainWindow::on_itemDoubleClicked(int index)
......@@ -266,36 +291,60 @@ void MainWindow::on_itemDoubleClicked(int index)
void MainWindow::on_viewerDrop(const QString &fileName)
{
HGImage img = nullptr;
HGPdfReader pdfReader = nullptr;
HGImgFmt_OpenPdfReader(getStdString(fileName).c_str(), &pdfReader);
if (nullptr != pdfReader)
int index = -1;
int count = 0;
m_thumb->getItemCount(&count);
for (int i = 0; i < count; ++i)
{
HGPdfPageInfo pageInfo = {0, 0};
if (HGBASE_ERR_OK == HGImgFmt_GetPdfPageInfo(pdfReader, 0, &pageInfo))
QString fName;
m_thumb->getItemFileName(i, fName);
assert(!fName.isEmpty());
if (fName == fileName)
{
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);
index = i;
break;
}
}
HGImgFmt_ClosePdfReader(pdfReader);
if (-1 != index)
{
m_thumb->setCurrItem(index);
}
else
{
HGImgFmt_LoadImage(getStdString(fileName).c_str(), 0, nullptr, HGBASE_IMGTYPE_RGB, HGBASE_IMGORIGIN_TOP, &img);
}
HGImage img = nullptr;
if (nullptr == img)
{
return;
}
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);
}
m_view->addImage(img);
HGBase_DestroyImage(img);
m_modify = false;
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;
}
}
void MainWindow::on_act_thumbnailBar_triggered(bool checked)
......@@ -351,6 +400,8 @@ void MainWindow::on_act_last_triggered()
HGImage MainWindow::createImage()
{
qDebug("createImage");
assert(-1 != m_currIndex && -1 != m_multiIndex);
assert(!m_currFilePath.isEmpty());
......@@ -431,13 +482,15 @@ void MainWindow::on_act_previousPage_triggered()
{
m_view->addImage(img);
HGBase_DestroyImage(img);
m_relation = true;
m_modify = false;
}
else
{
m_view->clearImage();
m_relation = false;
m_modify = false;
}
m_modify = false;
}
}
......@@ -452,13 +505,15 @@ void MainWindow::on_act_nextPage_triggered()
{
m_view->addImage(img);
HGBase_DestroyImage(img);
m_relation = true;
m_modify = false;
}
else
{
m_view->clearImage();
m_relation = false;
m_modify = false;
}
m_modify = false;
}
}
......@@ -473,13 +528,15 @@ void MainWindow::on_act_firstPage_triggered()
{
m_view->addImage(img);
HGBase_DestroyImage(img);
m_relation = true;
m_modify = false;
}
else
{
m_view->clearImage();
m_relation = false;
m_modify = false;
}
m_modify = false;
}
}
......@@ -494,13 +551,15 @@ void MainWindow::on_act_lastPage_triggered()
{
m_view->addImage(img);
HGBase_DestroyImage(img);
m_relation = true;
m_modify = false;
}
else
{
m_view->clearImage();
m_relation = false;
m_modify = false;
}
m_modify = false;
}
}
......@@ -553,26 +612,9 @@ void MainWindow::on_act_exit_triggered()
void MainWindow::on_act_save_triggered()
{
if (-1 == m_currIndex)
{
return;
}
HGImage img = nullptr;
m_view->getImage(&img);
if (nullptr == img)
{
return;
}
// 没有修改不用保存
if (!m_modify)
{
return;
}
// 如果是多张,不保存
if (1 != m_multiPageCount)
if (nullptr == img || !m_relation || !m_modify || -1 == m_currIndex || 1 != m_multiPageCount)
{
return;
}
......@@ -720,7 +762,7 @@ void MainWindow::on_act_imageInfo_triggered()
HGImgFmt_OpenImageReader(getStdString(m_currFilePath).c_str(), 0, &imgFmtReader);
if (nullptr != imgFmtReader)
{
HGImgFmt_LoadImageFromReader(imgFmtReader, m_multiIndex, &imgInfo, 0, 0, nullptr);
HGImgFmt_LoadImageFromReader(imgFmtReader, (HGUInt)m_multiIndex, &imgInfo, 0, 0, nullptr);
HGImgFmt_CloseImageReader(imgFmtReader);
}
......@@ -774,7 +816,7 @@ void MainWindow::on_act_imageInfo_triggered()
imageValues.append(QString::number(imgInfo.width));//add image width
imageValues.append(QString::number(imgInfo.height));//add image height
int depth = imgInfo.bpp;
int depth = (int)imgInfo.bpp;
imageValues.append(QString::number(depth));//add image depth
imageValues.append(depth == 0 ? tr("None") : (depth == 1 ? tr("Mono") : (depth == 8 ? tr("Gray") : tr("Color"))));//add image color
QString dpi = QString::number(imgInfo.xDpi) + " x " + QString::number(imgInfo.yDpi);
......@@ -799,7 +841,7 @@ void MainWindow::closeEvent(QCloseEvent *e)
HGImage img = nullptr;
m_view->getImage(&img);
if (nullptr != img && m_modify && -1 != m_currIndex && m_multiPageCount == 1)
if (nullptr != img && m_relation && m_modify && -1 != m_currIndex && m_multiPageCount == 1)
{
int ret = QMessageBox::question(this, tr("Question"), tr("modified, save it?"));
if (ret == QMessageBox::Yes)
......
......@@ -105,6 +105,7 @@ private:
int m_currIndex;
int m_multiPageCount;
int m_multiIndex;
bool m_relation; // m_view上的图像是否关联到m_thumb
bool m_modify; // m_view上面的图像是否改变
class Dialog_FullScreen *m_dlgFullScreen;
......
......@@ -1193,12 +1193,17 @@ HGResult HGImgThumb::insertItems(const QStringList &fileNames, int pos)
reset();
bool emitItemCount = false;
bool emitCurrItemChange = false;
bool emitSelectChanged = false;
int oldItemCount = (int)m_frontItems.size();
int oldCurrItemIndex = m_curItemIndex;
QString oldCurrItemFilePath;
if (-1 != oldCurrItemIndex)
oldCurrItemFilePath = m_frontItems[oldCurrItemIndex]->fileName;
std::vector<int> oldSelectedIndexs;
for (int i = 0; i < (int)m_frontItems.size(); ++i)
{
if (m_frontItems[i]->selected)
oldSelectedIndexs.push_back(i);
m_frontItems[i]->selected = false;
}
......@@ -1270,19 +1275,29 @@ HGResult HGImgThumb::insertItems(const QStringList &fileNames, int pos)
m_thumbRect.bottom = m_thumbRect.top + (double)showHeight;
locateItem(posEx - 1);
recalcShowRect(this->width(), this->height(), m_scrollSize, m_type, m_hScroll, m_vScroll, m_showThumb, m_thumbRect);
emitItemCount = true;
emitCurrItemChange = true;
emitSelectChanged = true;
}
m_hotItemIndex = getItemIndex(mapFromGlobal(QCursor::pos()), m_mouseMoveStatus);
Show();
if (emitItemCount)
int newItemCount = (int)m_frontItems.size();
int newCurrItemIndex = m_curItemIndex;
QString newCurrItemFilePath;
if (-1 != newCurrItemIndex)
newCurrItemFilePath = m_frontItems[newCurrItemIndex]->fileName;
std::vector<int> newSelectedIndexs;
for (int i = 0; i < (int)m_frontItems.size(); ++i)
{
if (m_frontItems[i]->selected)
newSelectedIndexs.push_back(i);
}
if (newItemCount != oldItemCount)
emit itemCountChanged((int)m_frontItems.size());
if (emitCurrItemChange)
if (newCurrItemIndex != oldCurrItemIndex || newCurrItemFilePath != oldCurrItemFilePath)
emit currItemChanged(m_curItemIndex);
if (emitSelectChanged)
if (newSelectedIndexs != oldSelectedIndexs)
emit itemSelectingChanged();
return HGBASE_ERR_OK;
}
......@@ -1602,7 +1617,7 @@ HGResult HGImgThumb::updateItem(int index, const QString &fileName)
break;
}
}
m_backList.push_back(stdFileName);
m_backList.push_front(stdFileName);
HGBase_LeaveLock(m_lockBack);
HGBase_SetEvent(m_event);
......@@ -1621,43 +1636,22 @@ HGResult HGImgThumb::refreshItem(int index)
return HGBASE_ERR_INVALIDARG;
}
HGImage image = nullptr;
HGResult ret = HGImgFmt_LoadImage(getStdString(m_frontItems[index]->fileName).c_str(), 0, nullptr, HGBASE_IMGTYPE_RGB, HGBASE_IMGORIGIN_TOP, &image);
if (nullptr == image)
{
return ret;
}
QImage *img = createItemImage(image, m_itemSize);
if (nullptr == img)
{
HGBase_DestroyImage(image);
return HGBASE_ERR_FAIL;
}
QString fileName = m_frontItems[index]->fileName;
HGBase_EnterLock(m_lockBack);
std::list<QString>::iterator iter;
for (iter = m_backList.begin(); iter != m_backList.end(); ++iter)
{
if (0 == (*iter).compare(m_frontItems[index]->fileName))
if (0 == (*iter).compare(fileName))
{
m_backList.erase(iter);
break;
}
}
m_backList.push_front(fileName);
HGBase_LeaveLock(m_lockBack);
HGBase_SetEvent(m_event);
HGImageInfo imgInfo;
HGBase_GetImageInfo(image, &imgInfo);
HGBase_EnterLock(m_lockFront);
m_frontItems[index]->width = imgInfo.width;
m_frontItems[index]->height = imgInfo.height;
delete m_frontItems[index]->image;
m_frontItems[index]->image = img;
HGBase_LeaveLock(m_lockFront);
Show();
HGBase_DestroyImage(image);
return HGBASE_ERR_OK;
}
......@@ -2983,9 +2977,18 @@ void HGImgThumb::dragLeaveEvent(QDragLeaveEvent *e)
void HGImgThumb::dropEvent(QDropEvent *e)
{
bool emitItemCount = false;
bool emitCurrItemChange = false;
bool emitSelectChanged = false;
int oldItemCount = (int)m_frontItems.size();
int oldCurrItemIndex = m_curItemIndex;
QString oldCurrItemFilePath;
if (-1 != oldCurrItemIndex)
oldCurrItemFilePath = m_frontItems[oldCurrItemIndex]->fileName;
std::vector<int> oldSelectedIndexs;
for (int i = 0; i < (int)m_frontItems.size(); ++i)
{
if (m_frontItems[i]->selected)
oldSelectedIndexs.push_back(i);
}
QList<QUrl> urls = e->mimeData()->urls();
if (-1 != m_curInsertPos && !urls.isEmpty())
......@@ -3066,10 +3069,6 @@ void HGImgThumb::dropEvent(QDropEvent *e)
m_thumbRect.bottom = m_thumbRect.top + (double)showHeight;
locateItem(posEx - 1);
recalcShowRect(this->width(), this->height(), m_scrollSize, m_type, m_hScroll, m_vScroll, m_showThumb, m_thumbRect);
emitItemCount = true;
emitCurrItemChange = true;
emitSelectChanged = true;
}
}
......@@ -3079,11 +3078,25 @@ void HGImgThumb::dropEvent(QDropEvent *e)
m_hotItemIndex = getItemIndex(mapFromGlobal(QCursor::pos()), m_mouseMoveStatus);
Show();
if (emitItemCount)
int newItemCount = (int)m_frontItems.size();
int newCurrItemIndex = m_curItemIndex;
QString newCurrItemFilePath;
if (-1 != newCurrItemIndex)
newCurrItemFilePath = m_frontItems[newCurrItemIndex]->fileName;
std::vector<int> newSelectedIndexs;
for (int i = 0; i < (int)m_frontItems.size(); ++i)
{
if (m_frontItems[i]->selected)
newSelectedIndexs.push_back(i);
}
if (newItemCount != oldItemCount)
emit itemCountChanged((int)m_frontItems.size());
if (emitCurrItemChange)
if (newCurrItemIndex != oldCurrItemIndex || newCurrItemFilePath != oldCurrItemFilePath)
emit currItemChanged(m_curItemIndex);
if (emitSelectChanged)
if (newSelectedIndexs != oldSelectedIndexs)
emit itemSelectingChanged();
}
......@@ -4304,7 +4317,7 @@ QRect HGImgThumb::getNullScrollPos()
void HGImgThumb::Show()
{
update();
repaint();
}
void HGImgThumb::ThreadFunc(HGThread thread, HGPointer param)
......
......@@ -2372,5 +2372,5 @@ QRect HGImgView::getNullScrollPos()
void HGImgView::Show()
{
update();
repaint();
}
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