130 lines
3.6 KiB
C++
130 lines
3.6 KiB
C++
#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();
|
|
connect(TCHttpService::getInstance(), &TCHttpService::signal_uploadFileSec, this, &FrmUpload::slot_uploadFileSec);
|
|
}
|
|
|
|
FrmUpload::~FrmUpload()
|
|
{
|
|
delete ui;
|
|
}
|
|
|
|
void FrmUpload::slot_uploadFileSec(QString url)
|
|
{
|
|
QClipboard* clipboard = QApplication::clipboard();
|
|
|
|
if (copyState == 0) {
|
|
clipboard->setText(QString("").arg(url));
|
|
}
|
|
else {
|
|
clipboard->setText(url);
|
|
}
|
|
}
|
|
|
|
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));
|
|
ui->btnHTML->setText("HTML");
|
|
ui->btnFastUpload->setText("剪贴板上传");
|
|
ui->btnMarkdown->setText("Markdown");
|
|
ui->btnUrl->setText("URL");
|
|
ui->btnUBB->setText("UBB");
|
|
}
|
|
|
|
void FrmUpload::initWidget()
|
|
{
|
|
ui->frmUpload->installEventFilter(this);
|
|
this->setAcceptDrops(true);
|
|
// ui->frmUpload->setAcceptDrops(true);
|
|
}
|
|
|
|
void FrmUpload::uploadFiles(QStringList fileList)
|
|
{
|
|
if (!TCHttpService::getInstance()->getOnlineState())
|
|
return;
|
|
foreach (QString p, fileList) {
|
|
qDebug() << "upload:" << p;
|
|
TCHttpService::getInstance()->apiUpload(p);
|
|
}
|
|
// TCHttpService::getInstance()->apiMyfileCount();
|
|
// TCHttpService::getInstance()->apiMyfileNormal();
|
|
|
|
}
|