mirror of
https://gitee.com/spark-store-project/spark-store
synced 2025-07-12 08:32:21 +08:00
添加了首页的雏形,和一个关于如何添加页面的文档
This commit is contained in:
parent
7756bda006
commit
58a0336a23
@ -50,6 +50,7 @@ set(SOURCE_FILES
|
||||
resource/resource.qrc
|
||||
|
||||
gui/page/ui/settings.ui
|
||||
gui/page/ui/homepage.ui
|
||||
${WRAPPED_UI_FILES}
|
||||
|
||||
inc/gitver.h
|
||||
@ -76,8 +77,10 @@ set(SOURCE_FILES
|
||||
inc/spkpopup.h gui/spkpopup.cpp
|
||||
inc/spkstretchlayout.h gui/spkstretchlayout.cpp
|
||||
inc/spkfocuslineedit.h
|
||||
inc/spknotifydot.h gui/spknotifydot.cpp
|
||||
|
||||
inc/page/spkpagebase.h gui/page/spkpagebase.cpp
|
||||
inc/page/spkpagehome.h gui/page/spkpagehome.cpp
|
||||
inc/page/spkpageuitest.h gui/page/spkpageuitest.cpp
|
||||
inc/page/spkpageapplist.h gui/page/spkpageapplist.cpp
|
||||
inc/page/spkpageappdetails.h gui/page/spkpageappdetails.cpp
|
||||
@ -113,7 +116,8 @@ add_link_options(-rdynamic)
|
||||
find_package(Qt${QT_VERSION} COMPONENTS ${REQUIRED_LIBS} REQUIRED)
|
||||
|
||||
QT5_WRAP_UI(WRAPPED_UI_FILES
|
||||
gui/page/ui/settings.ui)
|
||||
gui/page/ui/settings.ui
|
||||
gui/page/ui/homepage.ui)
|
||||
|
||||
add_executable(${EXECUTABLE_NAME} ${SOURCE_FILES})
|
||||
|
||||
|
@ -1,6 +1,29 @@
|
||||
|
||||
#include "page/spkpagebase.h"
|
||||
|
||||
/*
|
||||
* Documentation on
|
||||
* How to Add a New Page to Main Window Side Bar
|
||||
*
|
||||
* 1. Derive your page widget class from SpkPageBase (reference implementation
|
||||
* in SpkPageSettings) and add them to CMakeLists
|
||||
*
|
||||
* 2. Add the ID for the page in enum SpkUi::SpkStackedPages (in spkmainwindow.h)
|
||||
* and add it as a resource context if needed
|
||||
*
|
||||
* 3. Include the page's header file in spkmainwindow.h and add a pointer to it in
|
||||
* SpkUi::SpkMainWidget
|
||||
*
|
||||
* 4. Add a tree item or icon button for the corresponding page inside
|
||||
* SpkUi::SpkMainWidget, and initialize it in SpkUi::SpkMainWidget::SpkMainWidget.
|
||||
* Take references of existing entries, and write similar code close to each other
|
||||
* to make the source look nice. Don't forget to add the item to the UI.
|
||||
*
|
||||
* 5. Make the linkage between the page and the sidebar item at the end of
|
||||
* SpkUi::SpkMainWidget::SpkMainWidget().
|
||||
*
|
||||
*/
|
||||
|
||||
SpkPageBase::SpkPageBase(QWidget *parent) : QWidget(parent)
|
||||
{
|
||||
|
||||
|
39
gui/page/spkpagehome.cpp
Normal file
39
gui/page/spkpagehome.cpp
Normal file
@ -0,0 +1,39 @@
|
||||
|
||||
#include <QDesktopServices>
|
||||
|
||||
#include "page/spkpagehome.h"
|
||||
#include "spkabout.h"
|
||||
#include "gitver.h"
|
||||
|
||||
SpkUi::SpkPageHome::SpkPageHome(QWidget *parent) :
|
||||
SpkPageBase(parent)
|
||||
{
|
||||
ui = new Ui::SpkHomepage;
|
||||
ui->setupUi(this);
|
||||
|
||||
SetupUi();
|
||||
}
|
||||
|
||||
void SpkUi::SpkPageHome::LinkActivated(QString s)
|
||||
{
|
||||
QDesktopServices::openUrl(QUrl(s));
|
||||
}
|
||||
|
||||
void SpkUi::SpkPageHome::SetupUi()
|
||||
{
|
||||
ui->lblIcon->setPixmap(QIcon(":/icons/spark-store.svg").pixmap(QSize(128, 128)));
|
||||
|
||||
ui->hlayTitle->setAlignment(Qt::AlignHCenter);
|
||||
|
||||
ui->lblVersion->setText(ui->lblVersion->text().arg(GitVer::DescribeTags()));
|
||||
|
||||
connect(ui->lblAuthor, &QLabel::linkActivated,
|
||||
this, &SpkPageHome::LinkActivated);
|
||||
connect(ui->btnFeedback, &QPushButton::clicked,
|
||||
[&](){ LinkActivated("https://www.deepinos.org/t/spark-feedback"); });
|
||||
connect(ui->btnDonation, &QPushButton::clicked,
|
||||
[&](){ LinkActivated("https://spark.deepinos.org.cn/"); });
|
||||
connect(ui->btnAbout, &QPushButton::clicked,
|
||||
[&](){ SpkAbout::Show(); });
|
||||
ui->lblNewAnnouncement->setVisible(false);
|
||||
}
|
271
gui/page/ui/homepage.ui
Normal file
271
gui/page/ui/homepage.ui
Normal file
@ -0,0 +1,271 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>SpkHomepage</class>
|
||||
<widget class="QWidget" name="SpkHomepage">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>648</width>
|
||||
<height>468</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Fixed" vsizetype="Maximum">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Form</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<spacer name="verticalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeType">
|
||||
<enum>QSizePolicy::Fixed</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>40</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="hlayTitle">
|
||||
<item>
|
||||
<widget class="QLabel" name="lblIcon">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Maximum" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>{spark-store-icon}</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="lblTitle">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Maximum" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="font">
|
||||
<font>
|
||||
<pointsize>40</pointsize>
|
||||
</font>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Spark Store</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="lblAuthor">
|
||||
<property name="text">
|
||||
<string><html><head/><body><p>Brought to you by <a href="spark-app.store"><span style=" text-decoration: underline; color:#007af4;">Spark Project</span></a>, an open source software project.</p></body></html></string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="verticalSpacer_3">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeType">
|
||||
<enum>QSizePolicy::Fixed</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>50</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||
<item>
|
||||
<layout class="QGridLayout" name="vlayBtns">
|
||||
<item row="1" column="0">
|
||||
<widget class="QPushButton" name="btnAnnouncements">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>150</width>
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Announcements</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<widget class="QPushButton" name="btnFeedback">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>150</width>
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Feedback</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="lblAboutProject">
|
||||
<property name="text">
|
||||
<string>About this project...</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="0">
|
||||
<widget class="QPushButton" name="btnDonation">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>150</width>
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Donation</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="SpkNotifyDot" name="lblNewAnnouncement">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>0</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer_3">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeType">
|
||||
<enum>QSizePolicy::Expanding</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="verticalSpacer_2">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeType">
|
||||
<enum>QSizePolicy::Expanding</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>40</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<widget class="QLabel" name="lblVersion">
|
||||
<property name="text">
|
||||
<string>Version %1</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="btnAbout">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Maximum" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>About</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>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
<class>SpkNotifyDot</class>
|
||||
<extends>QLabel</extends>
|
||||
<header>spknotifydot.h</header>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
@ -454,6 +454,10 @@ SpkUi::SpkMainWidget::SpkMainWidget(QWidget *parent) : QFrame(parent)
|
||||
CategoryWidget->setSelectionMode(QAbstractItemView::SelectionMode::SingleSelection);
|
||||
|
||||
//============ Sidebar entries BEGIN ============
|
||||
HomepageItem = new QTreeWidgetItem(QStringList(tr("Home")));
|
||||
HomepageItem->setData(0, SpkSidebarSelector::RoleItemIsCategory, false);
|
||||
HomepageItem->setData(0, SpkSidebarSelector::RoleItemCategoryPageId, SpkStackedPages::PgHomepage);
|
||||
|
||||
AppDetailsItem = new QTreeWidgetItem(QStringList(tr("App Details")));
|
||||
AppDetailsItem->setData(0, SpkSidebarSelector::RoleItemIsCategory, false);
|
||||
AppDetailsItem->setData(0, SpkSidebarSelector::RoleItemCategoryPageId, SpkStackedPages::PgAppDetails);
|
||||
@ -471,6 +475,7 @@ SpkUi::SpkMainWidget::SpkMainWidget(QWidget *parent) : QFrame(parent)
|
||||
#endif
|
||||
//============ Sidebar entries END ============
|
||||
|
||||
CategoryWidget->addTopLevelItem(HomepageItem);
|
||||
SidebarMgr->AddUnusableItem(CategoryParentItem);
|
||||
CategoryWidget->addTopLevelItem(AppDetailsItem);
|
||||
CategoryWidget->addTopLevelItem(CategoryParentItem);
|
||||
@ -566,6 +571,10 @@ SpkUi::SpkMainWidget::SpkMainWidget(QWidget *parent) : QFrame(parent)
|
||||
PageSettings->setProperty("spk_pageid", SpkStackedPages::PgSettings);
|
||||
sorter[PgSettings] = PageSettings;
|
||||
|
||||
PageHome = new SpkUi::SpkPageHome(this);
|
||||
PageSettings->setProperty("spk_pageid", SpkStackedPages::PgHomepage);
|
||||
sorter[PgHomepage] = PageHome;
|
||||
|
||||
#ifndef NDEBUG // If only in debug mode should we initialize QSS test page
|
||||
PageQssTest = new SpkUi::SpkPageUiTest(this);
|
||||
PageQssTest->setProperty("spk_pageid", SpkStackedPages::PgQssTest);
|
||||
@ -575,5 +584,8 @@ SpkUi::SpkMainWidget::SpkMainWidget(QWidget *parent) : QFrame(parent)
|
||||
for(auto i : sorter)
|
||||
Pager->addWidget(i);
|
||||
|
||||
// Default page selection : homepage
|
||||
HomepageItem->setSelected(true);
|
||||
|
||||
setLayout(HorizontalDivide);
|
||||
}
|
||||
|
35
gui/spknotifydot.cpp
Normal file
35
gui/spknotifydot.cpp
Normal file
@ -0,0 +1,35 @@
|
||||
|
||||
#include <QPaintEvent>
|
||||
#include <QPainter>
|
||||
#include <QBrush>
|
||||
#include "spknotifydot.h"
|
||||
#include "spkstore.h"
|
||||
|
||||
/*
|
||||
* The font size and the actual geometry of this widget is hard coded
|
||||
* If you want to use this widget code please consider improving it
|
||||
*/
|
||||
|
||||
SpkNotifyDot::SpkNotifyDot(QWidget *parent) :
|
||||
QLabel(parent)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void SpkNotifyDot::paintEvent(QPaintEvent *e)
|
||||
{
|
||||
QPainter p(this);
|
||||
|
||||
int h = height();
|
||||
|
||||
p.setRenderHint(QPainter::Antialiasing);
|
||||
p.setBrush(QBrush(QColor(255, 70, 50)));
|
||||
p.setPen(Qt::transparent);
|
||||
p.drawEllipse(0, 0, h, h);
|
||||
p.setBrush(QBrush(QColor(Qt::white)));
|
||||
p.setPen(Qt::white);
|
||||
p.setFont(QFont("sansserif", 10, 1000));
|
||||
p.drawText(QRect(0, 0, h, h), Qt::AlignHCenter | Qt::AlignVCenter, text());
|
||||
|
||||
p.end();
|
||||
}
|
25
inc/page/spkpagehome.h
Normal file
25
inc/page/spkpagehome.h
Normal file
@ -0,0 +1,25 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <QVBoxLayout>
|
||||
#include "page/spkpagebase.h"
|
||||
#include "ui_homepage.h"
|
||||
|
||||
namespace SpkUi
|
||||
{
|
||||
class SpkPageHome : public SpkPageBase
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
SpkPageHome(QWidget *parent = nullptr);
|
||||
~SpkPageHome() { }
|
||||
|
||||
Ui::SpkHomepage *ui;
|
||||
|
||||
private slots:
|
||||
void LinkActivated(QString);
|
||||
|
||||
private:
|
||||
void SetupUi();
|
||||
};
|
||||
}
|
@ -17,6 +17,7 @@
|
||||
#include "spkfocuslineedit.h"
|
||||
#include "spkiconbutton.h"
|
||||
#include "page/spkpageuitest.h"
|
||||
#include "page/spkpagehome.h"
|
||||
#include "page/spkpageapplist.h"
|
||||
#include "page/spkpageappdetails.h"
|
||||
#include "page/spkpagedownloads.h"
|
||||
@ -29,6 +30,7 @@ namespace SpkUi
|
||||
enum SpkStackedPages
|
||||
{
|
||||
PgInvalid = -1,
|
||||
PgHomepage,
|
||||
PgAppList,
|
||||
PgAppDetails,
|
||||
PgDownloads,
|
||||
@ -170,7 +172,8 @@ namespace SpkUi
|
||||
QMap<int, QTreeWidgetItem> *CategoryItemMap;
|
||||
SpkSidebarSelector *SidebarMgr;
|
||||
|
||||
QTreeWidgetItem *CategoryParentItem,
|
||||
QTreeWidgetItem *HomepageItem,
|
||||
*CategoryParentItem,
|
||||
*AppDetailsItem,
|
||||
*DownloadsItem,
|
||||
*UiTestItem;
|
||||
@ -182,6 +185,8 @@ namespace SpkUi
|
||||
|
||||
//Pages
|
||||
SpkPageUiTest *PageQssTest;
|
||||
|
||||
SpkPageHome *PageHome;
|
||||
SpkPageAppList *PageAppList;
|
||||
SpkPageAppDetails *PageAppDetails;
|
||||
SpkPageDownloads *PageDownloads;
|
||||
|
17
inc/spknotifydot.h
Normal file
17
inc/spknotifydot.h
Normal file
@ -0,0 +1,17 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <QLabel>
|
||||
|
||||
class SpkNotifyDot : public QLabel
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
SpkNotifyDot(QWidget *parent = nullptr);
|
||||
~SpkNotifyDot() {}
|
||||
|
||||
protected:
|
||||
virtual void paintEvent(QPaintEvent *) override;
|
||||
// virtual int widthForHeight(int h) override;
|
||||
};
|
@ -187,6 +187,16 @@ SpkAppItem
|
||||
SpkAppItem::hover
|
||||
{
|
||||
background: DCTL1;
|
||||
}
|
||||
/* homepage*/
|
||||
#lblTitle
|
||||
{
|
||||
font-weiget: 700;
|
||||
font-size: 40px;
|
||||
}
|
||||
|
||||
#btnAnnouncements, #btnFeedback, #btnDonation
|
||||
{
|
||||
}
|
||||
|
||||
#styAppItmTitle
|
||||
|
Loading…
x
Reference in New Issue
Block a user