feat: 添加新页面

This commit is contained in:
sleepwithoutbz
2025-09-21 18:35:32 +08:00
parent 91d314a888
commit 9fe3007600
9 changed files with 381 additions and 8 deletions

View File

@@ -169,7 +169,8 @@ void ElaCentralStackedWidget::doWindowStackSwitch(ElaWindowType::StackSwitchMode
void ElaCentralStackedWidget::paintEvent(QPaintEvent *event) {
QRect targetRect = this->rect();
// ADDZY: 左上角向右下移动(1, 1),右下角向右下收缩(10, 10)
targetRect.adjust(1, 1, 10, 10);
// targetRect.adjust(1, 1, 10, 10);
targetRect.adjust(0, 0, -3, -3);
QPainter painter(this);
painter.save();
painter.setRenderHints(QPainter::Antialiasing);
@@ -177,6 +178,7 @@ void ElaCentralStackedWidget::paintEvent(QPaintEvent *event) {
painter.setPen(QPen(ElaThemeColor(_themeMode, BasicBaseLine), 1.5));
painter.setBrush(ElaThemeColor(_themeMode, WindowCentralStackBase));
if (_isHasRadius) {
// ADDZY: 顶点圆角
painter.drawRoundedRect(targetRect, 10, 10);
} else {
painter.drawRect(targetRect);

View File

@@ -154,6 +154,12 @@ enum NodeOperateReturnType {
};
Q_ENUM_CREATE(NodeOperateReturnType)
/* ADDZY
* Auto: 根据窗口尺寸调整
* Minimal: 点击标题栏的按钮展开,点击其他位置隐藏
* Compact: 侧边栏持续最小化显示
* Maximal: 侧边栏持续最大化显示
*/
enum NavigationDisplayMode {
Auto = 0x0000,
Minimal = 0x0001,

View File

@@ -170,7 +170,7 @@ void ElaAppBarPrivate::_onThemeModeChange(ElaThemeType::ThemeMode themeMode) {
_themeChangeButton->setElaIcon(ElaIconType::SunBright);
}
}
// ADDZY: 计算得到最小宽度,控制窗口宽度
int ElaAppBarPrivate::_calculateMinimumWidth() {
Q_Q(ElaAppBar);
int width = 0;
@@ -183,9 +183,14 @@ int ElaAppBarPrivate::_calculateMinimumWidth() {
width += 10;
}
bool isHasNavigationBar = false;
if (q->parentWidget()->findChild<ElaNavigationBar *>()) {
// FIXME: 这里是不是不应该只检测是否有`ElaNavigationBar`子节点?
// TODO: 调整判断逻辑
ElaNavigationBar *navigationBar = q->parentWidget()->findChild<ElaNavigationBar *>();
if (navigationBar && navigationBar->isMaximized()) {
isHasNavigationBar = true;
width += 305;
} else if (navigationBar && navigationBar->isMinimized()) {
width += 10;
} else {
width += 5;
}
@@ -205,6 +210,8 @@ int ElaAppBarPrivate::_calculateMinimumWidth() {
width += button->width();
}
}
// width -= 200;
// qDebug()<<"width: "<<width;
return width;
}
@@ -221,4 +228,4 @@ QVBoxLayout *ElaAppBarPrivate::_createVLayout(QWidget *widget) {
vLayout->addWidget(widget);
vLayout->addStretch();
return vLayout;
}
}

85
src/UI/CBBase.cpp Normal file
View File

@@ -0,0 +1,85 @@
#include "CBBase.h"
#include <QHBoxLayout>
#include <QVBoxLayout>
#include "ElaMenu.h"
#include "ElaText.h"
#include "ElaTheme.h"
#include "ElaToolButton.h"
CBBase::CBBase(QWidget* parent)
: ElaScrollPage(parent)
{
connect(eTheme, &ElaTheme::themeModeChanged, this, [=]() {
if (!parent)
{
update();
}
});
}
CBBase::~CBBase()
{
}
void CBBase::createCustomWidget(QString desText)
{
// 顶部元素
QWidget* customWidget = new QWidget(this);
ElaText* subTitleText = new ElaText(this);
subTitleText->setText("https://github.com/Liniyous/ElaWidgetTools");
subTitleText->setTextInteractionFlags(Qt::TextSelectableByMouse);
subTitleText->setTextPixelSize(11);
ElaToolButton* documentationButton = new ElaToolButton(this);
documentationButton->setFixedHeight(35);
documentationButton->setIsTransparent(false);
documentationButton->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
//_toolButton->setPopupMode(QToolButton::MenuButtonPopup);
documentationButton->setText("Documentation");
documentationButton->setElaIcon(ElaIconType::FileDoc);
ElaMenu* documentationMenu = new ElaMenu(this);
documentationMenu->addElaIconAction(ElaIconType::CardsBlank, "CardsBlank");
documentationMenu->addElaIconAction(ElaIconType::EarthAmericas, "EarthAmericas");
documentationButton->setMenu(documentationMenu);
ElaToolButton* sourceButton = new ElaToolButton(this);
sourceButton->setFixedHeight(35);
sourceButton->setIsTransparent(false);
sourceButton->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
sourceButton->setText("Source");
sourceButton->setElaIcon(ElaIconType::NfcSymbol);
ElaMenu* sourceMenu = new ElaMenu(this);
sourceMenu->addElaIconAction(ElaIconType::FireBurner, "FireBurner");
sourceMenu->addElaIconAction(ElaIconType::Galaxy, "Galaxy~~~~");
sourceButton->setMenu(sourceMenu);
ElaToolButton* themeButton = new ElaToolButton(this);
themeButton->setFixedSize(35, 35);
themeButton->setIsTransparent(false);
themeButton->setElaIcon(ElaIconType::MoonStars);
connect(themeButton, &ElaToolButton::clicked, this, [=]() {
eTheme->setThemeMode(eTheme->getThemeMode() == ElaThemeType::Light ? ElaThemeType::Dark : ElaThemeType::Light);
});
QHBoxLayout* buttonLayout = new QHBoxLayout();
buttonLayout->addWidget(documentationButton);
buttonLayout->addSpacing(5);
buttonLayout->addWidget(sourceButton);
buttonLayout->addStretch();
buttonLayout->addWidget(themeButton);
buttonLayout->addSpacing(15);
ElaText* descText = new ElaText(this);
descText->setText(desText);
descText->setTextPixelSize(13);
QVBoxLayout* topLayout = new QVBoxLayout(customWidget);
topLayout->setContentsMargins(0, 0, 0, 0);
topLayout->addWidget(subTitleText);
topLayout->addSpacing(5);
topLayout->addLayout(buttonLayout);
topLayout->addSpacing(5);
topLayout->addWidget(descText);
setCustomWidget(customWidget);
}

14
src/UI/CBBase.h Normal file
View File

@@ -0,0 +1,14 @@
#pragma once
#include <ElaScrollPage.h>
class QVBoxLayout;
class CBBase : public ElaScrollPage
{
Q_OBJECT
public:
explicit CBBase(QWidget* parent = nullptr);
~CBBase() override;
protected:
void createCustomWidget(QString desText);
};

View File

@@ -1 +1,230 @@
#include "CBTable.h"
#include <QDebug>
#include <QDesktopServices>
#include <QHBoxLayout>
#include <QMouseEvent>
#include <QPainter>
#include <QVBoxLayout>
#include "ElaAcrylicUrlCard.h"
#include "ElaFlowLayout.h"
#include "ElaImageCard.h"
#include "ElaMenu.h"
#include "ElaMessageBar.h"
#include "ElaNavigationRouter.h"
#include "ElaPopularCard.h"
#include "ElaScrollArea.h"
#include "ElaText.h"
#include "ElaToolTip.h"
CBTable::CBTable(QWidget *parent) : CBBase(parent) {
// 预览窗口标题
setWindowTitle("Home");
setTitleVisible(false);
setContentsMargins(2, 2, 0, 0);
// 标题卡片区域
ElaText *desText = new ElaText("FluentUI For QWidget", this);
desText->setTextPixelSize(18);
ElaText *titleText = new ElaText("ElaWidgetTools", this);
titleText->setTextPixelSize(35);
QVBoxLayout *titleLayout = new QVBoxLayout();
titleLayout->setContentsMargins(30, 60, 0, 0);
titleLayout->addWidget(desText);
titleLayout->addWidget(titleText);
ElaImageCard *backgroundCard = new ElaImageCard(this);
backgroundCard->setBorderRadius(10);
backgroundCard->setFixedHeight(400);
backgroundCard->setMaximumAspectRatio(1.7);
backgroundCard->setCardImage(QImage(":/Resource/Image/Home_Background.png"));
ElaAcrylicUrlCard *urlCard1 = new ElaAcrylicUrlCard(this);
urlCard1->setCardPixmapSize(QSize(62, 62));
urlCard1->setFixedSize(195, 225);
urlCard1->setTitlePixelSize(17);
urlCard1->setTitleSpacing(25);
urlCard1->setSubTitleSpacing(13);
urlCard1->setUrl("https://github.com/Liniyous/ElaWidgetTools");
urlCard1->setCardPixmap(QPixmap(":/Resource/Image/github.png"));
urlCard1->setTitle("ElaTool Github");
urlCard1->setSubTitle("Use ElaWidgetTools To Create A Cool Project");
ElaToolTip *urlCard1ToolTip = new ElaToolTip(urlCard1);
urlCard1ToolTip->setToolTip("https://github.com/Liniyous/ElaWidgetTools");
ElaAcrylicUrlCard *urlCard2 = new ElaAcrylicUrlCard(this);
urlCard2->setCardPixmapSize(QSize(62, 62));
urlCard2->setFixedSize(195, 225);
urlCard2->setTitlePixelSize(17);
urlCard2->setTitleSpacing(25);
urlCard2->setSubTitleSpacing(13);
urlCard2->setUrl("https://space.bilibili.com/21256707");
urlCard2->setCardPixmap(QPixmap(":/Resource/Image/Moon.jpg"));
urlCard2->setTitle("ElaWidgetTool");
urlCard2->setSubTitle("80985@qq.com");
ElaScrollArea *cardScrollArea = new ElaScrollArea(this);
cardScrollArea->setWidgetResizable(true);
cardScrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
cardScrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
cardScrollArea->setIsGrabGesture(true, 0);
cardScrollArea->setIsOverShoot(Qt::Horizontal, true);
QWidget *cardScrollAreaWidget = new QWidget(this);
cardScrollAreaWidget->setStyleSheet("background-color:transparent;");
cardScrollArea->setWidget(cardScrollAreaWidget);
QHBoxLayout *urlCardLayout = new QHBoxLayout();
urlCardLayout->setSpacing(15);
urlCardLayout->setContentsMargins(30, 0, 0, 6);
urlCardLayout->addWidget(urlCard1);
urlCardLayout->addWidget(urlCard2);
urlCardLayout->addStretch();
QVBoxLayout *cardScrollAreaWidgetLayout = new QVBoxLayout(cardScrollAreaWidget);
cardScrollAreaWidgetLayout->setContentsMargins(0, 0, 0, 0);
cardScrollAreaWidgetLayout->addStretch();
cardScrollAreaWidgetLayout->addLayout(urlCardLayout);
QVBoxLayout *backgroundLayout = new QVBoxLayout(backgroundCard);
backgroundLayout->setContentsMargins(0, 0, 0, 0);
backgroundLayout->addLayout(titleLayout);
backgroundLayout->addWidget(cardScrollArea);
// 推荐卡片
ElaText *flowText = new ElaText("热门免费应用", this);
flowText->setTextPixelSize(20);
QHBoxLayout *flowTextLayout = new QHBoxLayout();
flowTextLayout->setContentsMargins(33, 0, 0, 0);
flowTextLayout->addWidget(flowText);
// ElaFlowLayout
ElaPopularCard *homeCard = new ElaPopularCard(this);
connect(homeCard, &ElaPopularCard::popularCardButtonClicked, this,
[=]() { QDesktopServices::openUrl(QUrl("https://github.com/Liniyous/ElaWidgetTools")); });
homeCard->setCardPixmap(QPixmap(":/Resource/Image/Cirno.jpg"));
homeCard->setTitle("ElaWidgetTool");
homeCard->setSubTitle("5.0⭐ 实用程序与工具");
homeCard->setInteractiveTips("免费下载");
homeCard->setDetailedText(
"ElaWidgetTools致力于为QWidget用户提供一站式的外观和实用功能解决方案,只需数十MB内存和极少CPU占用以支持高效而美观的界面开发");
homeCard->setCardFloatPixmap(QPixmap(":/Resource/Image/IARC/IARC_7+.svg.png"));
ElaPopularCard *homeCard1 = new ElaPopularCard(this);
connect(homeCard1, &ElaPopularCard::popularCardButtonClicked, this, [=]() { Q_EMIT elaScreenNavigation(); });
homeCard1->setTitle("ElaScreen");
homeCard1->setSubTitle("5.0⭐ 实用程序与工具");
homeCard1->setCardPixmap(QPixmap(":/Resource/Image/control/AutomationProperties.png"));
homeCard1->setInteractiveTips("免费使用");
homeCard1->setDetailedText("使用ElaDxgiManager获取屏幕的实时数据以QImage的形式处理数据支持切换采集设备和输出设备。");
homeCard1->setCardFloatPixmap(QPixmap(":/Resource/Image/IARC/IARC_7+.svg.png"));
ElaPopularCard *homeCard2 = new ElaPopularCard(this);
connect(homeCard2, &ElaPopularCard::popularCardButtonClicked, this, [=]() { Q_EMIT elaSceneNavigation(); });
homeCard2->setTitle("ElaScene");
homeCard2->setSubTitle("5.0⭐ 实用程序与工具");
homeCard2->setCardPixmap(QPixmap(":/Resource/Image/control/Canvas.png"));
homeCard2->setInteractiveTips("免费使用");
homeCard2->setDetailedText("使用ElaScene封装的高集成度API进行快速拓扑绘图开发对基于连接的网络拓扑特化处理。");
homeCard2->setCardFloatPixmap(QPixmap(":/Resource/Image/IARC/IARC_7+.svg.png"));
ElaPopularCard *homeCard3 = new ElaPopularCard(this);
connect(homeCard3, &ElaPopularCard::popularCardButtonClicked, this, [=]() { Q_EMIT elaBaseComponentNavigation(); });
homeCard3->setTitle("ElaBaseComponent");
homeCard3->setSubTitle("5.0⭐ 实用程序与工具");
homeCard3->setCardPixmap(QPixmap(":/Resource/Image/control/StandardUICommand.png"));
homeCard3->setInteractiveTips("免费使用");
homeCard3->setDetailedText("添加ElaBaseComponent页面中的基础组件到你的项目中以进行快捷开发使用方便结构整洁API规范");
homeCard3->setCardFloatPixmap(QPixmap(":/Resource/Image/IARC/IARC_7+.svg.png"));
ElaPopularCard *homeCard4 = new ElaPopularCard(this);
connect(homeCard4, &ElaPopularCard::popularCardButtonClicked, this, [=]() { Q_EMIT elaCardNavigation(); });
homeCard4->setTitle("ElaCard");
homeCard4->setSubTitle("5.0⭐ 实用程序与工具");
homeCard4->setCardPixmap(QPixmap(":/Resource/Image/control/FlipView.png"));
homeCard4->setInteractiveTips("免费使用");
homeCard4->setDetailedText("使用ElaCard系列组件包括促销卡片和促销卡片视窗来快速建立循环动画。");
homeCard4->setCardFloatPixmap(QPixmap(":/Resource/Image/IARC/IARC_7+.svg.png"));
ElaPopularCard *homeCard5 = new ElaPopularCard(this);
connect(homeCard5, &ElaPopularCard::popularCardButtonClicked, this, [=]() { Q_EMIT elaIconNavigation(); });
homeCard5->setTitle("ElaIcon");
homeCard5->setSubTitle("5.0⭐ 实用程序与工具");
homeCard5->setCardPixmap(QPixmap(":/Resource/Image/control/CommandBarFlyout.png"));
homeCard5->setInteractiveTips("免费使用");
homeCard5->setDetailedText("在该界面快速挑选你喜欢的图标应用到项目中,以枚举的形式使用它");
homeCard5->setCardFloatPixmap(QPixmap(":/Resource/Image/IARC/IARC_7+.svg.png"));
ElaFlowLayout *flowLayout = new ElaFlowLayout(0, 5, 5);
flowLayout->setContentsMargins(30, 0, 0, 0);
flowLayout->setIsAnimation(true);
flowLayout->addWidget(homeCard);
flowLayout->addWidget(homeCard1);
flowLayout->addWidget(homeCard2);
flowLayout->addWidget(homeCard3);
flowLayout->addWidget(homeCard4);
flowLayout->addWidget(homeCard5);
// 菜单
_homeMenu = new ElaMenu(this);
ElaMenu *checkMenu = _homeMenu->addMenu(ElaIconType::Cubes, "查看");
checkMenu->addAction("查看1");
checkMenu->addAction("查看2");
checkMenu->addAction("查看3");
checkMenu->addAction("查看4");
ElaMenu *checkMenu1 = _homeMenu->addMenu(ElaIconType::Cubes, "查看");
checkMenu1->addAction("查看1");
checkMenu1->addAction("查看2");
checkMenu1->addAction("查看3");
checkMenu1->addAction("查看4");
ElaMenu *checkMenu2 = checkMenu->addMenu(ElaIconType::Cubes, "查看");
checkMenu2->addAction("查看1");
checkMenu2->addAction("查看2");
checkMenu2->addAction("查看3");
checkMenu2->addAction("查看4");
// QKeySequence key = QKeySequence(Qt::CTRL | Qt::Key_S);
_homeMenu->addSeparator();
_homeMenu->addElaIconAction(ElaIconType::BoxCheck, "排序方式", QKeySequence::Save);
_homeMenu->addElaIconAction(ElaIconType::ArrowRotateRight, "刷新");
QAction *action = _homeMenu->addElaIconAction(ElaIconType::ArrowRotateLeft, "撤销");
connect(action, &QAction::triggered, this, [=]() { ElaNavigationRouter::getInstance()->navigationRouteBack(); });
_homeMenu->addElaIconAction(ElaIconType::Copy, "复制");
_homeMenu->addElaIconAction(ElaIconType::MagnifyingGlassPlus, "显示设置");
QWidget *centralWidget = new QWidget(this);
centralWidget->setWindowTitle("Home");
QVBoxLayout *centerVLayout = new QVBoxLayout(centralWidget);
centerVLayout->setSpacing(0);
centerVLayout->setContentsMargins(0, 0, 0, 0);
centerVLayout->addWidget(backgroundCard);
centerVLayout->addSpacing(20);
centerVLayout->addLayout(flowTextLayout);
centerVLayout->addSpacing(10);
centerVLayout->addLayout(flowLayout);
centerVLayout->addStretch();
addCentralWidget(centralWidget);
// 初始化提示
ElaMessageBar::success(ElaMessageBarType::BottomRight, "Success", "初始化成功!", 2000);
}
CBTable::~CBTable() {}
void CBTable::mouseReleaseEvent(QMouseEvent *event) {
switch (event->button()) {
case Qt::RightButton: {
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
_homeMenu->popup(event->globalPosition().toPoint());
#else
_homeMenu->popup(event->globalPos());
#endif
break;
}
default: {
break;
}
}
ElaScrollPage::mouseReleaseEvent(event);
}

View File

@@ -1 +1,23 @@
#pragma once
#pragma once
#include "CBBase.h"
class ElaMenu;
class CBTable : public CBBase {
Q_OBJECT
public:
Q_INVOKABLE explicit CBTable(QWidget *parent = nullptr);
~CBTable();
Q_SIGNALS:
Q_SIGNAL void elaScreenNavigation();
Q_SIGNAL void elaBaseComponentNavigation();
Q_SIGNAL void elaSceneNavigation();
Q_SIGNAL void elaCardNavigation();
Q_SIGNAL void elaIconNavigation();
protected:
virtual void mouseReleaseEvent(QMouseEvent *event);
private:
ElaMenu *_homeMenu{nullptr};
};

View File

@@ -6,6 +6,7 @@
#include <QMouseEvent>
#include "ElaContentDialog.h"
#include "ElaDef.h"
#include "ElaDockWidget.h"
#include "ElaEventBus.h"
#include "ElaLog.h"
@@ -17,6 +18,7 @@
#include "ElaTheme.h"
#include "ElaToolBar.h"
#include "ElaToolButton.h"
#include "UI/CBTable.h"
#ifdef Q_OS_WIN
#include "ElaApplication.h"
@@ -29,9 +31,13 @@ MainWindow::~MainWindow() {}
void MainWindow::initWindow() {
qDebug() << "Window: Init the window.";
qDebug() << "Window: Set to fixed size";
// setIsFixedSize(true);
setNavigationBarDisplayMode(ElaNavigationType::NavigationDisplayMode::Minimal);
resize(480, 640);
setIsFixedSize(true);
// TODO: Set the subtitle of user info card
setUserInfoCardSubTitle("Nothing!");
// resize(600,480);
_tablePage = new CBTable(this);
addPageNode("剪贴板历史", _tablePage, ElaIconType::TableTree);
}

View File

@@ -1,6 +1,7 @@
#pragma once
#include "ElaWindow.h"
#include "UI/CBTable.h"
#include <QMainWindow>
class MainWindow : public ElaWindow {
@@ -12,6 +13,7 @@ public:
private:
void initWindow();
CBTable* _tablePage{nullptr};
protected:
};