Skip to content

Commit

Permalink
fix: Packing icons with the buildin icon rule
Browse files Browse the repository at this point in the history
1. Packing icons with the buildin icon rule.
2. Using icon theme to get icon.

Log: 

Bug: https://pms.uniontech.com/bug-view-231629.html
Bug: https://pms.uniontech.com/bug-view-231637.html
  • Loading branch information
Clauszy committed Dec 12, 2023
1 parent 3c094c9 commit 0e124fe
Show file tree
Hide file tree
Showing 36 changed files with 58 additions and 66 deletions.
2 changes: 1 addition & 1 deletion src/grand-search/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ set(SRCS

# 指定资源文件
set(QRCS
gui/searchconfig/resource.qrc
gui/searchconfig/icons/images.qrc
gui/exhibition/preview/resource.qrc
gui/exhibition/matchresult/resource.qrc
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,9 @@ DetailItem::DetailItem(QWidget *parent)
: QWidget(parent)
{
setFixedSize(360, 36);

m_backgroundColor = QColor(0, 0, 0, int(255*0.05));

setContentsMargins(20, 0, 10, 0);

m_radius = 8;

m_tagLabel = new DLabel(this);
m_tagLabel->setAlignment(Qt::AlignLeft | Qt::AlignVCenter);

Expand Down Expand Up @@ -150,7 +146,10 @@ void DetailItem::paintEvent(QPaintEvent *event)
{
QPainter p(this);
p.setPen(Qt::NoPen);
p.setBrush(m_backgroundColor);
if (m_backgroundColor.isValid())
p.setBrush(m_backgroundColor);
else
p.setBrush(getDefalutBackground());

QRect roundRect(0, 0, m_radius * 2, m_radius * 2);
QPainterPath path;
Expand Down Expand Up @@ -195,7 +194,7 @@ void DetailItem::paintEvent(QPaintEvent *event)

QColor DetailItem::getTagColor()
{
static QColor tagTextColor;
static QColor tagTextColor;
if (!tagTextColor.isValid()) {
tagTextColor = QColor(0, 0, 0, int(255*0.7));
if (DGuiApplicationHelper::instance()->themeType() == DGuiApplicationHelper::DarkType)
Expand All @@ -206,11 +205,23 @@ QColor DetailItem::getTagColor()

QColor DetailItem::getContentColor()
{
static QColor contentTextColor;
static QColor contentTextColor;
if (!contentTextColor.isValid()) {
contentTextColor = QColor(0, 0, 0, int(255*0.9));
if (DGuiApplicationHelper::instance()->themeType() == DGuiApplicationHelper::DarkType)
contentTextColor = QColor(255, 255, 255, int(255*0.9));
}
return contentTextColor;
}

QColor DetailItem::getDefalutBackground()
{
static QColor bkgColor;
if (!bkgColor.isValid()) {
if (DGuiApplicationHelper::instance()->themeType() == DGuiApplicationHelper::DarkType)
bkgColor = QColor(255, 255, 255, int(255 * 0.05));
else
bkgColor = QColor(0, 0, 0, int(255 * 0.05));
}
return bkgColor;
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class DetailItem : public QWidget
private:
QColor getTagColor();
QColor getContentColor();
QColor getDefalutBackground();
protected:
bool m_topRound = false;
bool m_bottomRound = false;
Expand Down
6 changes: 1 addition & 5 deletions src/grand-search/gui/searchconfig/bestmatchwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,8 @@ void BestMatchWidget::updateIcons()
{
Q_ASSERT(m_switchWidgets.count() == m_displayIcons.count());

QString suffix = Utils::iconThemeSuffix();

for (int i = 0; i < m_switchWidgets.count(); ++i) {

QString iconName = m_displayIcons.at(i);
QIcon icon = QIcon(QString(":/icons/%1%2.svg").arg(iconName).arg(suffix));
QIcon icon = QIcon::fromTheme(m_displayIcons.at(i));

auto switchWidget = m_switchWidgets.at(i);
Q_ASSERT(switchWidget);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,18 +62,9 @@ void BlackListDelegate::drawPathsText(QPainter *painter, const QStyleOptionViewI
QFontMetrics pathFontMetrics(pathFont);
QString elidedPath = pathFontMetrics.elidedText(path, Qt::ElideMiddle, ListTextMaxWidth);

const BlackListView *listView = qobject_cast<const BlackListView *>(option.widget);
auto selected = listView->selectionModel();
QColor pathColor;
if (selected->isSelected(index)) {
pathColor = QColor("#FFFFFF");
} else {
if (DGuiApplicationHelper::instance()->themeType() == DGuiApplicationHelper::LightType) {
pathColor = QColor("#414D68");
} else {
pathColor = QColor("#C0C6D4");
}
}
QBrush pathColor = option.state & QStyle::State_Selected
? option.palette.highlightedText()

Check warning on line 66 in src/grand-search/gui/searchconfig/blacklistview/blacklistdelegate.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Suspicious calculation. Please use parentheses to clarify the code. The code ''a&b?c:d'' should be written as either ''(a&b)?c:d'' or ''a&(b?c:d)''.
: option.palette.text();

QTextDocument pathDocument;
pathDocument.setDocumentMargin(0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ DeleteDialog::DeleteDialog(QWidget *parent)
{
const QString content(tr("Do you want to remove the path from the exclusion list?"));
setMessage(content);
setIcon(QIcon(QString(":/icons/%1.svg").arg("dde-grand-search-setting")));
setIcon(QIcon::fromTheme("dde-grand-search-setting"));

// the cancel button
{
Expand Down
6 changes: 3 additions & 3 deletions src/grand-search/gui/searchconfig/blacklistwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ BlackListWidget::BlackListWidget(QWidget *parent)

m_contentLabel->setWordWrap(true);
DFontSizeManager::instance()->bind(m_contentLabel, DFontSizeManager::T8);
QPalette p(m_contentLabel->palette());
p.setColor(QPalette::Active, QPalette::WindowText, QColor("#526A7F"));
m_contentLabel->setPalette(p);
// QPalette p(m_contentLabel->palette());
// p.setColor(QPalette::Active, QPalette::WindowText, QColor("#526A7F"));
// m_contentLabel->setPalette(p);

m_childHLayout->addStretch();

Expand Down
2 changes: 1 addition & 1 deletion src/grand-search/gui/searchconfig/configwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ void ConfigWidget::initUI()
this->titlebar()->setMenuVisible(false);

// 设置图标
QIcon tmpIcon = QIcon(QString(":/icons/%1.svg").arg("dde-grand-search-setting"));
QIcon tmpIcon = QIcon::fromTheme("dde-grand-search-setting");
this->titlebar()->setIcon(tmpIcon);
setWindowIcon(tmpIcon);

Expand Down
27 changes: 27 additions & 0 deletions src/grand-search/gui/searchconfig/icons/images.qrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<RCC>
<qresource prefix="/icons/deepin/builtin/">
<file>dark/texts/appsearch_36px.svg</file>
<file>dark/texts/documentsearch_36px.svg</file>
<file>dark/texts/foldersearch_36px.svg</file>
<file>dark/texts/videosearch_36px.svg</file>
<file>dark/texts/audiosearch_36px.svg</file>
<file>dark/texts/experienceplan_36px.svg</file>
<file>dark/texts/picturesearch_36px.svg</file>
<file>dark/texts/bestmatch_36px.svg</file>
<file>dark/texts/filesearch_36px.svg</file>
<file>dark/texts/settingsearch_36px.svg</file>
<file>dark/texts/websearch_36px.svg</file>
<file>light/texts/appsearch_36px.svg</file>
<file>light/texts/documentsearch_36px.svg</file>
<file>light/texts/foldersearch_36px.svg</file>
<file>light/texts/videosearch_36px.svg</file>
<file>light/texts/audiosearch_36px.svg</file>
<file>light/texts/experienceplan_36px.svg</file>
<file>light/texts/picturesearch_36px.svg</file>
<file>light/texts/bestmatch_36px.svg</file>
<file>light/texts/filesearch_36px.svg</file>
<file>light/texts/settingsearch_36px.svg</file>
<file>light/texts/websearch_36px.svg</file>
<file>icons/dde-grand-search-setting_32px.svg</file>
</qresource>
</RCC>
3 changes: 1 addition & 2 deletions src/grand-search/gui/searchconfig/planwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,7 @@ void PlanWidget::onSwitchStateChanged(const bool checked)

void PlanWidget::updateIcons()
{
QString suffix = Utils::iconThemeSuffix();
QIcon icon = QIcon(QString(":/icons/%1%2.svg").arg(m_displayIcon).arg(suffix));
QIcon icon = QIcon::fromTheme(m_displayIcon);
m_switchWidget->setIcon(icon, QSize(SWITCHWIDGETICONSIZE, SWITCHWIDGETICONSIZE));

update();
Expand Down
27 changes: 0 additions & 27 deletions src/grand-search/gui/searchconfig/resource.qrc

This file was deleted.

7 changes: 1 addition & 6 deletions src/grand-search/gui/searchconfig/scopewidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,8 @@ void ScopeWidget::updateIcons()
{
Q_ASSERT(m_switchWidgets.count() == m_displayIcons.count());

QString suffix = Utils::iconThemeSuffix();

for (int i = 0; i < m_switchWidgets.count(); ++i) {

QString iconName = m_displayIcons.at(i);
QIcon icon = QIcon(QString(":/icons/%1%2.svg").arg(iconName).arg(suffix));

QIcon icon = QIcon::fromTheme(m_displayIcons.at(i));
auto switchWidget = m_switchWidgets.at(i);
Q_ASSERT(switchWidget);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ SwitchWidget::SwitchWidget(QWidget *parent, QWidget *leftWidget)
: QWidget (parent)
, m_leftWidget(leftWidget)
{

m_iconLabel = new QLabel(this);
m_iconLabel->setFixedSize(ICONLABELSIZE, ICONLABELSIZE);

Expand Down

0 comments on commit 0e124fe

Please sign in to comment.