http模块有问题,需要修改

This commit is contained in:
2025-03-24 00:05:08 +08:00
commit 9d8c7baa36
66 changed files with 4602 additions and 0 deletions

16
core_form/core_form.pri Normal file
View File

@@ -0,0 +1,16 @@
CONFIG += QMAKE_CXXFLAGS_WARN_OFF
INCLUDEPATH += $$PWD
INCLUDEPATH += $$PWD/frmupload
INCLUDEPATH += $$PWD/frmsetting
INCLUDEPATH += $$PWD/frmalbum
INCLUDEPATH += $$PWD/frmimgshow
INCLUDEPATH += $$PWD/switchbutton
INCLUDEPATH += $$PWD/serversetting
include($$PWD/frmupload/frmupload.pri)
include($$PWD/frmsetting/frmsetting.pri)
include($$PWD/frmalbum/frmalbum.pri)
include($$PWD/frmimgshow/frmimgshow.pri)
include($$PWD/switchbutton/switchbutton.pri)
include($$PWD/serversetting/serversetting.pri)

View File

@@ -0,0 +1,14 @@
#include "frmalbum.h"
#include "ui_frmalbum.h"
FrmAlbum::FrmAlbum(QWidget *parent)
: QWidget(parent)
, ui(new Ui::FrmAlbum)
{
ui->setupUi(this);
}
FrmAlbum::~FrmAlbum()
{
delete ui;
}

View File

@@ -0,0 +1,22 @@
#ifndef FRMALBUM_H
#define FRMALBUM_H
#include <QWidget>
namespace Ui {
class FrmAlbum;
}
class FrmAlbum : public QWidget
{
Q_OBJECT
public:
explicit FrmAlbum(QWidget *parent = nullptr);
~FrmAlbum();
private:
Ui::FrmAlbum *ui;
};
#endif // FRMALBUM_H

View File

@@ -0,0 +1,8 @@
FORMS += \
$$PWD/frmalbum.ui
HEADERS += \
$$PWD/frmalbum.h
SOURCES += \
$$PWD/frmalbum.cpp

View File

@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>FrmAlbum</class>
<widget class="QWidget" name="FrmAlbum">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
</widget>
<resources/>
<connections/>
</ui>

View File

@@ -0,0 +1,92 @@
#include "frmimgshow.h"
FrmImgShow::FrmImgShow(QString& url, QWidget *parent) : QWidget(parent)
{
initForm();
initForm();
initManager();
this->url = url;
manager->get(QNetworkRequest(QUrl(url)));
}
bool FrmImgShow::eventFilter(QObject *watched, QEvent *event)
{
if (watched == btnCopy) {
if (event->type() == QEvent::Enter) {
btnCopy->setIcon(QIcon(QPixmap(":/qrc/image/copy_blue.png")));
return true;
}
else if (event->type() == QEvent::Leave) {
btnCopy->setIcon(QIcon(QPixmap(":/qrc/image/copy_white.png")));
return true;
}
else {
return false;
}
}
if (watched == btnDelete) {
if (event->type() == QEvent::Enter) {
btnDelete->setIcon(QIcon(QPixmap(":/qrc/image/delete_red.png")));
return true;
}
else if (event->type() == QEvent::Leave) {
btnDelete->setIcon(QIcon(QPixmap(":/qrc/image/delete_white.png")));
return true;
}
else {
return false;
}
}
return QWidget::eventFilter(watched, event);
}
void FrmImgShow::onFinished(QNetworkReply *reply)
{
if (reply->error() == QNetworkReply::NoError) {
QByteArray imageData = reply->readAll();
QPixmap pix;
pix.loadFromData(imageData);
this->labImg->setPixmap(pix);
}
}
void FrmImgShow::initForm()
{
labImg = new QLabel();
btnCopy = new QToolButton();
btnDelete = new QToolButton();
horizenSpacer = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
hLayout = new QHBoxLayout();
vLayout = new QVBoxLayout();
hLayout->addWidget(btnCopy);
hLayout->addSpacerItem(horizenSpacer);
vLayout->addWidget(labImg);
vLayout->addLayout(hLayout);
this->setLayout(vLayout);
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);
}
void FrmImgShow::initWidget()
{
btnCopy->installEventFilter(this);
btnDelete->installEventFilter(this);
}
void FrmImgShow::initManager()
{
manager = new QNetworkAccessManager();
QClipboard* clipboard = QGuiApplication::clipboard();
connect(manager, &QNetworkAccessManager::finished,
this, &FrmImgShow::onFinished);
connect(btnCopy, &QToolButton::clicked, [&](){
clipboard->setText(this->url);
});
}

View File

@@ -0,0 +1,50 @@
#ifndef FRMIMGSHOW_H
#define FRMIMGSHOW_H
#include <QWidget>
#include <QPushButton>
#include <QLabel>
#include <QHBoxLayout>
#include <QVBoxLayout>
#include <QToolButton>
#include <QSpacerItem>
#include <QNetworkAccessManager>
#include <QNetworkRequest>
#include <QUrl>
#include <QNetworkReply>
#include <QClipboard>
#include <QGuiApplication>
class FrmImgShow : public QWidget
{
Q_OBJECT
public:
explicit FrmImgShow(QString& url, QWidget *parent = nullptr);
private:
QLabel* labImg;
QToolButton* btnCopy;
QToolButton* btnDelete;
QSpacerItem* horizenSpacer;
QHBoxLayout* hLayout;
QVBoxLayout* vLayout;
QNetworkAccessManager* manager;
QString url;
protected:
virtual bool eventFilter(QObject* watched, QEvent* event);
private slots:
void onFinished(QNetworkReply *reply);
private:
void initForm();
void initWidget();
void initManager();
signals:
};
#endif // FRMIMGSHOW_H

View File

@@ -0,0 +1,5 @@
HEADERS += \
$$PWD/frmimgshow.h
SOURCES += \
$$PWD/frmimgshow.cpp

View File

@@ -0,0 +1,129 @@
#include "frmsetting.h"
#include "ui_frmsetting.h"
#include <QDebug>
FrmSetting::FrmSetting(FileConfigDecode* fileConfig, QWidget *parent)
: QWidget(parent)
, ui(new Ui::FrmSetting)
{
ui->setupUi(this);
this->fileConfig = fileConfig;
initForm();
initWidget();
}
FrmSetting::~FrmSetting()
{
delete ui;
}
void FrmSetting::initForm()
{
ui->schRename->setBgColorOn(QColor("#409EFF"));
ui->schRename->enableText(false);
ui->schRename->setAnimation(true);
ui->schAutoSetup->setBgColorOn(QColor("#409EFF"));
ui->schAutoSetup->enableText(false);
ui->schAutoSetup->setAnimation(true);
ui->schTimeRename->setBgColorOn(QColor("#409EFF"));
ui->schTimeRename->enableText(false);
ui->schTimeRename->setAnimation(true);
ui->schEnableSsl->setBgColorOn(QColor("#409EFF"));
ui->schEnableSsl->enableText(false);
ui->schEnableSsl->setAnimation(true);
ui->btnServer->setCursor(Qt::PointingHandCursor);
ui->schRename->setCursor(Qt::PointingHandCursor);
serversetting = new ServerSetting();
serversetting->hide();
}
void FrmSetting::initWidget()
{
if (fileConfig->getRename()) {
ui->labRenameOpen->setStyleSheet(OPENQSS);
ui->labRenameClose->setStyleSheet(CLOSEQSS);
}
else {
ui->labRenameOpen->setStyleSheet(CLOSEQSS);
ui->labRenameClose->setStyleSheet(OPENQSS);
}
if (fileConfig->getAutoSetup()) {
ui->labAutoSetupOpen->setStyleSheet(OPENQSS);
ui->labAutoSetupClose->setStyleSheet(CLOSEQSS);
}
else {
ui->labAutoSetupOpen->setStyleSheet(CLOSEQSS);
ui->labAutoSetupClose->setStyleSheet(OPENQSS);
}
if (fileConfig->getTimeRename()) {
ui->labTimeRenameOpen->setStyleSheet(OPENQSS);
ui->labTimeRenameClose->setStyleSheet(CLOSEQSS);
}
else {
ui->labTimeRenameOpen->setStyleSheet(CLOSEQSS);
ui->labTimeRenameClose->setStyleSheet(OPENQSS);
}
if (fileConfig->getAutoCopy()) {
ui->labEnableSsl->setStyleSheet(OPENQSS);
ui->labEnableSsl->setStyleSheet(CLOSEQSS);
}
else {
ui->labEnableSsl->setStyleSheet(CLOSEQSS);
ui->labEnableSsl->setStyleSheet(OPENQSS);
}
ui->schRename->setChecked(fileConfig->getRename());
ui->schAutoSetup->setChecked(fileConfig->getAutoSetup());
ui->schTimeRename->setChecked(fileConfig->getTimeRename());
ui->schEnableSsl->setChecked(fileConfig->getAutoCopy());
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->btnServer, &QPushButton::clicked, serversetting, &ServerSetting::show);
}
void FrmSetting::schRenameSlot(bool checked)
{
fileConfig->setRename(checked);
ui->labRenameOpen->setStyleSheet(checked?OPENQSS:CLOSEQSS);
ui->labRenameClose->setStyleSheet(checked?CLOSEQSS:OPENQSS);
}
void FrmSetting::schAutoSetup(bool checked)
{
fileConfig->setAutoSetup(checked);
ui->labAutoSetupOpen->setStyleSheet(checked?OPENQSS:CLOSEQSS);
ui->labAutoSetupClose->setStyleSheet(checked?CLOSEQSS:OPENQSS);
}
void FrmSetting::schTimeRename(bool checked)
{
fileConfig->setTimeRename(checked);
ui->labTimeRenameOpen->setStyleSheet(checked?OPENQSS:CLOSEQSS);
ui->labTimeRenameClose->setStyleSheet(checked?CLOSEQSS:OPENQSS);
}
void FrmSetting::schEnableSsl(bool checked)
{
fileConfig->setAutoCopy(checked);
ui->labEnableSslOpen->setStyleSheet(checked?OPENQSS:CLOSEQSS);
ui->labEnableSslClose->setStyleSheet(checked?CLOSEQSS:OPENQSS);
TCHttpService::getInstance()->setSsl(checked);
}

View File

@@ -0,0 +1,47 @@
#ifndef FRMSETTING_H
#define FRMSETTING_H
#include <QWidget>
#include "fileconfigdecode.h"
#include "serversetting.h"
#include "tchttpservice.h"
// 开机自启动
// 域名/地址
// 端口
// 上传前重命名
// 时间戳重命名
// 上传后复制URL
#define OPENQSS "QLabel{color:#409EFF;}"
#define CLOSEQSS "QLabel{color:#FFFFFF;}"
namespace Ui {
class FrmSetting;
}
class FrmSetting : public QWidget
{
Q_OBJECT
public:
explicit FrmSetting(FileConfigDecode* fileConfig, QWidget *parent = nullptr);
~FrmSetting();
private:
void initForm();
void initWidget();
private slots:
void schRenameSlot(bool checked);
void schAutoSetup(bool checked);
void schTimeRename(bool checked);
void schEnableSsl(bool checked);
private:
Ui::FrmSetting *ui;
FileConfigDecode* fileConfig = nullptr;
ServerSetting* serversetting;
};
#endif // FRMSETTING_H

View File

@@ -0,0 +1,8 @@
FORMS += \
$$PWD/frmsetting.ui
HEADERS += \
$$PWD/frmsetting.h
SOURCES += \
$$PWD/frmsetting.cpp

View File

@@ -0,0 +1,364 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>FrmSetting</class>
<widget class="QWidget" name="FrmSetting">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>731</width>
<height>439</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="labServer">
<property name="text">
<string>设置Server</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="btnServer">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>100</width>
<height>35</height>
</size>
</property>
<property name="text">
<string>点击设置</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="Line" name="line">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QLabel" name="labAutoSetup">
<property name="text">
<string>开机自启</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QLabel" name="labAutoSetupClose">
<property name="text">
<string>关</string>
</property>
</widget>
</item>
<item>
<widget class="SwitchButton" name="schAutoSetup" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Minimum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>200</width>
<height>30</height>
</size>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="labAutoSetupOpen">
<property name="text">
<string>开</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="Line" name="line1">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<widget class="QLabel" name="labRename">
<property name="text">
<string>上传重命名</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_3">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QLabel" name="labRenameClose">
<property name="text">
<string>关</string>
</property>
</widget>
</item>
<item>
<widget class="SwitchButton" name="schRename" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Minimum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>200</width>
<height>30</height>
</size>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="labRenameOpen">
<property name="text">
<string>开</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="Line" name="line2">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_4">
<item>
<widget class="QLabel" name="labTimeRename">
<property name="text">
<string>时间戳重命名</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_4">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QLabel" name="labTimeRenameClose">
<property name="text">
<string>关</string>
</property>
</widget>
</item>
<item>
<widget class="SwitchButton" name="schTimeRename" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Minimum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>200</width>
<height>30</height>
</size>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="labTimeRenameOpen">
<property name="text">
<string>开</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="Line" name="line3">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_5">
<item>
<widget class="QLabel" name="labEnableSsl">
<property name="text">
<string>开启SSL</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_5">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QLabel" name="labEnableSslClose">
<property name="text">
<string>关</string>
</property>
</widget>
</item>
<item>
<widget class="SwitchButton" name="schEnableSsl" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Minimum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>200</width>
<height>30</height>
</size>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="labEnableSslOpen">
<property name="text">
<string>开</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>SwitchButton</class>
<extends>QWidget</extends>
<header location="global">switchbutton.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<resources/>
<connections/>
</ui>

View File

@@ -0,0 +1,103 @@
#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();
}
FrmUpload::~FrmUpload()
{
delete ui;
}
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));
}
void FrmUpload::initWidget()
{
ui->frmUpload->installEventFilter(this);
this->setAcceptDrops(true);
// ui->frmUpload->setAcceptDrops(true);
}
void FrmUpload::uploadFiles(QStringList fileList)
{
}

View File

@@ -0,0 +1,42 @@
#ifndef FRMUPLOAD_H
#define FRMUPLOAD_H
#include <QWidget>
#include <QMouseEvent>
#include <QEvent>
#include <QDropEvent>
#include <QMoveEvent>
#include <QFileDialog>
#include <QMimeData>
#include <QDragEnterEvent>
#include <tchttpservice.h>
#define DEBUG 1
namespace Ui {
class FrmUpload;
}
class FrmUpload : public QWidget
{
Q_OBJECT
public:
explicit FrmUpload(QWidget *parent = nullptr);
~FrmUpload();
protected:
virtual bool eventFilter(QObject* watched, QEvent* event);
virtual void dragEnterEvent(QDragEnterEvent *event) override;
virtual void dropEvent(QDropEvent *event) override;
private:
void initFrom();
void initWidget();
void uploadFiles(QStringList fileList);
private:
Ui::FrmUpload *ui;
};
#endif // FRMUPLOAD_H

View File

@@ -0,0 +1,8 @@
FORMS += \
$$PWD/frmupload.ui
HEADERS += \
$$PWD/frmupload.h
SOURCES += \
$$PWD/frmupload.cpp

View File

@@ -0,0 +1,158 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>FrmUpload</class>
<widget class="QWidget" name="FrmUpload">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>953</width>
<height>560</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<property name="leftMargin">
<number>0</number>
</property>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QFrame" name="frmUpload">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>800</width>
<height>450</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>800</width>
<height>450</height>
</size>
</property>
<property name="styleSheet">
<string notr="true"/>
</property>
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>75</height>
</size>
</property>
</spacer>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QLabel" name="labPixmap">
<property name="text">
<string/>
</property>
<property name="pixmap">
<pixmap resource="../../image.qrc">:/qrc/image/upload_white.png</pixmap>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_3">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<widget class="QLabel" name="labText">
<property name="font">
<font>
<family>Microsoft YaHei UI</family>
<pointsize>26</pointsize>
</font>
</property>
<property name="text">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p align=&quot;center&quot;&gt;&lt;span style=&quot; color:white;&quot;&gt;将文件拖拽到此处,或&lt;/span&gt;&lt;span style=&quot; color:#407AB4;&quot;&gt;点击上传&lt;/span&gt;。&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer_2">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>74</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Fixed</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
</layout>
</widget>
<resources>
<include location="../../image.qrc"/>
</resources>
<connections/>
</ui>

View File

@@ -0,0 +1,48 @@
#include "serversetting.h"
#include "ui_serversetting.h"
ServerSetting::ServerSetting(QWidget *parent) :
QWidget(parent),
ui(new Ui::ServerSetting)
{
ui->setupUi(this);
initForm();
initWidget();
}
ServerSetting::~ServerSetting()
{
delete ui;
}
void ServerSetting::initForm()
{
this->setWindowFlag(Qt::FramelessWindowHint);
this->setWindowFlags(this->windowFlags() | Qt::WindowSystemMenuHint | Qt::WindowMaximizeButtonHint);
ui->ledAddress->setPlaceholderText("example.com/ip:port");
ui->ledPort->setPlaceholderText("admin");
}
void ServerSetting::initWidget()
{
connect(ui->btnCencel, &QPushButton::clicked, [&](){
this->hide();
});
connect(ui->btnOk, &QPushButton::clicked, [&](){
emit okClicked(ui->ledAddress->text(), ui->ledPort->text().toInt());
this->hide();
});
}
void ServerSetting::on_btnOk_clicked()
{
if (ui->ledAddress->text().isEmpty() || ui->ledPort->text().isEmpty() ||
ui->ledPwd->text().isEmpty())
return;
QString address = ui->ledAddress->text();
QString userName = ui->ledPort->text();
QString password = ui->ledPwd->text();
TCHttpService::getInstance()->setConfiguration(userName, password, address);
}

View File

@@ -0,0 +1,33 @@
#ifndef SERVERSETTING_H
#define SERVERSETTING_H
#include <QWidget>
#include "tchttpservice.h"
namespace Ui {
class ServerSetting;
}
class ServerSetting : public QWidget
{
Q_OBJECT
public:
explicit ServerSetting(QWidget *parent = nullptr);
~ServerSetting();
signals:
void okClicked(QString addr, quint16 port);
private slots:
void on_btnOk_clicked();
private:
Ui::ServerSetting *ui;
private:
void initForm();
void initWidget();
};
#endif // SERVERSETTING_H

View File

@@ -0,0 +1,8 @@
FORMS += \
$$PWD/serversetting.ui
HEADERS += \
$$PWD/serversetting.h
SOURCES += \
$$PWD/serversetting.cpp

View File

@@ -0,0 +1,101 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>ServerSetting</class>
<widget class="QWidget" name="ServerSetting">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>281</width>
<height>188</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QFormLayout" name="formLayout">
<item row="0" column="0">
<widget class="QLabel" name="labAddress">
<property name="text">
<string>Server</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="labPort">
<property name="text">
<string>Name</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="ledAddress"/>
</item>
<item row="1" column="1">
<widget class="QLineEdit" name="ledPort"/>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Password</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QLineEdit" name="ledPwd"/>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="btnCencel">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>取消</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="btnOk">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="styleSheet">
<string notr="true"/>
</property>
<property name="text">
<string>确定</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>

View File

@@ -0,0 +1,473 @@
#pragma execution_character_set("utf-8")
#include "switchbutton.h"
#include "qpainter.h"
#include <QPainterPath>
#include "qevent.h"
#include "qtimer.h"
#include "qdebug.h"
SwitchButton::SwitchButton(QWidget *parent): QWidget(parent)
{
space = 2;
rectRadius = 5;
checked = false;
showText = true;
showCircle = false;
animation = false;
buttonStyle = ButtonStyle_CircleIn;
bgColorOff = QColor(111, 122, 126);
bgColorOn = QColor(21, 156, 119);
sliderColorOff = QColor(255, 255, 255);
sliderColorOn = QColor(255, 255, 255);
textColorOff = QColor(250, 250, 250);
textColorOn = QColor(255, 255, 255);
textOff = "关闭";
textOn = "开启";
step = 0;
startX = 0;
endX = 0;
timer = new QTimer(this);
timer->setInterval(30);
connect(timer, SIGNAL(timeout()), this, SLOT(updateValue()));
}
SwitchButton::~SwitchButton()
{
if (timer->isActive()) {
timer->stop();
}
}
void SwitchButton::mousePressEvent(QMouseEvent *)
{
checked = !checked;
emit checkedChanged(checked);
//每次移动的步长
step = width() / 7;
//状态切换改变后自动计算终点坐标
if (checked) {
if (buttonStyle == ButtonStyle_Rect) {
endX = width() - width() / 2;
} else if (buttonStyle == ButtonStyle_CircleIn) {
endX = width() - height();
} else if (buttonStyle == ButtonStyle_CircleOut) {
endX = width() - height();
}
} else {
endX = 0;
}
if (animation) {
timer->start();
} else {
startX = endX;
this->update();
}
}
void SwitchButton::resizeEvent(QResizeEvent *)
{
//每次移动的步长为宽度的 50分之一
step = width() / 50;
//尺寸大小改变后自动设置起点坐标为终点
if (checked) {
if (buttonStyle == ButtonStyle_Rect) {
startX = width() - width() / 2;
} else if (buttonStyle == ButtonStyle_CircleIn) {
startX = width() - height();
} else if (buttonStyle == ButtonStyle_CircleOut) {
startX = width() - height();
}
} else {
startX = 0;
}
this->update();
}
void SwitchButton::paintEvent(QPaintEvent *)
{
//绘制准备工作,启用反锯齿
QPainter painter(this);
painter.setRenderHints(QPainter::Antialiasing | QPainter::TextAntialiasing);
//绘制背景
drawBg(&painter);
//绘制滑块
drawSlider(&painter);
}
void SwitchButton::drawBg(QPainter *painter)
{
painter->save();
painter->setPen(Qt::NoPen);
QColor bgColor = checked ? bgColorOn : bgColorOff;
if (!isEnabled()) {
bgColor.setAlpha(60);
}
painter->setBrush(bgColor);
if (buttonStyle == ButtonStyle_Rect) {
painter->drawRoundedRect(rect(), rectRadius, rectRadius);
} else if (buttonStyle == ButtonStyle_CircleIn) {
QRect rect(0, 0, width(), height());
//半径为高度的一半
int side = qMin(rect.width(), rect.height());
//左侧圆
QPainterPath path1;
path1.addEllipse(rect.x(), rect.y(), side, side);
//右侧圆
QPainterPath path2;
path2.addEllipse(rect.width() - side, rect.y(), side, side);
//中间矩形
QPainterPath path3;
path3.addRect(rect.x() + side / 2, rect.y(), rect.width() - side, rect.height());
QPainterPath path;
path = path3 + path1 + path2;
painter->drawPath(path);
} else if (buttonStyle == ButtonStyle_CircleOut) {
QRect rect(height() / 2, space, width() - height(), height() - space * 2);
painter->drawRoundedRect(rect, rectRadius, rectRadius);
}
if (buttonStyle == ButtonStyle_Rect || buttonStyle == ButtonStyle_CircleIn) {
//绘制文本和小圆,互斥
if (showText) {
int sliderWidth = qMin(width(), height()) - space * 2;
if (buttonStyle == ButtonStyle_Rect) {
sliderWidth = width() / 2 - 5;
} else if (buttonStyle == ButtonStyle_CircleIn) {
sliderWidth -= 5;
}
if (checked) {
QRect textRect(0, 0, width() - sliderWidth, height());
painter->setPen(textColorOn);
painter->drawText(textRect, Qt::AlignCenter, textOn);
} else {
QRect textRect(sliderWidth, 0, width() - sliderWidth, height());
painter->setPen(textColorOff);
painter->drawText(textRect, Qt::AlignCenter, textOff);
}
} else if (showCircle) {
int side = qMin(width(), height()) / 2;
int y = (height() - side) / 2;
if (checked) {
QRect circleRect(side / 2, y, side, side);
QPen pen(textColorOn, 2);
painter->setPen(pen);
painter->setBrush(Qt::NoBrush);
painter->drawEllipse(circleRect);
} else {
QRect circleRect(width() - (side * 1.5), y, side, side);
QPen pen(textColorOff, 2);
painter->setPen(pen);
painter->setBrush(Qt::NoBrush);
painter->drawEllipse(circleRect);
}
}
}
painter->restore();
}
void SwitchButton::drawSlider(QPainter *painter)
{
painter->save();
painter->setPen(Qt::NoPen);
if (!checked) {
painter->setBrush(sliderColorOff);
} else {
painter->setBrush(sliderColorOn);
}
if (buttonStyle == ButtonStyle_Rect) {
int sliderWidth = width() / 2 - space * 2;
int sliderHeight = height() - space * 2;
QRect sliderRect(startX + space, space, sliderWidth , sliderHeight);
painter->drawRoundedRect(sliderRect, rectRadius, rectRadius);
} else if (buttonStyle == ButtonStyle_CircleIn) {
QRect rect(0, 0, width(), height());
int sliderWidth = qMin(rect.width(), rect.height()) - space * 2;
QRect sliderRect(startX + space, space, sliderWidth, sliderWidth);
painter->drawEllipse(sliderRect);
} else if (buttonStyle == ButtonStyle_CircleOut) {
int sliderWidth = this->height();
QRect sliderRect(startX, 0, sliderWidth, sliderWidth);
QColor color1 = (checked ? Qt::white : bgColorOff);
QColor color2 = (checked ? sliderColorOn : sliderColorOff);
QRadialGradient radialGradient(sliderRect.center(), sliderWidth / 2);
radialGradient.setColorAt(0, checked ? color1 : color2);
radialGradient.setColorAt(0.5, checked ? color1 : color2);
radialGradient.setColorAt(0.6, checked ? color2 : color1);
radialGradient.setColorAt(1.0, checked ? color2 : color1);
painter->setBrush(radialGradient);
painter->drawEllipse(sliderRect);
}
painter->restore();
}
void SwitchButton::change()
{
mousePressEvent(NULL);
}
void SwitchButton::updateValue()
{
if (checked) {
if (startX < endX) {
startX = startX + step;
} else {
startX = endX;
timer->stop();
}
} else {
if (startX > endX) {
startX = startX - step;
} else {
startX = endX;
timer->stop();
}
}
this->update();
}
int SwitchButton::getSpace() const
{
return this->space;
}
int SwitchButton::getRectRadius() const
{
return this->rectRadius;
}
bool SwitchButton::getChecked() const
{
return this->checked;
}
bool SwitchButton::getShowText() const
{
return this->showText;
}
bool SwitchButton::getShowCircle() const
{
return this->showCircle;
}
bool SwitchButton::getAnimation() const
{
return this->animation;
}
SwitchButton::ButtonStyle SwitchButton::getButtonStyle() const
{
return this->buttonStyle;
}
QColor SwitchButton::getBgColorOff() const
{
return bgColorOff;
}
QColor SwitchButton::getBgColorOn() const
{
return this->bgColorOn;
}
QColor SwitchButton::getSliderColorOff() const
{
return this->sliderColorOff;
}
QColor SwitchButton::getSliderColorOn() const
{
return this->sliderColorOn;
}
QColor SwitchButton::getTextColorOff() const
{
return this->textColorOff;
}
QColor SwitchButton::getTextColorOn() const
{
return this->textColorOn;
}
QString SwitchButton::getTextOff() const
{
return this->textOff;
}
QString SwitchButton::getTextOn() const
{
return this->textOn;
}
QSize SwitchButton::sizeHint() const
{
return QSize(70, 30);
}
QSize SwitchButton::minimumSizeHint() const
{
return QSize(10, 5);
}
void SwitchButton::setSpace(int space)
{
if (this->space != space) {
this->space = space;
this->update();
}
}
void SwitchButton::setRectRadius(int rectRadius)
{
if (this->rectRadius != rectRadius) {
this->rectRadius = rectRadius;
this->update();
}
}
void SwitchButton::setChecked(bool checked)
{
//如果刚刚初始化完成的属性改变则延时处理
if (this->checked != checked) {
if (step == 0) {
QTimer::singleShot(10, this, SLOT(change()));
} else {
mousePressEvent(NULL);
}
}
}
void SwitchButton::setShowText(bool showText)
{
if (this->showText != showText) {
this->showText = showText;
this->update();
}
}
void SwitchButton::setShowCircle(bool showCircle)
{
if (this->showCircle != showCircle) {
this->showCircle = showCircle;
this->update();
}
}
void SwitchButton::setAnimation(bool animation)
{
if (this->animation != animation) {
this->animation = animation;
this->update();
}
}
void SwitchButton::setButtonStyle(const SwitchButton::ButtonStyle &buttonStyle)
{
if (this->buttonStyle != buttonStyle) {
this->buttonStyle = buttonStyle;
this->update();
}
}
void SwitchButton::setBgColorOff(const QColor &bgColorOff)
{
if (this->bgColorOff != bgColorOff) {
this->bgColorOff = bgColorOff;
this->update();
}
}
void SwitchButton::setBgColorOn(const QColor &bgColorOn)
{
if (this->bgColorOn != bgColorOn) {
this->bgColorOn = bgColorOn;
this->update();
}
}
void SwitchButton::setSliderColorOff(const QColor &sliderColorOff)
{
if (this->sliderColorOff != sliderColorOff) {
this->sliderColorOff = sliderColorOff;
this->update();
}
}
void SwitchButton::setSliderColorOn(const QColor &sliderColorOn)
{
if (this->sliderColorOn != sliderColorOn) {
this->sliderColorOn = sliderColorOn;
this->update();
}
}
void SwitchButton::setTextColorOff(const QColor &textColorOff)
{
if (this->textColorOff != textColorOff) {
this->textColorOff = textColorOff;
this->update();
}
}
void SwitchButton::setTextColorOn(const QColor &textColorOn)
{
if (this->textColorOn != textColorOn) {
this->textColorOn = textColorOn;
this->update();
}
}
void SwitchButton::enableText(bool enable)
{
if (!enable) {
this->textOn = "";
this->textOff = "";
this->update();
}
}
void SwitchButton::setTextOff(const QString &textOff)
{
if (this->textOff != textOff) {
this->textOff = textOff;
this->update();
}
}
void SwitchButton::setTextOn(const QString &textOn)
{
if (this->textOn != textOn) {
this->textOn = textOn;
this->update();
}
}

View File

@@ -0,0 +1,159 @@
#ifndef SWITCHBUTTON_H
#define SWITCHBUTTON_H
/**
* 开关按钮控件 作者:feiyangqingyun(QQ:517216493) 2016-11-6
* 1:可设置开关按钮的样式 圆角矩形/内圆形/外圆形
* 2:可设置选中和未选中时的背景颜色
* 3:可设置选中和未选中时的滑块颜色
* 4:可设置显示的文本
* 5:可设置滑块离背景的间隔
* 6:可设置圆角角度
* 7:可设置是否显示动画过渡效果
*/
#include <QWidget>
#include <QPainterPath>
#ifdef quc
#if (QT_VERSION < QT_VERSION_CHECK(5,7,0))
#include <QtDesigner/QDesignerExportWidget>
#else
#include <QtUiPlugin/QDesignerExportWidget>
#endif
class QDESIGNER_WIDGET_EXPORT SwitchButton : public QWidget
#else
class SwitchButton : public QWidget
#endif
{
Q_OBJECT
Q_ENUMS(ButtonStyle)
Q_PROPERTY(int space READ getSpace WRITE setSpace)
Q_PROPERTY(int rectRadius READ getRectRadius WRITE setRectRadius)
Q_PROPERTY(bool checked READ getChecked WRITE setChecked)
Q_PROPERTY(bool showText READ getShowText WRITE setShowText)
Q_PROPERTY(bool showCircle READ getShowCircle WRITE setShowCircle)
Q_PROPERTY(bool animation READ getAnimation WRITE setAnimation)
Q_PROPERTY(ButtonStyle buttonStyle READ getButtonStyle WRITE setButtonStyle)
Q_PROPERTY(QColor bgColorOff READ getBgColorOff WRITE setBgColorOff)
Q_PROPERTY(QColor bgColorOn READ getBgColorOn WRITE setBgColorOn)
Q_PROPERTY(QColor sliderColorOff READ getSliderColorOff WRITE setSliderColorOff)
Q_PROPERTY(QColor sliderColorOn READ getSliderColorOn WRITE setSliderColorOn)
Q_PROPERTY(QColor textColorOff READ getTextColorOff WRITE setTextColorOff)
Q_PROPERTY(QColor textColorOn READ getTextColorOn WRITE setTextColorOn)
Q_PROPERTY(QString textOff READ getTextOff WRITE setTextOff)
Q_PROPERTY(QString textOn READ getTextOn WRITE setTextOn)
public:
enum ButtonStyle {
ButtonStyle_Rect = 0, //圆角矩形
ButtonStyle_CircleIn = 1, //内圆形
ButtonStyle_CircleOut = 2 //外圆形
};
SwitchButton(QWidget *parent = 0);
~SwitchButton();
protected:
void mousePressEvent(QMouseEvent *);
void resizeEvent(QResizeEvent *);
void paintEvent(QPaintEvent *);
void drawBg(QPainter *painter);
void drawSlider(QPainter *painter);
private:
int space; //滑块离背景间隔
int rectRadius; //圆角角度
bool checked; //是否选中
bool showText; //显示文字
bool showCircle; //显示小圆
bool animation; //动画过渡
ButtonStyle buttonStyle; //开关按钮样式
QColor bgColorOff; //关闭时背景颜色
QColor bgColorOn; //打开时背景颜色
QColor sliderColorOff; //关闭时滑块颜色
QColor sliderColorOn; //打开时滑块颜色
QColor textColorOff; //关闭时文字颜色
QColor textColorOn; //打开时文字颜色
QString textOff; //关闭时显示的文字
QString textOn; //打开时显示的文字
int step; //每次移动的步长
int startX; //滑块开始X轴坐标
int endX; //滑块结束X轴坐标
QTimer *timer; //定时器绘制
private slots:
void change();
void updateValue();
public:
int getSpace() const;
int getRectRadius() const;
bool getChecked() const;
bool getShowText() const;
bool getShowCircle() const;
bool getAnimation() const;
ButtonStyle getButtonStyle() const;
QColor getBgColorOff() const;
QColor getBgColorOn() const;
QColor getSliderColorOff() const;
QColor getSliderColorOn() const;
QColor getTextColorOff() const;
QColor getTextColorOn() const;
QString getTextOff() const;
QString getTextOn() const;
QSize sizeHint() const;
QSize minimumSizeHint() const;
public Q_SLOTS:
//设置间隔
void setSpace(int space);
//设置圆角角度
void setRectRadius(int rectRadius);
//设置是否选中
void setChecked(bool checked);
//设置是否显示文字
void setShowText(bool showText);
//设置是否显示小圆
void setShowCircle(bool showCircle);
//设置是否动画过渡
void setAnimation(bool animation);
//设置风格样式
void setButtonStyle(const ButtonStyle &buttonStyle);
//设置背景颜色
void setBgColorOff(const QColor &bgColorOff);
void setBgColorOn(const QColor &bgColorOn);
//设置滑块颜色
void setSliderColorOff(const QColor &sliderColorOff);
void setSliderColorOn(const QColor &sliderColorOn);
//设置文字颜色
void setTextColorOff(const QColor &textColorOff);
void setTextColorOn(const QColor &textColorOn);
void enableText(bool enable);
//设置文字
void setTextOff(const QString &textOff);
void setTextOn(const QString &textOn);
Q_SIGNALS:
void checkedChanged(bool checked);
};
#endif // SWITCHBUTTON_H

View File

@@ -0,0 +1,5 @@
HEADERS += \
$$PWD/switchbutton.h
SOURCES += \
$$PWD/switchbutton.cpp