http模块有问题,需要修改
This commit is contained in:
103
core_form/frmupload/frmupload.cpp
Normal file
103
core_form/frmupload/frmupload.cpp
Normal file
@@ -0,0 +1,103 @@
|
||||
#include "frmupload.h"
|
||||
#include "ui_frmupload.h"
|
||||
#include <QtDebug>
|
||||
#include <QImageReader>
|
||||
|
||||
FrmUpload::FrmUpload(QWidget *parent)
|
||||
: QWidget(parent)
|
||||
, ui(new Ui::FrmUpload)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
initFrom();
|
||||
initWidget();
|
||||
}
|
||||
|
||||
FrmUpload::~FrmUpload()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
|
||||
bool FrmUpload::eventFilter(QObject *watched, QEvent *event)
|
||||
{
|
||||
static bool mousePressed = false;
|
||||
if (watched == ui->frmUpload) {
|
||||
QMouseEvent* mouseEvent = static_cast<QMouseEvent*>(event);
|
||||
if (mouseEvent->type() == QMouseEvent::MouseButtonPress && mouseEvent->button() == Qt::LeftButton) {
|
||||
mousePressed = true;
|
||||
return true;
|
||||
}
|
||||
else if (mouseEvent->type() == QMouseEvent::MouseButtonRelease && mouseEvent->button() == Qt::LeftButton && mousePressed == true) {
|
||||
QStringList fileList = QFileDialog::getOpenFileNames(this, "选择图片", "C:\\", "Files (*);;"
|
||||
"PNG (*.png);;"
|
||||
"JPG (*.jpg);;"
|
||||
"JPEG (*.jpeg);;"
|
||||
"SVG (*.svg)");
|
||||
uploadFiles(fileList);
|
||||
mousePressed = false;
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return QWidget::eventFilter(watched, event);
|
||||
}
|
||||
|
||||
void FrmUpload::dragEnterEvent(QDragEnterEvent *event)
|
||||
{
|
||||
if (event->mimeData()->hasUrls()) {
|
||||
event->acceptProposedAction();
|
||||
}
|
||||
else {
|
||||
event->ignore();
|
||||
}
|
||||
}
|
||||
|
||||
void FrmUpload::dropEvent(QDropEvent *event)
|
||||
{
|
||||
QStringList uploadList;
|
||||
const QMimeData* mimeData = event->mimeData();
|
||||
if (!mimeData->hasUrls()) {
|
||||
return;
|
||||
}
|
||||
QList<QUrl> urlList = mimeData->urls();
|
||||
|
||||
|
||||
#if DEBUG
|
||||
foreach (QUrl url, urlList) {
|
||||
qDebug() << url.toLocalFile();
|
||||
}
|
||||
#endif
|
||||
|
||||
foreach (QUrl url, urlList) {
|
||||
QFileInfo fileInfo(url.toLocalFile());
|
||||
if (fileInfo.isDir()) {
|
||||
continue;
|
||||
}
|
||||
else {
|
||||
// QImageReader reader(url.toLocalFile());
|
||||
// if (!reader.imageFormat()) {
|
||||
// uploadList << url.toLocalFile();
|
||||
// TCHttpService::getInstance()->apiMd5(fileInfo.absoluteFilePath());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void FrmUpload::initFrom()
|
||||
{
|
||||
ui->frmUpload->setMinimumSize(QSize(400, 200));
|
||||
}
|
||||
|
||||
void FrmUpload::initWidget()
|
||||
{
|
||||
ui->frmUpload->installEventFilter(this);
|
||||
this->setAcceptDrops(true);
|
||||
// ui->frmUpload->setAcceptDrops(true);
|
||||
}
|
||||
|
||||
void FrmUpload::uploadFiles(QStringList fileList)
|
||||
{
|
||||
|
||||
}
|
||||
42
core_form/frmupload/frmupload.h
Normal file
42
core_form/frmupload/frmupload.h
Normal file
@@ -0,0 +1,42 @@
|
||||
#ifndef FRMUPLOAD_H
|
||||
#define FRMUPLOAD_H
|
||||
|
||||
#include <QWidget>
|
||||
#include <QMouseEvent>
|
||||
#include <QEvent>
|
||||
#include <QDropEvent>
|
||||
#include <QMoveEvent>
|
||||
#include <QFileDialog>
|
||||
#include <QMimeData>
|
||||
#include <QDragEnterEvent>
|
||||
#include <tchttpservice.h>
|
||||
|
||||
#define DEBUG 1
|
||||
|
||||
namespace Ui {
|
||||
class FrmUpload;
|
||||
}
|
||||
|
||||
class FrmUpload : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit FrmUpload(QWidget *parent = nullptr);
|
||||
~FrmUpload();
|
||||
|
||||
protected:
|
||||
virtual bool eventFilter(QObject* watched, QEvent* event);
|
||||
virtual void dragEnterEvent(QDragEnterEvent *event) override;
|
||||
virtual void dropEvent(QDropEvent *event) override;
|
||||
|
||||
private:
|
||||
void initFrom();
|
||||
void initWidget();
|
||||
void uploadFiles(QStringList fileList);
|
||||
|
||||
private:
|
||||
Ui::FrmUpload *ui;
|
||||
};
|
||||
|
||||
#endif // FRMUPLOAD_H
|
||||
8
core_form/frmupload/frmupload.pri
Normal file
8
core_form/frmupload/frmupload.pri
Normal file
@@ -0,0 +1,8 @@
|
||||
FORMS += \
|
||||
$$PWD/frmupload.ui
|
||||
|
||||
HEADERS += \
|
||||
$$PWD/frmupload.h
|
||||
|
||||
SOURCES += \
|
||||
$$PWD/frmupload.cpp
|
||||
158
core_form/frmupload/frmupload.ui
Normal file
158
core_form/frmupload/frmupload.ui
Normal file
@@ -0,0 +1,158 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>FrmUpload</class>
|
||||
<widget class="QWidget" name="FrmUpload">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>953</width>
|
||||
<height>560</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Form</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<widget class="QFrame" name="frmUpload">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>800</width>
|
||||
<height>450</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>800</width>
|
||||
<height>450</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="styleSheet">
|
||||
<string notr="true"/>
|
||||
</property>
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::NoFrame</enum>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||
<item>
|
||||
<spacer name="verticalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>75</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||
<item>
|
||||
<spacer name="horizontalSpacer_2">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="labPixmap">
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
<property name="pixmap">
|
||||
<pixmap resource="../../image.qrc">:/qrc/image/upload_white.png</pixmap>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer_3">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="labText">
|
||||
<property name="font">
|
||||
<font>
|
||||
<family>Microsoft YaHei UI</family>
|
||||
<pointsize>26</pointsize>
|
||||
</font>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string><html><head/><body><p align="center"><span style=" color:white;">将文件拖拽到此处,或</span><span style=" color:#407AB4;">点击上传</span>。</p></body></html></string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="verticalSpacer_2">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>74</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeType">
|
||||
<enum>QSizePolicy::Fixed</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources>
|
||||
<include location="../../image.qrc"/>
|
||||
</resources>
|
||||
<connections/>
|
||||
</ui>
|
||||
Reference in New Issue
Block a user