yhkylin-backup-tools/kybackup/gsettingswrapper.cpp

42 lines
1.5 KiB
C++
Raw Normal View History

2021-09-16 16:05:46 +08:00
/**
* @brief 使
*/
#include "gsettingswrapper.h"
#include <QIcon>
#include <QLabel>
#include <QGSettings/qgsettings.h>
#define FITTHEMEWINDOW "org.ukui.style"
/**
* @brief UKui风格的主题
* @param QWidget *,
*/
void GSettingsWrapper::connectUkuiStyleSchema(QWidget * widgetPtr, QSize size)
{
if (widgetPtr != nullptr && QGSettings::isSchemaInstalled(FITTHEMEWINDOW)) {
// c++11后能确保多线程并发场景的局部静态对象的唯一性
static QGSettings *pGsettingThemeData = new QGSettings(FITTHEMEWINDOW);
QObject::connect(pGsettingThemeData, &QGSettings::changed, [=](const QString &key) {
if (key == "iconThemeName") {
QIcon titleIcon = QIcon::fromTheme("yhkylin-backup-tools");
if (widgetPtr->inherits("QLabel")) {
QLabel *labelPtr = qobject_cast<QLabel *>(widgetPtr);
const QPixmap * pixmapPtr = labelPtr->pixmap();
if (pixmapPtr != nullptr) {
labelPtr->setPixmap(titleIcon.pixmap(titleIcon.actualSize(size)));
} else {
labelPtr->setPixmap(titleIcon.pixmap(titleIcon.actualSize(QSize(24, 24))));
}
} else {
widgetPtr->setWindowIcon(titleIcon);
}
}
});
}
}