Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 23 additions & 5 deletions plugins/dde-dock/common/commoniconbutton.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,15 +133,19 @@ void CommonIconButton::setIcon(const QString &icon, const QString &fallback, con
addDarkMark(tmp);
addDarkMark(tmpFallback);
}
m_icon = QIcon::fromTheme(tmp);
QIcon newIcon = QIcon::fromTheme(tmp);

if (m_icon.isNull()) {
m_icon = QIcon::fromTheme(tmpFallback);
if (newIcon.isNull()) {
newIcon = QIcon::fromTheme(tmpFallback);
}

if (m_icon.isNull()) {
if (newIcon.isNull()) {
QString defaultIcon = m_fileMapping[State::Default].first;
m_icon = QIcon::fromTheme(defaultIcon);
newIcon = QIcon::fromTheme(defaultIcon);
}

if (!newIcon.isNull()) {
m_icon = newIcon;
}
update();
}
Expand Down Expand Up @@ -213,6 +217,20 @@ void CommonIconButton::mouseReleaseEvent(QMouseEvent *event)
void CommonIconButton::refreshIcon()
{
setState(m_state);

if (m_icon.isNull()) {
// 主题切换后图标主题可能尚未加载完成,进行有限次重试
if (m_refreshRetryCount < kMaxRefreshRetries) {
m_refreshRetryCount++;
QTimer::singleShot(50, this, [this]() {
refreshIcon();
});
} else {
m_refreshRetryCount = 0;
}
} else {
m_refreshRetryCount = 0;
}
}

void CommonIconButton::setIconSize(const QSize &size)
Expand Down
3 changes: 3 additions & 0 deletions plugins/dde-dock/common/commoniconbutton.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ public Q_SLOTS:
QSize m_iconSize;
qreal m_rotation;
QPalette m_defaultPalette;

static constexpr int kMaxRefreshRetries = 10;
int m_refreshRetryCount = 0;
};

#endif // DOCKICONBUTTON_H
5 changes: 4 additions & 1 deletion src/loader/widgetplugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@
#include <QMenu>
#include <QPainter>
#include <QProcess>
#include <QVBoxLayout>

Check warning on line 14 in src/loader/widgetplugin.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QVBoxLayout> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QMouseEvent>

Check warning on line 15 in src/loader/widgetplugin.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QMouseEvent> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QToolTip>

Check warning on line 16 in src/loader/widgetplugin.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QToolTip> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QTimer>

Check warning on line 17 in src/loader/widgetplugin.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QTimer> not found. Please note: Cppcheck does not need standard library headers to get proper results.

#include <DGuiApplicationHelper>

Check warning on line 19 in src/loader/widgetplugin.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <DGuiApplicationHelper> not found. Please note: Cppcheck does not need standard library headers to get proper results.

DGUI_USE_NAMESPACE

Expand Down Expand Up @@ -337,7 +338,9 @@
void WidgetPlugin::onDockColorThemeChanged(uint32_t type)
{
qDebug() << "onDockColorThemeChanged:" << type;
DGuiApplicationHelper::instance()->setPaletteType(static_cast<DGuiApplicationHelper::ColorType>(type));
QTimer::singleShot(0, this, [type]() {
DGuiApplicationHelper::instance()->setPaletteType(static_cast<DGuiApplicationHelper::ColorType>(type));
});
}

void WidgetPlugin::onDockPositionChanged(uint32_t position)
Expand Down
Loading