-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmainwindow.cpp
140 lines (134 loc) · 3.82 KB
/
mainwindow.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QDebug>
#include <QDir>
#include <QFileDialog>
#include <QDragEnterEvent>
#include <QMimeData>
#include <QFileIconProvider>
#include <QClipboard>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
this->resize(300,200);
setAcceptDrops(true);
settingObject = new ASettingWidget();
if(settingObject->getIfStayOnTop())
{
setWindowFlags(Qt::WindowStaysOnTopHint);
}
qiniu = new AQiniuApi();
connect(qiniu,&AQiniuApi::sig_uploadResult,[=](bool result,QString msg){
if(result){
showFilePreview();
showStatusMessage(QString("上传成功"),5000);
m_remotePicUrl = settingObject->getDomain()+"/"+msg;
ui->lineEditUrl->setText(m_remotePicUrl);
autoDup();
}else{
showStatusMessage(QString("%1%2").arg("上传失败").arg(msg),5000);
}
});
}
MainWindow::~MainWindow()
{
delete ui;
delete settingObject;
}
void MainWindow::closeEvent(QCloseEvent *event)
{
event = event;
QCoreApplication::quit();
}
void MainWindow::dragEnterEvent(QDragEnterEvent *event)
{
//如果为文件,则支持拖放
if (event->mimeData()->hasFormat("text/uri-list"))
event->acceptProposedAction();
}
void MainWindow::dropEvent(QDropEvent *event)
{
QList<QUrl> urls = event->mimeData()->urls();
if(urls.isEmpty()){
showStatusMessage("没有文件!",5000);
return;
}
if(urls.count() > 1){
showStatusMessage("只支持单个文件上传!",5000);
return;
}
else{
m_localFilePath = urls.first().toString().split("file:///").last();
qiniu->upload(m_localFilePath);
showStatusMessage("正在上传",5000);
}
}
void MainWindow::on_pushButtonOpenFile_clicked()
{
m_localFilePath = QFileDialog::getOpenFileName(this,"select pic",QDir::currentPath(),"All (*)");
if(m_localFilePath.isEmpty())
return;
qiniu->upload(m_localFilePath);
showStatusMessage("正在上传",5000);
}
void MainWindow::showFilePreview()
{
qDebug()<<"showFilePreview"<<m_localFilePath;
QFileInfo fileInfo(m_localFilePath);
QString suffix = fileInfo.suffix().toLower();
if( suffix== "png" || suffix == "jpg"|| suffix == "jpeg"
|| suffix == "bmp" || suffix == "gif" || suffix == "pbm"
|| suffix == "pgm" || suffix == "ppm" || suffix == "xbm"
|| suffix == "xpm")
{
QImage *image = new QImage(m_localFilePath);
ui->labelFilePreview->setPixmap(QPixmap::fromImage(*image)
.scaledToWidth(ui->labelFilePreview->width()));
}
else
{
QFileIconProvider iconPprovider;
QIcon icon = iconPprovider.icon(fileInfo);
ui->labelFilePreview->setPixmap(icon.pixmap(30,30));
}
}
void MainWindow::setClipboardText(QString data)
{
QClipboard *board = QApplication::clipboard();
board->setText(data);
}
void MainWindow::autoDup()
{
if(settingObject->getIfAutoDup())
{
if(settingObject->getIfCopyMDUrl())
{
setClipboardText("");
}
else
{
setClipboardText(m_remotePicUrl);
}
showStatusMessage("复制链接完成",5000);
}
}
void MainWindow::showStatusMessage(QString message,int timeout)
{
ui->statusBar->showMessage(message,timeout);
}
void MainWindow::on_pushButtonSetting_clicked()
{
settingObject->show();
}
void MainWindow::on_pushButtonOriginCopy_clicked()
{
setClipboardText(m_remotePicUrl);
showStatusMessage("复制链接完成",5000);
}
void MainWindow::on_pushButtonMarkdownCopy_clicked()
{
setClipboardText("");
showStatusMessage("复制链接完成",5000);
}