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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user