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
76
77
78
79
|
#include <QSignalMapper>
#include <QMessageBox>
#include <QSettings>
#include <QApplication>
#include <QFontDialog>
#include <QDir>
#include <QFile>
#include "lthemeengine.h"
#include "fontspage.h"
#include "fontconfigdialog.h"
#include "ui_fontspage.h"
FontsPage::FontsPage(QWidget *parent) : TabPage(parent), m_ui(new Ui::FontsPage){
m_ui->setupUi(this);
QSignalMapper *mapper = new QSignalMapper(this);
mapper->setMapping(m_ui->changeGeneralFontButton, m_ui->generalFontLabel);
mapper->setMapping(m_ui->changeFixedWidthFontButton, m_ui->fixedFontLabel);
connect(m_ui->changeGeneralFontButton, SIGNAL(clicked()), mapper, SLOT(map()));
connect(m_ui->changeFixedWidthFontButton, SIGNAL(clicked()), mapper, SLOT(map()));
connect(mapper, SIGNAL(mapped(QWidget*)), SLOT(onFontChangeRequested(QWidget*)));
readSettings();
//icons
m_ui->createFontsConfButton->setIcon(QIcon::fromTheme("document-new"));
m_ui->removeFontsConfButton->setIcon(QIcon::fromTheme("edit-delete"));
}
FontsPage::~FontsPage(){
delete m_ui;
}
void FontsPage::writeSettings(){
QSettings settings(lthemeengine::configFile(), QSettings::IniFormat);
settings.beginGroup("Fonts");
settings.setValue("general", m_ui->generalFontLabel->font());
settings.setValue("fixed", m_ui->fixedFontLabel->font());
settings.endGroup();
}
void FontsPage::onFontChangeRequested(QWidget *widget){
bool ok = false;
QFont font = QFontDialog::getFont (&ok, widget->font(), this);
if(ok){
widget->setFont(font);
qobject_cast<QLabel*>(widget)->setText(font.family () + " " + QString::number(font.pointSize ()));
}
}
void FontsPage::readSettings(){
QSettings settings(lthemeengine::configFile(), QSettings::IniFormat);
settings.beginGroup("Fonts");
loadFont(&settings, m_ui->generalFontLabel, "general");
loadFont(&settings, m_ui->fixedFontLabel, "fixed");
settings.endGroup();
}
void FontsPage::loadFont(QSettings *settings, QLabel *label, const QString &key){
QFont font = settings->value(key, QApplication::font()).value<QFont>();
label->setText(font.family () + " " + QString::number(font.pointSize ()));
label->setFont(font);
}
void FontsPage::on_createFontsConfButton_clicked(){
FontConfigDialog d(this);
d.exec();
}
void FontsPage::on_removeFontsConfButton_clicked(){
QString path = QDir::homePath() + "/.config/fontconfig/fonts.conf";
if(QFile::exists(path)){
if(QMessageBox::question(this, tr("Remove Font Configuration"), tr("Are you sure you want to delete <i>%1</i>?").arg(path), QMessageBox::Yes | QMessageBox::No) == QMessageBox::No){
return;
}
QFile::remove(path + ".back");
QFile::copy(path, path + ".back");
QFile::remove(path);
}
}
|