mirror of
https://gitee.com/spark-store-project/spark-store
synced 2025-12-14 21:02:04 +08:00
下载页面雏形,修复SpkPopup(改用弹出),添加应用列表固定图标缓存
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
#include "page/spkpageappdetails.h"
|
||||
#include "spkutils.h"
|
||||
#include "spkappitem.h"
|
||||
|
||||
namespace SpkUi
|
||||
{
|
||||
@@ -112,8 +113,8 @@ namespace SpkUi
|
||||
mAuthor->SetTitle(tr("Author"));
|
||||
mContributor = new SpkDetailEntry;
|
||||
mContributor->SetTitle(tr("Contributor"));
|
||||
mSite = new SpkDetailEntry;
|
||||
mSite->SetTitle(tr("Website"));
|
||||
// mSite = new SpkDetailEntry;
|
||||
// mSite->SetTitle(tr("Website"));
|
||||
mArch = new SpkDetailEntry;
|
||||
mArch->SetTitle(tr("Architecture"));
|
||||
mSize = new SpkDetailEntry;
|
||||
|
||||
@@ -7,6 +7,9 @@ namespace SpkUi
|
||||
{
|
||||
SpkPageAppList::SpkPageAppList(QWidget *parent) : SpkPageBase(parent)
|
||||
{
|
||||
mLoadingIcon = new QPixmap(QIcon(":/icons/loading-icon.svg").pixmap(SpkAppItem::IconSize_));
|
||||
mBrokenIcon = new QPixmap(QIcon(":/icons/broken-icon.svg").pixmap(SpkAppItem::IconSize_));
|
||||
|
||||
mAppsWidget = new QWidget;
|
||||
mAppsArea = new QScrollArea(this);
|
||||
mMainLay = new QVBoxLayout(this);
|
||||
@@ -63,6 +66,7 @@ namespace SpkUi
|
||||
|
||||
auto iconRes = RES->RequestResource(id, pkgName, SpkResource::ResourceType::AppIcon,
|
||||
iconUrl, 0);
|
||||
// TODO: cache scaled icons
|
||||
QPixmap icon;
|
||||
if(iconRes.status == SpkResource::ResourceStatus::Ready)
|
||||
{
|
||||
@@ -72,13 +76,13 @@ namespace SpkUi
|
||||
Qt::SmoothTransformation));
|
||||
else
|
||||
{
|
||||
item->SetIcon(QIcon(":/icons/broken-icon.svg").pixmap(SpkAppItem::IconSize_));
|
||||
item->SetIcon(*mBrokenIcon);
|
||||
RES->PurgeCachedResource(pkgName, SpkResource::ResourceType::AppIcon, 0);
|
||||
}
|
||||
}
|
||||
//TODO: prepare icons for loading entries
|
||||
// else
|
||||
// item->SetIcon(QPixmap(":/icons/loading_icon.svg").scaled(SpkAppItem::IconSize_));
|
||||
//TODO: [TEST] prepare icons for loading entries
|
||||
else
|
||||
item->SetIcon(*mLoadingIcon);
|
||||
|
||||
mAppItemList.append(item);
|
||||
mItemLay->addWidget(item);
|
||||
@@ -110,11 +114,11 @@ namespace SpkUi
|
||||
Qt::IgnoreAspectRatio,
|
||||
Qt::SmoothTransformation));
|
||||
else
|
||||
item->SetIcon(QIcon(":/icons/broken-icon.svg").pixmap(SpkAppItem::IconSize_));
|
||||
item->SetIcon(*mBrokenIcon);
|
||||
}
|
||||
else if(result.status == SpkResource::ResourceStatus::Failed)
|
||||
{
|
||||
item->SetIcon(QIcon(":/icons/broken-icon.svg").pixmap(SpkAppItem::IconSize_));
|
||||
item->SetIcon(*mBrokenIcon);
|
||||
RES->PurgeCachedResource(item->property("pkg_name").toString(),
|
||||
SpkResource::ResourceType::AppIcon, 0);
|
||||
}
|
||||
|
||||
29
gui/page/spkpagedownloads.cpp
Normal file
29
gui/page/spkpagedownloads.cpp
Normal file
@@ -0,0 +1,29 @@
|
||||
|
||||
|
||||
#include "page/spkpagedownloads.h"
|
||||
#include "spkutils.h"
|
||||
|
||||
SpkUi::SpkPageDownloads::SpkPageDownloads(QWidget *parent) :
|
||||
SpkPageBase(parent)
|
||||
{
|
||||
mMainLay = new QVBoxLayout(this);
|
||||
mLayEntries = new QVBoxLayout;
|
||||
mScrollWidget = new QWidget;
|
||||
mScrollArea = new QScrollArea(this);
|
||||
|
||||
mScrollWidget->setLayout(mLayEntries);
|
||||
mScrollArea->setWidget(mScrollWidget);
|
||||
mScrollArea->setWidgetResizable(true);
|
||||
mMainLay->addWidget(mScrollArea);
|
||||
setLayout(mMainLay);
|
||||
}
|
||||
|
||||
SpkUi::SpkPageDownloads::~SpkPageDownloads()
|
||||
{
|
||||
// TODO
|
||||
}
|
||||
|
||||
void SpkUi::SpkPageDownloads::DownloadProgress(qint64 downloadedBytes, qint64 totalBytes, int id)
|
||||
{
|
||||
// TODO
|
||||
}
|
||||
111
gui/spkdownloadentry.cpp
Normal file
111
gui/spkdownloadentry.cpp
Normal file
@@ -0,0 +1,111 @@
|
||||
|
||||
#include "spkdownloadentry.h"
|
||||
#include "spklogging.h"
|
||||
|
||||
constexpr QSize SpkDownloadEntry::IconSize;
|
||||
|
||||
SpkDownloadEntry::SpkDownloadEntry(QWidget *parent)
|
||||
{
|
||||
mIcon = new QLabel;
|
||||
mAppName = new ElidedLabel;
|
||||
mMessage = new QLabel;
|
||||
mProgress = new QProgressBar;
|
||||
mLoading = new SpkLoading;
|
||||
mBtnDelete = new QPushButton;
|
||||
mBtnActions = new QPushButton;
|
||||
|
||||
mLayInfo = new QVBoxLayout;
|
||||
mLayMsgs = new QHBoxLayout;
|
||||
mLayMain = new QHBoxLayout;
|
||||
|
||||
mLoading->setVisible(false);
|
||||
mIcon->setFixedSize(IconSize);
|
||||
mProgress->setRange(0, 1000);
|
||||
|
||||
mLayMsgs->addWidget(mAppName);
|
||||
mLayMsgs->addStretch();
|
||||
mLayMsgs->addWidget(mMessage);
|
||||
|
||||
mLayInfo->addLayout(mLayMsgs);
|
||||
mLayInfo->addWidget(mProgress);
|
||||
mLayInfo->setAlignment(Qt::AlignVCenter);
|
||||
|
||||
mLayMain->addWidget(mIcon);
|
||||
mLayMain->addLayout(mLayInfo);
|
||||
mLayMain->addWidget(mLoading);
|
||||
mLayMain->addWidget(mBtnActions);
|
||||
mLayMain->addWidget(mBtnDelete);
|
||||
|
||||
setLayout(mLayMain);
|
||||
}
|
||||
|
||||
|
||||
SpkDownloadEntry::~SpkDownloadEntry()
|
||||
{
|
||||
// TODO
|
||||
}
|
||||
|
||||
void SpkDownloadEntry::SetBasicInfo(QString name, QPixmap icon)
|
||||
{
|
||||
mAppName->setText(name);
|
||||
mIcon->setPixmap(icon.scaled(IconSize, Qt::IgnoreAspectRatio, Qt::SmoothTransformation));
|
||||
}
|
||||
|
||||
void SpkDownloadEntry::SetStatus(DownloadEntryStatus status)
|
||||
{
|
||||
switch(status)
|
||||
{
|
||||
case Waiting:
|
||||
mMessage->setText(tr("Waiting for download"));
|
||||
mProgress->setVisible(false);
|
||||
mBtnActions->setVisible(false);
|
||||
mBtnDelete->setVisible(true);
|
||||
break;
|
||||
|
||||
case Downloading:
|
||||
mMessage->setText(tr(""));
|
||||
mProgress->setVisible(true);
|
||||
mBtnActions->setVisible(true);
|
||||
break;
|
||||
|
||||
case Paused:
|
||||
mMessage->setText(tr("Paused"));
|
||||
break;
|
||||
|
||||
case Failed:
|
||||
mMessage->setText(tr("Download Failed"));
|
||||
mProgress->setVisible(false);
|
||||
break;
|
||||
|
||||
case ToBeInstalled:
|
||||
mMessage->setText(tr("Download Finished"));
|
||||
mProgress->setVisible(false);
|
||||
break;
|
||||
|
||||
case Installing:
|
||||
mMessage->setText("");
|
||||
mProgress->setVisible(false);
|
||||
mLoading->setVisible(true);
|
||||
mLoading->Begin();
|
||||
|
||||
case Installed:
|
||||
mMessage->setText(tr("Installed"));
|
||||
mLoading->End();
|
||||
mLoading->setVisible(false);
|
||||
break;
|
||||
|
||||
case InstallFailed:
|
||||
mMessage->setText(tr("Install Failed"));
|
||||
mLoading->End();
|
||||
mLoading->setVisible(false);
|
||||
break;
|
||||
|
||||
case Invalid:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void SpkDownloadEntry::SetProgress(int p)
|
||||
{
|
||||
mProgress->setValue(p);
|
||||
}
|
||||
@@ -435,8 +435,13 @@ SpkUi::SpkMainWidget::SpkMainWidget(QWidget *parent) : QFrame(parent)
|
||||
AppDetailsItem = new QTreeWidgetItem(QStringList(tr("App Details")));
|
||||
AppDetailsItem->setData(0, SpkSidebarSelector::RoleItemIsCategory, false);
|
||||
AppDetailsItem->setData(0, SpkSidebarSelector::RoleItemCategoryPageId, SpkStackedPages::PgAppDetails);
|
||||
|
||||
CategoryParentItem = new QTreeWidgetItem(QStringList(tr("Categories")));
|
||||
CategoryParentItem->setFlags(CategoryParentItem->flags().setFlag(Qt::ItemIsSelectable, false));
|
||||
|
||||
DownloadsItem = new QTreeWidgetItem(QStringList(tr("Downloads")));
|
||||
DownloadsItem->setData(0, SpkSidebarSelector::RoleItemIsCategory, false);
|
||||
DownloadsItem->setData(0, SpkSidebarSelector::RoleItemCategoryPageId, SpkStackedPages::PgDownloads);
|
||||
#ifndef NDEBUG
|
||||
UiTestItem = new QTreeWidgetItem(QStringList(tr("UI TEST")));
|
||||
UiTestItem->setData(0, SpkSidebarSelector::RoleItemIsCategory, false);
|
||||
@@ -525,6 +530,10 @@ SpkUi::SpkMainWidget::SpkMainWidget(QWidget *parent) : QFrame(parent)
|
||||
PageAppDetails->setProperty("spk_pageid", SpkStackedPages::PgAppDetails);
|
||||
sorter[PgAppDetails] = PageAppDetails;
|
||||
|
||||
PageDownloads = new SpkUi::SpkPageDownloads(this);
|
||||
PageDownloads->setProperty("spk_pageid", SpkStackedPages::PgDownloads);
|
||||
sorter[PgDownloads] = PageDownloads;
|
||||
|
||||
#ifndef NDEBUG // If only in debug mode should we initialize QSS test page
|
||||
PageQssTest = new SpkUi::SpkPageUiTest(this);
|
||||
PageQssTest->setProperty("spk_pageid", SpkStackedPages::PgQssTest);
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include <QGuiApplication>
|
||||
#include <QScreen>
|
||||
#include "spkui_general.h"
|
||||
#include "spkmainwindow.h"
|
||||
#include "spkmsgbox.h"
|
||||
#include "spkstore.h"
|
||||
|
||||
|
||||
@@ -1,13 +1,14 @@
|
||||
|
||||
#include "spkmainwindow.h"
|
||||
#include "spkpopup.h"
|
||||
#include <QDebug>
|
||||
|
||||
namespace SpkUi
|
||||
{
|
||||
SpkPopup::SpkPopup(QWidget *parent, int aMillis) : QWidget(parent)
|
||||
{
|
||||
setAttribute(Qt::WA_TransparentForMouseEvents);
|
||||
setAttribute(Qt::WA_TranslucentBackground);
|
||||
setWindowFlags(Qt::ToolTip | Qt::FramelessWindowHint);
|
||||
setWindowFlags(Qt::FramelessWindowHint);
|
||||
mText = new QLabel();
|
||||
mText->setStyleSheet("border-radius: 11px;"
|
||||
"background-color: rgba(0,0,0,150);"
|
||||
@@ -22,19 +23,33 @@ namespace SpkUi
|
||||
// Qt::WA_TranslucentBackground will cause the entire background of QLabel transparent.
|
||||
// Therefore we need a container (SpkPopup) with a transparent background as the canvas layer
|
||||
// of the actual displayed text.
|
||||
mAnimFadeIn = new QPropertyAnimation(this, "windowOpacity");
|
||||
mAnimFadeOut = new QPropertyAnimation(this, "windowOpacity");
|
||||
mAnim = new QSequentialAnimationGroup(this);
|
||||
mAnimFadeIn->setStartValue(0);
|
||||
mAnimFadeIn->setEndValue(1);
|
||||
|
||||
// Disabled as translucency doesn't work well on every platform
|
||||
// mAnimFadeIn = new QPropertyAnimation(this, "windowOpacity");
|
||||
// mAnimFadeOut = new QPropertyAnimation(this, "windowOpacity");
|
||||
// mAnimFadeIn->setStartValue(0.0);
|
||||
// mAnimFadeIn->setEndValue(1.0);
|
||||
// mAnimFadeOut->setStartValue(1.0);
|
||||
// mAnimFadeOut->setEndValue(0.0);
|
||||
// Using moving animation instead
|
||||
mAnimFadeIn = new QPropertyAnimation(this, "pos");
|
||||
mAnimFadeOut = new QPropertyAnimation(this, "pos");
|
||||
mAnimFadeIn->setDuration(250);
|
||||
mAnimFadeOut->setStartValue(1);
|
||||
mAnimFadeOut->setEndValue(0);
|
||||
mAnimFadeOut->setDuration(250);
|
||||
mAnimFadeIn->setEasingCurve(QEasingCurve::InQuad);
|
||||
mAnimFadeOut->setEasingCurve(QEasingCurve::InQuad);
|
||||
|
||||
mAnim->addAnimation(mAnimFadeIn);
|
||||
mAnim->addPause(aMillis);
|
||||
mAnim->addAnimation(mAnimFadeOut);
|
||||
setVisible(false);
|
||||
|
||||
connect(mAnim, &QAnimationGroup::stateChanged,
|
||||
[=](QAbstractAnimation::State newState, QAbstractAnimation::State oldState)
|
||||
{
|
||||
qDebug() << "OldState" << oldState << "NewState" << newState;
|
||||
});
|
||||
}
|
||||
|
||||
void SpkPopup::Show(QString aText)
|
||||
@@ -44,11 +59,22 @@ namespace SpkUi
|
||||
QSize parentSize = parentWidget()->size();
|
||||
mText->setText(aText);
|
||||
adjustSize();
|
||||
move(QPoint((parentSize.width() - width()) / 2, parentSize.height() - height() - 30) +
|
||||
parentWidget()->pos());
|
||||
move(QPoint((parentSize.width() - width()) / 2, parentSize.height() - height() - 30)/* +
|
||||
parentWidget()->pos()*/);
|
||||
setMaximumWidth(parentSize.width() - 200);
|
||||
setWindowOpacity(1);
|
||||
show();
|
||||
|
||||
mAnimFadeIn->setStartValue(QPoint((parentSize.width() - width()) / 2,
|
||||
parentSize.height() + height()));
|
||||
mAnimFadeIn->setEndValue(QPoint((parentSize.width() - width()) / 2,
|
||||
parentSize.height() - height() - 80));
|
||||
mAnimFadeOut->setStartValue(QPoint((parentSize.width() - width()) / 2,
|
||||
parentSize.height() - height() - 80));
|
||||
mAnimFadeOut->setEndValue(QPoint((parentSize.width() - width()) / 2,
|
||||
parentSize.height() + height()));
|
||||
|
||||
qDebug() << "Popup size " << size() << "position" << pos() << "parent size" << parentWidget()->size();
|
||||
mAnim->start();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user