mirror of
https://gitee.com/spark-store-project/spark-store
synced 2025-12-14 21:02:04 +08:00
添加应用详情页面
This commit is contained in:
182
gui/page/spkpageappdetails.cpp
Normal file
182
gui/page/spkpageappdetails.cpp
Normal file
@@ -0,0 +1,182 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
|
||||
#include "page/spkpageappdetails.h"
|
||||
#include "spkutils.h"
|
||||
|
||||
|
||||
namespace SpkUi
|
||||
{
|
||||
constexpr QSize SpkPageAppDetails::IconSize;
|
||||
|
||||
void SpkPageAppDetails::LoadAppResources(QString aPkgName, QString aIcon, QStringList aScreenshots,
|
||||
QStringList aTags)
|
||||
{
|
||||
QPixmap pic;
|
||||
|
||||
// Load icon
|
||||
auto res = RES->RequestResource(0, aPkgName, SpkResource::ResourceType::AppIcon, aIcon);
|
||||
if(res.status == SpkResource::ResourceStatus::Ready)
|
||||
{
|
||||
if(pic.loadFromData(res.data))
|
||||
mAppIcon->setPixmap(pic.scaled(IconSize,
|
||||
Qt::IgnoreAspectRatio,
|
||||
Qt::SmoothTransformation));
|
||||
else
|
||||
{
|
||||
mAppIcon->setPixmap(QIcon::fromTheme("dialog-error").pixmap(SpkAppItem::IconSize_));
|
||||
RES->PurgeCachedResource(aPkgName, SpkResource::ResourceType::AppIcon, 0);
|
||||
}
|
||||
}
|
||||
|
||||
// Load screenshots
|
||||
if(aScreenshots.isEmpty())
|
||||
return;
|
||||
|
||||
int shotId = 0;
|
||||
for(auto &i : aScreenshots)
|
||||
{
|
||||
shotId++;
|
||||
res = RES->RequestResource(shotId, aPkgName, SpkResource::ResourceType::AppScreenshot, aIcon,
|
||||
shotId);
|
||||
if(res.status == SpkResource::ResourceStatus::Ready)
|
||||
{
|
||||
if(pic.loadFromData(res.data))
|
||||
;// TODO
|
||||
else
|
||||
{
|
||||
// TODO
|
||||
// mAppIcon->setPixmap(QIcon::fromTheme("dialog-error").pixmap(SpkAppItem::IconSize_));
|
||||
RES->PurgeCachedResource(aPkgName, SpkResource::ResourceType::AppScreenshot, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: tags
|
||||
}
|
||||
|
||||
SpkPageAppDetails::SpkPageAppDetails(QWidget *parent) : SpkPageBase(parent)
|
||||
{
|
||||
mMainArea = new QScrollArea;
|
||||
mMainArea->setWidgetResizable(true);
|
||||
mMainArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||
|
||||
mLay4MainArea = new QVBoxLayout(this);
|
||||
mLay4MainArea->addWidget(mMainArea);
|
||||
|
||||
mMainLay = new QVBoxLayout(mMainArea);
|
||||
mMainLay->setSizeConstraint(QLayout::SetMinAndMaxSize);
|
||||
|
||||
mAppIcon = new QLabel;
|
||||
|
||||
mAppTitle = new QLabel;
|
||||
mAppTitle->setObjectName("styDetTitle");
|
||||
|
||||
mAppDescription = new QLabel;
|
||||
mAppDescription->setObjectName("styDetDesc");
|
||||
mAppDescription->setWordWrap(true);
|
||||
mAppShortDesc = new QLabel;
|
||||
mAppShortDesc->setObjectName("styDetDesc");
|
||||
mAppShortDesc->setWordWrap(true);
|
||||
// NOTE: Seems Qt have trouble dealing with wrapped text here. Removing the following operations
|
||||
// to mAppShortDesc will result in broken layout. Very possible that it's a Qt bug.
|
||||
mAppShortDesc->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Preferred);
|
||||
mAppShortDesc->setMinimumWidth(100);
|
||||
mVersion = new QLabel;
|
||||
mPkgName = new QLabel;
|
||||
mPkgName->setObjectName("styDetPkg");
|
||||
|
||||
mTitleLay = new QVBoxLayout;
|
||||
mTitleLay->setAlignment(Qt::AlignTop);
|
||||
mTitleLay->addWidget(mAppTitle);
|
||||
mTitleLay->addWidget(mVersion);
|
||||
mTitleLay->addWidget(mAppShortDesc);
|
||||
mTitleLay->addWidget(mPkgName);
|
||||
mTitleLay->setSpacing(0);
|
||||
|
||||
mIconTitleLay = new QHBoxLayout;
|
||||
mIconTitleLay->setAlignment(Qt::AlignLeft);
|
||||
mIconTitleLay->addWidget(mAppIcon);
|
||||
mIconTitleLay->addSpacing(15);
|
||||
mIconTitleLay->addLayout(mTitleLay);
|
||||
|
||||
mIconTitleWidget = new QWidget;
|
||||
mIconTitleWidget->setLayout(mIconTitleLay);
|
||||
|
||||
mAuthor = new SpkDetailEntry;
|
||||
mAuthor->SetTitle(tr("Author"));
|
||||
mContributor = new SpkDetailEntry;
|
||||
mContributor->SetTitle(tr("Contributor"));
|
||||
mSite = new SpkDetailEntry;
|
||||
mSite->SetTitle(tr("Website"));
|
||||
mArch = new SpkDetailEntry;
|
||||
mArch->SetTitle(tr("Architecture"));
|
||||
mSize = new SpkDetailEntry;
|
||||
mSize->SetTitle(tr("Size"));
|
||||
|
||||
mDetailLay = new SpkStretchLayout;
|
||||
mDetailLay->setSpacing(12);
|
||||
mDetailLay->addWidget(mAuthor);
|
||||
mDetailLay->addWidget(mContributor);
|
||||
mDetailLay->addWidget(mSize);
|
||||
mDetailLay->addWidget(mArch);
|
||||
mDetailLay->addWidget(mSite);
|
||||
|
||||
// mDetailWidget = new QWidget;
|
||||
// mDetailWidget->setLayout(mDetailLay);
|
||||
// mDetailWidget->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding);
|
||||
|
||||
mMainLay->setAlignment(Qt::AlignTop);
|
||||
mMainLay->addWidget(mIconTitleWidget);
|
||||
mMainLay->addLayout(mDetailLay);
|
||||
mMainLay->addWidget(mAppDescription);
|
||||
// mMainLay->addStretch();
|
||||
mWid4MainArea = new QWidget;
|
||||
mWid4MainArea->setLayout(mMainLay);
|
||||
|
||||
mMainArea->setWidget(mWid4MainArea);
|
||||
}
|
||||
|
||||
void SpkPageAppDetails::ResourceAcquisitionFinished(int id, ResourceResult result)
|
||||
{
|
||||
QPixmap icon;
|
||||
if(!id)
|
||||
{
|
||||
// id == 0, icon
|
||||
if(result.status == SpkResource::ResourceStatus::Ready)
|
||||
{
|
||||
if(icon.loadFromData(result.data))
|
||||
mAppIcon->setPixmap(icon.scaled(SpkAppItem::IconSize_,
|
||||
Qt::IgnoreAspectRatio,
|
||||
Qt::SmoothTransformation));
|
||||
else
|
||||
mAppIcon->setPixmap(QIcon::fromTheme("dialog-error").pixmap(SpkAppItem::IconSize_));
|
||||
}
|
||||
else if(result.status == SpkResource::ResourceStatus::Failed)
|
||||
{
|
||||
mAppIcon->setPixmap(QIcon::fromTheme("dialog-error").pixmap(SpkAppItem::IconSize_));
|
||||
RES->PurgeCachedResource(mPkgName->text(), SpkResource::ResourceType::AppIcon, 0);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// TODO: screenshots
|
||||
}
|
||||
}
|
||||
|
||||
void SpkPageAppDetails::Activated()
|
||||
{
|
||||
RES->Acquire(this, false);
|
||||
}
|
||||
|
||||
SpkDetailEntry::SpkDetailEntry(QWidget *parent) : QWidget(parent)
|
||||
{
|
||||
setLayout(&mLay);
|
||||
mLay.addWidget(&mTitle);
|
||||
mLay.addWidget(&mField);
|
||||
mTitle.setAlignment(Qt::AlignLeft);
|
||||
mField.setAlignment(Qt::AlignRight);
|
||||
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
|
||||
setMinimumWidth(300);
|
||||
setAutoFillBackground(true);
|
||||
}
|
||||
}
|
||||
@@ -53,6 +53,7 @@ namespace SpkUi
|
||||
auto item = new SpkAppItem(appId, this);
|
||||
auto id = mAppItemList.size();
|
||||
|
||||
connect(item, &SpkAppItem::clicked, this, &SpkPageAppList::ApplicationClicked);
|
||||
item->SetTitle(name);
|
||||
item->SetDescription(description);
|
||||
item->setProperty("pkg_name", pkgName);
|
||||
|
||||
@@ -51,6 +51,18 @@ SpkUi::SpkPageUiTest::SpkPageUiTest(QWidget *parent) : QSplitter(parent)
|
||||
"Phasellus finibus risus id aliquam pulvinar.");
|
||||
AppItem->SetIcon(QIcon::fromTheme("dialog-information").pixmap(72, 72));
|
||||
|
||||
Detail1 = new SpkDetailEntry; Detail1->SetTitle("Foo"); Detail1->SetValue("1");
|
||||
Detail2 = new SpkDetailEntry; Detail2->SetTitle("Foo"); Detail2->SetValue("1");
|
||||
Detail3 = new SpkDetailEntry; Detail3->SetTitle("Foo"); Detail3->SetValue("1");
|
||||
|
||||
DetailsLay = new SpkStretchLayout;
|
||||
DetailsLay->addWidget(Detail1);
|
||||
DetailsLay->addWidget(Detail2);
|
||||
DetailsLay->addWidget(Detail3);
|
||||
|
||||
DetailsWidget = new QWidget;
|
||||
DetailsWidget->setLayout(DetailsLay);
|
||||
|
||||
PopupText = new QLineEdit(this);
|
||||
PopupText->setObjectName("spk_pg_qsstest_poptext");
|
||||
PopupText->setText("Hello, world");
|
||||
@@ -85,6 +97,7 @@ SpkUi::SpkPageUiTest::SpkPageUiTest(QWidget *parent) : QSplitter(parent)
|
||||
VLayTestWidgets->addWidget(ShowPopup);
|
||||
VLayTestWidgets->addWidget(ShowAbout);
|
||||
VLayTestWidgets->addWidget(AppItem);
|
||||
VLayTestWidgets->addWidget(DetailsWidget);
|
||||
|
||||
Group = new QGroupBox(this);
|
||||
Group->setObjectName("spk_pg_qsstest_groupbox");
|
||||
|
||||
Reference in New Issue
Block a user