From fcbfbcbfeca9a31c5ed39ecb6fdc43476b1cd08a Mon Sep 17 00:00:00 2001 From: Marco Martin Date: Fri, 15 Jan 2021 16:15:06 +0000 Subject: [PATCH] properly size date label in vertical panels the Text.Fit sizing policy will size the font in order to fit given a fixed size of the label, but it can't really cause the other way around which we need: cause a vertical resize in order to accomodate a larger font. In order to fake that, we fix the date label to an arbitrary tall height (will overflow outside the applet) and then size the applet based on the label contentheight instead, leaving the invisible part of the label outside. In order to avoid the huge text it used to have, limit the maximum size to an arbitrarly small value, in this case Math.min(0.7 * timeLabel.height, theme.defaultFont.pixelSize * 1.4) BUG:417852 FIXED-IN: 5.21 --- .../package/contents/ui/DigitalClock.qml | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/applets/digital-clock/package/contents/ui/DigitalClock.qml b/applets/digital-clock/package/contents/ui/DigitalClock.qml index 1ff90e0a0..e404da522 100644 --- a/applets/digital-clock/package/contents/ui/DigitalClock.qml +++ b/applets/digital-clock/package/contents/ui/DigitalClock.qml @@ -152,6 +152,7 @@ Item { height: 0.8 * timeLabel.height width: dateLabel.paintedWidth + verticalAlignment: Text.AlignVCenter font.pixelSize: dateLabel.height } @@ -212,6 +213,8 @@ Item { height: timeLabel.height width: dateLabel.paintedWidth + font.pixelSize: 1024 + verticalAlignment: Text.AlignVCenter anchors.rightMargin: labelsGrid.columnSpacing fontSizeMode: Text.VerticalFit @@ -268,7 +271,7 @@ Item { PropertyChanges { target: contentItem - height: main.showDate ? labelsGrid.height + dateLabel.height : labelsGrid.height + height: main.showDate ? labelsGrid.height + dateLabel.contentHeight : labelsGrid.height width: main.width } @@ -303,9 +306,15 @@ Item { target: dateLabel width: main.width + //NOTE: in order for Text.Fit to work as intended, the actual height needs to be quite big, in order for the font to enlarge as much it needs for the available width, and then request a sensible height, for which contentHeight will need to be considered as opposed to height + height: PlasmaCore.Units.gridUnit * 10 fontSizeMode: Text.Fit - font.minimumPixelSize: Math.max(theme.smallestFont.pixelSize, timeLabel.height) + verticalAlignment: Text.AlignTop + // Those magic numbers are purely what looks nice as maximum size, here we have it the smallest + // between slightly bigger than the default font (1.4 times) and a bit smaller than the time font + font.pixelSize: Math.min(0.7 * timeLabel.height, PlasmaCore.Theme.defaultFont.pixelSize * 1.4) + font.minimumPixelSize: theme.smallestFont.pixelSize elide: Text.ElideRight wrapMode: Text.WordWrap } @@ -374,8 +383,10 @@ Item { PropertyChanges { target: dateLabel - height: 0.8 * timeLabel.height + height: 0.7 * timeLabel.height + font.pixelSize: 1024 width: Math.max(timeLabel.contentWidth, units.gridUnit * 3) + verticalAlignment: Text.AlignVCenter fontSizeMode: Text.Fit minimumPixelSize: 1