HGGitLab

Commit 17fd7e6d authored by luoliangyi's avatar luoliangyi

完善缩略图控件

parent 1d53f5f9
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "../../../imgfmt/HGImgFmt.h"
#include <math.h>
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
......@@ -49,9 +50,9 @@ MainWindow::MainWindow(QWidget *parent)
QImage img2("D:\\ImageSrc\\image.png");
m_thumb->setDefItemImage(&img2);
m_thumb->setType(HGImgThumb::ThumbType_Grid);
m_thumb->setGapSize(20);
m_thumb->setGapSize(0);
m_thumb->setItemSize(80);
//m_thumb->setItemTextHeight(0);
m_thumb->setItemTextHeight(20);
m_thumb->setScrollSize(20);
m_thumb->setMinScrollSliderSize(40);
......@@ -71,7 +72,7 @@ MainWindow::MainWindow(QWidget *parent)
HGRect vStretchRect = {0, 20, 20, 60};
m_thumb->setVScrollSliderImage(&vScrollSliderImage, &vStretchRect, &vScrollSliderImage, &vStretchRect, &vScrollSliderImage, &vStretchRect);
for (int i = 0; i < 19999; ++i)
for (int i = 0; i < 20000; ++i)
{
char fileName[256];
sprintf(fileName, "D:\\Pictures\\%d.jpg", i);
......
This diff is collapsed.
......@@ -97,6 +97,14 @@ private:
bool selected;
};
struct ThumbRect
{
double left;
double top;
double right;
double bottom;
};
enum MouseStatus
{
MouseStatus_Null = 0,
......@@ -137,7 +145,7 @@ private:
static void DrawImage(QPainter &painter, const QRect &destRect, const QImage *image, const QRect &stretchRect);
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, HGRectF &thumbRect);
static void recalcShowRect(int wndWidth, int wndHeight, int scrollSize, ThumbType type, bool hScroll, bool vScroll, bool showThumb, ThumbRect &thumbRect);
void locateItemEx(int index);
QPoint getItemLoc(int index);
......@@ -199,7 +207,7 @@ private:
bool m_hScroll;
bool m_vScroll;
bool m_showThumb;
HGRectF m_thumbRect;
ThumbRect m_thumbRect;
int m_mousePosX;
int m_mousePosY;
MouseStatus m_mouseMoveStatus;
......
......@@ -202,7 +202,7 @@ HGResult HGImgView::zoomIn(const HGPoint *pCenter)
if (fabs(fMaxWidth - fCurWidth) > 1e-3 || fabs(fMaxHeight - fCurHeight) > 1e-3)
{
if (fNewWidth - fMaxWidth > -1e-3 || fNewHeight - fMaxHeight > -1e-3
|| (int)(100.0f * fNewWidth / (float)info.width + 0.5f) == (int)(100.0f * fMaxWidth / (float)info.width + 0.5f))
|| round(100.0f * fNewWidth / (float)info.width) == round(100.0f * fMaxWidth / (float)info.width))
{
fNewWidth = fMaxWidth;
fNewHeight = fMaxHeight;
......@@ -246,7 +246,7 @@ HGResult HGImgView::zoomOut(const HGPoint *pCenter)
if (fabs(fMinWidth - fCurWidth) > 1e-3 || fabs(fMinHeight - fCurHeight) > 1e-3)
{
if (fNewWidth - fMinWidth < 1e-3 || fNewHeight - fMinHeight < 1e-3
|| (int)(100.0f * fNewWidth / (float)info.width + 0.5f) == (int)(100.0f * fMinWidth / (float)info.width + 0.5f))
|| round(100.0f * fNewWidth / (float)info.width) == round(100.0f * fMinWidth / (float)info.width))
{
fNewWidth = fMinWidth;
fNewHeight = fMinHeight;
......@@ -551,10 +551,10 @@ void HGImgView::paintEvent(QPaintEvent* e)
int xSrc, ySrc, wSrc, hSrc;
HGRect rcShowImage; // 绘制的图像区域
rcShowImage.left = (int)(m_showRect.left + 0.5f);
rcShowImage.top = (int)(m_showRect.top + 0.5f);
rcShowImage.right = (int)(m_showRect.right + 0.5f);
rcShowImage.bottom = (int)(m_showRect.bottom + 0.5f);
rcShowImage.left = round(m_showRect.left);
rcShowImage.top = round(m_showRect.top);
rcShowImage.right = round(m_showRect.right);
rcShowImage.bottom = round(m_showRect.bottom);
int nShowWidth = rcShowImage.right - rcShowImage.left;
int nShowHeight = rcShowImage.bottom - rcShowImage.top;
......@@ -562,11 +562,11 @@ void HGImgView::paintEvent(QPaintEvent* e)
{
float fPixel = (float)nImgWidth * (rcWnd.left - rcShowImage.left) / nShowWidth;
float fPixelR = (float)nImgWidth * (rcShowImage.right - rcWnd.right) / nShowWidth;
xDest = rcShowImage.left + (int)((int)fPixel * (float)nShowWidth / nImgWidth + 0.5f);
int xDestR = rcShowImage.right - (int)((int)fPixelR * (float)nShowWidth / nImgWidth + 0.5f);
xDest = rcShowImage.left + round((int)fPixel * (float)nShowWidth / nImgWidth);
int xDestR = rcShowImage.right - round((int)fPixelR * (float)nShowWidth / nImgWidth);
wDest = xDestR - xDest;
wSrc = (int)((float)nImgWidth * wDest / nShowWidth + 0.5f);
xSrc = (int)((float)(xDest - rcShowImage.left) * nImgWidth / nShowWidth + 0.5f);
wSrc = round((float)nImgWidth * wDest / nShowWidth);
xSrc = round((float)(xDest - rcShowImage.left) * nImgWidth / nShowWidth);
}
else
{
......@@ -580,11 +580,11 @@ void HGImgView::paintEvent(QPaintEvent* e)
{
float fPixel = (float)nImgHeight * (rcWnd.top - rcShowImage.top) / nShowHeight;
float fPixelB = (float)nImgHeight * (rcShowImage.bottom - rcWnd.bottom) / nShowHeight;
yDest = rcShowImage.top + (int)((int)fPixel * (float)nShowHeight / nImgHeight + 0.5f);
int yDestB = rcShowImage.bottom - (int)((int)fPixelB * (float)nShowHeight / nImgHeight + 0.5f);
yDest = rcShowImage.top + round((int)fPixel * (float)nShowHeight / nImgHeight);
int yDestB = rcShowImage.bottom - round((int)fPixelB * (float)nShowHeight / nImgHeight);
hDest = yDestB - yDest;
hSrc = (int)((float)nImgHeight * hDest / nShowHeight + 0.5f);
ySrc = (int)((float)(yDest - rcShowImage.top) * nImgHeight / nShowHeight + 0.5f);
hSrc = round((float)nImgHeight * hDest / nShowHeight);
ySrc = round((float)(yDest - rcShowImage.top) * nImgHeight / nShowHeight);
}
else
{
......
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