forked from openkylin/ukui-search
Fix: Icon in detail view will not refresh when icon-theme changed.
修复主题图标改变时详情页图标未更新的问题.
This commit is contained in:
parent
f4ea89dec8
commit
d94ea704cd
|
@ -30,7 +30,6 @@
|
|||
#include <QFileInfo>
|
||||
#include <QProcess>
|
||||
#include <QClipboard>
|
||||
#include <QApplication>
|
||||
#include <QFileInfo>
|
||||
#include <QDateTime>
|
||||
#include <QDBusMetaType>
|
||||
|
@ -40,6 +39,7 @@
|
|||
using namespace Zeeker;
|
||||
SearchDetailView::SearchDetailView(QWidget *parent) : QWidget(parent) {
|
||||
initUI();
|
||||
connect(qApp, &QApplication::paletteChanged, this, &SearchDetailView::refreshIcon);
|
||||
}
|
||||
|
||||
SearchDetailView::~SearchDetailView() {
|
||||
|
@ -200,9 +200,7 @@ void SearchDetailView::setAppWidget(const QString &appname, const QString &path,
|
|||
m_typeLabel->show();
|
||||
m_hLine->show();
|
||||
|
||||
QIcon icon;
|
||||
if(path.isEmpty() || path == "") {
|
||||
icon = QIcon(iconpath);
|
||||
m_optionView->setupOptions(m_type, false);
|
||||
//未安装应用有一个label显示软件描述
|
||||
if(description != "" && !description.isEmpty()) {
|
||||
|
@ -210,17 +208,13 @@ void SearchDetailView::setAppWidget(const QString &appname, const QString &path,
|
|||
m_contentLabel->show();
|
||||
m_contentLabel->setText(QString(tr("Introduction: %1")).arg(description));
|
||||
}
|
||||
setIcon(iconpath, false);
|
||||
} else {
|
||||
m_optionView->setupOptions(m_type, true);
|
||||
if(QIcon::fromTheme(iconpath).isNull()) {
|
||||
icon = QIcon(":/res/icons/desktop.png");
|
||||
} else {
|
||||
icon = QIcon::fromTheme(iconpath);
|
||||
}
|
||||
setIcon(iconpath, true);
|
||||
}
|
||||
m_optionView->show();
|
||||
|
||||
m_iconLabel->setPixmap(icon.pixmap(icon.actualSize(QSize(96, 96))));
|
||||
QFontMetrics fontMetrics = m_nameLabel->fontMetrics();
|
||||
QString showname = fontMetrics.elidedText(m_name, Qt::ElideRight, 274); //当字体长度超过215时显示为省略号
|
||||
m_nameLabel->setText(showname);
|
||||
|
@ -352,8 +346,7 @@ void SearchDetailView::setupWidget(const int& type, const QString& path) {
|
|||
case SearchListView::ResType::Content:
|
||||
case SearchListView::ResType::Dir :
|
||||
case SearchListView::ResType::File : {
|
||||
QIcon icon = FileUtils::getFileIcon(QUrl::fromLocalFile(path).toString());
|
||||
m_iconLabel->setPixmap(icon.pixmap(icon.actualSize(QSize(96, 96))));
|
||||
setIcon(path);
|
||||
QFontMetrics fontMetrics = m_nameLabel->fontMetrics();
|
||||
QString wholeName = FileUtils::getFileName(path);
|
||||
QString name = fontMetrics.elidedText(wholeName, Qt::ElideRight, 274);
|
||||
|
@ -366,8 +359,7 @@ void SearchDetailView::setupWidget(const int& type, const QString& path) {
|
|||
break;
|
||||
}
|
||||
case SearchListView::ResType::Setting : {
|
||||
QIcon icon = FileUtils::getSettingIcon(path, true);
|
||||
m_iconLabel->setPixmap(icon.pixmap(icon.actualSize(QSize(96, 96))));
|
||||
setIcon(path);
|
||||
QString settingType = path.mid(path.indexOf("/") + 1, path.lastIndexOf("/") - path.indexOf("/") - 1); //配置项所属控制面板插件名
|
||||
m_nameLabel->setText(settingType);
|
||||
m_typeLabel->setText(FileUtils::getSettingName(path));
|
||||
|
@ -567,6 +559,42 @@ void SearchDetailView::initUI() {
|
|||
this->clearLayout(); //初始化时隐藏所有控件
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief SearchDetailView::refreshIcon 图标主题变更时,刷新图标的槽函数
|
||||
*/
|
||||
void SearchDetailView::refreshIcon() {
|
||||
this->setIcon(m_iconPath);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief SearchDetailView::setIcon 设置图标区域
|
||||
* @param path 图标路径或图标名
|
||||
* @param installed 如果是应用,是否已安装
|
||||
*/
|
||||
void SearchDetailView::setIcon(const QString &path, const bool &installed)
|
||||
{
|
||||
m_iconPath = path;
|
||||
if (m_type == SearchListView::ResType::App) {
|
||||
QIcon icon;
|
||||
if(!installed) {
|
||||
icon = QIcon(path);
|
||||
} else {
|
||||
if(QIcon::fromTheme(path).isNull()) {
|
||||
icon = QIcon(":/res/icons/desktop.png");
|
||||
} else {
|
||||
icon = QIcon::fromTheme(path);
|
||||
}
|
||||
}
|
||||
m_iconLabel->setPixmap(icon.pixmap(icon.actualSize(QSize(96, 96))));
|
||||
} else if (m_type == SearchListView::ResType::Setting) {
|
||||
QIcon icon = FileUtils::getSettingIcon(path, true);
|
||||
m_iconLabel->setPixmap(icon.pixmap(icon.actualSize(QSize(96, 96))));
|
||||
} else {
|
||||
QIcon icon = FileUtils::getFileIcon(QUrl::fromLocalFile(path).toString());
|
||||
m_iconLabel->setPixmap(icon.pixmap(icon.actualSize(QSize(96, 96))));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief SearchDetailView::addDesktopShortcut 添加到桌面快捷方式
|
||||
* @return
|
||||
|
|
|
@ -71,6 +71,8 @@ private:
|
|||
QString m_pkgname = 0; //目前只有未安装应用在打开软件商店时需要此参数
|
||||
|
||||
void initUI();
|
||||
void setIcon(const QString& path, const bool &installed = true);
|
||||
QString m_iconPath;
|
||||
QLabel * m_iconLabel = nullptr;
|
||||
QFrame * m_nameFrame = nullptr;
|
||||
QHBoxLayout * m_nameLayout = nullptr;
|
||||
|
@ -105,6 +107,7 @@ Q_SIGNALS:
|
|||
void configFileChanged();
|
||||
private Q_SLOTS:
|
||||
void execActions(const int&, const int&, const QString&);
|
||||
void refreshIcon();
|
||||
};
|
||||
|
||||
//此类用于url拦截
|
||||
|
|
Loading…
Reference in New Issue