-
Notifications
You must be signed in to change notification settings - Fork 142
/
LVGLFontDialog.cpp
75 lines (64 loc) · 1.83 KB
/
LVGLFontDialog.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#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 ¤tText)
{
m_ui->preview->setText(m_name[currentText]);
}