Add font settings

pull/2/head
reionwong 4 years ago
parent 61bb5ef23e
commit 6fd9b3ff47

@ -34,6 +34,7 @@ set(SRCS
src/processhelper.h
src/processhelper.cpp
src/utils.cpp
src/fonts.cpp
)
set(RESOURCES

@ -0,0 +1,43 @@
/*
* Copyright (C) 2021 CutefishOS Team.
*
* Author: Reion Wong <reionwong@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "fonts.h"
Fonts::Fonts(QObject *parent) : QObject(parent)
{
init();
}
QStringList Fonts::families() const
{
return m_families;
}
void Fonts::init()
{
m_families.clear();
for (const QString &family : m_fontDatabase.families()) {
if (m_fontDatabase.isFixedPitch(family)) {
m_families << family;
}
}
emit familiesChanged();
}

@ -0,0 +1,50 @@
/*
* Copyright (C) 2021 CutefishOS Team.
*
* Author: Reion Wong <reionwong@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef FONTS_H
#define FONTS_H
#include <QObject>
#include <QList>
#include <QFontDatabase>
#include <QStringList>
class Fonts : public QObject
{
Q_OBJECT
Q_PROPERTY(QStringList families READ families NOTIFY familiesChanged)
public:
explicit Fonts(QObject *parent = nullptr);
QStringList families() const;
Q_SIGNALS:
void familiesChanged();
protected:
void init();
private:
QStringList m_families;
QFontDatabase m_fontDatabase;
};
#endif // FONTS_H

@ -27,6 +27,7 @@
#include "processhelper.h"
#include "utils.h"
#include "fonts.h"
int main(int argc, char *argv[])
{
@ -52,6 +53,7 @@ int main(int argc, char *argv[])
engine.rootContext()->setContextProperty("Process", new ProcessHelper);
engine.rootContext()->setContextProperty("Utils", new Utils);
engine.rootContext()->setContextProperty("Fonts", new Fonts);
engine.addImportPath(QStringLiteral("qrc:/"));
engine.load(QUrl(QStringLiteral("qrc:/qml/main.qml")));

@ -24,6 +24,7 @@ Settings {
property int width: 750
property int height: 500
property int fontPointSize: 10
property string fontName: "Noto Mono"
property bool blinkingCursor: true
property real opacity: 1.0

@ -24,6 +24,92 @@ FishUI.Window {
anchors.rightMargin: FishUI.Units.largeSpacing
spacing: FishUI.Units.largeSpacing
Item {
Layout.fillWidth: true
Layout.preferredHeight: 45
Rectangle {
anchors.fill: parent
color: FishUI.Theme.secondBackgroundColor
radius: FishUI.Theme.smallRadius
}
RowLayout {
anchors.fill: parent
anchors.leftMargin: FishUI.Units.largeSpacing
anchors.rightMargin: FishUI.Units.largeSpacing
Label {
text: qsTr("Font")
}
Item {
width: FishUI.Units.largeSpacing
}
ComboBox {
id: fontsCombobox
model: Fonts.families
Layout.fillHeight: true
Layout.fillWidth: true
onCurrentTextChanged: {
settings.fontName = currentText
}
Component.onCompleted: {
for (var i = 0; i <= fontsCombobox.model.length; ++i) {
if (fontsCombobox.model[i] === settings.fontName) {
fontsCombobox.currentIndex = i
break
}
}
}
}
}
}
// Font size
Item {
Layout.fillWidth: true
Layout.preferredHeight: 45
Rectangle {
anchors.fill: parent
color: FishUI.Theme.secondBackgroundColor
radius: FishUI.Theme.smallRadius
}
RowLayout {
anchors.fill: parent
anchors.leftMargin: FishUI.Units.largeSpacing
anchors.rightMargin: FishUI.Units.largeSpacing
Label {
text: qsTr("Font Size")
}
Item {
width: FishUI.Units.largeSpacing
}
Slider {
id: fontSizeSlider
Layout.fillHeight: true
Layout.fillWidth: true
from: 5
to: 30
stepSize: 1
Component.onCompleted: {
fontSizeSlider.value = settings.fontPointSize
}
onValueChanged: settings.fontPointSize = fontSizeSlider.value
}
}
}
Item {
Layout.fillWidth: true
Layout.preferredHeight: 45

@ -107,7 +107,7 @@ Page {
id: _terminal
anchors.fill: parent
colorScheme: FishUI.Theme.darkMode ? "Cutefish-Dark" : "Cutefish-Light"
font.family: "Noto Sans Mono"
font.family: settings.fontName
font.pointSize: settings.fontPointSize
blinkingCursor: settings.blinkingCursor
fullCursorHeight: true
@ -223,6 +223,7 @@ Page {
anchors.right: parent.right
anchors.top: parent.top
anchors.bottom: parent.bottom
anchors.bottomMargin: FishUI.Units.smallSpacing * 1.5
hoverEnabled: true
active: hovered || pressed
orientation: Qt.Vertical

@ -23,11 +23,21 @@
<name>SettingsDialog</name>
<message>
<location filename="../src/qml/SettingsDialog.qml" line="43"/>
<source>Font</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/qml/SettingsDialog.qml" line="89"/>
<source>Font Size</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/qml/SettingsDialog.qml" line="129"/>
<source>Transparency</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/qml/SettingsDialog.qml" line="83"/>
<location filename="../src/qml/SettingsDialog.qml" line="169"/>
<source>Window Blur</source>
<translation type="unfinished"></translation>
</message>

@ -23,11 +23,21 @@
<name>SettingsDialog</name>
<message>
<location filename="../src/qml/SettingsDialog.qml" line="43"/>
<source>Font</source>
<translation></translation>
</message>
<message>
<location filename="../src/qml/SettingsDialog.qml" line="89"/>
<source>Font Size</source>
<translation></translation>
</message>
<message>
<location filename="../src/qml/SettingsDialog.qml" line="129"/>
<source>Transparency</source>
<translation></translation>
</message>
<message>
<location filename="../src/qml/SettingsDialog.qml" line="83"/>
<location filename="../src/qml/SettingsDialog.qml" line="169"/>
<source>Window Blur</source>
<translation></translation>
</message>

Loading…
Cancel
Save