Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add ability to choose font style #97

Merged
merged 1 commit into from
May 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 21,7 @@ A Plasma 5 version of the widget is available in the [plasma5 branch](https://gi

### 🛠️ Configurations
- **Icon customization:** Change the widget's icon in the panel view to suit your preferences. You can also choose to display the album cover.
- **Font customization:** Change the widget's text font to suit your preferences.
- **Playback controls visibility:** Choose whether to display Play, Pause, Next, and Previous controls in the panel view.
- **Preferred source**: Change the widget preferred source for music information (spotify, vlc, etc). The name of the source is the same as the desktop file name of the application (see `/usr/share/applications/`).
- **Playing song max display width**: Determine the maximum width for displaying the currently playing song in the panel. When the song's text exceeds this maximum width, the text will scroll horizontally.
Expand Down
6 changes: 6 additions & 0 deletions src/contents/config/main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 33,11 @@
<entry name="textScrollingBehaviour" type="int">
<default>0</default>
</entry>
<entry name="useCustomFont" type="Bool">
<default>false</default>
</entry>
<entry name="customFont" type="Font">
<default></default>
</entry>
</group>
</kcfg>
44 changes: 44 additions & 0 deletions src/contents/ui/ConfigGeneral.qml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 4,11 @@ import QtQuick.Layouts 1.15
import org.kde.kirigami as Kirigami
import org.kde.plasma.components as PlasmaComponents3
import org.kde.kcmutils as KCM
import QtQuick.Dialogs as QtDialogs

KCM.SimpleKCM {
id: configPage

property alias cfg_panelIcon: panelIcon.value
property alias cfg_useAlbumCoverAsPanelIcon: useAlbumCoverAsPanelIcon.checked
property alias cfg_albumCoverRadius: albumCoverRadius.value
Expand All @@ -17,6 20,9 @@ KCM.SimpleKCM {
property alias cfg_separateText: separateText.checked
property alias cfg_textScrollingBehaviour: scrollingBehaviourRadio.value

property alias cfg_useCustomFont: customFontCheckbox.checked
property alias cfg_customFont: fontDialog.fontChosen

Kirigami.FormLayout {
Kirigami.Separator {
Kirigami.FormData.isSection: true
Expand Down Expand Up @@ -63,6 69,32 @@ KCM.SimpleKCM {
Kirigami.FormData.isSection: true
Kirigami.FormData.label: "Song text"
}

RowLayout {
Kirigami.FormData.label: i18n("Font:")

CheckBox {
id: customFontCheckbox
text: i18n("Use custom font style")
}

Button {
text: i18n("Choose Style…")
icon.name: "settings-configure"
enabled: customFontCheckbox.checked
onClicked: {
fontDialog.open()
}
}

Label {
visible: customFontCheckbox.checked && fontDialog.fontChosen.family && fontDialog.fontChosen.pointSize
text: i18n("%1pt %2", fontDialog.fontChosen.pointSize, fontDialog.fontChosen.family)
textFormat: Text.PlainText
font: fontDialog.fontChosen
}
}

SpinBox {
id: maxSongWidthInPanel
from: 0
Expand Down Expand Up @@ -128,4 160,16 @@ KCM.SimpleKCM {
Kirigami.FormData.label: i18n("Show controls:")
}
}

QtDialogs.FontDialog {
id: fontDialog
title: i18n("Choose a Font")
modality: Qt.WindowModal
parentWindow: configPage.Window.window
property font fontChosen: Qt.font()
onAccepted: {
fontChosen = selectedFont
}
}

}
12 changes: 10 additions & 2 deletions src/contents/ui/main.qml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 11,11 @@ PlasmoidItem {

Plasmoid.status: PlasmaCore.Types.HiddenStatus

readonly property font textFont: {
return plasmoid.configuration.useCustomFont ? plasmoid.configuration.customFont : Kirigami.Theme.defaultFont
}
readonly property font boldTextFont: Qt.font(Object.assign({}, textFont, {weight: Font.Bold}))

Player {
id: player
sourceName: plasmoid.configuration.sources[plasmoid.configuration.sourceIndex]
Expand Down Expand Up @@ -62,13 67,14 @@ PlasmoidItem {
anchors.fill: parent
ScrollingText {
overflowBehaviour: plasmoid.configuration.textScrollingBehaviour
font.bold: true
font: widget.boldTextFont
speed: plasmoid.configuration.textScrollingSpeed
maxWidth: plasmoid.configuration.maxSongWidthInPanel
text: player.title
}
ScrollingText {
overflowBehaviour: plasmoid.configuration.textScrollingBehaviour
font: widget.textFont
speed: plasmoid.configuration.textScrollingSpeed
maxWidth: plasmoid.configuration.maxSongWidthInPanel
text: player.artists
Expand All @@ -82,6 88,7 @@ PlasmoidItem {
speed: plasmoid.configuration.textScrollingSpeed
maxWidth: plasmoid.configuration.maxSongWidthInPanel
text: [player.artists, player.title].filter((x) => x).join(" - ")
font: widget.textFont
}

PlasmaComponents3.ToolButton {
Expand Down Expand Up @@ -154,13 161,14 @@ PlasmoidItem {

ScrollingText {
speed: plasmoid.configuration.textScrollingSpeed
font.bold: true
font: widget.boldTextFont
maxWidth: 250
text: player.title
}

ScrollingText {
speed: plasmoid.configuration.textScrollingSpeed
font: widget.textFont
maxWidth: 250
text: player.artists
}
Expand Down