http模块有问题,需要修改
This commit is contained in:
92
core_form/frmimgshow/frmimgshow.cpp
Normal file
92
core_form/frmimgshow/frmimgshow.cpp
Normal file
@@ -0,0 +1,92 @@
|
||||
#include "frmimgshow.h"
|
||||
|
||||
FrmImgShow::FrmImgShow(QString& url, QWidget *parent) : QWidget(parent)
|
||||
{
|
||||
initForm();
|
||||
initForm();
|
||||
initManager();
|
||||
this->url = url;
|
||||
manager->get(QNetworkRequest(QUrl(url)));
|
||||
}
|
||||
|
||||
bool FrmImgShow::eventFilter(QObject *watched, QEvent *event)
|
||||
{
|
||||
if (watched == btnCopy) {
|
||||
if (event->type() == QEvent::Enter) {
|
||||
btnCopy->setIcon(QIcon(QPixmap(":/qrc/image/copy_blue.png")));
|
||||
return true;
|
||||
}
|
||||
else if (event->type() == QEvent::Leave) {
|
||||
btnCopy->setIcon(QIcon(QPixmap(":/qrc/image/copy_white.png")));
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (watched == btnDelete) {
|
||||
if (event->type() == QEvent::Enter) {
|
||||
btnDelete->setIcon(QIcon(QPixmap(":/qrc/image/delete_red.png")));
|
||||
return true;
|
||||
}
|
||||
else if (event->type() == QEvent::Leave) {
|
||||
btnDelete->setIcon(QIcon(QPixmap(":/qrc/image/delete_white.png")));
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return QWidget::eventFilter(watched, event);
|
||||
}
|
||||
|
||||
void FrmImgShow::onFinished(QNetworkReply *reply)
|
||||
{
|
||||
if (reply->error() == QNetworkReply::NoError) {
|
||||
QByteArray imageData = reply->readAll();
|
||||
QPixmap pix;
|
||||
pix.loadFromData(imageData);
|
||||
this->labImg->setPixmap(pix);
|
||||
}
|
||||
}
|
||||
|
||||
void FrmImgShow::initForm()
|
||||
{
|
||||
labImg = new QLabel();
|
||||
btnCopy = new QToolButton();
|
||||
btnDelete = new QToolButton();
|
||||
horizenSpacer = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
|
||||
hLayout = new QHBoxLayout();
|
||||
vLayout = new QVBoxLayout();
|
||||
|
||||
hLayout->addWidget(btnCopy);
|
||||
hLayout->addSpacerItem(horizenSpacer);
|
||||
vLayout->addWidget(labImg);
|
||||
vLayout->addLayout(hLayout);
|
||||
this->setLayout(vLayout);
|
||||
|
||||
btnCopy->setIcon(QIcon(QPixmap(":/qrc/image/copy_white.png")));
|
||||
btnDelete->setIcon(QIcon(QPixmap(":/qrc/image/delete_white.png")));
|
||||
btnCopy->setFixedSize(32, 32);
|
||||
btnCopy->setCursor(Qt::PointingHandCursor);
|
||||
}
|
||||
|
||||
void FrmImgShow::initWidget()
|
||||
{
|
||||
btnCopy->installEventFilter(this);
|
||||
btnDelete->installEventFilter(this);
|
||||
}
|
||||
|
||||
void FrmImgShow::initManager()
|
||||
{
|
||||
manager = new QNetworkAccessManager();
|
||||
QClipboard* clipboard = QGuiApplication::clipboard();
|
||||
connect(manager, &QNetworkAccessManager::finished,
|
||||
this, &FrmImgShow::onFinished);
|
||||
|
||||
connect(btnCopy, &QToolButton::clicked, [&](){
|
||||
clipboard->setText(this->url);
|
||||
});
|
||||
}
|
||||
50
core_form/frmimgshow/frmimgshow.h
Normal file
50
core_form/frmimgshow/frmimgshow.h
Normal file
@@ -0,0 +1,50 @@
|
||||
#ifndef FRMIMGSHOW_H
|
||||
#define FRMIMGSHOW_H
|
||||
|
||||
#include <QWidget>
|
||||
#include <QPushButton>
|
||||
#include <QLabel>
|
||||
#include <QHBoxLayout>
|
||||
#include <QVBoxLayout>
|
||||
#include <QToolButton>
|
||||
#include <QSpacerItem>
|
||||
#include <QNetworkAccessManager>
|
||||
#include <QNetworkRequest>
|
||||
#include <QUrl>
|
||||
#include <QNetworkReply>
|
||||
#include <QClipboard>
|
||||
#include <QGuiApplication>
|
||||
|
||||
class FrmImgShow : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit FrmImgShow(QString& url, QWidget *parent = nullptr);
|
||||
|
||||
private:
|
||||
QLabel* labImg;
|
||||
QToolButton* btnCopy;
|
||||
QToolButton* btnDelete;
|
||||
QSpacerItem* horizenSpacer;
|
||||
QHBoxLayout* hLayout;
|
||||
QVBoxLayout* vLayout;
|
||||
|
||||
QNetworkAccessManager* manager;
|
||||
QString url;
|
||||
|
||||
protected:
|
||||
virtual bool eventFilter(QObject* watched, QEvent* event);
|
||||
|
||||
private slots:
|
||||
void onFinished(QNetworkReply *reply);
|
||||
|
||||
private:
|
||||
void initForm();
|
||||
void initWidget();
|
||||
void initManager();
|
||||
|
||||
signals:
|
||||
|
||||
};
|
||||
|
||||
#endif // FRMIMGSHOW_H
|
||||
5
core_form/frmimgshow/frmimgshow.pri
Normal file
5
core_form/frmimgshow/frmimgshow.pri
Normal file
@@ -0,0 +1,5 @@
|
||||
HEADERS += \
|
||||
$$PWD/frmimgshow.h
|
||||
|
||||
SOURCES += \
|
||||
$$PWD/frmimgshow.cpp
|
||||
Reference in New Issue
Block a user