完成搜索功能

This commit is contained in:
metanoia1989 2020-12-01 22:10:52 +08:00
parent 4315f04023
commit 91fcab56df
4 changed files with 132 additions and 67 deletions

View File

@ -6,12 +6,20 @@
#include <QNetworkRequest> #include <QNetworkRequest>
#include <QEventLoop> #include <QEventLoop>
#include <QPainter> #include <QPainter>
#include <QGraphicsDropShadowEffect>
AppItem::AppItem(QWidget *parent) : AppItem::AppItem(QWidget *parent) :
QWidget(parent), QWidget(parent),
ui(new Ui::AppItem) ui(new Ui::AppItem)
{ {
ui->setupUi(this); ui->setupUi(this);
// auto shadow = new QGraphicsDropShadowEffect();
// shadow->setXOffset(0);
// shadow->setYOffset(1);
// shadow->setBlurRadius(2);
// shadow->setColor(QColor::fromRgba(qRgba(0, 0, 0, 180)));
// ui->container->setGraphicsEffect(shadow);
} }
AppItem::~AppItem() AppItem::~AppItem()
@ -28,13 +36,19 @@ void AppItem::setTitle(QString title)
void AppItem::setDescription(QString description) void AppItem::setDescription(QString description)
{ {
m_description = description; m_description = description;
ui->lbl_desc->setText(description); QString elidedText = ui->lbl_desc->fontMetrics().elidedText(
description, Qt::ElideRight,
ui->lbl_desc->width(), Qt::TextShowMnemonic);
ui->lbl_desc->setText(elidedText);
ui->lbl_desc->setAlignment(Qt::AlignTop);
} }
void AppItem::setIcon(QString icon) void AppItem::setIcon(QString icon)
{ {
m_icon = icon; m_icon = icon;
if (!icon.isEmpty()) {
downloadIcon(icon); downloadIcon(icon);
}
} }
void AppItem::setUrl(QString url) void AppItem::setUrl(QString url)
@ -65,6 +79,7 @@ void AppItem::downloadIcon(QString icon)
QPixmap pixmap; QPixmap pixmap;
pixmap.loadFromData(reply->readAll()); pixmap.loadFromData(reply->readAll());
qDebug() << "图标下载完毕:" << pixmap; qDebug() << "图标下载完毕:" << pixmap;
qDebug() << icon << "响应有报错吗?" << reply->errorString();
pixmap = pixmap.scaled(78, 78, Qt::IgnoreAspectRatio, Qt::SmoothTransformation); pixmap = pixmap.scaled(78, 78, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
if (reply->error() == QNetworkReply::NoError) { if (reply->error() == QNetworkReply::NoError) {
QMetaObject::invokeMethod(this, "loadIcon", Qt::QueuedConnection, QMetaObject::invokeMethod(this, "loadIcon", Qt::QueuedConnection,

View File

@ -6,8 +6,8 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>331</width> <width>333</width>
<height>131</height> <height>133</height>
</rect> </rect>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">
@ -20,6 +20,15 @@
margin: 15px; margin: 15px;
color: #6d6d6d; color: #6d6d6d;
border-radius: 18px; border-radius: 18px;
background-color: width: 300px;
height: 100px;
margin: 15px;
color: #6d6d6d;
border-radius: 18px;
background-color: #F4F4F6;
}
QWidget#container {
background-color: #F4F4F6; background-color: #F4F4F6;
} }
@ -30,10 +39,10 @@ QLabel#lbl_icon {
QLabel#lbl_title { QLabel#lbl_title {
text-align: left; text-align: left;
font-weight: lighter;
white-space: nowrap; white-space: nowrap;
padding-right: 10px; padding-right: 10px;
font-size: 19px; font-size: 19px;
} }
QLabel#lbl_desc { QLabel#lbl_desc {
@ -44,7 +53,40 @@ QLabel#lbl_desc {
color: grey; color: grey;
}</string> }</string>
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<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>
<item>
<widget class="QWidget" name="container" native="true">
<layout class="QHBoxLayout" name="horizontalLayout"> <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>
<item> <item>
<widget class="QLabel" name="lbl_icon"> <widget class="QLabel" name="lbl_icon">
<property name="minimumSize"> <property name="minimumSize">
@ -110,6 +152,9 @@ padding: 10px;</string>
</item> </item>
</layout> </layout>
</widget> </widget>
</item>
</layout>
</widget>
<resources/> <resources/>
<connections/> <connections/>
</ui> </ui>

View File

@ -725,6 +725,7 @@ void Widget::searchApp(QString text)
// sendNotification(tr("Spark store could only process spk:// links for now. The search feature is coming soon!")); // sendNotification(tr("Spark store could only process spk:// links for now. The search feature is coming soon!"));
// ui->webView->setUrl(QUrl("http://www.baidu.com/s?wd="+text));//这东西对接百度 // ui->webView->setUrl(QUrl("http://www.baidu.com/s?wd="+text));//这东西对接百度
// ui->stackedWidget->setCurrentIndex(0); // ui->stackedWidget->setCurrentIndex(0);
// 关键字搜索处理 // 关键字搜索处理
httpClient->get("http://192.168.0.103:8000/appinfo/search") httpClient->get("http://192.168.0.103:8000/appinfo/search")
.header("content-type", "application/json") .header("content-type", "application/json")
@ -743,6 +744,7 @@ void Widget::searchApp(QString text)
}) })
.onError([](QString errorStr) { .onError([](QString errorStr) {
qDebug() << "请求出错:" << errorStr; qDebug() << "请求出错:" << errorStr;
sendNotification(QString("请求出错:%1").arg(errorStr));
}) })
.timeout(10 * 1000) .timeout(10 * 1000)
.exec(); .exec();

View File

@ -345,7 +345,7 @@
<number>0</number> <number>0</number>
</property> </property>
<property name="currentIndex"> <property name="currentIndex">
<number>2</number> <number>3</number>
</property> </property>
<widget class="QWidget" name="page"> <widget class="QWidget" name="page">
<layout class="QVBoxLayout" name="verticalLayout_4"> <layout class="QVBoxLayout" name="verticalLayout_4">
@ -1390,6 +1390,9 @@
<layout class="QVBoxLayout" name="verticalLayout_3"> <layout class="QVBoxLayout" name="verticalLayout_3">
<item> <item>
<widget class="QScrollArea" name="applist_scrollarea"> <widget class="QScrollArea" name="applist_scrollarea">
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
</property>
<property name="widgetResizable"> <property name="widgetResizable">
<bool>true</bool> <bool>true</bool>
</property> </property>
@ -1398,8 +1401,8 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>98</width> <width>881</width>
<height>28</height> <height>659</height>
</rect> </rect>
</property> </property>
</widget> </widget>