更新代码

master
feiyangqingyun 2022-01-14 19:14:16 +08:00
parent a51560be09
commit 88a3662b92
4 changed files with 44 additions and 7 deletions

View File

@ -28,8 +28,10 @@ bool frmIconHelper::eventFilter(QObject *watched, QEvent *event)
QLabel *lab = (QLabel *)watched;
if (lab != 0) {
//由于有图形字体的范围值冲突需要手动切换索引
if (ui->rbtnFontWeather->isChecked()) {
if (ui->rbtnFontAwesome6->isChecked()) {
IconHelper::iconFontIndex = 2;
} else if (ui->rbtnFontWeather->isChecked()) {
IconHelper::iconFontIndex = 3;
} else {
IconHelper::iconFontIndex = -1;
}
@ -54,6 +56,8 @@ bool frmIconHelper::eventFilter(QObject *watched, QEvent *event)
QFont font = IconHelper::getIconFontAwesome();
if (ui->rbtnFontAliBaBa->isChecked()) {
font = IconHelper::getIconFontAliBaBa();
} else if (ui->rbtnFontAwesome6->isChecked()) {
font = IconHelper::getIconFontAwesome6();
} else if (ui->rbtnFontWeather->isChecked()) {
font = IconHelper::getIconFontWeather();
}
@ -99,9 +103,10 @@ void frmIconHelper::initForm()
ui->btnImage->setIcon(QIcon(pix));
//关联单选框切换
connect(ui->rbtnFontAliBaBa, SIGNAL(toggled(bool)), this, SLOT(toggled(bool)));
connect(ui->rbtnFontAwesome, SIGNAL(toggled(bool)), this, SLOT(toggled(bool)));
connect(ui->rbtnFontWeather, SIGNAL(toggled(bool)), this, SLOT(toggled(bool)));
QList<QRadioButton *> rbtns = ui->widgetRight->findChildren<QRadioButton *>();
foreach (QRadioButton *rbtn, rbtns) {
connect(rbtn, SIGNAL(toggled(bool)), this, SLOT(toggled(bool)));
}
ui->tabWidget->setCurrentIndex(0);
}
@ -121,11 +126,16 @@ void frmIconHelper::initPanel()
start = 0xe500;
end = 0xea5d;
iconFont = IconHelper::getIconFontAliBaBa();
} else if (ui->rbtnFontAwesome6->isChecked()) {
start = 0xe000;
end = 0xf8ff;
iconFont = IconHelper::getIconFontAwesome6();
IconHelper::iconFontIndex = 2;
} else if (ui->rbtnFontWeather->isChecked()) {
start = 0xe900;
end = 0xe9cf;
iconFont = IconHelper::getIconFontWeather();
IconHelper::iconFontIndex = 2;
IconHelper::iconFontIndex = 3;
}
//设置字体大小
@ -134,11 +144,15 @@ void frmIconHelper::initPanel()
//加载图形字体面板
QStringList list;
for (int icon = start; icon <= end; icon++) {
//阿里巴巴图形字体中间有一段是空的,可以自行屏蔽下面这段代码查看这段空的值对应的文字
//中间有一段是空的,可以自行屏蔽下面这段代码查看这段空的值对应的文字
if (ui->rbtnFontAliBaBa->isChecked()) {
if (icon >= 0xe76c && icon <= 0xe8f8) {
continue;
}
} else if (ui->rbtnFontAwesome6->isChecked()) {
if (icon >= 0xe33d && icon <= 0xefff) {
continue;
}
}
QString tip = "0x" + QString::number(icon, 16);

View File

@ -743,7 +743,7 @@
</widget>
</item>
<item>
<widget class="QWidget" name="widget_2" native="true">
<widget class="QWidget" name="widgetRight" native="true">
<property name="minimumSize">
<size>
<width>130</width>
@ -773,6 +773,13 @@
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="rbtnFontAwesome6">
<property name="text">
<string>FontAwesome6</string>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="rbtnFontAliBaBa">
<property name="text">

View File

@ -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,6 +17,9 @@ 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");
}
@ -34,6 +38,12 @@ QFont IconHelper::getIconFontAwesome()
return iconFontAwesome->getIconFont();
}
QFont IconHelper::getIconFontAwesome6()
{
initFont();
return iconFontAwesome6->getIconFont();
}
QFont IconHelper::getIconFontWeather()
{
initFont();
@ -48,6 +58,7 @@ IconHelper *IconHelper::getIconHelper(int icon)
//没指定则自动根据不同的字体的值选择对应的类
//由于部分值范围冲突所以可以指定索引来取
//fontawesome 0xf000-0xf2e0
//fontawesome6 0xe000-0xe33d 0xf000-0xf8ff
//iconfont 0xe501-0xe793 0xe8d5-0xea5d
//weather 0xe900-0xe9cf
@ -61,6 +72,8 @@ IconHelper *IconHelper::getIconHelper(int icon)
} else if (iconFontIndex == 1) {
iconHelper = iconFontAwesome;
} else if (iconFontIndex == 2) {
iconHelper = iconFontAwesome6;
} else if (iconFontIndex == 3) {
iconHelper = iconFontWeather;
}

View File

@ -94,6 +94,8 @@ public:
static IconHelper *iconFontAliBaBa;
//FontAwesome图形字体类
static IconHelper *iconFontAwesome;
//FontAwesome6图形字体类
static IconHelper *iconFontAwesome6;
//天气图形字体类
static IconHelper *iconFontWeather;
//图形字体索引
@ -105,6 +107,7 @@ public:
//获取图形字体
static QFont getIconFontAliBaBa();
static QFont getIconFontAwesome();
static QFont getIconFontAwesome6();
static QFont getIconFontWeather();
//根据值获取图形字体类