Skip to content

Commit

Permalink
[Controls] Fixup set font path
Browse files Browse the repository at this point in the history
  • Loading branch information
neochapay committed Oct 29, 2023
1 parent b4e7f5e commit 2d44776
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 20 deletions.
9 changes: 7 additions & 2 deletions src/controls/qml/Button.qml
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,19 @@ Button {

// The label of the button.
contentItem: Text {
renderType: Text.NativeRendering
FontLoader {
id: localFont
source: Theme.fontPath
}

verticalAlignment: Text.AlignVCenter
horizontalAlignment: Text.AlignHCenter
text: control.text
color: Theme.textColor
font.family: Theme.fontFamily
font.pixelSize: Theme.fontSizeMedium
font.weight: control.primary ? Theme.fontWeightLarge : Theme.fontWeightMedium
font.family: localFont.font.family
font.styleName: localFont.font.styleName
opacity: control.enabled ? 1.0 : 0.7
}
}
2 changes: 1 addition & 1 deletion src/controls/qml/HeaderToolsLayout.qml
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ Item {
right: parent.right
verticalCenter: parent.verticalCenter
}
height: toolsLayoutItem.height
height: toolsLayoutItem.height/2
width: height
visible: drawerLevels && drawerLevels.length > 1

Expand Down
9 changes: 6 additions & 3 deletions src/controls/qml/Label.qml
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,13 @@ import QtQuick 2.6
import Nemo

Text {
renderType: Text.NativeRendering
font.family: Theme.fontFamily
FontLoader {
id: localFont
source: Theme.fontPath
}
color: Theme.textColor
font.pixelSize: Theme.fontSizeMedium
font.weight: Font.Light
font.family: localFont.font.family
font.styleName: localFont.font.styleName
elide: horizontalAlignment == Text.AlignLeft ? Text.ElideRight : (horizontalAlignment == Text.AlignRight ? Text.ElideLeft : Text.ElideMiddle)
}
15 changes: 12 additions & 3 deletions src/controls/qml/TextField.qml
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,21 @@ TextField {
selectedTextColor: Theme.textColor
selectionColor: Theme.accentColor
font.pixelSize: Theme.fontSizeMedium
font.family: Theme.fontFamily
font.family: localFont.font.family
font.styleName: localFont.font.styleName
placeholderTextColor: Theme.fillColor

FontLoader {
id: localFont
source: Theme.fontPath
}

onActiveFocusChanged: {
if(activeFocus) NemoFocus.nemoregister(this)
else NemoFocus.nemoregister(null)
if(activeFocus) {
NemoFocus.nemoregister(this)
} else {
NemoFocus.nemoregister(null)
}
}

background: Item {
Expand Down
5 changes: 3 additions & 2 deletions src/controls/qml/ToolButton.qml
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,10 @@ Item {
id: iconImage
width: toolButton.height/2
height: toolButton.height/2
color: bMouseArea.pressed ? Theme.accentColor : active ? Theme.accentColor : Theme.textColor
anchors.centerIn: parent
fillMode: Image.PreserveAspectFit
anchors.margins: Theme.itemSpacingExtraSmall
source: toolButton.iconSource + "?" + (active ? Theme.accentColor : Theme.textColor)
source: toolButton.iconSource + "?" + ( active ? Theme.accentColor : Theme.textColor)
}

Rectangle{
Expand Down Expand Up @@ -89,5 +88,7 @@ Item {
id: bMouseArea
anchors.fill: parent
onClicked: toolButton.clicked()
onPressed: iconImage.source = toolButton.iconSource + "?" + Theme.accentColor
onReleased: iconImage.source = toolButton.iconSource + "?" + ( active ? Theme.accentColor : Theme.textColor)
}
}
10 changes: 5 additions & 5 deletions src/core/theme.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -209,14 +209,14 @@ void Theme::setThemeValues()
updated = true;
}

if (theme.value("fontFamily").toString() != "" && theme.value("fontFamily").toString() != m_fontFamily) {
if (theme.value("fontPath").toString() != "" && theme.value("fontPath").toString() != m_fontPath) {
QFile fontFile;
fontFile.setFileName(theme.value("fontFamily").toString());
fontFile.setFileName(theme.value("fontPath").toString());
if (!themeFile.exists()) {
qDebug() << "Font file " << fontFile.fileName() << " not found";
} else {
m_fontFamily = theme.value("fontFamily").toString();
emit fontFamilyChanged();
m_fontPath = theme.value("fontPath").toString();
emit fontPathChanged();
updated = true;
}
}
Expand Down Expand Up @@ -298,7 +298,7 @@ void Theme::loadDefaultValue()
m_fontSizeTiny = floor(14 * size->dpScaleFactor());
m_fontWeightLarge = 63 * size->dpScaleFactor();
m_fontWeightMedium = 25 * size->dpScaleFactor();
m_fontFamily = "/usr/share/fonts/google-opensans/OpenSans-Regular.ttf";
m_fontPath = "/usr/share/fonts/google-opensans/OpenSans-Regular.ttf";

m_accentColor = "#0091e5";
m_fillColor = "#474747";
Expand Down
8 changes: 4 additions & 4 deletions src/core/theme.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class Theme : public QObject {
Q_PROPERTY(int fontWeightLarge READ fontWeightLarge NOTIFY fontWeightLargeChanged)
Q_PROPERTY(int fontWeightMedium READ fontWeightMedium NOTIFY fontWeightMediumChanged)

Q_PROPERTY(QString fontFamily READ fontFamily NOTIFY fontFamilyChanged)
Q_PROPERTY(QString fontPath READ fontPath NOTIFY fontPathChanged)

Q_PROPERTY(QString accentColor READ accentColor NOTIFY accentColorChanged)
Q_PROPERTY(QString fillColor READ fillColor NOTIFY fillColorChanged)
Expand Down Expand Up @@ -79,7 +79,7 @@ class Theme : public QObject {
int fontWeightLarge() { return m_fontWeightLarge; }
int fontWeightMedium() { return m_fontWeightMedium; }

QString fontFamily() { return m_fontFamily; }
QString fontPath() { return m_fontPath; }

QString accentColor() { return m_accentColor; }
QString fillColor() { return m_fillColor; }
Expand Down Expand Up @@ -126,7 +126,7 @@ class Theme : public QObject {
void fontSizeTinyChanged();
void fontWeightLargeChanged();
void fontWeightMediumChanged();
void fontFamilyChanged();
void fontPathChanged();

void accentColorChanged();
void fillColorChanged();
Expand Down Expand Up @@ -174,7 +174,7 @@ private slots:
int m_fontSizeTiny; // 16
int m_fontWeightLarge; // 63
int m_fontWeightMedium; // 25
QString m_fontFamily; //???
QString m_fontPath; //???

QString m_accentColor; //#0091e5
QString m_fillColor; //#474747
Expand Down

0 comments on commit 2d44776

Please sign in to comment.