资源简介
qt实现本地\网络图片查看器,网络图片支持缓存。支持图片放大、缩小、翻转已经另存为。支持切换上一张下一张。
代码片段和文件信息
#include “CImageView.h“
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
CImageView::CImageView(QWidget * parent)
: QWidget(parent)
m_oSrcollAreaMaxSize(QSize(0 0))
m_nExpandMultiple(0)
m_bMousePressed(false)
m_bIsUrl(false)
m_bIsLoadFail(false)
m_imageCachePath(“D:/imageCache/“)
pReply(NULL)
{
QDir dir(m_imageCachePath);
if (!dir.exists())
{
dir.mkpath(m_imageCachePath);//创建多级目录
}
this->setAttribute(Qt::WA_DeleteOnClose false);
this->setWindowtitle(QStringLiteral(“图片查看“));
m_pNetworkManager = new QNetworkAccessManager(this);
connect(m_pNetworkManager SIGNAL(finished(QNetworkReply *)) this SLOT(replyFinished(QNetworkReply *)));
init();
}
void CImageView::init()
{
m_pCenterWidget = new QWidget(this);
m_pImageLabel = new QLabel(m_pCenterWidget);
m_pCenterWidget->installEventFilter(this);
m_pImageLabel->setScaledContents(true);
m_pImageLabel->installEventFilter(this);
m_pUp = new QPushButton(this);
m_pUp->setFlat(true);
m_pUp->setFixedSize(64 64);
connect(m_pUp &QPushButton::clicked this &CImageView::onUp);
m_pUp->setstyleSheet(“QPushButton{border-image: url(:/iocn/res/left.png);}\
QPushButton:hover{border-image:url(:/iocn/res/left_hover.png);}“);
m_pDown = new QPushButton(this);
m_pDown->setFlat(true);
m_pDown->setFixedSize(64 64);
connect(m_pDown &QPushButton::clicked this &CImageView::onDown);
m_pDown->setstyleSheet(“QPushButton{border-image: url(:/iocn/res/right.png);}\
QPushButton:hover{border-image:url(:/iocn/res/right_hover.png);}“);
m_pWaitLabel = new QLabel(this);
m_pWaitMovie = new QMovie(“:/iocn/res/loading.gif“);
m_pWaitLabel->setMovie(m_pWaitMovie);
m_pWaitMovie->setSpeed(200);
QHBoxLayout *pWaitLabelLayout = new QHBoxLayout;
pWaitLabelLayout->addSpacing(20);
pWaitLabelLayout->addWidget(m_pUp);
pWaitLabelLayout->addStretch();
pWaitLabelLayout->addWidget(m_pWaitLabel);
pWaitLabelLayout->addStretch();
pWaitLabelLayout->addWidget(m_pDown);
pWaitLabelLayout->addSpacing(20);
QVBoxLayout *pWaitLayout = new QVBoxLayout;
pWaitLayout->addStretch();
pWaitLayout->addLayout(pWaitLabelLayout);
pWaitLayout->addStretch();
m_pCenterWidget->setLayout(pWaitLayout);
m_pExpandBtn = new QPushButton(this);
m_pExpandBtn->setFlat(true);
m_pExpandBtn->setIcon(QIcon(“:/iocn/res/Expand.png“));
connect(m_pExpandBtn &QPushButton::clicked this &CImageView::onExpand);
m_pExpandBtn->setEnabled(false);
m_pNarrowBtn = new QPushButton(this);
m_pNarrowBtn->setFlat(true);
m_pNarrowBtn->setIcon(QIcon(“:/iocn/res/Narrow.png“));
connect(m_pNarrowBtn &QPushButton::clicked this &CImageVie
评论
共有 条评论