Verified Commit e421073f authored by Fushan Wen's avatar Fushan Wen 💬
Browse files

calendar: Add support for sublabel in DayDelegate

The sublabel will be displayed under the day number.

CCBUG: 429892
parent 54728d54
......@@ -11,6 +11,7 @@ import QtQuick 2.0
import org.kde.plasma.core 2.0 as PlasmaCore
import org.kde.plasma.components 3.0 as PlasmaComponents3
import org.kde.plasma.extras 2.0 as PlasmaExtras
import QtQml 2.15 // For Date
import QtQml.Models 2.15
import org.kde.kirigami 2.12 as Kirigami
......@@ -74,15 +75,19 @@ PlasmaComponents3.AbstractButton {
Loader {
active: model.eventCount !== undefined && model.eventCount > 0
anchors.bottom: parent.bottom
anchors.bottomMargin: PlasmaCore.Units.smallSpacing
anchors.bottomMargin: subDayLabel.item ? subDayLabel.item.implicitHeight
: PlasmaCore.Units.smallSpacing
anchors.horizontalCenter: parent.horizontalCenter
sourceComponent: Row {
spacing: PlasmaCore.Units.smallSpacing
property bool hasSubDayLabel: false
Repeater {
model: DelegateModel {
model: dayStyle.dayModel
delegate: Rectangle {
width: PlasmaCore.Units.smallSpacing * 1.5
width: PlasmaCore.Units.smallSpacing * (hasSubDayLabel ? 1 : 1.5)
height: width
radius: width / 2
color: model.eventColor ? Kirigami.ColorUtils.linearInterpolation(model.eventColor, PlasmaCore.Theme.textColor, 0.2) : PlasmaCore.Theme.highlightColor
......@@ -92,16 +97,69 @@ PlasmaComponents3.AbstractButton {
}
}
}
onLoaded: item.hasSubDayLabel = Qt.binding(() => subDayLabel.active)
}
contentItem: PlasmaExtras.Heading {
id: label
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter
text: model.label || dayNumber
opacity: isCurrent ? 1.0 : 0.5
wrapMode: Text.NoWrap
elide: Text.ElideRight
fontSizeMode: Text.HorizontalFit
contentItem: Item {
// ColumnLayout makes scrolling too slow, so use anchors to position labels
anchors.fill: parent
PlasmaExtras.Heading {
id: label
anchors {
left: parent.left
right: parent.right
top: parent.top
bottom: subDayLabel.top
}
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter
text: model.label || dayNumber
opacity: isCurrent ? 1.0 : 0.5
wrapMode: Text.NoWrap
elide: Text.ElideRight
fontSizeMode: Text.HorizontalFit
}
Loader {
id: subDayLabel
active: (!!model.subDayLabel && model.subDayLabel.length > 0)
|| typeof(model.alternateDayNumber) === "number"
anchors {
left: parent.left
right: parent.right
bottom: parent.bottom
}
sourceComponent: PlasmaComponents3.Label {
elide: Text.ElideRight
font.pointSize: Kirigami.Theme.smallFont.pointSize
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter
maximumLineCount: 1
opacity: label.opacity
// Prefer sublabel over day number
text: model.subDayLabel || model.alternateDayNumber.toString()
textFormat: Text.PlainText
wrapMode: Text.NoWrap
}
}
Loader {
id: tooltipLoader
active: !!model.subLabel
sourceComponent: PlasmaComponents3.ToolTip {
visible: Kirigami.Settings.isMobile? dayStyle.pressed : dayStyle.hovered
text: model.subLabel
}
onLoaded: {
if (dayStyle.today) {
root.todayAuxilliaryText = model.subLabel;
}
}
}
}
}
......@@ -40,6 +40,9 @@ PinchArea { // TODO KF6 switch to Item
property QtObject date
property date currentDate
property string todayAuxilliaryText: ""
// Bind to todayAuxilliaryText so sublabel can be visible on debut
property string currentDateAuxilliaryText: todayAuxilliaryText
property date showDate: new Date()
......@@ -79,6 +82,7 @@ PinchArea { // TODO KF6 switch to Item
function resetToToday() {
calendarBackend.resetToToday();
root.currentDate = root.today;
root.currentDateAuxilliaryText = root.todayAuxilliaryText;
swipeView.currentIndex = 0;
}
......@@ -352,6 +356,10 @@ PinchArea { // TODO KF6 switch to Item
const rowNumber = Math.floor(index / columns);
week = 1 + calendarBackend.weeksModel[rowNumber];
root.currentDate = new Date(date.yearNumber, date.monthNumber - 1, date.dayNumber)
if (date.subLabel) {
root.currentDateAuxilliaryText = date.subLabel;
}
}
onScrollUp: root.nextView()
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment