Skip to content

Commit

Permalink
Switch to and reset font.pixelSize to avoid the headache
Browse files Browse the repository at this point in the history
I don't know why I used pointSize in the first place but it was not a
good choice. This also adds the ability to choose a different font size
for messages.

Previous settings will be ignored, sorry.

Closes #163
  • Loading branch information
MartinBriza committed Oct 14, 2023
1 parent dda02b3 commit a85c6a8
Show file tree
Hide file tree
Showing 29 changed files with 158 additions and 103 deletions.
8 changes: 3 additions & 5 deletions app/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,12 @@ int main(int argc, char* argv[]) {
QFont font("Inconsolata");
#endif
if (fontFamilyFromSettings.length() != 0) { // fontFamilyFromSettings could be NULL (unlikely) or empty (not so unlikely)
font = QFont(fontFamilyFromSettings
); // if the font doesn't exist, it doesn't matter atm, Qt fallsback to a monospace font on our behalf
// if the font doesn't exist, it doesn't matter atm, Qt fallsback to a monospace font on our behalf
font = QFont(fontFamilyFromSettings);
}
font.setKerning(false);
font.setHintingPreference(QFont::PreferNoHinting);
font.setStyleHint(QFont::Monospace);
font.setPixelSize(Settings::instance()->baseFontPixelSizeGet());
app.setFont(font);
app.setFont(font, "monospace");

// Start the engine
engine.load(QUrl(QLatin1String("qrc:/qt/qml/App/main.qml")));
Expand Down
8 changes: 5 additions & 3 deletions modules/Lith/Core/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,16 @@ class LITHCORE_EXPORT Settings : public QObject {
static inline const QStringList c_hotlistDefaultFormat {"%1: %2/%3", "short_name", "hotMessages", "unreadMessages"};

SETTING(int, lastOpenBuffer, -1)
// TODO revisit this, it's really really awkward to have different defaults for both font size and face
// TODO revisit this, it's really really awkward to have different defaults for font families
#if defined(Q_OS_MACOS)
SETTING(QString, baseFontFamily, "Menlo")
SETTING(qreal, baseFontSize, 13)
#else
SETTING(QString, baseFontFamily, "Inconsolata")
SETTING(qreal, baseFontSize, 11)
#endif
SETTING(int, baseFontPixelSize, 14)
SETTING(bool, useBaseFontPixelSizeForMessages, true)
SETTING(int, messageFontPixelSize, 14)

SETTING(bool, shortenLongUrls, true)
SETTING(int, shortenLongUrlsThreshold, 50)
SETTING(int, nickCutoffThreshold, -1)
Expand Down
2 changes: 1 addition & 1 deletion modules/Lith/Style/Button.qml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ T.Button {
icon.width: 32
icon.height: 32

font.pointSize: Lith.settings.baseFontSize
font.pixelSize: FontSizes.regular

contentItem: Item {

Expand Down
2 changes: 1 addition & 1 deletion modules/Lith/Style/CheckBox.qml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ T.CheckBox {

indicator: Rectangle {
id: backgroundRect
implicitWidth: 26 * Math.max(1.0, Lith.settings.baseFontSize / 20)
implicitWidth: FontSizes.regular + 12
implicitHeight: implicitWidth
anchors.verticalCenter: parent.verticalCenter

Expand Down
3 changes: 1 addition & 2 deletions modules/Lith/Style/ItemDelegate.qml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ T.ItemDelegate {
icon.height: 24
icon.color: control.LithPalette.regular.text

font.pointSize: Lith.settings.baseFontSize
font.pixelSize: FontSizes.regular

property alias textFormat: label.textFormat

Expand All @@ -30,7 +30,6 @@ T.ItemDelegate {
text: control.text
font: control.font
color: control.checked ? LithPalette.regular.highlightedText : LithPalette.regular.text
size: Label.Large
}

background: Rectangle {
Expand Down
29 changes: 1 addition & 28 deletions modules/Lith/Style/Label.qml
Original file line number Diff line number Diff line change
Expand Up @@ -5,33 +5,6 @@ import Lith.Core
import Lith.Style

T.Label {
enum Size {
Tiny,
Small,
Regular,
Medium,
Large,
Header
}
property int size: Label.Size.Regular

color: LithPalette.regular.windowText

font.pointSize: {
switch (size) {
case Label.Tiny:
return Lith.settings.baseFontSize * 0.75
case Label.Small:
return Lith.settings.baseFontSize * 0.875
case Label.Regular:
return Lith.settings.baseFontSize
case Label.Medium:
return Lith.settings.baseFontSize * 1.125
case Label.Large:
return Lith.settings.baseFontSize * 1.25
case Label.Header:
return Lith.settings.baseFontSize * 1.375
}
return Lith.settings.baseFontSize
}
font.pixelSize: FontSizes.regular
}
3 changes: 2 additions & 1 deletion modules/Lith/Style/RadioButton.qml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import QtQuick
import QtQuick.Templates as T

import Lith.Core
import Lith.Style

T.RadioButton {
id: control
Expand All @@ -19,7 +20,7 @@ T.RadioButton {

indicator: Rectangle {
id: backgroundRect
implicitWidth: 26 * Math.max(1.0, Lith.settings.baseFontSize / 20)
implicitWidth: FontSizes.regular + 12
implicitHeight: implicitWidth
anchors.verticalCenter: parent.verticalCenter

Expand Down
2 changes: 2 additions & 0 deletions modules/Lith/Style/SpinBox.qml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ T.SpinBox {
leftPadding: padding + (control.mirrored ? (up.indicator ? up.indicator.width : 0) : (down.indicator ? down.indicator.width : 0))
rightPadding: padding + (control.mirrored ? (down.indicator ? down.indicator.width : 0) : (up.indicator ? up.indicator.width : 0))

font.pixelSize: FontSizes.regular

validator: IntValidator {
locale: control.locale.name
bottom: Math.min(control.from, control.to)
Expand Down
4 changes: 3 additions & 1 deletion modules/Lith/Style/Switch.qml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import QtQuick
import QtQuick.Templates as T

import Lith.Core
import Lith.Style
import Lith.UI

T.Switch {
id: control
Expand All @@ -15,7 +17,7 @@ T.Switch {
property color onColor: LithPalette.regular.highlight
property color offColor: LithPalette.regular.window

font.pointSize: Lith.settings.baseFontSize
font.pixelSize: FontSizes.regular

indicator: Rectangle {
id: backgroundRect
Expand Down
2 changes: 1 addition & 1 deletion modules/Lith/Style/TabButton.qml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ T.TabButton {
icon.width: 28
icon.height: 28

font.pointSize: Lith.settings.baseFontSize
font.pixelSize: FontSizes.regular

contentItem: IconLabel {
spacing: control.spacing
Expand Down
4 changes: 2 additions & 2 deletions modules/Lith/Style/TextArea.qml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ T.TextArea {
placeholderTextColor: LithPalette.disabled.text
verticalAlignment: Text.AlignVCenter

font.pointSize: Lith.settings.baseFontSize
font.pixelSize: FontSizes.regular

property color borderColor: "transparent"
property color backgroundColor: "transparent"
Expand Down Expand Up @@ -52,7 +52,7 @@ T.TextArea {
horizontalAlignment: control.horizontalAlignment
leftPadding: control.leftPadding
rightPadding: control.rightPadding
font.pointSize: control.font.pointSize
font.pixelSize: control.font.pixelSize
color: control.placeholderTextColor
text: control.placeholderText
}
Expand Down
4 changes: 2 additions & 2 deletions modules/Lith/Style/TextField.qml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ T.TextField {
placeholderTextColor: LithPalette.disabled.text
verticalAlignment: Text.AlignVCenter

font.pointSize: Lith.settings.baseFontSize
font.pixelSize: FontSizes.regular

property color borderColor: "transparent"
property color backgroundColor: ColorUtils.mixColors(LithPalette.regular.window, LithPalette.regular.base, control.enabled ? 0.5 : 0.95)
Expand Down Expand Up @@ -50,7 +50,7 @@ T.TextField {
horizontalAlignment: control.horizontalAlignment
leftPadding: control.leftPadding
rightPadding: control.rightPadding
font.pointSize: control.font.pointSize
font.pixelSize: control.font.pixelSize
color: control.placeholderTextColor
text: control.placeholderText
}
Expand Down
41 changes: 28 additions & 13 deletions modules/Lith/Style/constants.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,44 @@

FontSizes::FontSizes(QObject* parent)
: m_settings(Lith::settingsGet()) {
connect(m_settings, &Settings::baseFontSizeChanged, this, &FontSizes::fontSizesChanged);
connect(m_settings, &Settings::baseFontPixelSizeChanged, this, &FontSizes::fontSizesChanged);
connect(m_settings, &Settings::useBaseFontPixelSizeForMessagesChanged, this, &FontSizes::messageChanged);
connect(m_settings, &Settings::messageFontPixelSizeChanged, this, &FontSizes::messageChanged);
connect(this, &FontSizes::fontSizesChanged, this, [this]() {
if (m_settings->useBaseFontPixelSizeForMessagesGet()) {
emit messageChanged();
}
});
}

qreal FontSizes::tiny() const {
return 0.75 * m_settings->baseFontSizeGet();
int FontSizes::tiny() const {
return 0.75 * m_settings->baseFontPixelSizeGet();
}

qreal FontSizes::small() const {
return 0.875 * m_settings->baseFontSizeGet();
int FontSizes::small() const {
return 0.875 * m_settings->baseFontPixelSizeGet();
}

qreal FontSizes::regular() const {
return 1.0 * m_settings->baseFontSizeGet();
int FontSizes::regular() const {
return m_settings->baseFontPixelSizeGet();
}

qreal FontSizes::medium() const {
return 1.125 * m_settings->baseFontSizeGet();
int FontSizes::medium() const {
return 1.125 * m_settings->baseFontPixelSizeGet();
}

qreal FontSizes::large() const {
return 1.25 * m_settings->baseFontSizeGet();
int FontSizes::large() const {
return 1.25 * m_settings->baseFontPixelSizeGet();
}

qreal FontSizes::header() const {
return 1.375 * m_settings->baseFontSizeGet();
int FontSizes::header() const {
return 1.375 * m_settings->baseFontPixelSizeGet();
}

int FontSizes::message() const {
if (m_settings->useBaseFontPixelSizeForMessagesGet()) {
return regular();
} else {
return m_settings->messageFontPixelSizeGet();
}
}
29 changes: 17 additions & 12 deletions modules/Lith/Style/constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,31 @@ class FontSizes : public QObject {
Q_OBJECT
QML_ELEMENT
QML_SINGLETON
Q_PROPERTY(qreal tiny READ tiny NOTIFY fontSizesChanged)
Q_PROPERTY(qreal small READ small NOTIFY fontSizesChanged)
Q_PROPERTY(qreal regular READ regular NOTIFY fontSizesChanged)
Q_PROPERTY(qreal medium READ medium NOTIFY fontSizesChanged)
Q_PROPERTY(qreal large READ large NOTIFY fontSizesChanged)
Q_PROPERTY(qreal header READ header NOTIFY fontSizesChanged)
Q_PROPERTY(int tiny READ tiny NOTIFY fontSizesChanged)
Q_PROPERTY(int small READ small NOTIFY fontSizesChanged)
Q_PROPERTY(int regular READ regular NOTIFY fontSizesChanged)
Q_PROPERTY(int medium READ medium NOTIFY fontSizesChanged)
Q_PROPERTY(int large READ large NOTIFY fontSizesChanged)
Q_PROPERTY(int header READ header NOTIFY fontSizesChanged)

Q_PROPERTY(int message READ message NOTIFY messageChanged)
public:
explicit FontSizes(QObject* parent = nullptr);
static FontSizes* create(QQmlEngine* qmlEngine, QJSEngine* jsEngine) {
return new FontSizes(qmlEngine);
}

qreal tiny() const;
qreal small() const;
qreal regular() const;
qreal medium() const;
qreal large() const;
qreal header() const;
int tiny() const;
int small() const;
int regular() const;
int medium() const;
int large() const;
int header() const;

int message() const;
signals:
void fontSizesChanged();
void messageChanged();

private:
Settings* m_settings = nullptr;
Expand Down
2 changes: 1 addition & 1 deletion modules/Lith/UI/BufferList.qml
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ Item {
radius: 2
Label {
text: buffer && buffer.number > 0 ? buffer.number : ""
font.pointSize: FontSizes.small
font.pixelSize: FontSizes.small
anchors.centerIn: parent
color: buffer && buffer.number > 0 && buffer.number <= 10 && !buffer.isServer ? LithPalette.regular.text : LithPalette.disabled.text
}
Expand Down
2 changes: 1 addition & 1 deletion modules/Lith/UI/ChannelHeader.qml
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ Rectangle {
elide: Label.ElideRight
wrapMode: Label.Wrap
maximumLineCount: 2
font.pointSize: FontSizes.tiny
font.pixelSize: FontSizes.tiny
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter
onLinkActivated: {
Expand Down
4 changes: 4 additions & 0 deletions modules/Lith/UI/ChannelMessage.qml
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ Item {
visible: text.length > 0
width: parent.width
horizontalAlignment: Label.AlignHCenter
font.pixelSize: FontSizes.message
topPadding: 3
bottomPadding: 3
Rectangle {
Expand Down Expand Up @@ -152,6 +153,7 @@ Item {
spacing: 0
Label {
Layout.alignment: Qt.AlignTop
font.pixelSize: FontSizes.message
text: messageModel.date.toLocaleString(Qt.locale(), Lith.settings.timestampFormat) + "\u00A0"
color: LithPalette.disabled.text
textFormat: Text.RichText
Expand All @@ -161,6 +163,7 @@ Item {
Label {
id: nickLabel
Layout.alignment: Qt.AlignTop
font.pixelSize: FontSizes.message
font.bold: true
visible: Lith.settings.nickCutoffThreshold !== 0
text: messageModel.prefix.toTrimmedHtml(Lith.settings.nickCutoffThreshold) + "\u00A0"
Expand All @@ -177,6 +180,7 @@ Item {
id: messageText
text: messageModel.message
Layout.fillWidth: true
font.pixelSize: FontSizes.message
wrapMode: Text.WrapAtWordBoundaryOrAnywhere
color: LithPalette.regular.text
textFormat: Text.RichText
Expand Down
2 changes: 1 addition & 1 deletion modules/Lith/UI/ChannelMessageActionMenu.qml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ Dialog {
topPadding: 20
text: qsTr("Copy")
font.bold: true
font.pointSize: FontSizes.medium
font.pixelSize: FontSizes.medium
horizontalAlignment: Label.AlignHCenter
}

Expand Down
2 changes: 1 addition & 1 deletion modules/Lith/UI/ChannelMessageList.qml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ ListView {
TextMetrics {
id: timeMetrics
text: Qt.formatTime(new Date(), Locale.LongFormat)
font.pointSize: Lith.settings.baseFontSize
font.pixelSize: FontSizes.regular
}

ScrollBar.vertical: ScrollBar {
Expand Down
4 changes: 1 addition & 3 deletions modules/Lith/UI/HotListItem.qml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ Rectangle {
property bool hot: false

property real layoutSpacing
readonly property real textSize: theLabel.font.pointSize
readonly property int labelType: Lith.settings.hotlistCompact ? Label.Small : Label.Regular
readonly property real textSize: Lith.settings.hotlistCompact ? FontSizes.small : FontSizes.regular
readonly property real padding: Lith.settings.hotlistCompact ? 8 : 16

signal clicked
Expand All @@ -29,7 +28,6 @@ Rectangle {
spacing: Lith.settings.hotlistCompact ? 1 : 3
Label {
id: theLabel
size: root.labelType
font.bold: true
color: hot ? LithPalette.regular.highlightedText : LithPalette.regular.window
}
Expand Down
Loading

0 comments on commit a85c6a8

Please sign in to comment.