更新代码
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
IconHelper *IconHelper::iconFontAliBaBa = 0;
|
||||
IconHelper *IconHelper::iconFontAwesome = 0;
|
||||
IconHelper *IconHelper::iconFontAwesome6 = 0;
|
||||
IconHelper *IconHelper::iconFontWeather = 0;
|
||||
int IconHelper::iconFontIndex = -1;
|
||||
|
||||
@@ -16,12 +17,20 @@ void IconHelper::initFont()
|
||||
if (iconFontAwesome == 0) {
|
||||
iconFontAwesome = new IconHelper(":/font/fontawesome-webfont.ttf", "FontAwesome");
|
||||
}
|
||||
if (iconFontAwesome6 == 0) {
|
||||
iconFontAwesome6 = new IconHelper(":/font/fa-regular-400.ttf", "Font Awesome 6 Pro Regular");
|
||||
}
|
||||
if (iconFontWeather == 0) {
|
||||
iconFontWeather = new IconHelper(":/font/pe-icon-set-weather.ttf", "pe-icon-set-weather");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void IconHelper::setIconFontIndex(int index)
|
||||
{
|
||||
iconFontIndex = index;
|
||||
}
|
||||
|
||||
QFont IconHelper::getIconFontAliBaBa()
|
||||
{
|
||||
initFont();
|
||||
@@ -34,6 +43,12 @@ QFont IconHelper::getIconFontAwesome()
|
||||
return iconFontAwesome->getIconFont();
|
||||
}
|
||||
|
||||
QFont IconHelper::getIconFontAwesome6()
|
||||
{
|
||||
initFont();
|
||||
return iconFontAwesome6->getIconFont();
|
||||
}
|
||||
|
||||
QFont IconHelper::getIconFontWeather()
|
||||
{
|
||||
initFont();
|
||||
@@ -48,6 +63,7 @@ IconHelper *IconHelper::getIconHelper(int icon)
|
||||
//没指定则自动根据不同的字体的值选择对应的类
|
||||
//由于部分值范围冲突所以可以指定索引来取
|
||||
//fontawesome 0xf000-0xf2e0
|
||||
//fontawesome6 0xe000-0xe33d 0xf000-0xf8ff
|
||||
//iconfont 0xe501-0xe793 0xe8d5-0xea5d
|
||||
//weather 0xe900-0xe9cf
|
||||
|
||||
@@ -61,6 +77,8 @@ IconHelper *IconHelper::getIconHelper(int icon)
|
||||
} else if (iconFontIndex == 1) {
|
||||
iconHelper = iconFontAwesome;
|
||||
} else if (iconFontIndex == 2) {
|
||||
iconHelper = iconFontAwesome6;
|
||||
} else if (iconFontIndex == 3) {
|
||||
iconHelper = iconFontWeather;
|
||||
}
|
||||
|
||||
@@ -115,7 +133,7 @@ IconHelper::IconHelper(const QString &fontFile, const QString &fontName, QObject
|
||||
{
|
||||
//判断图形字体是否存在,不存在则加入
|
||||
QFontDatabase fontDb;
|
||||
if (!fontDb.families().contains(fontName)) {
|
||||
if (!fontDb.families().contains(fontName) && QFile(fontFile).exists()) {
|
||||
int fontId = fontDb.addApplicationFont(fontFile);
|
||||
QStringList listName = fontDb.applicationFontFamilies(fontId);
|
||||
if (listName.count() == 0) {
|
||||
|
||||
@@ -31,6 +31,18 @@ class IconHelper : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
private:
|
||||
//阿里巴巴图形字体类
|
||||
static IconHelper *iconFontAliBaBa;
|
||||
//FontAwesome图形字体类
|
||||
static IconHelper *iconFontAwesome;
|
||||
//FontAwesome6图形字体类
|
||||
static IconHelper *iconFontAwesome6;
|
||||
//天气图形字体类
|
||||
static IconHelper *iconFontWeather;
|
||||
//图形字体索引
|
||||
static int iconFontIndex;
|
||||
|
||||
public:
|
||||
//样式颜色结构体
|
||||
struct StyleColor {
|
||||
@@ -90,21 +102,16 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
//阿里巴巴图形字体类
|
||||
static IconHelper *iconFontAliBaBa;
|
||||
//FontAwesome图形字体类
|
||||
static IconHelper *iconFontAwesome;
|
||||
//天气图形字体类
|
||||
static IconHelper *iconFontWeather;
|
||||
//图形字体索引
|
||||
static int iconFontIndex;
|
||||
|
||||
//初始化图形字体
|
||||
static void initFont();
|
||||
//设置引用图形字体文件索引
|
||||
static void setIconFontIndex(int index);
|
||||
|
||||
//获取图形字体
|
||||
static QFont getIconFontAliBaBa();
|
||||
static QFont getIconFontAwesome();
|
||||
static QFont getIconFontAwesome6();
|
||||
static QFont getIconFontWeather();
|
||||
|
||||
//根据值获取图形字体类
|
||||
|
||||
BIN
ui/iconhelper/font/fa-regular-400.ttf
Normal file
BIN
ui/iconhelper/font/fa-regular-400.ttf
Normal file
Binary file not shown.
@@ -29,11 +29,11 @@ bool frmIconHelper::eventFilter(QObject *watched, QEvent *event)
|
||||
if (lab != 0) {
|
||||
//由于有图形字体的范围值冲突需要手动切换索引
|
||||
if (ui->rbtnFontAwesome6->isChecked()) {
|
||||
IconHelper::iconFontIndex = 2;
|
||||
IconHelper::setIconFontIndex(2);
|
||||
} else if (ui->rbtnFontWeather->isChecked()) {
|
||||
IconHelper::iconFontIndex = 3;
|
||||
IconHelper::setIconFontIndex(3);
|
||||
} else {
|
||||
IconHelper::iconFontIndex = -1;
|
||||
IconHelper::setIconFontIndex(-1);
|
||||
}
|
||||
|
||||
//对应图形字体的16进制值已经赋值给了 toolTip
|
||||
@@ -121,7 +121,8 @@ void frmIconHelper::initPanel()
|
||||
int start = 0xf000;
|
||||
int end = 0xf2e0;
|
||||
QFont iconFont = IconHelper::getIconFontAwesome();
|
||||
IconHelper::iconFontIndex = -1;
|
||||
IconHelper::setIconFontIndex(-1);
|
||||
|
||||
if (ui->rbtnFontAliBaBa->isChecked()) {
|
||||
start = 0xe500;
|
||||
end = 0xea5d;
|
||||
@@ -130,12 +131,12 @@ void frmIconHelper::initPanel()
|
||||
start = 0xe000;
|
||||
end = 0xf8ff;
|
||||
iconFont = IconHelper::getIconFontAwesome6();
|
||||
IconHelper::iconFontIndex = 2;
|
||||
IconHelper::setIconFontIndex(2);
|
||||
} else if (ui->rbtnFontWeather->isChecked()) {
|
||||
start = 0xe900;
|
||||
end = 0xe9cf;
|
||||
iconFont = IconHelper::getIconFontWeather();
|
||||
IconHelper::iconFontIndex = 3;
|
||||
IconHelper::setIconFontIndex(3);
|
||||
}
|
||||
|
||||
//设置字体大小
|
||||
|
||||
@@ -26,6 +26,11 @@ void IconHelper::initFont()
|
||||
}
|
||||
}
|
||||
|
||||
void IconHelper::setIconFontIndex(int index)
|
||||
{
|
||||
iconFontIndex = index;
|
||||
}
|
||||
|
||||
QFont IconHelper::getIconFontAliBaBa()
|
||||
{
|
||||
initFont();
|
||||
@@ -128,7 +133,7 @@ IconHelper::IconHelper(const QString &fontFile, const QString &fontName, QObject
|
||||
{
|
||||
//判断图形字体是否存在,不存在则加入
|
||||
QFontDatabase fontDb;
|
||||
if (!fontDb.families().contains(fontName)) {
|
||||
if (!fontDb.families().contains(fontName) && QFile(fontFile).exists()) {
|
||||
int fontId = fontDb.addApplicationFont(fontFile);
|
||||
QStringList listName = fontDb.applicationFontFamilies(fontId);
|
||||
if (listName.count() == 0) {
|
||||
|
||||
@@ -31,6 +31,18 @@ class IconHelper : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
private:
|
||||
//阿里巴巴图形字体类
|
||||
static IconHelper *iconFontAliBaBa;
|
||||
//FontAwesome图形字体类
|
||||
static IconHelper *iconFontAwesome;
|
||||
//FontAwesome6图形字体类
|
||||
static IconHelper *iconFontAwesome6;
|
||||
//天气图形字体类
|
||||
static IconHelper *iconFontWeather;
|
||||
//图形字体索引
|
||||
static int iconFontIndex;
|
||||
|
||||
public:
|
||||
//样式颜色结构体
|
||||
struct StyleColor {
|
||||
@@ -90,19 +102,11 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
//阿里巴巴图形字体类
|
||||
static IconHelper *iconFontAliBaBa;
|
||||
//FontAwesome图形字体类
|
||||
static IconHelper *iconFontAwesome;
|
||||
//FontAwesome6图形字体类
|
||||
static IconHelper *iconFontAwesome6;
|
||||
//天气图形字体类
|
||||
static IconHelper *iconFontWeather;
|
||||
//图形字体索引
|
||||
static int iconFontIndex;
|
||||
|
||||
//初始化图形字体
|
||||
static void initFont();
|
||||
//设置引用图形字体文件索引
|
||||
static void setIconFontIndex(int index);
|
||||
|
||||
//获取图形字体
|
||||
static QFont getIconFontAliBaBa();
|
||||
|
||||
@@ -3,5 +3,6 @@
|
||||
<file>font/fontawesome-webfont.ttf</file>
|
||||
<file>font/iconfont.ttf</file>
|
||||
<file>font/pe-icon-set-weather.ttf</file>
|
||||
<file>font/fa-regular-400.ttf</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
|
||||
Reference in New Issue
Block a user