mirror of
https://github.com/Swordfish90/cool-retro-term.git
synced 2025-02-21 20:39:00 +00:00
Initial support for system monospace fonts.
This commit is contained in:
parent
fe4704d0f6
commit
e4c014c1a8
@ -4,10 +4,12 @@ TARGET = cool-retro-term
|
||||
DESTDIR = $$OUT_PWD/../
|
||||
|
||||
HEADERS += \
|
||||
fileio.h
|
||||
fileio.h \
|
||||
monospacefontmanager.h
|
||||
|
||||
SOURCES = main.cpp \
|
||||
fileio.cpp
|
||||
fileio.cpp \
|
||||
monospacefontmanager.cpp
|
||||
|
||||
macx:ICON = icons/crt.icns
|
||||
|
||||
|
@ -10,7 +10,10 @@
|
||||
#include <QDebug>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <QFontDatabase>
|
||||
|
||||
#include <fileio.h>
|
||||
#include <monospacefontmanager.h>
|
||||
|
||||
QString getNamedArgument(QStringList args, QString name, QString defaultName)
|
||||
{
|
||||
@ -42,6 +45,7 @@ int main(int argc, char *argv[])
|
||||
|
||||
QQmlApplicationEngine engine;
|
||||
FileIO fileIO;
|
||||
MonospaceFontManager monospaceFontManager;
|
||||
|
||||
#if !defined(Q_OS_MAC)
|
||||
app.setWindowIcon(QIcon::fromTheme("cool-retro-term", QIcon(":../icons/32x32/cool-retro-term.png")));
|
||||
@ -83,6 +87,7 @@ int main(int argc, char *argv[])
|
||||
|
||||
engine.rootContext()->setContextProperty("workdir", getNamedArgument(args, "--workdir", "$HOME"));
|
||||
engine.rootContext()->setContextProperty("fileIO", &fileIO);
|
||||
engine.rootContext()->setContextProperty("monospaceSystemFonts", monospaceFontManager.retrieveMonospaceFonts());
|
||||
|
||||
engine.rootContext()->setContextProperty("devicePixelRatio", app.devicePixelRatio());
|
||||
|
||||
|
25
app/monospacefontmanager.cpp
Normal file
25
app/monospacefontmanager.cpp
Normal file
@ -0,0 +1,25 @@
|
||||
#include "monospacefontmanager.h"
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
MonospaceFontManager::MonospaceFontManager(QObject *parent) : QObject(parent)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
QStringList MonospaceFontManager::retrieveMonospaceFonts() {
|
||||
QStringList result;
|
||||
|
||||
QFontDatabase fontDatabase;
|
||||
QStringList fontFamilies = fontDatabase.families();
|
||||
|
||||
for (int i = 0; i < fontFamilies.size(); i++) {
|
||||
QString fontFamily = fontFamilies[i];
|
||||
QFont font(fontFamily);
|
||||
if (fontDatabase.isFixedPitch(font.family())) {
|
||||
result.append(fontFamily);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
15
app/monospacefontmanager.h
Normal file
15
app/monospacefontmanager.h
Normal file
@ -0,0 +1,15 @@
|
||||
#ifndef MONOSPACEFONTMANAGER_H
|
||||
#define MONOSPACEFONTMANAGER_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QFontDatabase>
|
||||
|
||||
class MonospaceFontManager : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit MonospaceFontManager(QObject *parent = nullptr);
|
||||
Q_INVOKABLE QStringList retrieveMonospaceFonts();
|
||||
};
|
||||
|
||||
#endif // MONOSPACEFONTMANAGER_H
|
@ -102,7 +102,7 @@ QtObject{
|
||||
property var fontNames: ["TERMINUS_SCALED", "COMMODORE_PET", "COMMODORE_PET"]
|
||||
property var fontlist: fontManager.item.fontlist
|
||||
|
||||
signal terminalFontChanged(string fontSource, int pixelSize, int lineSpacing, real screenScaling, real fontWidth)
|
||||
signal terminalFontChanged(string fontFamily, int pixelSize, int lineSpacing, real screenScaling, real fontWidth)
|
||||
|
||||
signal initializedSettings()
|
||||
|
||||
@ -119,12 +119,15 @@ QtObject{
|
||||
onLoaded: handleFontChanged()
|
||||
}
|
||||
|
||||
property FontLoader fontLoader: FontLoader { }
|
||||
|
||||
onFontScalingChanged: handleFontChanged();
|
||||
onFontWidthChanged: handleFontChanged();
|
||||
|
||||
function getIndexByName(name) {
|
||||
for (var i = 0; i < fontlist.count; i++) {
|
||||
if (name === fontlist.get(i).name)
|
||||
var requestedName = fontlist.get(i).name;
|
||||
if (name === requestedName)
|
||||
return i;
|
||||
}
|
||||
return 0; // If the font is not available default to 0.
|
||||
@ -154,10 +157,17 @@ QtObject{
|
||||
var lineSpacing = fontManager.item.lineSpacing;
|
||||
var screenScaling = fontManager.item.screenScaling;
|
||||
var fontWidth = fontManager.item.defaultFontWidth * appSettings.fontWidth;
|
||||
var fontFamily = fontManager.item.family;
|
||||
var isSystemFont = fontManager.item.isSystemFont;
|
||||
|
||||
lowResolutionFont = fontManager.item.lowResolutionFont;
|
||||
|
||||
terminalFontChanged(fontSource, pixelSize, lineSpacing, screenScaling, fontWidth);
|
||||
if (!isSystemFont) {
|
||||
fontLoader.source = fontSource;
|
||||
fontFamily = fontLoader.name;
|
||||
}
|
||||
|
||||
terminalFontChanged(fontFamily, pixelSize, lineSpacing, screenScaling, fontWidth);
|
||||
}
|
||||
|
||||
// FRAMES /////////////////////////////////////////////////////////////////
|
||||
@ -496,7 +506,7 @@ QtObject{
|
||||
Component.onDestruction: {
|
||||
storeSettings();
|
||||
storeCustomProfiles();
|
||||
//storage.dropSettings(); //DROPS THE SETTINGS!.. REMEMBER TO DISABLE ONCE ENABLED!!
|
||||
// storage.dropSettings(); //DROPS THE SETTINGS!.. REMEMBER TO DISABLE ONCE ENABLED!!
|
||||
}
|
||||
|
||||
// VARS ///////////////////////////////////////////////////////////////////
|
||||
|
@ -41,6 +41,10 @@ QtObject{
|
||||
|
||||
property real defaultFontWidth: fontlist.get(selectedFontIndex).fontWidth
|
||||
|
||||
property string family: fontlist.get(selectedFontIndex).family
|
||||
|
||||
property bool isSystemFont: fontlist.get(selectedFontIndex).isSystemFont
|
||||
|
||||
// There are two kind of fonts: low resolution and high resolution.
|
||||
// Low resolution font sets the lowResolutionFont property to true.
|
||||
// They are rendered at a fixed pixel size and the texture is upscaled
|
||||
@ -49,7 +53,7 @@ QtObject{
|
||||
// size of the screen, and the scaling directly controls their pixels size.
|
||||
// Those are slower to render but are not pixelated.
|
||||
|
||||
property ListModel fontlist: ListModel{
|
||||
property ListModel fontlist: ListModel {
|
||||
ListElement{
|
||||
name: "TERMINUS_SCALED"
|
||||
text: "Terminus (Modern)"
|
||||
@ -59,6 +63,8 @@ QtObject{
|
||||
baseScaling: 3.0
|
||||
fontWidth: 1.0
|
||||
lowResolutionFont: true
|
||||
isSystemFont: false
|
||||
family: ""
|
||||
}
|
||||
ListElement{
|
||||
name: "PRO_FONT_SCALED"
|
||||
@ -69,6 +75,8 @@ QtObject{
|
||||
baseScaling: 3.0
|
||||
fontWidth: 1.0
|
||||
lowResolutionFont: true
|
||||
isSystemFont: false
|
||||
family: ""
|
||||
}
|
||||
ListElement{
|
||||
name: "EXCELSIOR_SCALED"
|
||||
@ -79,6 +87,8 @@ QtObject{
|
||||
baseScaling: 2.4
|
||||
fontWidth: 1.0
|
||||
lowResolutionFont: true
|
||||
isSystemFont: false
|
||||
family: ""
|
||||
}
|
||||
ListElement{
|
||||
name: "COMMODORE_PET_SCALED"
|
||||
@ -89,6 +99,8 @@ QtObject{
|
||||
baseScaling: 3.5
|
||||
fontWidth: 0.7
|
||||
lowResolutionFont: true
|
||||
isSystemFont: false
|
||||
family: ""
|
||||
}
|
||||
ListElement{
|
||||
name: "PROGGY_TINY_SCALED"
|
||||
@ -99,6 +111,8 @@ QtObject{
|
||||
baseScaling: 3.0
|
||||
fontWidth: 0.9
|
||||
lowResolutionFont: true
|
||||
isSystemFont: false
|
||||
family: ""
|
||||
}
|
||||
ListElement{
|
||||
name: "APPLE_II_SCALED"
|
||||
@ -109,6 +123,8 @@ QtObject{
|
||||
baseScaling: 3.5
|
||||
fontWidth: 0.8
|
||||
lowResolutionFont: true
|
||||
isSystemFont: false
|
||||
family: ""
|
||||
}
|
||||
ListElement{
|
||||
name: "ATARI_400_SCALED"
|
||||
@ -119,6 +135,8 @@ QtObject{
|
||||
baseScaling: 3.5
|
||||
fontWidth: 0.7
|
||||
lowResolutionFont: true
|
||||
isSystemFont: false
|
||||
family: ""
|
||||
}
|
||||
ListElement{
|
||||
name: "COMMODORE_64_SCALED"
|
||||
@ -129,6 +147,8 @@ QtObject{
|
||||
baseScaling: 3.5
|
||||
fontWidth: 0.7
|
||||
lowResolutionFont: true
|
||||
isSystemFont: false
|
||||
family: ""
|
||||
}
|
||||
ListElement{
|
||||
name: "ATARI_ST_SCALED"
|
||||
@ -139,6 +159,8 @@ QtObject{
|
||||
baseScaling: 2.0
|
||||
fontWidth: 1.0
|
||||
lowResolutionFont: true
|
||||
isSystemFont: false
|
||||
family: ""
|
||||
}
|
||||
ListElement{
|
||||
name: "IBM_DOS"
|
||||
@ -149,6 +171,8 @@ QtObject{
|
||||
baseScaling: 2.0
|
||||
fontWidth: 1.0
|
||||
lowResolutionFont: true
|
||||
isSystemFont: false
|
||||
family: ""
|
||||
}
|
||||
ListElement{
|
||||
name: "HERMIT"
|
||||
@ -158,6 +182,8 @@ QtObject{
|
||||
pixelSize: 28
|
||||
fontWidth: 1.0
|
||||
lowResolutionFont: false
|
||||
isSystemFont: false
|
||||
family: ""
|
||||
}
|
||||
ListElement{
|
||||
name: "TERMINUS"
|
||||
@ -167,6 +193,8 @@ QtObject{
|
||||
pixelSize: 35
|
||||
fontWidth: 1.0
|
||||
lowResolutionFont: false
|
||||
isSystemFont: false
|
||||
family: ""
|
||||
}
|
||||
ListElement{
|
||||
name: "PRO_FONT"
|
||||
@ -176,6 +204,8 @@ QtObject{
|
||||
pixelSize: 35
|
||||
fontWidth: 1.0
|
||||
lowResolutionFont: false
|
||||
isSystemFont: false
|
||||
family: ""
|
||||
}
|
||||
ListElement{
|
||||
name: "MONACO"
|
||||
@ -185,6 +215,8 @@ QtObject{
|
||||
pixelSize: 30
|
||||
fontWidth: 1.0
|
||||
lowResolutionFont: false
|
||||
isSystemFont: false
|
||||
family: ""
|
||||
}
|
||||
ListElement{
|
||||
name: "INCONSOLATA"
|
||||
@ -194,6 +226,8 @@ QtObject{
|
||||
pixelSize: 35
|
||||
fontWidth: 1.0
|
||||
lowResolutionFont: false
|
||||
isSystemFont: false
|
||||
family: ""
|
||||
}
|
||||
ListElement{
|
||||
name: "IBM_3278"
|
||||
@ -203,6 +237,8 @@ QtObject{
|
||||
pixelSize: 32
|
||||
fontWidth: 1.0
|
||||
lowResolutionFont: false
|
||||
isSystemFont: false
|
||||
family: ""
|
||||
}
|
||||
ListElement{
|
||||
name: "Knight_TV"
|
||||
@ -213,6 +249,33 @@ QtObject{
|
||||
fontWidth: 1.0
|
||||
baseScaling: 3.0
|
||||
lowResolutionFont: true
|
||||
isSystemFont: false
|
||||
family: ""
|
||||
}
|
||||
}
|
||||
|
||||
Component.onCompleted: addSystemFonts()
|
||||
|
||||
function addSystemFonts() {
|
||||
var families = monospaceSystemFonts;
|
||||
for (var i = 0; i < families.length; i++) {
|
||||
console.log("Adding system font: ", families[i])
|
||||
fontlist.append(convertToListElement(families[i]))
|
||||
}
|
||||
}
|
||||
|
||||
function convertToListElement(family) {
|
||||
return {
|
||||
name: "System: " + family,
|
||||
text: qsTr("System: ") + family,
|
||||
source: "",
|
||||
lineSpacing: 0.1,
|
||||
pixelSize: 30,
|
||||
fontWidth: 1.0,
|
||||
baseScaling: 1.0,
|
||||
lowResolutionFont: false,
|
||||
isSystemFont: true,
|
||||
family: family
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -114,14 +114,10 @@ Item{
|
||||
}
|
||||
}
|
||||
|
||||
FontLoader{ id: fontLoader }
|
||||
|
||||
function handleFontChange(fontSource, pixelSize, lineSpacing, screenScaling, fontWidth){
|
||||
fontLoader.source = fontSource;
|
||||
|
||||
function handleFontChanged(fontFamily, pixelSize, lineSpacing, screenScaling, fontWidth) {
|
||||
kterminal.antialiasText = !appSettings.lowResolutionFont;
|
||||
font.pixelSize = pixelSize;
|
||||
font.family = fontLoader.name;
|
||||
font.family = fontFamily;
|
||||
|
||||
terminalContainer.fontWidth = fontWidth;
|
||||
terminalContainer.screenScaling = screenScaling;
|
||||
@ -129,6 +125,7 @@ Item{
|
||||
|
||||
kterminal.lineSpacing = lineSpacing;
|
||||
}
|
||||
|
||||
function startSession() {
|
||||
appSettings.initializedSettings.disconnect(startSession);
|
||||
|
||||
@ -152,7 +149,7 @@ Item{
|
||||
forceActiveFocus();
|
||||
}
|
||||
Component.onCompleted: {
|
||||
appSettings.terminalFontChanged.connect(handleFontChange);
|
||||
appSettings.terminalFontChanged.connect(handleFontChanged);
|
||||
appSettings.initializedSettings.connect(startSession);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user