2 Star 1 Fork 1

ssda/LVGLBuilder

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
LVGLFontDialog.cpp 1.83 KB
一键复制 编辑 原始数据 按行查看 历史
#include "LVGLFontDialog.h"
#include "ui_LVGLFontDialog.h"
#include <QSettings>
#include <QFile>
#include <QFileDialog>
LVGLFontDialog::LVGLFontDialog(QWidget *parent)
: QDialog(parent)
, m_ui(new Ui::LVGLFontDialog)
{
m_ui->setupUi(this);
// from https://www.qtcentre.org/threads/26924-Retrieve-the-filename-of-a-QFont
QSettings settings("HKEY_LOCAL_MACHINE\\Software\\Microsoft\\Windows NT\\CurrentVersion\\Fonts", QSettings::NativeFormat);
QStringList list = settings.allKeys();
QString winPath = QString::fromUtf8(qgetenv("windir"));
for (int i = 0; i < list.size(); ++i) {
QString key = list.at(i);
QString text = settings.value(key).toString();
if (!text.endsWith(".ttf", Qt::CaseInsensitive))
continue;
QString fileName = winPath + "\\Fonts\\" + text;
if (!QFile(fileName).exists())
continue;
QStringList keys = key.split(" & ");
QString last = keys.last();
keys[keys.size()-1] = last.left(last.indexOf(" ("));
for(int j = 0; j < keys.size(); ++j) {
m_index.insert(keys[j], j);
m_name.insert(keys[j], fileName);
m_ui->list_font->addItem(keys[j]);
}
}
}
LVGLFontDialog::~LVGLFontDialog()
{
delete m_ui;
}
QString LVGLFontDialog::selectedFontPath() const
{
return m_ui->preview->text();
}
uint8_t LVGLFontDialog::selectedFontSize() const
{
return m_ui->spin_size->value() & 0xff;
}
uint8_t LVGLFontDialog::selectedBPP() const
{
if (m_ui->comboBox->currentIndex() == 0)
return 4;
else if (m_ui->comboBox->currentIndex() == 1)
return 2;
else
return 1;
}
void LVGLFontDialog::on_button_select_clicked()
{
QString fileName = QFileDialog::getOpenFileName(this, "Select font", "", "TTF Font (*.ttf)");
if (fileName.isEmpty())
return;
m_ui->preview->setText(fileName);
}
void LVGLFontDialog::on_list_font_currentTextChanged(const QString &currentText)
{
m_ui->preview->setText(m_name[currentText]);
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/shaoshunda/LVGLBuilder.git
git@gitee.com:shaoshunda/LVGLBuilder.git
shaoshunda
LVGLBuilder
LVGLBuilder
master

搜索帮助