1.0 finish
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
#include "ui_frmupload.h"
|
||||
#include <QtDebug>
|
||||
#include <QImageReader>
|
||||
#include <QStandardPaths>
|
||||
|
||||
FrmUpload::FrmUpload(QWidget *parent)
|
||||
: QWidget(parent)
|
||||
@@ -11,6 +12,29 @@ FrmUpload::FrmUpload(QWidget *parent)
|
||||
initFrom();
|
||||
initWidget();
|
||||
connect(TCHttpService::getInstance(), &TCHttpService::signal_uploadFileSec, this, &FrmUpload::slot_uploadFileSec);
|
||||
|
||||
QButtonGroup *buttonGroup = new QButtonGroup(this);
|
||||
buttonGroup->setExclusive(true); // 确保每次只有一个按钮被选中
|
||||
|
||||
// 添加按钮到组中
|
||||
buttonGroup->addButton(ui->btnHTML);
|
||||
buttonGroup->addButton(ui->btnMarkdown);
|
||||
buttonGroup->addButton(ui->btnUBB);
|
||||
buttonGroup->addButton(ui->btnUrl);
|
||||
|
||||
// 设置样式表
|
||||
QString buttonStyle = R"(
|
||||
QPushButton {
|
||||
color: black;
|
||||
}
|
||||
QPushButton:checked {
|
||||
color: #409EFF
|
||||
}
|
||||
)";
|
||||
ui->btnHTML->setStyleSheet(buttonStyle);
|
||||
ui->btnMarkdown->setStyleSheet(buttonStyle);
|
||||
ui->btnUBB->setStyleSheet(buttonStyle);
|
||||
ui->btnUrl->setStyleSheet(buttonStyle);
|
||||
}
|
||||
|
||||
FrmUpload::~FrmUpload()
|
||||
@@ -20,14 +44,26 @@ FrmUpload::~FrmUpload()
|
||||
|
||||
void FrmUpload::slot_uploadFileSec(QString url)
|
||||
{
|
||||
qDebug() << "slot_uploadFileSec:" << url;
|
||||
QClipboard* clipboard = QApplication::clipboard();
|
||||
|
||||
if (copyState == 0) {
|
||||
|
||||
if (copyType == COPY_TYPE_MARKDOWN) {
|
||||
clipboard->setText(QString("").arg(url));
|
||||
}
|
||||
else {
|
||||
if (copyType == COPY_TYPE_URL) {
|
||||
clipboard->setText(url);
|
||||
}
|
||||
if (copyType == COPY_TYPE_UBB) {
|
||||
// [IMG]https://imagehyj.oss-cn-hangzhou.aliyuncs.com/blog/logo512.png[/IMG]
|
||||
clipboard->setText(QString("[IMG]%1[/IMG]").arg(url));
|
||||
}
|
||||
if (copyType == COPY_TYPE_HTML) {
|
||||
clipboard->setText(QString("<img src=\"%1\"/>").arg(url));
|
||||
|
||||
// QThread::sleep(50);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
bool FrmUpload::eventFilter(QObject *watched, QEvent *event)
|
||||
@@ -106,12 +142,19 @@ void FrmUpload::initFrom()
|
||||
ui->btnMarkdown->setText("Markdown");
|
||||
ui->btnUrl->setText("URL");
|
||||
ui->btnUBB->setText("UBB");
|
||||
|
||||
ui->btnMarkdown->setChecked(true);
|
||||
ui->btnHTML->setChecked(false);
|
||||
ui->btnUBB->setChecked(false);
|
||||
ui->btnUrl->setChecked(false);
|
||||
}
|
||||
|
||||
void FrmUpload::initWidget()
|
||||
{
|
||||
ui->frmUpload->installEventFilter(this);
|
||||
this->setAcceptDrops(true);
|
||||
setWindowFlags(Qt::FramelessWindowHint); // 移除系统边框
|
||||
setAttribute(Qt::WA_TranslucentBackground); // 启用透明背景
|
||||
// ui->frmUpload->setAcceptDrops(true);
|
||||
}
|
||||
|
||||
@@ -127,3 +170,108 @@ void FrmUpload::uploadFiles(QStringList fileList)
|
||||
// TCHttpService::getInstance()->apiMyfileNormal();
|
||||
|
||||
}
|
||||
|
||||
void FrmUpload::on_btnFastUpload_clicked()
|
||||
{
|
||||
// QString addDataPath = QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation);
|
||||
// QString cacheDirPath = addDataPath + "/cache/";
|
||||
QDir cacheDir(QStandardPaths::writableLocation(QStandardPaths::CacheLocation));
|
||||
if (!cacheDir.exists()) {
|
||||
cacheDir.mkpath(".");
|
||||
}
|
||||
QClipboard* clipboard = QApplication::clipboard();
|
||||
const QMimeData* mimeData = clipboard->mimeData();
|
||||
|
||||
if (mimeData->hasImage()) {
|
||||
QImage image = clipboard->image();
|
||||
if (!image.isNull()) {
|
||||
RenameType renametype = FileConfigDecode::getInstance()->getRenameType();
|
||||
qDebug() << "renameType:" << renametype;
|
||||
if (renametype == RENAME_TYPE_NORMAL) {
|
||||
bool ok;
|
||||
QString timestamp = QDateTime::currentDateTime().toString("yyyyMMdd_hhmmsszzz");
|
||||
QString text = QInputDialog::getText(this, "重命名图片", "输入文件名", QLineEdit::Normal, timestamp, &ok);
|
||||
if (ok && !text.isEmpty()) {
|
||||
QString filePath = cacheDir.filePath(text + ".png");
|
||||
|
||||
if (image.save(filePath, "PNG")) {
|
||||
TCHttpService::getInstance()->apiUpload(filePath);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (renametype == RENAME_TYPE_TIME) {
|
||||
qDebug() << "time rename";
|
||||
QString timestamp = QDateTime::currentDateTime().toString("yyyyMMdd_hhmmsszzz");
|
||||
QString filePath = cacheDir.filePath(timestamp + ".png");
|
||||
|
||||
if (image.save(filePath, "PNG")) {
|
||||
TCHttpService::getInstance()->apiUpload(filePath);
|
||||
}
|
||||
}
|
||||
else {
|
||||
QString timestamp = QDateTime::currentDateTime().toString("yyyyMMdd_hhmmsszzz");
|
||||
QString filePath = cacheDir.filePath("clipboard_" + timestamp + ".png");
|
||||
|
||||
if (image.save(filePath, "PNG")) {
|
||||
TCHttpService::getInstance()->apiUpload(filePath);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
clipboard->clear();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void FrmUpload::on_btnMarkdown_clicked()
|
||||
{
|
||||
if (!ui->btnMarkdown->isChecked())
|
||||
return;
|
||||
copyType = COPY_TYPE_MARKDOWN;
|
||||
ui->btnMarkdown->setChecked(true);
|
||||
ui->btnUrl->setChecked(false);
|
||||
ui->btnHTML->setChecked(false);
|
||||
ui->btnUBB->setChecked(false);
|
||||
qDebug() << copyType;
|
||||
}
|
||||
|
||||
|
||||
void FrmUpload::on_btnUrl_clicked()
|
||||
{
|
||||
if (!ui->btnUrl->isChecked())
|
||||
return;
|
||||
copyType = COPY_TYPE_URL;
|
||||
ui->btnMarkdown->setChecked(false);
|
||||
ui->btnUrl->setChecked(true);
|
||||
ui->btnHTML->setChecked(false);
|
||||
ui->btnUBB->setChecked(false);
|
||||
qDebug() << copyType;
|
||||
}
|
||||
|
||||
|
||||
void FrmUpload::on_btnHTML_clicked()
|
||||
{
|
||||
if (!ui->btnHTML->isChecked())
|
||||
return;
|
||||
copyType = COPY_TYPE_HTML;
|
||||
ui->btnMarkdown->setChecked(false);
|
||||
ui->btnUrl->setChecked(false);
|
||||
ui->btnHTML->setChecked(true);
|
||||
ui->btnUBB->setChecked(false);
|
||||
qDebug() << copyType;
|
||||
}
|
||||
|
||||
|
||||
void FrmUpload::on_btnUBB_clicked()
|
||||
{
|
||||
if (!ui->btnUBB->isChecked())
|
||||
return;
|
||||
copyType = COPY_TYPE_UBB;
|
||||
ui->btnMarkdown->setChecked(false);
|
||||
ui->btnUrl->setChecked(false);
|
||||
ui->btnHTML->setChecked(false);
|
||||
ui->btnUBB->setChecked(true);
|
||||
qDebug() << copyType;
|
||||
}
|
||||
|
||||
|
||||
@@ -12,10 +12,26 @@
|
||||
#include <tchttpservice.h>
|
||||
#include <QFileInfo>
|
||||
#include <QClipboard>
|
||||
#include <QPixmap>
|
||||
#include <QMimeData>
|
||||
#include <QDebug>
|
||||
#include <QBuffer>
|
||||
#include <QDateTime>
|
||||
#include <QInputDialog>
|
||||
#include <QButtonGroup>
|
||||
#include <QThread>
|
||||
#include "fileconfigdecode.h"
|
||||
#include "tchttpservice.h"
|
||||
|
||||
#define DEBUG 1
|
||||
|
||||
typedef enum{
|
||||
COPY_TYPE_MARKDOWN = 0,
|
||||
COPY_TYPE_URL,
|
||||
COPY_TYPE_UBB,
|
||||
COPY_TYPE_HTML
|
||||
} CopyType;
|
||||
|
||||
namespace Ui {
|
||||
class FrmUpload;
|
||||
}
|
||||
@@ -36,12 +52,23 @@ protected:
|
||||
virtual void dragEnterEvent(QDragEnterEvent *event) override;
|
||||
virtual void dropEvent(QDropEvent *event) override;
|
||||
|
||||
private slots:
|
||||
void on_btnFastUpload_clicked();
|
||||
|
||||
void on_btnMarkdown_clicked();
|
||||
|
||||
void on_btnUrl_clicked();
|
||||
|
||||
void on_btnHTML_clicked();
|
||||
|
||||
void on_btnUBB_clicked();
|
||||
|
||||
private:
|
||||
void initFrom();
|
||||
void initWidget();
|
||||
void uploadFiles(QStringList fileList);
|
||||
// 0 md 1 url
|
||||
int copyState = 0;
|
||||
CopyType copyType = COPY_TYPE_MARKDOWN;
|
||||
|
||||
private:
|
||||
Ui::FrmUpload *ui;
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
<item>
|
||||
<widget class="QLabel" name="labTitle">
|
||||
<property name="text">
|
||||
<string>LennDFS 快捷助手</string>
|
||||
<string>LennDFS PicPanel</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignmentFlag::AlignCenter</set>
|
||||
@@ -208,12 +208,18 @@
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>100</width>
|
||||
<height>20</height>
|
||||
<height>25</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="cursor">
|
||||
<cursorShape>PointingHandCursor</cursorShape>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>PushButton</string>
|
||||
</property>
|
||||
<property name="checkable">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
@@ -227,12 +233,18 @@
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>75</width>
|
||||
<height>20</height>
|
||||
<height>25</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="cursor">
|
||||
<cursorShape>PointingHandCursor</cursorShape>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>PushButton</string>
|
||||
</property>
|
||||
<property name="checkable">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
@@ -246,12 +258,18 @@
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>75</width>
|
||||
<height>20</height>
|
||||
<height>25</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="cursor">
|
||||
<cursorShape>PointingHandCursor</cursorShape>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>PushButton</string>
|
||||
</property>
|
||||
<property name="checkable">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
@@ -265,12 +283,18 @@
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>100</width>
|
||||
<height>20</height>
|
||||
<height>25</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="cursor">
|
||||
<cursorShape>PointingHandCursor</cursorShape>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>PushButton</string>
|
||||
</property>
|
||||
<property name="checkable">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
@@ -313,9 +337,12 @@
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>100</width>
|
||||
<height>20</height>
|
||||
<height>25</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="cursor">
|
||||
<cursorShape>PointingHandCursor</cursorShape>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>PushButton</string>
|
||||
</property>
|
||||
|
||||
Reference in New Issue
Block a user