有个不必现错误,预览初步完成
This commit is contained in:
@@ -7,6 +7,7 @@ INCLUDEPATH += $$PWD/frmalbum
|
||||
INCLUDEPATH += $$PWD/frmimgshow
|
||||
INCLUDEPATH += $$PWD/switchbutton
|
||||
INCLUDEPATH += $$PWD/serversetting
|
||||
INCLUDEPATH += $$PWD/panelwidget
|
||||
|
||||
include($$PWD/frmupload/frmupload.pri)
|
||||
include($$PWD/frmsetting/frmsetting.pri)
|
||||
@@ -14,3 +15,4 @@ include($$PWD/frmalbum/frmalbum.pri)
|
||||
include($$PWD/frmimgshow/frmimgshow.pri)
|
||||
include($$PWD/switchbutton/switchbutton.pri)
|
||||
include($$PWD/serversetting/serversetting.pri)
|
||||
include($$PWD/panelwidget/panelwidget.pri)
|
||||
|
||||
@@ -1,14 +1,46 @@
|
||||
#include "frmalbum.h"
|
||||
#include "ui_frmalbum.h"
|
||||
#include <QUrl>
|
||||
|
||||
FrmAlbum::FrmAlbum(QWidget *parent)
|
||||
: QWidget(parent)
|
||||
, ui(new Ui::FrmAlbum)
|
||||
|
||||
FrmAlbum::FrmAlbum(QWidget *parent) : QWidget(parent)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
initForm();
|
||||
}
|
||||
|
||||
FrmAlbum::~FrmAlbum()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void FrmAlbum::initForm()
|
||||
{
|
||||
layout = new QHBoxLayout(this);
|
||||
panelWidget = new PanelWidget(this);
|
||||
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->setAutoHeight(false);
|
||||
panelWidget->setAutoWidth(false);
|
||||
panelWidget->setAutoHeight(false);
|
||||
panelWidget->setAutoWidth(false);
|
||||
|
||||
// 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"),
|
||||
};
|
||||
|
||||
foreach (const QUrl& u, urls) {
|
||||
FrmImgShow* widget = new FrmImgShow(this);
|
||||
widget->loadImage(u);
|
||||
picWidgetList.push_front(widget);
|
||||
}
|
||||
|
||||
panelWidget->setWidget(picWidgetList, 3);
|
||||
}
|
||||
|
||||
@@ -2,6 +2,9 @@
|
||||
#define FRMALBUM_H
|
||||
|
||||
#include <QWidget>
|
||||
#include "panelwidget.h"
|
||||
#include "frmimgshow.h"
|
||||
#include <QHBoxLayout>
|
||||
|
||||
namespace Ui {
|
||||
class FrmAlbum;
|
||||
@@ -17,6 +20,10 @@ public:
|
||||
|
||||
private:
|
||||
Ui::FrmAlbum *ui;
|
||||
QList<QWidget*> picWidgetList;
|
||||
PanelWidget* panelWidget;
|
||||
QHBoxLayout* layout;
|
||||
void initForm();
|
||||
};
|
||||
|
||||
#endif // FRMALBUM_H
|
||||
|
||||
@@ -6,13 +6,30 @@
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>400</width>
|
||||
<height>300</height>
|
||||
<width>632</width>
|
||||
<height>414</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Form</string>
|
||||
</property>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<property name="spacing">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
|
||||
@@ -1,47 +1,84 @@
|
||||
#include "frmimgshow.h"
|
||||
|
||||
FrmImgShow::FrmImgShow(QString& url, QWidget *parent) : QWidget(parent)
|
||||
FrmImgShow::FrmImgShow(QWidget *parent) : QWidget(parent)
|
||||
{
|
||||
initForm();
|
||||
initForm();
|
||||
initManager();
|
||||
this->url = url;
|
||||
manager->get(QNetworkRequest(QUrl(url)));
|
||||
connect(TCHttpService::getInstance(), &TCHttpService::signal_imageDownloaded,
|
||||
this, [this](const QString& requestId, const QPixmap& pixmap){
|
||||
if (requestId == m_requestId) {
|
||||
setLoadingState(false);
|
||||
setImage(pixmap);
|
||||
}
|
||||
});
|
||||
|
||||
connect(TCHttpService::getInstance(), &TCHttpService::signal_downloadFailed,
|
||||
this, [this](const QString& requestId, const QString& error){
|
||||
if (requestId == m_requestId) {
|
||||
setLoadingState(true);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
bool FrmImgShow::eventFilter(QObject *watched, QEvent *event)
|
||||
void FrmImgShow::loadImage(const QUrl &imageUrl)
|
||||
{
|
||||
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);
|
||||
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";
|
||||
labImg->setPixmap(pixmap.scaled(200, 200, Qt::KeepAspectRatio, Qt::SmoothTransformation));
|
||||
}
|
||||
|
||||
void FrmImgShow::setLoadingState(bool loading)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
QSize FrmImgShow::sizeHint()
|
||||
{
|
||||
return QSize(300, 300);
|
||||
}
|
||||
|
||||
// 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) {
|
||||
@@ -54,39 +91,43 @@ void FrmImgShow::onFinished(QNetworkReply *reply)
|
||||
|
||||
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();
|
||||
labImg = new QLabel(this);
|
||||
// btnCopy = new QPushButton(this);
|
||||
// btnCopy->setMaximumHeight(18);
|
||||
// btnDelete = new QPushButton(this);
|
||||
// btnDelete->setMaximumHeight(18);
|
||||
// horizenSpacer = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
|
||||
// hLayout = new QHBoxLayout();
|
||||
|
||||
hLayout->addWidget(btnCopy);
|
||||
hLayout->addSpacerItem(horizenSpacer);
|
||||
// ckbSelect = new QCheckBox(this);
|
||||
// ckbSelect->setMaximumHeight(18);
|
||||
// hLayout->addWidget(btnCopy);
|
||||
// hLayout->addWidget(btnDelete);
|
||||
// hLayout->setContentsMargins(0, 0, 0, 0);
|
||||
// hLayout->addSpacerItem(horizenSpacer);
|
||||
// hLayout->addWidget(ckbSelect);
|
||||
vLayout = new QVBoxLayout();
|
||||
vLayout->addWidget(labImg);
|
||||
vLayout->addLayout(hLayout);
|
||||
// vLayout->addLayout(hLayout);
|
||||
vLayout->setContentsMargins(0, 0, 0, 0);
|
||||
// vLayout->addLayout(vLayout);
|
||||
|
||||
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);
|
||||
// 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");
|
||||
|
||||
setFixedSize(140, 160);
|
||||
|
||||
this->labImg->setFixedSize(140, 140);
|
||||
}
|
||||
|
||||
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);
|
||||
});
|
||||
// btnCopy->installEventFilter(this);
|
||||
// btnDelete->installEventFilter(this);
|
||||
}
|
||||
|
||||
@@ -8,32 +8,36 @@
|
||||
#include <QVBoxLayout>
|
||||
#include <QToolButton>
|
||||
#include <QSpacerItem>
|
||||
#include <QNetworkAccessManager>
|
||||
#include <QNetworkRequest>
|
||||
#include <QUrl>
|
||||
#include <QNetworkReply>
|
||||
#include <QClipboard>
|
||||
#include <QCheckBox>
|
||||
#include <QGuiApplication>
|
||||
#include "tchttpservice.h"
|
||||
|
||||
class FrmImgShow : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit FrmImgShow(QString& url, QWidget *parent = nullptr);
|
||||
explicit FrmImgShow(QWidget *parent = nullptr);
|
||||
|
||||
void loadImage(const QUrl& imageUrl);
|
||||
void setImage(const QPixmap& pixmap);
|
||||
void setLoadingState(bool loading);
|
||||
|
||||
QSize sizeHint();
|
||||
private:
|
||||
QLabel* labImg;
|
||||
QToolButton* btnCopy;
|
||||
QToolButton* btnDelete;
|
||||
// QLabel* labLoading;
|
||||
// QMovie* movieLoading;
|
||||
|
||||
QPushButton* btnCopy;
|
||||
QPushButton* btnDelete;
|
||||
QSpacerItem* horizenSpacer;
|
||||
QHBoxLayout* hLayout;
|
||||
QCheckBox* ckbSelect;
|
||||
QVBoxLayout* vLayout;
|
||||
|
||||
QNetworkAccessManager* manager;
|
||||
QString url;
|
||||
|
||||
protected:
|
||||
virtual bool eventFilter(QObject* watched, QEvent* event);
|
||||
// virtual bool eventFilter(QObject* watched, QEvent* event);
|
||||
|
||||
private slots:
|
||||
void onFinished(QNetworkReply *reply);
|
||||
@@ -41,10 +45,9 @@ private slots:
|
||||
private:
|
||||
void initForm();
|
||||
void initWidget();
|
||||
void initManager();
|
||||
|
||||
signals:
|
||||
|
||||
QString m_requestId;
|
||||
QUrl m_currentUrl;
|
||||
};
|
||||
|
||||
#endif // FRMIMGSHOW_H
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>731</width>
|
||||
<height>439</height>
|
||||
<height>464</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
@@ -352,6 +352,82 @@
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="Line" name="line3_2">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="orientation">
|
||||
<enum>Qt::Orientation::Horizontal</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_6">
|
||||
<item>
|
||||
<widget class="QLabel" name="labEnableSsl_2">
|
||||
<property name="styleSheet">
|
||||
<string notr="true">color: rgb(255, 255, 255);</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>自动连接</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer_6">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Orientation::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_2">
|
||||
<property name="text">
|
||||
<string>关</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="SwitchButton" name="schEnableSsl_2" 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>100</width>
|
||||
<height>25</height>
|
||||
</size>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="labEnableSslOpen_2">
|
||||
<property name="text">
|
||||
<string>开</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<customwidgets>
|
||||
|
||||
@@ -50,16 +50,20 @@ void FrmUpload::slot_uploadFileSec(QString url)
|
||||
|
||||
if (copyType == COPY_TYPE_MARKDOWN) {
|
||||
clipboard->setText(QString("").arg(url));
|
||||
emit signal_uploadSuccess(url);
|
||||
}
|
||||
if (copyType == COPY_TYPE_URL) {
|
||||
clipboard->setText(url);
|
||||
emit signal_uploadSuccess(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));
|
||||
emit signal_uploadSuccess(url);
|
||||
}
|
||||
if (copyType == COPY_TYPE_HTML) {
|
||||
clipboard->setText(QString("<img src=\"%1\"/>").arg(url));
|
||||
emit signal_uploadSuccess(url);
|
||||
|
||||
// QThread::sleep(50);
|
||||
}
|
||||
|
||||
@@ -70,6 +70,9 @@ private:
|
||||
// 0 md 1 url
|
||||
CopyType copyType = COPY_TYPE_MARKDOWN;
|
||||
|
||||
signals:
|
||||
void signal_uploadSuccess(QString url);
|
||||
|
||||
private:
|
||||
Ui::FrmUpload *ui;
|
||||
};
|
||||
|
||||
158
core_form/panelwidget/panelwidget.cpp
Normal file
158
core_form/panelwidget/panelwidget.cpp
Normal file
@@ -0,0 +1,158 @@
|
||||
#pragma execution_character_set("utf-8")
|
||||
|
||||
#include "panelwidget.h"
|
||||
#include "qscrollarea.h"
|
||||
#include "qframe.h"
|
||||
#include "qboxlayout.h"
|
||||
#include "qdebug.h"
|
||||
|
||||
PanelWidget::PanelWidget(QWidget *parent) : QWidget(parent)
|
||||
{
|
||||
scrollArea = new QScrollArea(this);
|
||||
scrollArea->setObjectName("scrollAreaMain");
|
||||
scrollArea->setWidgetResizable(true);
|
||||
|
||||
scrollAreaWidgetContents = new QWidget();
|
||||
scrollAreaWidgetContents->setGeometry(QRect(0, 0, 100, 100));
|
||||
|
||||
verticalLayout = new QVBoxLayout(scrollAreaWidgetContents);
|
||||
verticalLayout->setSpacing(0);
|
||||
verticalLayout->setContentsMargins(0, 0, 0, 0);
|
||||
|
||||
frame = new QFrame(scrollAreaWidgetContents);
|
||||
frame->setObjectName("frameMain");
|
||||
|
||||
gridLayout = new QGridLayout(frame);
|
||||
gridLayout->setSpacing(0);
|
||||
gridLayout->setContentsMargins(0, 0, 0, 0);
|
||||
|
||||
verticalLayout->addWidget(frame);
|
||||
scrollArea->setWidget(scrollAreaWidgetContents);
|
||||
frame->setStyleSheet("QFrame#frameMain{border-width:0px;}");
|
||||
|
||||
margin = 0;
|
||||
space = 0;
|
||||
autoWidth = false;
|
||||
autoHeight = false;
|
||||
}
|
||||
|
||||
void PanelWidget::resizeEvent(QResizeEvent *)
|
||||
{
|
||||
scrollArea->resize(this->size());
|
||||
}
|
||||
|
||||
QSize PanelWidget::sizeHint() const
|
||||
{
|
||||
return QSize(300, 200);
|
||||
}
|
||||
|
||||
QSize PanelWidget::minimumSizeHint() const
|
||||
{
|
||||
return QSize(20, 20);
|
||||
}
|
||||
|
||||
int PanelWidget::getMargin() const
|
||||
{
|
||||
return this->margin;
|
||||
}
|
||||
|
||||
int PanelWidget::getSpace() const
|
||||
{
|
||||
return this->space;
|
||||
}
|
||||
|
||||
bool PanelWidget::getAutoWidth() const
|
||||
{
|
||||
return this->autoWidth;
|
||||
}
|
||||
|
||||
bool PanelWidget::getAutoHeight() const
|
||||
{
|
||||
return this->autoHeight;
|
||||
}
|
||||
|
||||
QList<QWidget *> PanelWidget::getWidgets()
|
||||
{
|
||||
return this->widgets;
|
||||
}
|
||||
|
||||
int PanelWidget::getColumnCount()
|
||||
{
|
||||
return this->columnCount;
|
||||
}
|
||||
|
||||
void PanelWidget::setWidget(QList<QWidget *> widgets, int columnCount)
|
||||
{
|
||||
this->widgets = widgets;
|
||||
this->columnCount = columnCount;
|
||||
|
||||
int row = 0;
|
||||
int column = 0;
|
||||
int index = 0;
|
||||
|
||||
//先把之前的所有移除并不可见
|
||||
foreach (QWidget *widget, widgets) {
|
||||
gridLayout->removeWidget(widget);
|
||||
widget->setVisible(false);
|
||||
}
|
||||
|
||||
//重新添加到布局中并可见
|
||||
foreach (QWidget *widget, widgets) {
|
||||
gridLayout->addWidget(widget, row, column);
|
||||
widget->setVisible(true);
|
||||
|
||||
column++;
|
||||
index++;
|
||||
if (index % columnCount == 0) {
|
||||
row++;
|
||||
column = 0;
|
||||
}
|
||||
}
|
||||
|
||||
row++;
|
||||
|
||||
//设置右边弹簧
|
||||
if (!autoWidth) {
|
||||
QSpacerItem *hSpacer = new QSpacerItem(1, 1, QSizePolicy::Expanding, QSizePolicy::Minimum);
|
||||
gridLayout->addItem(hSpacer, 0, gridLayout->columnCount());
|
||||
}
|
||||
|
||||
//设置底边弹簧
|
||||
if (!autoHeight) {
|
||||
QSpacerItem *vSpacer = new QSpacerItem(1, 1, QSizePolicy::Minimum, QSizePolicy::Expanding);
|
||||
gridLayout->addItem(vSpacer, row, 0);
|
||||
}
|
||||
}
|
||||
|
||||
void PanelWidget::setMargin(int left, int top, int right, int bottom)
|
||||
{
|
||||
gridLayout->setContentsMargins(left, top, right, bottom);
|
||||
}
|
||||
|
||||
void PanelWidget::setMargin(int margin)
|
||||
{
|
||||
if (this->margin != margin) {
|
||||
setMargin(margin, margin, margin, margin);
|
||||
}
|
||||
}
|
||||
|
||||
void PanelWidget::setSpace(int space)
|
||||
{
|
||||
if (this->space != space) {
|
||||
gridLayout->setSpacing(space);
|
||||
}
|
||||
}
|
||||
|
||||
void PanelWidget::setAutoWidth(bool autoWidth)
|
||||
{
|
||||
if (this->autoWidth != autoWidth) {
|
||||
this->autoWidth = autoWidth;
|
||||
}
|
||||
}
|
||||
|
||||
void PanelWidget::setAutoHeight(bool autoHeight)
|
||||
{
|
||||
if (this->autoHeight != autoHeight) {
|
||||
this->autoHeight = autoHeight;
|
||||
}
|
||||
}
|
||||
74
core_form/panelwidget/panelwidget.h
Normal file
74
core_form/panelwidget/panelwidget.h
Normal file
@@ -0,0 +1,74 @@
|
||||
#ifndef PANELWIDGET_H
|
||||
#define PANELWIDGET_H
|
||||
|
||||
#include <QWidget>
|
||||
#include <QPainterPath>
|
||||
|
||||
class QScrollArea;
|
||||
class QFrame;
|
||||
class QVBoxLayout;
|
||||
class QGridLayout;
|
||||
|
||||
#ifdef quc
|
||||
#if (QT_VERSION < QT_VERSION_CHECK(5,7,0))
|
||||
#include <QtDesigner/QDesignerExportWidget>
|
||||
#else
|
||||
#include <QtUiPlugin/QDesignerExportWidget>
|
||||
#endif
|
||||
|
||||
class QDESIGNER_WIDGET_EXPORT PanelWidget : public QWidget
|
||||
#else
|
||||
class PanelWidget : public QWidget
|
||||
#endif
|
||||
|
||||
{
|
||||
Q_OBJECT
|
||||
// Q_PROPERTY(int margin READ getMargin WRITE setMargin)
|
||||
// Q_PROPERTY(int space READ getSpace WRITE setSpace)
|
||||
// Q_PROPERTY(bool autoWidth READ getAutoWidth WRITE setAutoWidth)
|
||||
// Q_PROPERTY(bool autoHeight READ getAutoHeight WRITE setAutoHeight)
|
||||
|
||||
public:
|
||||
explicit PanelWidget(QWidget *parent = 0);
|
||||
|
||||
protected:
|
||||
void resizeEvent(QResizeEvent *);
|
||||
|
||||
private:
|
||||
QScrollArea *scrollArea; //滚动区域
|
||||
QWidget *scrollAreaWidgetContents; //滚动区域载体
|
||||
QFrame *frame; //放置设备的框架,自动变宽变高
|
||||
QVBoxLayout *verticalLayout; //设备面板总布局
|
||||
QGridLayout *gridLayout; //设备表格布局
|
||||
|
||||
int margin; //边距
|
||||
int space; //设备之间的间隔
|
||||
bool autoWidth; //宽度自动拉伸
|
||||
bool autoHeight; //高度自动拉伸
|
||||
|
||||
QList<QWidget *> widgets; //设备面板对象集合
|
||||
int columnCount; //面板列数
|
||||
|
||||
public:
|
||||
QSize sizeHint() const;
|
||||
QSize minimumSizeHint() const;
|
||||
|
||||
int getMargin() const;
|
||||
int getSpace() const;
|
||||
bool getAutoWidth() const;
|
||||
bool getAutoHeight() const;
|
||||
|
||||
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);
|
||||
void setMargin(int margin);
|
||||
void setSpace(int space);
|
||||
void setAutoWidth(bool autoWidth);
|
||||
void setAutoHeight(bool autoHeight);
|
||||
|
||||
};
|
||||
|
||||
#endif // PANELWIDGET_H
|
||||
5
core_form/panelwidget/panelwidget.pri
Normal file
5
core_form/panelwidget/panelwidget.pri
Normal file
@@ -0,0 +1,5 @@
|
||||
HEADERS += \
|
||||
$$PWD/panelwidget.h
|
||||
|
||||
SOURCES += \
|
||||
$$PWD/panelwidget.cpp
|
||||
Reference in New Issue
Block a user