HGGitLab
Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
app
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
CI / CD Analytics
Repository Analytics
Value Stream Analytics
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
luoliangyi
app
Commits
b54a7a51
Commit
b54a7a51
authored
Mar 16, 2022
by
luoliangyi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
实现缩略图的简单功能
parent
0e00a507
Changes
6
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
1253 additions
and
87 deletions
+1253
-87
app/Scanner/Scanner/mainwindow.cpp
app/Scanner/Scanner/mainwindow.cpp
+16
-2
app/Scanner/Scanner/mainwindow.h
app/Scanner/Scanner/mainwindow.h
+1
-0
ui/HGImgThumb.cpp
ui/HGImgThumb.cpp
+1124
-58
ui/HGImgThumb.hpp
ui/HGImgThumb.hpp
+79
-7
ui/HGImgView.cpp
ui/HGImgView.cpp
+30
-19
ui/HGImgView.hpp
ui/HGImgView.hpp
+3
-1
No files found.
app/Scanner/Scanner/mainwindow.cpp
View file @
b54a7a51
...
...
@@ -6,6 +6,7 @@ MainWindow::MainWindow(QWidget *parent)
:
QMainWindow
(
parent
)
,
ui
(
new
Ui
::
MainWindow
)
,
m_view
(
new
HGImgView
(
this
))
,
m_thumb
(
new
HGImgThumb
(
this
))
{
ui
->
setupUi
(
this
);
// 隐藏centralwidget
...
...
@@ -33,13 +34,26 @@ MainWindow::MainWindow(QWidget *parent)
ui
->
toolBar
->
addSeparator
();
ui
->
toolBar
->
addAction
(
ui
->
act_help
);
m_view
->
resize
(
600
,
500
);
m_view
->
move
(
100
,
100
);
//m_view->move(0, 100);
//m_view->resize(400, height() - 150);
m_thumb
->
move
(
00
,
100
);
m_thumb
->
resize
(
800
,
height
()
-
150
);
HGImage
img
=
NULL
;
HGImgFmt_LoadImage
(
"D:
\\
1.jpg"
,
0
,
NULL
,
HGBASE_IMGTYPE_RGB
,
HGBASE_IMGORIGIN_TOP
,
&
img
);
m_view
->
addImage
(
img
);
HGBase_DestroyImage
(
img
);
QImage
img2
(
"D:
\\
image.png"
);
m_thumb
->
setDefItemImage
(
&
img2
);
m_thumb
->
setType
(
ThumbType_Grid
);
for
(
int
i
=
0
;
i
<
1000
;
++
i
)
{
char
fileName
[
256
];
sprintf
(
fileName
,
"D:
\\
Pictures
\\
%d.jpg"
,
i
);
m_thumb
->
addItem
(
fileName
);
}
}
MainWindow
::~
MainWindow
()
...
...
app/Scanner/Scanner/mainwindow.h
View file @
b54a7a51
...
...
@@ -45,5 +45,6 @@ private slots:
private:
Ui
::
MainWindow
*
ui
;
HGImgView
*
m_view
;
HGImgThumb
*
m_thumb
;
};
#endif // MAINWINDOW_H
ui/HGImgThumb.cpp
View file @
b54a7a51
This diff is collapsed.
Click to expand it.
ui/HGImgThumb.hpp
View file @
b54a7a51
...
...
@@ -7,7 +7,14 @@
#include "../base/HGEvent.h"
#include "../base/HGThread.h"
#include "../base/HGImage.h"
#include <QListWidget>
#include <QWidget>
enum
ThumbType
{
ThumbType_Hori
=
0
,
// 水平, item垂直居中
ThumbType_Vert
=
1
,
// 垂直, item水平居中
ThumbType_Grid
=
2
// 网格, 可以放大缩小
};
enum
ThumbRemoveFlag
{
...
...
@@ -18,18 +25,36 @@ enum ThumbRemoveFlag
struct
HGImgThumbItem
{
HGImgThumbItem
()
{
image
=
NULL
;
selected
=
false
;
}
~
HGImgThumbItem
()
{
delete
image
;
image
=
NULL
;
}
QString
fileName
;
QListWidgetItem
*
item
;
QImage
*
image
;
bool
selected
;
};
class
HGImgThumb
:
public
Q
List
Widget
class
HGImgThumb
:
public
QWidget
{
Q_OBJECT
public:
HGImgThumb
(
QWidget
*
parent
=
nullptr
);
virtual
~
HGImgThumb
();
HGResult
setDefItemImage
(
HGImage
image
);
HGResult
setType
(
ThumbType
type
);
HGResult
setGap
(
int
width
);
HGResult
zoomIn
(
const
HGPoint
*
pCenter
);
HGResult
zoomOut
(
const
HGPoint
*
pCenter
);
HGResult
setDefItemImage
(
const
QImage
*
image
);
HGResult
getItemCount
(
int
*
count
);
HGResult
addItem
(
const
QString
&
fileName
);
HGResult
insertItem
(
const
QString
&
fileName
,
int
pos
);
...
...
@@ -44,21 +69,68 @@ public:
HGResult
refreshItem
(
int
index
);
HGResult
refreshAllItems
();
signals:
void
currentItemChanged
(
int
index
);
void
itemClicked
(
int
index
);
void
itemDoubleClicked
(
int
index
);
void
itemCountChanged
(
int
count
);
void
itemSelectingChanged
();
void
contextMenuEvent
(
int
index
);
protected:
virtual
void
mousePressEvent
(
QMouseEvent
*
e
);
virtual
void
mouseMoveEvent
(
QMouseEvent
*
e
);
virtual
void
mouseReleaseEvent
(
QMouseEvent
*
e
);
virtual
void
enterEvent
(
QEvent
*
e
);
virtual
void
leaveEvent
(
QEvent
*
e
);
virtual
void
paintEvent
(
QPaintEvent
*
e
);
virtual
void
wheelEvent
(
QWheelEvent
*
e
);
virtual
void
resizeEvent
(
QResizeEvent
*
e
);
virtual
void
keyPressEvent
(
QKeyEvent
*
e
);
virtual
void
keyReleaseEvent
(
QKeyEvent
*
e
);
virtual
void
focusInEvent
(
QFocusEvent
*
e
);
virtual
void
focusOutEvent
(
QFocusEvent
*
e
);
virtual
void
contextMenuEvent
(
QContextMenuEvent
*
e
);
signals:
void
updateItem
();
private
slots
:
void
on_updateItem
();
private:
static
QIcon
createIcon
(
HGImage
image
);
static
QImage
*
createItemImage
(
const
QImage
*
srcImage
,
int
itemSize
);
static
QImage
*
createItemImage
(
HGImage
srcImage
,
int
itemSize
);
void
updateShowRect
();
bool
wnd2ShowRect
(
QPoint
&
pt
);
bool
showRect2Wnd
(
QPoint
&
pt
);
bool
getItemLoc
(
int
index
,
QPoint
&
pt
,
int
&
row
,
int
&
col
);
int
getItem
(
const
QPoint
&
pt
);
int
getInsertPos
(
const
QPoint
&
pt
);
int
findIndex
(
const
QString
&
fileName
);
int
findIndex
(
const
QListWidgetItem
*
item
);
void
Show
(
);
static
void
ThreadFunc
(
HGThread
thread
,
HGPointer
param
);
private:
HGLock
m_lockFront
;
HGLock
m_lockBack
;
HGLock
m_lockItemSize
;
HGEvent
m_event
;
ThumbType
m_type
;
QImage
*
m_defItemImage
;
QImage
*
m_itemImage
;
int
m_gapWidth
;
int
m_itemSize
;
int
m_curItemIndex
;
int
m_hotItemIndex
;
int
m_signItemIndex
;
bool
m_stopThread
;
HGThread
m_thread
;
QIcon
m_defItemIcon
;
std
::
vector
<
HGImgThumbItem
>
m_frontItems
;
std
::
list
<
QString
>
m_backList
;
bool
m_showThumb
;
HGRect
m_showRect
;
int
m_mousePosX
;
int
m_mousePosY
;
};
#endif
/* __HGIMGTHUMB_HPP__ */
ui/HGImgView.cpp
View file @
b54a7a51
...
...
@@ -374,6 +374,25 @@ HGResult HGImgView::showColorInfo(bool show)
return
HGBASE_ERR_OK
;
}
void
HGImgView
::
mousePressEvent
(
QMouseEvent
*
e
)
{
assert
(
0
==
m_operate
);
if
(
NULL
==
m_image
||
!
m_showImage
)
{
return
;
}
HGRect
rcWnd
=
{
0
,
0
,
this
->
width
(),
this
->
height
()};
if
((
m_showRect
.
left
-
(
float
)
rcWnd
.
left
<
-
1e-3
)
||
(
m_showRect
.
right
-
(
float
)
rcWnd
.
right
>
1e-3
)
||
(
m_showRect
.
top
-
(
float
)
rcWnd
.
top
<
-
1e-3
)
||
(
m_showRect
.
bottom
-
(
float
)
rcWnd
.
bottom
>
1e-3
))
{
m_operate
=
1
;
m_beginX
=
e
->
pos
().
x
();
m_beginY
=
e
->
pos
().
y
();
updateCursor
();
}
}
void
HGImgView
::
mouseMoveEvent
(
QMouseEvent
*
e
)
{
if
(
1
==
m_operate
)
...
...
@@ -458,25 +477,6 @@ void HGImgView::mouseMoveEvent(QMouseEvent* e)
updateCursor
();
}
void
HGImgView
::
mousePressEvent
(
QMouseEvent
*
e
)
{
assert
(
0
==
m_operate
);
if
(
NULL
==
m_image
||
!
m_showImage
)
{
return
;
}
HGRect
rcWnd
=
{
0
,
0
,
this
->
width
(),
this
->
height
()};
if
((
m_showRect
.
left
-
(
float
)
rcWnd
.
left
<
-
1e-3
)
||
(
m_showRect
.
right
-
(
float
)
rcWnd
.
right
>
1e-3
)
||
(
m_showRect
.
top
-
(
float
)
rcWnd
.
top
<
-
1e-3
)
||
(
m_showRect
.
bottom
-
(
float
)
rcWnd
.
bottom
>
1e-3
))
{
m_operate
=
1
;
m_beginX
=
e
->
pos
().
x
();
m_beginY
=
e
->
pos
().
y
();
updateCursor
();
}
}
void
HGImgView
::
mouseReleaseEvent
(
QMouseEvent
*
e
)
{
Q_UNUSED
(
e
);
...
...
@@ -487,6 +487,17 @@ void HGImgView::mouseReleaseEvent(QMouseEvent* e)
updateCursor
();
}
void
HGImgView
::
enterEvent
(
QEvent
*
e
)
{
}
void
HGImgView
::
leaveEvent
(
QEvent
*
e
)
{
m_mousePosX
=
-
1
;
m_mousePosY
=
-
1
;
}
void
HGImgView
::
paintEvent
(
QPaintEvent
*
e
)
{
Q_UNUSED
(
e
);
...
...
ui/HGImgView.hpp
View file @
b54a7a51
...
...
@@ -35,9 +35,11 @@ signals:
void
scaleChanged
(
double
scale
);
protected:
virtual
void
mouseMoveEvent
(
QMouseEvent
*
e
);
virtual
void
mousePressEvent
(
QMouseEvent
*
e
);
virtual
void
mouseMoveEvent
(
QMouseEvent
*
e
);
virtual
void
mouseReleaseEvent
(
QMouseEvent
*
e
);
virtual
void
enterEvent
(
QEvent
*
e
);
virtual
void
leaveEvent
(
QEvent
*
e
);
virtual
void
paintEvent
(
QPaintEvent
*
e
);
virtual
void
wheelEvent
(
QWheelEvent
*
e
);
virtual
void
resizeEvent
(
QResizeEvent
*
e
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment