HGGitLab

Commit 497b4541 authored by luoliangyi's avatar luoliangyi

完善缩略图的滚动条功能

parent 81171da7
......@@ -39,6 +39,8 @@ MainWindow::MainWindow(QWidget *parent)
m_thumb->move(450, 100);
m_thumb->resize(200, height() - 150);
connect(m_thumb, SIGNAL(currItemChanged(int)), this, SLOT(on_currItemChanged(int)), Qt::QueuedConnection);
HGImage img = NULL;
HGImgFmt_LoadImage("D:\\1.jpg", 0, NULL, HGBASE_IMGTYPE_RGB, HGBASE_IMGORIGIN_TOP, &img);
m_view->addImage(img);
......@@ -46,9 +48,13 @@ MainWindow::MainWindow(QWidget *parent)
QImage img2("D:\\image.png");
m_thumb->setDefItemImage(&img2);
m_thumb->setType(ThumbType_Vert);
m_thumb->setType(ThumbType_Grid);
//m_thumb->setGapSize(30);
m_thumb->setItemSize(80);
//m_thumb->setItemTextHeight(0);
//m_thumb->setScrollSize(12);
for (int i = 0; i < 1000; ++i)
for (int i = 0; i < 20000; ++i)
{
char fileName[256];
sprintf(fileName, "D:\\Pictures\\%d.jpg", i);
......@@ -120,3 +126,20 @@ void MainWindow::on_act_fullscreen_triggered()
{
m_view->setFullScreen(true);
}
void MainWindow::on_currItemChanged(int index)
{
if (-1 != index)
{
QString fileName;
m_thumb->getItemFileName(index, fileName);
HGImage img = NULL;
HGImgFmt_LoadImage(fileName.toStdString().c_str(), 0, NULL, HGBASE_IMGTYPE_RGB, HGBASE_IMGORIGIN_TOP, &img);
if (NULL != img)
{
m_view->addImage(img);
HGBase_DestroyImage(img);
}
}
}
......@@ -42,6 +42,9 @@ private slots:
void on_act_fullscreen_triggered();
private slots:
void on_currItemChanged(int index);
private:
Ui::MainWindow *ui;
HGImgView *m_view;
......
This diff is collapsed.
......@@ -23,28 +23,6 @@ enum ThumbRemoveFlag
ThumbRemoveFlag_Delete = 2 // 从列表中删除,并删除文件
};
struct HGImgThumbItem
{
HGImgThumbItem()
{
image = NULL;
selected = false;
}
~HGImgThumbItem()
{
if (NULL != image)
{
delete image;
image = NULL;
}
}
QString fileName;
QImage *image;
bool selected;
};
class HGImgThumb : public QWidget
{
Q_OBJECT
......@@ -52,18 +30,22 @@ public:
HGImgThumb(QWidget* parent = nullptr);
virtual ~HGImgThumb();
enum MoveStauts
{
MoveStatus_Null = 0,
MoveStatus_HRoll = 1,
MoveStatus_VRoll = 2
};
HGResult setGapSize(int size);
HGResult setScrollSize(int size);
HGResult setItemSize(int size);
HGResult setItemTextHeight(int height);
HGResult setDefItemImage(const QImage *image);
HGResult setHScrollLeftImage(const QImage *normalImage, const QImage *hotImage, const QImage *pushImage);
HGResult setHScrollRightImage(const QImage *normalImage, const QImage *hotImage, const QImage *pushImage);
HGResult setVScrollTopImage(const QImage *normalImage, const QImage *hotImage, const QImage *pushImage);
HGResult setVScrollBottomImage(const QImage *normalImage, const QImage *hotImage, const QImage *pushImage);
HGResult setScrollImage(const QImage *image, const QRect *stretch);
HGResult setscrollSliderImage(const QImage *normalImage, const QRect *normalStretch, const QImage *hotImage, const QRect *hotStretch,
const QImage *pushImage, const QRect *pushStretch);
HGResult setType(ThumbType type);
HGResult setGap(int width);
HGResult zoomIn();
HGResult zoomOut();
HGResult setDefItemImage(const QImage *image);
HGResult getItemCount(int *count);
HGResult addItem(const QString &fileName);
......@@ -81,12 +63,50 @@ public:
HGResult locateItem(int index);
signals:
void currentItemChanged(int index);
void currItemChanged(int index);
void itemDoubleClicked(int index);
void itemCountChanged(int count);
void itemSelectingChanged();
void contextMenuEvent(int index);
private:
struct HGImgThumbItem
{
HGImgThumbItem()
{
image = NULL;
selected = false;
}
~HGImgThumbItem()
{
if (NULL != image)
{
delete image;
image = NULL;
}
}
QString fileName;
QImage *image;
bool selected;
};
enum MouseStatus
{
MouseStatus_Null = 0,
MouseStatus_HScroll,
MouseStatus_HScrollSlider,
MouseStatus_HScrollLeft,
MouseStatus_HScrollRight,
MouseStatus_VScroll,
MouseStatus_VScrollSlider,
MouseStatus_VScrollTop,
MouseStatus_VScrollBottom,
MouseStatus_NullScroll
};
protected:
virtual void mousePressEvent(QMouseEvent *e);
virtual void mouseMoveEvent(QMouseEvent* e);
......@@ -110,27 +130,30 @@ private slots:
private:
static QImage* createItemImage(const QImage *srcImage, int itemSize);
static QImage* createItemImage(HGImage srcImage, int itemSize);
static void calcShowSize(int wndWidth, int wndHeight, int rollWidth, ThumbType type, int itemSize, int gapWidth, int itemCount,
int &showWidth, int &showHeight, bool &hRoll, bool &vRoll);
static void recalcShowRect(int wndWidth, int wndHeight, int rollWidth, ThumbType type, bool hRoll, bool vRoll, bool showThumb, HGRect &showRect);
static void calcShowSize(int wndWidth, int wndHeight, int gapSize, int scrollSize, int itemSize, int itemTextHeight, ThumbType type, int itemCount,
int &showWidth, int &showHeight, bool &hScroll, bool &vScroll);
static void recalcShowRect(int wndWidth, int wndHeight, int scrollSize, ThumbType type, bool hScroll, bool vScroll, bool showThumb, HGRect &showRect);
void locateItemEx(int index);
QPoint getItemLoc(int index);
int getItemRow(int index);
int getItemCol(int index);
int getTotalRows();
int getTotalCols();
int getItem(const QPoint &pt);
int getItem(const QPoint &pt, MouseStatus &mouseMoveStatus);
int getInsertPos(const QPoint &pt);
int findIndex(const QString &fileName);
QRect getHRollPos();
QRect getHRollLeftPos();
QRect getHRollRightPos();
QRect getVRollPos();
QRect getVRollTopPos();
QRect getVRollBottomPos();
QRect getHRollSliderPos();
QRect getVRollSliderPos();
QRect getNullRollPos();
QRect getHScrollLeftPos();
QRect getHScrollRightPos();
QRect getHScrollPos();
QRect getHScrollSliderPos();
QRect getVScrollTopPos();
QRect getVScrollBottomPos();
QRect getVScrollPos();
QRect getVScrollSliderPos();
QRect getNullScrollPos();
void Show();
static void ThreadFunc(HGThread thread, HGPointer param);
......@@ -139,11 +162,23 @@ private:
HGLock m_lockBack;
HGLock m_lockItemSize;
HGEvent m_event;
ThumbType m_type;
int m_gapSize;
int m_scrollSize;
int m_itemSize;
int m_itemTextHeight;
QImage *m_defItemImage;
QImage *m_itemImage;
int m_gapWidth;
int m_itemSize;
QImage *m_hScrollLeftImage[3];
QImage *m_hScrollRightImage[3];
QImage *m_vScrollTopImage[3];
QImage *m_vScrollBottomImage[3];
QImage *m_scrollImage;
QRect m_scrollImageStretch;
QImage *m_scrollSliderImage[3];
QRect m_scrollSliderImageStretch[3];
ThumbType m_type;
int m_curItemIndex;
int m_hotItemIndex;
int m_signItemIndex;
......@@ -151,15 +186,16 @@ private:
HGThread m_thread;
std::vector<HGImgThumbItem *> m_frontItems;
std::list<QString> m_backList;
bool m_hRoll;
bool m_vRoll;
bool m_hScroll;
bool m_vScroll;
bool m_showThumb;
HGRect m_showRect;
int m_mousePosX;
int m_mousePosY;
MoveStauts m_moveStatus;
int m_beginX;
int m_beginY;
MouseStatus m_mouseMoveStatus;
MouseStatus m_mousePressStatus;
int m_mousePressBeginX;
int m_mousePressBeginY;
};
#endif /* __HGIMGTHUMB_HPP__ */
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