mirror of
https://github.com/Serial-Studio/Serial-Studio.git
synced 2025-01-15 05:22:53 +08:00
Use OS fonts & ensure minimum window sizes are respected
This commit is contained in:
parent
99f8ce99f2
commit
18f775114c
@ -94,7 +94,7 @@ Window {
|
||||
text: root.title
|
||||
visible: root.titlebarHeight > 0
|
||||
color: Cpp_ThemeManager.colors["text"]
|
||||
font: Cpp_Misc_CommonFonts.customUiFont(13, true)
|
||||
font: Cpp_Misc_CommonFonts.customUiFont(14, true)
|
||||
|
||||
anchors {
|
||||
topMargin: 6
|
||||
@ -199,7 +199,7 @@ Window {
|
||||
|
||||
Label {
|
||||
opacity: 0.8
|
||||
font.pixelSize: 12
|
||||
font.pointSize: 12
|
||||
Layout.fillWidth: true
|
||||
Layout.maximumWidth: 320
|
||||
wrapMode: Label.WrapAtWordBoundaryOrAnywhere
|
||||
|
@ -89,7 +89,7 @@ Window {
|
||||
text: root.title
|
||||
visible: root.titlebarHeight > 0
|
||||
color: Cpp_ThemeManager.colors["text"]
|
||||
font: Cpp_Misc_CommonFonts.customUiFont(13, true)
|
||||
font: Cpp_Misc_CommonFonts.customUiFont(14, true)
|
||||
|
||||
anchors {
|
||||
topMargin: 6
|
||||
|
@ -93,7 +93,7 @@ Window {
|
||||
text: root.title
|
||||
visible: root.titlebarHeight > 0
|
||||
color: Cpp_ThemeManager.colors["text"]
|
||||
font: Cpp_Misc_CommonFonts.customUiFont(13, true)
|
||||
font: Cpp_Misc_CommonFonts.customUiFont(14, true)
|
||||
|
||||
anchors {
|
||||
topMargin: 6
|
||||
|
@ -91,7 +91,7 @@ Window {
|
||||
text: root.title
|
||||
visible: root.titlebarHeight > 0
|
||||
color: Cpp_ThemeManager.colors["text"]
|
||||
font: Cpp_Misc_CommonFonts.customUiFont(13, true)
|
||||
font: Cpp_Misc_CommonFonts.customUiFont(14, true)
|
||||
|
||||
anchors {
|
||||
topMargin: 6
|
||||
@ -193,14 +193,14 @@ Window {
|
||||
Label {
|
||||
id: title
|
||||
Layout.fillWidth: true
|
||||
Layout.minimumHeight: font.pixelSize
|
||||
Layout.minimumHeight: font.pointSize
|
||||
font: Cpp_Misc_CommonFonts.customUiFont(16, true)
|
||||
text: qsTr("Support the development of %1!").arg(Cpp_AppName)
|
||||
}
|
||||
|
||||
Label {
|
||||
Layout.fillWidth: true
|
||||
Layout.minimumHeight: font.pixelSize * 3
|
||||
Layout.minimumHeight: font.pointSize * 3
|
||||
Layout.maximumWidth: title.implicitWidth
|
||||
wrapMode: Label.WrapAtWordBoundaryOrAnywhere
|
||||
text: qsTr("Serial Studio is free & open-source software supported by volunteers. " +
|
||||
@ -209,9 +209,9 @@ Window {
|
||||
|
||||
Label {
|
||||
opacity: 0.8
|
||||
font.pixelSize: 12
|
||||
font.pointSize: 12
|
||||
Layout.fillWidth: true
|
||||
Layout.minimumHeight: font.pixelSize * 2
|
||||
Layout.minimumHeight: font.pointSize * 2
|
||||
Layout.maximumWidth: title.implicitWidth
|
||||
wrapMode: Label.WrapAtWordBoundaryOrAnywhere
|
||||
text: qsTr("You can also support this project by sharing it, reporting bugs and proposing new features!")
|
||||
|
@ -83,7 +83,7 @@ Window {
|
||||
text: root.title
|
||||
visible: root.titlebarHeight > 0
|
||||
color: Cpp_ThemeManager.colors["text"]
|
||||
font: Cpp_Misc_CommonFonts.customUiFont(13, true)
|
||||
font: Cpp_Misc_CommonFonts.customUiFont(14, true)
|
||||
|
||||
anchors {
|
||||
topMargin: 6
|
||||
|
@ -95,7 +95,7 @@ Window {
|
||||
text: root.title
|
||||
visible: root.titlebarHeight > 0
|
||||
color: Cpp_ThemeManager.colors["text"]
|
||||
font: Cpp_Misc_CommonFonts.customUiFont(13, true)
|
||||
font: Cpp_Misc_CommonFonts.customUiFont(14, true)
|
||||
|
||||
anchors {
|
||||
topMargin: 6
|
||||
|
@ -171,7 +171,7 @@ Widgets.Pane {
|
||||
text: window.title
|
||||
visible: window.titlebarHeight > 0
|
||||
color: Cpp_ThemeManager.colors["text"]
|
||||
font: Cpp_Misc_CommonFonts.customUiFont(13, true)
|
||||
font: Cpp_Misc_CommonFonts.customUiFont(14, true)
|
||||
|
||||
anchors {
|
||||
topMargin: 6
|
||||
|
@ -32,6 +32,9 @@ Widgets.Pane {
|
||||
title: qsTr("Console")
|
||||
icon: "qrc:/rcc/icons/panes/console.svg"
|
||||
|
||||
Layout.minimumWidth: terminal.implicitWidth
|
||||
Layout.minimumHeight: terminal.implicitHeight
|
||||
|
||||
//
|
||||
// Custom properties
|
||||
//
|
||||
|
@ -33,6 +33,7 @@ Widgets.Pane {
|
||||
id: root
|
||||
title: qsTr("Setup")
|
||||
icon: "qrc:/rcc/icons/panes/setup.svg"
|
||||
implicitHeight: column.implicitHeight + 32
|
||||
|
||||
//
|
||||
// Custom properties
|
||||
|
@ -28,8 +28,9 @@ import QtQuick.Controls
|
||||
import SerialStudio
|
||||
import "../../Widgets" as Widgets
|
||||
|
||||
ToolBar {
|
||||
Rectangle {
|
||||
id: root
|
||||
implicitWidth: (layout.implicitWidth + 32)
|
||||
|
||||
//
|
||||
// Custom signals
|
||||
@ -72,7 +73,7 @@ ToolBar {
|
||||
text: mainWindow.title
|
||||
visible: root.titlebarHeight > 0
|
||||
color: Cpp_ThemeManager.colors["titlebar_text"]
|
||||
font: Cpp_Misc_CommonFonts.customUiFont(13, true)
|
||||
font: Cpp_Misc_CommonFonts.customUiFont(14, true)
|
||||
|
||||
anchors {
|
||||
topMargin: 6
|
||||
@ -84,36 +85,40 @@ ToolBar {
|
||||
//
|
||||
// Toolbar background
|
||||
//
|
||||
background: Rectangle {
|
||||
gradient: Gradient {
|
||||
GradientStop {
|
||||
position: 0
|
||||
color: Cpp_ThemeManager.colors["toolbar_top"]
|
||||
}
|
||||
|
||||
GradientStop {
|
||||
position: 1
|
||||
color: Cpp_ThemeManager.colors["toolbar_bottom"]
|
||||
}
|
||||
gradient: Gradient {
|
||||
GradientStop {
|
||||
position: 0
|
||||
color: Cpp_ThemeManager.colors["toolbar_top"]
|
||||
}
|
||||
|
||||
Rectangle {
|
||||
height: 1
|
||||
color: Cpp_ThemeManager.colors["toolbar_border"]
|
||||
|
||||
anchors {
|
||||
left: parent.left
|
||||
right: parent.right
|
||||
bottom: parent.bottom
|
||||
}
|
||||
GradientStop {
|
||||
position: 1
|
||||
color: Cpp_ThemeManager.colors["toolbar_bottom"]
|
||||
}
|
||||
}
|
||||
|
||||
DragHandler {
|
||||
target: null
|
||||
onActiveChanged: {
|
||||
if (active)
|
||||
mainWindow.startSystemMove()
|
||||
}
|
||||
//
|
||||
// Toolbar border
|
||||
//
|
||||
Rectangle {
|
||||
height: 1
|
||||
color: Cpp_ThemeManager.colors["toolbar_border"]
|
||||
|
||||
anchors {
|
||||
left: parent.left
|
||||
right: parent.right
|
||||
bottom: parent.bottom
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Drag main window with the toolbar
|
||||
//
|
||||
DragHandler {
|
||||
target: null
|
||||
onActiveChanged: {
|
||||
if (active)
|
||||
mainWindow.startSystemMove()
|
||||
}
|
||||
}
|
||||
|
||||
@ -121,6 +126,7 @@ ToolBar {
|
||||
// Toolbar controls
|
||||
//
|
||||
RowLayout {
|
||||
id: layout
|
||||
spacing: 8
|
||||
|
||||
anchors {
|
||||
@ -157,7 +163,7 @@ ToolBar {
|
||||
// Separator
|
||||
//
|
||||
Rectangle {
|
||||
width: 1
|
||||
implicitWidth: 1
|
||||
Layout.fillHeight: true
|
||||
Layout.maximumHeight: 64
|
||||
Layout.alignment: Qt.AlignVCenter
|
||||
@ -192,7 +198,7 @@ ToolBar {
|
||||
// Separator
|
||||
//
|
||||
Rectangle {
|
||||
width: 1
|
||||
implicitWidth: 1
|
||||
Layout.fillHeight: true
|
||||
Layout.maximumHeight: 64
|
||||
Layout.alignment: Qt.AlignVCenter
|
||||
@ -227,7 +233,7 @@ ToolBar {
|
||||
// Separator
|
||||
//
|
||||
Rectangle {
|
||||
width: 1
|
||||
implicitWidth: 1
|
||||
Layout.fillHeight: true
|
||||
Layout.maximumHeight: 64
|
||||
Layout.alignment: Qt.AlignVCenter
|
||||
@ -252,7 +258,7 @@ ToolBar {
|
||||
// Separator
|
||||
//
|
||||
Rectangle {
|
||||
width: 1
|
||||
implicitWidth: 1
|
||||
Layout.fillHeight: true
|
||||
Layout.maximumHeight: 64
|
||||
Layout.alignment: Qt.AlignVCenter
|
||||
@ -293,6 +299,7 @@ ToolBar {
|
||||
// Horizontal spacer
|
||||
//
|
||||
Item {
|
||||
implicitWidth: 1
|
||||
Layout.fillWidth: true
|
||||
}
|
||||
|
||||
@ -302,6 +309,7 @@ ToolBar {
|
||||
Widgets.BigButton {
|
||||
checked: Cpp_IO_Manager.connected
|
||||
Layout.alignment: Qt.AlignVCenter
|
||||
implicitWidth: metrics.width + 32
|
||||
font: Cpp_Misc_CommonFonts.boldUiFont
|
||||
Layout.minimumWidth: metrics.width + 32
|
||||
Layout.maximumWidth: metrics.width + 32
|
||||
@ -325,5 +333,12 @@ ToolBar {
|
||||
text: " " + qsTr("Disconnect") + " "
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Horizontal spacer
|
||||
//
|
||||
Item {
|
||||
implicitWidth: 1
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -32,9 +32,9 @@ import "../Widgets" as Widgets
|
||||
|
||||
Widgets.SmartWindow {
|
||||
id: root
|
||||
minimumWidth: 1100
|
||||
minimumHeight: 660
|
||||
category: "MainWindow"
|
||||
minimumWidth: layout.implicitWidth
|
||||
minimumHeight: layout.implicitHeight
|
||||
title: qsTr("%1 - %2").arg(documentTitle).arg(Cpp_AppName)
|
||||
|
||||
//
|
||||
@ -276,6 +276,8 @@ Widgets.SmartWindow {
|
||||
initialItem: terminal
|
||||
Layout.fillWidth: true
|
||||
Layout.fillHeight: true
|
||||
Layout.minimumHeight: Math.max(dashboard.implicitHeight, terminal.implicitHeight, setup.implicitHeight)
|
||||
Layout.minimumWidth: Math.max(dashboard.implicitWidth, terminal.implicitWidth) + (setup.visible ? 0 : setup.displayedWidth + 1)
|
||||
|
||||
data: [
|
||||
Panes.Console {
|
||||
|
@ -38,9 +38,9 @@ Widgets.SmartWindow {
|
||||
//
|
||||
// Window options
|
||||
//
|
||||
minimumWidth: 970
|
||||
minimumHeight: 640
|
||||
category: "ProjectEditor"
|
||||
minimumWidth: layout.implicitWidth + 32
|
||||
minimumHeight: layout.implicitHeight + 32
|
||||
title: qsTr("%1 - Project Editor").arg(Cpp_JSON_ProjectModel.title + (Cpp_JSON_ProjectModel.modified ? " (" + qsTr("modified") + ")" : ""))
|
||||
|
||||
//
|
||||
@ -133,6 +133,7 @@ Widgets.SmartWindow {
|
||||
Layout.topMargin: -1
|
||||
Layout.fillWidth: true
|
||||
Layout.fillHeight: true
|
||||
Layout.minimumHeight: 520
|
||||
|
||||
//
|
||||
// Project structure
|
||||
|
@ -29,9 +29,9 @@ import SerialStudio
|
||||
|
||||
import "../../Widgets" as Widgets
|
||||
|
||||
|
||||
ToolBar {
|
||||
Rectangle {
|
||||
id: root
|
||||
implicitWidth: layout.implicitWidth + 32
|
||||
|
||||
//
|
||||
// Calculate offset based on platform
|
||||
@ -57,7 +57,7 @@ ToolBar {
|
||||
text: projectEditor.title
|
||||
visible: root.titlebarHeight > 0
|
||||
color: Cpp_ThemeManager.colors["titlebar_text"]
|
||||
font: Cpp_Misc_CommonFonts.customUiFont(13, true)
|
||||
font: Cpp_Misc_CommonFonts.customUiFont(14, true)
|
||||
|
||||
anchors {
|
||||
topMargin: 6
|
||||
@ -69,36 +69,40 @@ ToolBar {
|
||||
//
|
||||
// Toolbar background
|
||||
//
|
||||
background: Rectangle {
|
||||
gradient: Gradient {
|
||||
GradientStop {
|
||||
position: 0
|
||||
color: Cpp_ThemeManager.colors["toolbar_top"]
|
||||
}
|
||||
|
||||
GradientStop {
|
||||
position: 1
|
||||
color: Cpp_ThemeManager.colors["toolbar_bottom"]
|
||||
}
|
||||
gradient: Gradient {
|
||||
GradientStop {
|
||||
position: 0
|
||||
color: Cpp_ThemeManager.colors["toolbar_top"]
|
||||
}
|
||||
|
||||
Rectangle {
|
||||
height: 1
|
||||
color: Cpp_ThemeManager.colors["toolbar_border"]
|
||||
|
||||
anchors {
|
||||
left: parent.left
|
||||
right: parent.right
|
||||
bottom: parent.bottom
|
||||
}
|
||||
GradientStop {
|
||||
position: 1
|
||||
color: Cpp_ThemeManager.colors["toolbar_bottom"]
|
||||
}
|
||||
}
|
||||
|
||||
DragHandler {
|
||||
target: null
|
||||
onActiveChanged: {
|
||||
if (active)
|
||||
projectEditor.startSystemMove()
|
||||
}
|
||||
//
|
||||
// Toolbar bottom border
|
||||
//
|
||||
Rectangle {
|
||||
height: 1
|
||||
color: Cpp_ThemeManager.colors["toolbar_border"]
|
||||
|
||||
anchors {
|
||||
left: parent.left
|
||||
right: parent.right
|
||||
bottom: parent.bottom
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Move window with toolbar
|
||||
//
|
||||
DragHandler {
|
||||
target: null
|
||||
onActiveChanged: {
|
||||
if (active)
|
||||
projectEditor.startSystemMove()
|
||||
}
|
||||
}
|
||||
|
||||
@ -106,6 +110,7 @@ ToolBar {
|
||||
// Toolbar controls
|
||||
//
|
||||
RowLayout {
|
||||
id: layout
|
||||
spacing: 8
|
||||
|
||||
anchors {
|
||||
|
@ -33,11 +33,21 @@ ToolButton {
|
||||
icon.height: 32
|
||||
icon.color: "transparent"
|
||||
display: AbstractButton.TextUnderIcon
|
||||
|
||||
Layout.minimumWidth: Math.max(implicitWidth, icon.width / 32 * 72)
|
||||
Layout.maximumWidth: Math.max(implicitWidth, icon.width / 32 * 72)
|
||||
palette.buttonText: Cpp_ThemeManager.colors["toolbar_text"]
|
||||
|
||||
Layout.minimumWidth: implicitWidth
|
||||
Layout.maximumWidth: implicitWidth
|
||||
implicitWidth: Math.max(Math.ceil(metrics.width + 32), icon.width / 32 * 72)
|
||||
|
||||
opacity: enabled ? 1 : 0.5
|
||||
Behavior on opacity {NumberAnimation{}}
|
||||
|
||||
TextMetrics {
|
||||
id: metrics
|
||||
text: root.text
|
||||
font: Cpp_Misc_CommonFonts.uiFont
|
||||
}
|
||||
|
||||
background: Item {
|
||||
Rectangle {
|
||||
radius: 3
|
||||
@ -55,7 +65,4 @@ ToolButton {
|
||||
visible: root.checked && !root.toolbarButton
|
||||
}
|
||||
}
|
||||
|
||||
opacity: enabled ? 1 : 0.5
|
||||
Behavior on opacity {NumberAnimation{}}
|
||||
}
|
||||
|
@ -29,6 +29,8 @@ import SerialStudio
|
||||
|
||||
Item {
|
||||
id: root
|
||||
implicitWidth: layout.implicitWidth + 32
|
||||
implicitHeight: layout.implicitHeight + 32
|
||||
property alias vt100emulation: terminal.vt100emulation
|
||||
|
||||
//
|
||||
@ -169,6 +171,7 @@ Item {
|
||||
// Controls
|
||||
//
|
||||
ColumnLayout {
|
||||
id: layout
|
||||
spacing: 4
|
||||
anchors.fill: parent
|
||||
anchors.topMargin: -6
|
||||
@ -181,6 +184,8 @@ Item {
|
||||
vt100emulation: true
|
||||
Layout.fillWidth: true
|
||||
Layout.fillHeight: true
|
||||
Layout.minimumWidth: terminal.charWidth * 80
|
||||
Layout.minimumHeight: terminal.charHeight * 24
|
||||
|
||||
Rectangle {
|
||||
border.width: 1
|
||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
app/rcc/fonts/SourceCodePro-Regular.ttf
Normal file
BIN
app/rcc/fonts/SourceCodePro-Regular.ttf
Normal file
Binary file not shown.
@ -108,11 +108,7 @@
|
||||
<file>actions/Xbox Y.svg</file>
|
||||
<file>actions/Zoom In.svg</file>
|
||||
<file>actions/Zoom Out.svg</file>
|
||||
<file>fonts/NotoSans-Bold.ttf</file>
|
||||
<file>fonts/NotoSans-Regular.ttf</file>
|
||||
<file>fonts/NotoSansMono-Regular.ttf</file>
|
||||
<file>fonts/NotoSansSC-Bold.ttf</file>
|
||||
<file>fonts/NotoSansSC-Regular.ttf</file>
|
||||
<file>fonts/SourceCodePro-Regular.ttf</file>
|
||||
<file>icons/buttons/apply.svg</file>
|
||||
<file>icons/buttons/center.svg</file>
|
||||
<file>icons/buttons/clear.svg</file>
|
||||
|
@ -391,7 +391,6 @@ void IO::Console::print()
|
||||
|
||||
// Set font
|
||||
auto font = Misc::CommonFonts::instance().monoFont();
|
||||
font.setPixelSize(10);
|
||||
font.setPointSize(10);
|
||||
document.setDefaultFont(font);
|
||||
|
||||
|
@ -775,7 +775,7 @@ void IO::Drivers::Serial::readSettings()
|
||||
for (int i = 0; i < list.count(); ++i)
|
||||
m_baudRateList.append(list.at(i));
|
||||
|
||||
// Sort baud rate list
|
||||
// Sort baud rate list
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(5, 12, 0)
|
||||
for (auto i = 0; i < m_baudRateList.count() - 1; ++i)
|
||||
{
|
||||
|
@ -24,7 +24,6 @@
|
||||
#include <QApplication>
|
||||
#include <QFontDatabase>
|
||||
|
||||
#include "Misc/Translator.h"
|
||||
#include "Misc/CommonFonts.h"
|
||||
|
||||
/**
|
||||
@ -42,21 +41,22 @@ Misc::CommonFonts::CommonFonts()
|
||||
(addFont(fonts), ...);
|
||||
};
|
||||
|
||||
// Add common fonts to application database
|
||||
// clang-format off
|
||||
addFonts(
|
||||
QStringLiteral(":/rcc/fonts/NotoSans-Bold.ttf"),
|
||||
QStringLiteral(":/rcc/fonts/NotoSansSC-Bold.ttf"),
|
||||
QStringLiteral(":/rcc/fonts/NotoSans-Regular.ttf"),
|
||||
QStringLiteral(":/rcc/fonts/NotoSansSC-Regular.ttf"),
|
||||
QStringLiteral(":/rcc/fonts/NotoSansMono-Regular.ttf")
|
||||
);
|
||||
// clang-format on
|
||||
// Register the monospace fonts only
|
||||
addFonts(QStringLiteral(":/rcc/fonts/SourceCodePro-Regular.ttf"));
|
||||
|
||||
// Load appropiate fonts for current language
|
||||
onLanguageChanged();
|
||||
connect(&Misc::Translator::instance(), &Misc::Translator::languageChanged,
|
||||
this, &Misc::CommonFonts::onLanguageChanged);
|
||||
// Set the UI font to the system default
|
||||
m_uiFont = QApplication::font();
|
||||
m_boldUiFont = m_uiFont;
|
||||
m_boldUiFont.setBold(true);
|
||||
|
||||
// Set the monospace font from the embedded font
|
||||
m_monoName = QStringLiteral("Source Code Pro");
|
||||
m_monoFont = QFontDatabase::font(m_monoName, QStringLiteral("Regular"),
|
||||
m_uiFont.pointSize());
|
||||
m_monoFont.setStyleHint(QFont::Monospace);
|
||||
|
||||
// Update application fonts
|
||||
QApplication::setFont(m_uiFont);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -98,74 +98,25 @@ const QFont &Misc::CommonFonts::boldUiFont() const
|
||||
|
||||
/**
|
||||
* @brief Creates a custom UI font with specified pixel size and boldness.
|
||||
* @param pixelSize The pixel size of the font.
|
||||
* @param pointSize The pixel size of the font.
|
||||
* @param bold True if the font should be bold, otherwise false.
|
||||
* @return The custom UI font.
|
||||
*/
|
||||
QFont Misc::CommonFonts::customUiFont(const int pixelSize, const bool bold)
|
||||
QFont Misc::CommonFonts::customUiFont(const int pointSize, const bool bold)
|
||||
{
|
||||
auto weight = bold ? QStringLiteral("Bold") : QStringLiteral("Regular");
|
||||
QFont font = QFontDatabase::font(m_uiName, weight, 12);
|
||||
font.setPixelSize(qMax(1, pixelSize));
|
||||
QFont font = bold ? m_boldUiFont : m_uiFont;
|
||||
font.setPointSize(qMax(1, pointSize));
|
||||
return font;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Creates a custom monospace font with specified pixel size.
|
||||
* @param pixelSize The pixel size of the font.
|
||||
* @param pointSize The pixel size of the font.
|
||||
* @return The custom monospace font.
|
||||
*/
|
||||
QFont Misc::CommonFonts::customMonoFont(const int pixelSize)
|
||||
QFont Misc::CommonFonts::customMonoFont(const int pointSize)
|
||||
{
|
||||
QFont font = QFontDatabase::font(m_monoName, QStringLiteral("Regular"), 12);
|
||||
font.setPixelSize(qMax(1, pixelSize));
|
||||
font.setPointSize(qMax(1, pointSize));
|
||||
return font;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Updates the UI and monospace fonts when the language is changed.
|
||||
*
|
||||
* This function sets the appropriate UI and monospace font names based on the
|
||||
* current language selected in the translator. It then loads the fonts with
|
||||
* specified attributes such as style and size from the QFontDatabase.
|
||||
*/
|
||||
void Misc::CommonFonts::onLanguageChanged()
|
||||
{
|
||||
// Obtain fonts to use for current language
|
||||
switch (Misc::Translator::instance().language())
|
||||
{
|
||||
case Misc::Translator::English:
|
||||
case Misc::Translator::Spanish:
|
||||
case Misc::Translator::German:
|
||||
case Misc::Translator::Russian:
|
||||
case Misc::Translator::French:
|
||||
m_uiName = QStringLiteral("Noto Sans");
|
||||
m_monoName = QStringLiteral("Noto Sans Mono");
|
||||
break;
|
||||
case Misc::Translator::Chinese:
|
||||
m_uiName = QStringLiteral("Noto Sans SC");
|
||||
m_monoName = QStringLiteral("Noto Sans Mono");
|
||||
break;
|
||||
}
|
||||
|
||||
// Load fonts
|
||||
m_uiFont = QFontDatabase::font(m_uiName, QStringLiteral("Regular"), 12);
|
||||
m_boldUiFont = QFontDatabase::font(m_uiName, QStringLiteral("Bold"), 12);
|
||||
m_monoFont = QFontDatabase::font(m_monoName, QStringLiteral("Regular"), 12);
|
||||
|
||||
// Set font size
|
||||
m_uiFont.setPixelSize(12);
|
||||
m_monoFont.setPixelSize(12);
|
||||
m_boldUiFont.setPixelSize(12);
|
||||
|
||||
// Set font properties
|
||||
m_uiFont.setStyleHint(QFont::SansSerif);
|
||||
m_monoFont.setStyleHint(QFont::Monospace);
|
||||
m_boldUiFont.setStyleHint(QFont::SansSerif);
|
||||
|
||||
// Update application fonts
|
||||
QApplication::setFont(m_uiFont);
|
||||
|
||||
// Update fonts
|
||||
Q_EMIT fontsChanged();
|
||||
}
|
||||
|
@ -64,11 +64,8 @@ public:
|
||||
[[nodiscard]] const QFont &monoFont() const;
|
||||
[[nodiscard]] const QFont &boldUiFont() const;
|
||||
|
||||
Q_INVOKABLE QFont customUiFont(int pixelSize = 12, bool bold = false);
|
||||
Q_INVOKABLE QFont customMonoFont(int pixelSize = 12);
|
||||
|
||||
private slots:
|
||||
void onLanguageChanged();
|
||||
Q_INVOKABLE QFont customUiFont(int pointSize = 12, bool bold = false);
|
||||
Q_INVOKABLE QFont customMonoFont(int pointSize = 12);
|
||||
|
||||
private:
|
||||
QFont m_uiFont;
|
||||
|
@ -322,6 +322,24 @@ void Widgets::Terminal::paint(QPainter *painter)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Returns the width of a single terminal character.
|
||||
* @return
|
||||
*/
|
||||
int Widgets::Terminal::charWidth() const
|
||||
{
|
||||
return m_cWidth;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Returns the height of a single terminal character.
|
||||
* @return
|
||||
*/
|
||||
int Widgets::Terminal::charHeight() const
|
||||
{
|
||||
return m_cHeight;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Gets the current font used by the terminal.
|
||||
*
|
||||
@ -637,10 +655,6 @@ void Widgets::Terminal::setFont(const QFont &font)
|
||||
m_cHeight = metrics.height();
|
||||
m_cWidth = metrics.averageCharWidth();
|
||||
|
||||
// Special case for Chinese
|
||||
if (Misc::Translator::instance().language() == Misc::Translator::Chinese)
|
||||
m_cWidth = font.pixelSize();
|
||||
|
||||
// Update terminal border
|
||||
m_borderX = qMax(m_cWidth, m_cHeight) / 2;
|
||||
m_borderY = qMax(m_cWidth, m_cHeight) / 2;
|
||||
|
@ -49,6 +49,12 @@ class Terminal : public QQuickPaintedItem
|
||||
READ font
|
||||
WRITE setFont
|
||||
NOTIFY fontChanged)
|
||||
Q_PROPERTY(int charWidth
|
||||
READ charWidth
|
||||
NOTIFY fontChanged)
|
||||
Q_PROPERTY(int charHeight
|
||||
READ charHeight
|
||||
NOTIFY fontChanged)
|
||||
Q_PROPERTY(bool autoscroll
|
||||
READ autoscroll
|
||||
WRITE setAutoscroll
|
||||
@ -100,6 +106,9 @@ public:
|
||||
};
|
||||
Q_ENUM(State);
|
||||
|
||||
[[nodiscard]] int charWidth() const;
|
||||
[[nodiscard]] int charHeight() const;
|
||||
|
||||
[[nodiscard]] QFont font() const;
|
||||
[[nodiscard]] QPalette palette() const;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user