bug/loadimage-dump

This commit is contained in:
2025-03-26 18:37:05 +08:00
parent c69a6899cb
commit 8b8b70c671
28 changed files with 816 additions and 363 deletions

View File

@@ -2,6 +2,7 @@
#include "ui_frmalbum.h"
#include <QUrl>
int FrmAlbum::m_copyType = 0;
FrmAlbum::FrmAlbum(QWidget *parent) : QWidget(parent)
{
@@ -13,52 +14,168 @@ FrmAlbum::~FrmAlbum()
delete ui;
}
// QSet<QString> FrmAlbum::getUrlSet()
// {
// return m_selectedImageSet;
// }
int FrmAlbum::getCopyType()
{
return m_copyType;
}
void FrmAlbum::slot_updateImage()
{
QList<QUrl> urls = {
QUrl("https://imagehyj.oss-cn-hangzhou.aliyuncs.com/blog/20250320201317.png"),
QUrl("https://imagehyj.oss-cn-hangzhou.aliyuncs.com/blog/EDH386.jpeg"),
QUrl("https://imagehyj.oss-cn-hangzhou.aliyuncs.com/blog/20250321103557.png"),
QUrl("https://imagehyj.oss-cn-hangzhou.aliyuncs.com/blog/logo512.png")
};
foreach (const QUrl& u, urls) {
FrmImgShow* widget = new FrmImgShow(this);
widget->loadImage(u);
picWidgetList.push_front(widget);
}
qDebug() <<"slot_updateImage";
// QList<QUrl> urls = ImageManager::instance()->getImageUrls(FileConfigDecode::getInstance()->getAddress(),
// FileConfigDecode::getInstance()->getUserName());
// foreach (const QUrl& u, urls) {
// qDebug() << "image url:" <<u;
// FrmImgShow* widget = new FrmImgShow;
// connect(widget, &FrmImgShow::signal_imageSelected, [this](const QString& url){
// m_selectedImageSet.insert(url);
// });
// connect(widget, &FrmImgShow::signal_imageUnselected, [this](const QString& url){
// m_selectedImageSet.remove(url);
// });
// widget->loadImage(u);
// picWidgetList.push_front(widget);
// panelWidget->setWidget(picWidgetList, 3);
// }
}
void FrmAlbum::initForm()
{
layout = new QHBoxLayout(this);
panelWidget = new PanelWidget(this);
layout = new QVBoxLayout();
setLayout(layout);
panelWidget = new PanelWidget();
panelWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
panelWidget->setStyleSheet("border:1px solid white;");
panelWidget->setSpace(5);
layout->addWidget(panelWidget);
layout->setContentsMargins(0, 0, 0, 0);
layout->setSpacing(0);
this->setLayout(layout);
panelWidget->setObjectName("widget");
panelWidget->setStyleSheet("background-color: rgb(63, 60, 55)");
// panelWidget->setStyleSheet("background-color: #FFFFFF");
panelWidget->setAutoHeight(false);
panelWidget->setAutoWidth(false);
panelWidget->setAutoHeight(false);
panelWidget->setAutoWidth(false);
btnCopy = new QPushButton;
btnCopy->setText("复制");
btnCopy->setCursor(Qt::PointingHandCursor);
btnCopy->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
btnCopy->setStyleSheet("height:25px;width:70px;background-color:#1B9EF3;color:white;border-style:none;border-radius:8px");
connect(btnCopy, &QPushButton::clicked, [this](){
qDebug() <<"btnCopy";
QString clipStr = "";
foreach (QString s, m_selectedImageSet) {
switch (cbbCopyType->currentIndex()) {
case 0:
{
QString curStr = QString("![](%1)").arg(s);
curStr += "\n";
clipStr += curStr;
break;
}
case 1:
{
QString curStr = QString("%1").arg(s);
curStr += "\n";
clipStr += curStr;
break;
}
case 2:
{
QString curStr = QString("<img src=\"%1\"/>").arg(s);
curStr += "\n";
clipStr += curStr;
break;
}
case 3:
{
QString curStr = QString("[IMG]%1[/IMG]").arg(s);
curStr += "\n";
clipStr += curStr;
break;
}
}
}
QClipboard* clipboard = QApplication::clipboard();
clipboard->setText(clipStr);
});
btnDelete = new QPushButton;
btnDelete->setText("删除");
btnDelete->setCursor(Qt::PointingHandCursor);
btnDelete->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
btnDelete->setStyleSheet("height:25px;width:70px;background-color:#F15140;color:white;border-style:none;border-radius:8px");
btnSelectAll = new QPushButton;
btnSelectAll->setText("全选");
btnSelectAll->setCursor(Qt::PointingHandCursor);
btnSelectAll->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
btnSelectAll->setStyleSheet("height:25px;width:70px;background-color:#44B363;color:white;border-style:none;border-radius:8px");
cbbCopyType = new QComboBox;
cbbCopyType->setCursor(Qt::PointingHandCursor);
cbbCopyType->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
cbbCopyType->setStyleSheet("height:25px;width:300;background-color:white;padding-left:16px;");
QList<QString> copyTypeList{"Markdown", "URL", "HTML", "UBB"};
cbbCopyType->addItems(copyTypeList);
connect(cbbCopyType, &QComboBox::currentIndexChanged, [this](int index){
m_copyType = index;
qDebug() << m_copyType;
});
spacerItem = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Fixed);
menuLayout = new QHBoxLayout();
menuLayout->setContentsMargins(0, 0, 0, 0);
menuLayout->setSpacing(8);
menuLayout->addWidget(cbbCopyType);
menuLayout->addWidget(btnCopy);
menuLayout->addWidget(btnDelete);
menuLayout->addWidget(btnSelectAll);
menuLayout->addSpacerItem(spacerItem);
layout->addLayout(menuLayout);
layout->addWidget(panelWidget);
layout->setSpacing(6);
// qDebug() << ui->widget;
QList<QUrl> urls = {
QUrl("https://imagehyj.oss-cn-hangzhou.aliyuncs.com/blog/20250320201317.png"),
QUrl("https://imagehyj.oss-cn-hangzhou.aliyuncs.com/blog/EDH386.jpeg"),
QUrl("https://imagehyj.oss-cn-hangzhou.aliyuncs.com/blog/20250321103557.png"),
QUrl("https://imagehyj.oss-cn-hangzhou.aliyuncs.com/blog/logo512.png")
};
connect(TCHttpService::getInstance(), &TCHttpService::signal_loginSuc, [this](){
qDebug() <<"login success";
QList<QUrl> urls = ImageManager::instance()->getImageUrls(FileConfigDecode::getInstance()->getAddress(),
FileConfigDecode::getInstance()->getUserName());
foreach (const QUrl& u, urls) {
qDebug() << "image url:" <<u;
FrmImgShow* widget = new FrmImgShow(panelWidget);
connect(widget, &FrmImgShow::signal_imageSelected, [this](const QString& url){
m_selectedImageSet.insert(url);
});
connect(widget, &FrmImgShow::signal_imageUnselected, [this](const QString& url){
m_selectedImageSet.remove(url);
});
widget->loadImage(u);
picWidgetList.push_front(widget);
panelWidget->setWidget(picWidgetList, 3);
}
});
foreach (const QUrl& u, urls) {
FrmImgShow* widget = new FrmImgShow(this);
widget->loadImage(u);
picWidgetList.push_front(widget);
}
panelWidget->setWidget(picWidgetList, 4);
panelWidget->setSpace(15);

View File

@@ -2,8 +2,12 @@
#define FRMALBUM_H
#include <QWidget>
#include <QPushButton>
#include <QComboBox>
#include <QSet>
#include "panelwidget.h"
#include "frmimgshow.h"
#include "fileconfigdecode.h"`
#include <QHBoxLayout>
namespace Ui {
@@ -18,6 +22,9 @@ public:
explicit FrmAlbum(QWidget *parent = nullptr);
~FrmAlbum();
// QSet<QString> getUrlSet();
static int getCopyType();
public slots:
void slot_updateImage();
@@ -25,8 +32,19 @@ private:
Ui::FrmAlbum *ui;
QList<QWidget*> picWidgetList;
PanelWidget* panelWidget;
QHBoxLayout* layout;
QVBoxLayout* layout;
void initForm();
QPushButton* btnCopy;
QPushButton* btnDelete;
QPushButton* btnSelectAll;
QComboBox* cbbCopyType;
QHBoxLayout* menuLayout;
QSpacerItem* spacerItem;
QSet<QString> m_selectedImageSet;
static int m_copyType;
};
#endif // FRMALBUM_H

View File

@@ -1,12 +1,15 @@
#include "frmimgshow.h"
#include "frmalbum.h"
FrmImgShow::FrmImgShow(QWidget *parent) : QWidget(parent)
{
initForm();
initSignalSlot();
connect(TCHttpService::getInstance(), &TCHttpService::signal_imageDownloaded,
this, [this](const QString& requestId, const QPixmap& pixmap){
if (requestId == m_requestId) {
setLoadingState(false);
// setLoadingState(false);
qDebug() << "load success";
setImage(pixmap);
}
});
@@ -14,7 +17,7 @@ FrmImgShow::FrmImgShow(QWidget *parent) : QWidget(parent)
connect(TCHttpService::getInstance(), &TCHttpService::signal_downloadFailed,
this, [this](const QString& requestId, const QString& error){
if (requestId == m_requestId) {
setLoadingState(true);
qDebug() << "load failed";
}
});
}
@@ -24,14 +27,11 @@ void FrmImgShow::loadImage(const QUrl &imageUrl)
qDebug() << "loadImage";
m_currentUrl = imageUrl;
m_requestId = QUuid::createUuid().toString();
setLoadingState(true);
qDebug() << "downlaodImage";
TCHttpService::getInstance()->downloadImage(m_requestId, imageUrl);
}
void FrmImgShow::setImage(const QPixmap &pixmap)
{
qDebug() << "setImage";
// int h = pixmap.height();
// int w = pixmap.width();
// int sh, sw;
@@ -51,6 +51,52 @@ void FrmImgShow::setLoadingState(bool loading)
}
void FrmImgShow::initSignalSlot()
{
connect(btnCopy, &QPushButton::clicked, [this](){
switch(FrmAlbum::getCopyType()) {
case 0:
{
QClipboard* clipboard = QApplication::clipboard();
QString mdStr = QString("![](%1)").arg(m_currentUrl.toString());
clipboard->setText(mdStr);
break;
}
case 1:
{
QClipboard* clipboard = QApplication::clipboard();
QString urlStr = m_currentUrl.toString();
clipboard->setText(urlStr);
break;
}
case 2:
{
QClipboard* clipboard = QApplication::clipboard();
QString htmlStr = QString("<img src=\"%1\"/>").arg(m_currentUrl.toString());
clipboard->setText(htmlStr);
break;
}
case 3:
{
QClipboard* clipboard = QApplication::clipboard();
QString ubbStr = QString("[IMG]%1[/IMG]").arg(m_currentUrl.toString());
clipboard->setText(ubbStr);
break;
}
}
});
connect(ckbSelect, &QCheckBox::checkStateChanged, [this](Qt::CheckState state){
if (state == Qt::Unchecked) {
emit signal_imageUnselected(m_currentUrl.toString());
}
if (state == Qt::Checked) {
emit signal_imageSelected(m_currentUrl.toString());
}
});
}
QSize FrmImgShow::sizeHint()
{
@@ -113,6 +159,7 @@ void FrmImgShow::initForm()
btnCopy->setMinimumSize(22, 22);
btnCopy->setFlat(true);
btnCopy->setIcon(QIcon(":/qrc/image/copy_white.png"));
btnCopy->setCursor(Qt::PointingHandCursor);
btnCopy->installEventFilter(this);
@@ -121,14 +168,17 @@ void FrmImgShow::initForm()
btnDelete->setFlat(true);
btnDelete->setIcon(QIcon(":/qrc/image/delete_white.png"));
btnDelete->installEventFilter(this);
btnDelete->setCursor(Qt::PointingHandCursor);
horizenSpacer = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
hLayout = new QHBoxLayout();
ckbSelect = new QCheckBox();
// ckbSelect->setMinimumSize(20, 20);
ckbSelect->setText("");
ckbSelect->setMinimumSize(20, 20);
ckbSelect->setCursor(Qt::PointingHandCursor);
// ckbSelect->setStyleSheet("border:1px solid white;border-radius:5px");
ckbSelect->setStyleSheet("border-style:none;");
// ckbSelect->setStyleSheet("border-style:none;background-color:green;spacing:0px;");
hLayout->addWidget(btnCopy);
hLayout->addWidget(btnDelete);
@@ -143,12 +193,13 @@ void FrmImgShow::initForm()
// btnCopy->setIcon(QIcon(QPixmap(":/qrc/image/copy_white.png")));
// btnDelete->setIcon(QIcon(QPixmap(":/qrc/image/delete_white.png")));
// btnCopy->setFixedSize(32, 32);
// btnCopy->setCursor(Qt::PointingHandCursor);
// setStyleSheet("background-color: #FF0000;border: 1px solid white");
setStyleSheet("background-color: #FF0000");
setFixedSize(134, 160);
@@ -158,6 +209,6 @@ void FrmImgShow::initForm()
void FrmImgShow::initWidget()
{
// btnCopy->installEventFilter(this);
// btnDelete->installEventFilter(this);
btnCopy->installEventFilter(this);
btnDelete->installEventFilter(this);
}

View File

@@ -10,6 +10,8 @@
#include <QSpacerItem>
#include <QUrl>
#include <QCheckBox>
#include <QClipboard>
#include <QApplication>
#include <QGuiApplication>
#include "tchttpservice.h"
@@ -23,7 +25,9 @@ public:
void setImage(const QPixmap& pixmap);
void setLoadingState(bool loading);
QSize sizeHint();
void initSignalSlot();
virtual QSize sizeHint();
private:
QLabel* labImg;
// QLabel* labLoading;
@@ -48,6 +52,10 @@ private:
QString m_requestId;
QUrl m_currentUrl;
signals:
void signal_imageSelected(QString);
void signal_imageUnselected(QString);
};
#endif // FRMIMGSHOW_H

View File

@@ -37,6 +37,10 @@ void FrmSetting::initForm()
ui->schEnableSsl->enableText(false);
ui->schEnableSsl->setAnimation(true);
ui->schAutoLogin->setBgColorOn(QColor("#409EFF"));
ui->schAutoLogin->enableText(false);
ui->schAutoLogin->setAnimation(true);
ui->btnServer->setCursor(Qt::PointingHandCursor);
ui->schRename->setCursor(Qt::PointingHandCursor);
@@ -81,23 +85,36 @@ void FrmSetting::initWidget()
ui->labTimeRenameClose->setStyleSheet(OPENQSS);
}
if (FileConfigDecode::getInstance()->getAutoCopy()) {
ui->labEnableSsl->setStyleSheet(OPENQSS);
ui->labEnableSsl->setStyleSheet(CLOSEQSS);
ui->labEnableSslOpen->setStyleSheet(OPENQSS);
ui->labEnableSslClose->setStyleSheet(CLOSEQSS);
}
else {
ui->labEnableSsl->setStyleSheet(CLOSEQSS);
ui->labEnableSsl->setStyleSheet(OPENQSS);
ui->labEnableSslOpen->setStyleSheet(CLOSEQSS);
ui->labEnableSslClose->setStyleSheet(OPENQSS);
}
if (FileConfigDecode::getInstance()->getAutoLogin()) {
ui->labAUtoLoginOpen->setStyleSheet(OPENQSS);
ui->labAUtoLoginOpen->setStyleSheet(CLOSEQSS);
TCHttpService::getInstance()->setConfiguration(FileConfigDecode::getInstance()->getUserName(),
FileConfigDecode::getInstance()->getPassword(),
FileConfigDecode::getInstance()->getAddress());
}
else {
ui->labAUtoLoginOpen->setStyleSheet(CLOSEQSS);
ui->labAUtoLoginOpen->setStyleSheet(OPENQSS);
}
ui->schRename->setChecked(FileConfigDecode::getInstance()->getRename());
ui->schAutoSetup->setChecked(FileConfigDecode::getInstance()->getAutoSetup());
ui->schTimeRename->setChecked(FileConfigDecode::getInstance()->getTimeRename());
ui->schEnableSsl->setChecked(FileConfigDecode::getInstance()->getAutoCopy());
ui->schAutoLogin->setChecked(FileConfigDecode::getInstance()->getAutoLogin());
connect(ui->schRename, &SwitchButton::checkedChanged, this, &FrmSetting::schRenameSlot);
connect(ui->schAutoSetup, &SwitchButton::checkedChanged, this, &FrmSetting::schAutoSetup);
connect(ui->schTimeRename, &SwitchButton::checkedChanged, this, &FrmSetting::schTimeRename);
connect(ui->schEnableSsl, &SwitchButton::checkedChanged, this, &FrmSetting::schEnableSsl);
connect(ui->schAutoLogin, &SwitchButton::checkedChanged, this, &FrmSetting::schAutoLogin);
connect(ui->btnServer, &QPushButton::clicked, serversetting, &ServerSetting::show);
}
@@ -136,6 +153,13 @@ void FrmSetting::schEnableSsl(bool checked)
}
void FrmSetting::schAutoLogin(bool checked)
{
FileConfigDecode::getInstance()->setAutoLogin(checked);
ui->labAUtoLoginOpen->setStyleSheet(checked?OPENQSS:CLOSEQSS);
ui->labAutoLoginClose->setStyleSheet(checked?CLOSEQSS:OPENQSS);
}
void FrmSetting::slot_updateServerConfig(QString address, QString username, QString password)
{
FileConfigDecode::getInstance()->setAddress(address);

View File

@@ -37,6 +37,7 @@ private slots:
void schAutoSetup(bool checked);
void schTimeRename(bool checked);
void schEnableSsl(bool checked);
void schAutoLogin(bool checked);
void slot_updateServerConfig(QString address, QString username, QString password);

View File

@@ -368,7 +368,7 @@
<item>
<layout class="QHBoxLayout" name="horizontalLayout_6">
<item>
<widget class="QLabel" name="labEnableSsl_2">
<widget class="QLabel" name="lanAUtoLogin">
<property name="styleSheet">
<string notr="true">color: rgb(255, 255, 255);</string>
</property>
@@ -391,14 +391,14 @@
</spacer>
</item>
<item>
<widget class="QLabel" name="labEnableSslClose_2">
<widget class="QLabel" name="labAutoLoginClose">
<property name="text">
<string>关</string>
</property>
</widget>
</item>
<item>
<widget class="SwitchButton" name="schEnableSsl_2" native="true">
<widget class="SwitchButton" name="schAutoLogin" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Minimum">
<horstretch>0</horstretch>
@@ -420,7 +420,7 @@
</widget>
</item>
<item>
<widget class="QLabel" name="labEnableSslOpen_2">
<widget class="QLabel" name="labAUtoLoginOpen">
<property name="text">
<string>开</string>
</property>

View File

@@ -47,7 +47,9 @@ void FrmUpload::slot_uploadFileSec(QString url)
qDebug() << "slot_uploadFileSec:" << url;
QClipboard* clipboard = QApplication::clipboard();
QString domain = FileConfigDecode::getInstance()->getAddress();
QString userName = FileConfigDecode::getInstance()->getUserName();
ImageManager::instance()->addImageUrl(domain, userName, url);
if (copyType == COPY_TYPE_MARKDOWN) {
clipboard->setText(QString("![](%1)").arg(url));
emit signal_uploadSuccess(url);
@@ -70,6 +72,11 @@ void FrmUpload::slot_uploadFileSec(QString url)
}
void FrmUpload::slot_progressUpdate(int v)
{
ui->progressBar->setValue(v);
}
bool FrmUpload::eventFilter(QObject *watched, QEvent *event)
{
static bool mousePressed = false;
@@ -159,6 +166,8 @@ void FrmUpload::initWidget()
this->setAcceptDrops(true);
setWindowFlags(Qt::FramelessWindowHint); // 移除系统边框
setAttribute(Qt::WA_TranslucentBackground); // 启用透明背景
connect(TCHttpService::getInstance(), &TCHttpService::signal_progressUpdate, this, &FrmUpload::slot_progressUpdate);
// ui->frmUpload->setAcceptDrops(true);
}
@@ -179,6 +188,7 @@ 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(".");
@@ -187,6 +197,7 @@ void FrmUpload::on_btnFastUpload_clicked()
const QMimeData* mimeData = clipboard->mimeData();
if (mimeData->hasImage()) {
ui->progressBar->setValue(0);
QImage image = clipboard->image();
if (!image.isNull()) {
RenameType renametype = FileConfigDecode::getInstance()->getRenameType();

View File

@@ -46,6 +46,7 @@ public:
public slots:
void slot_uploadFileSec(QString url);
void slot_progressUpdate(int v);
protected:
virtual bool eventFilter(QObject* watched, QEvent* event);

View File

@@ -162,6 +162,45 @@
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_5">
<item>
<widget class="QProgressBar" name="progressBar">
<property name="maximumSize">
<size>
<width>16777215</width>
<height>10</height>
</size>
</property>
<property name="value">
<number>0</number>
</property>
<property name="alignment">
<set>Qt::AlignmentFlag::AlignCenter</set>
</property>
<property name="textVisible">
<bool>false</bool>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_7">
<property name="orientation">
<enum>Qt::Orientation::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Policy::Fixed</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_4">
<item>

View File

@@ -94,6 +94,7 @@ void PanelWidget::setWidget(QList<QWidget *> widgets, int columnCount)
foreach (QWidget *widget, widgets) {
gridLayout->removeWidget(widget);
widget->setVisible(false);
delete widget;
}
//重新添加到布局中并可见

View File

@@ -61,6 +61,7 @@ public:
QList<QWidget *> getWidgets();
int getColumnCount();
public Q_SLOTS:
void setWidget(QList<QWidget *> widgets, int columnCount);
void setMargin(int left, int top, int right, int bottom);