diff options
author | Frederick Yin <fkfd@fkfd.me> | 2023-07-29 15:15:24 +0800 |
---|---|---|
committer | Frederick Yin <fkfd@fkfd.me> | 2023-07-29 15:15:24 +0800 |
commit | 3d6239a9288d091f0a365e775365e8fa033db822 (patch) | |
tree | 722b361f0d0c9d4625917a67451fdf8d7b98fa34 /contents/ui | |
parent | a49cf62f9c0d56e2edd8543fbf7e48d0b9b9bea3 (diff) | |
parent | c82c7b64b82657693a9e2b466a2d8803ce393f07 (diff) |
Merge branch 'expand'
Diffstat (limited to 'contents/ui')
-rw-r--r-- | contents/ui/ActivityView.qml | 201 | ||||
-rw-r--r-- | contents/ui/configCanvas.qml | 4 | ||||
-rw-r--r-- | contents/ui/kanvas.js | 2 | ||||
-rw-r--r-- | contents/ui/main.qml | 14 |
4 files changed, 121 insertions, 100 deletions
diff --git a/contents/ui/ActivityView.qml b/contents/ui/ActivityView.qml index 0e74a99..4b32cf4 100644 --- a/contents/ui/ActivityView.qml +++ b/contents/ui/ActivityView.qml @@ -10,121 +10,138 @@ import org.kde.plasma.extras 2.0 as PlasmaExtras import "activity.js" as Activity +// container for one single activity +// TODO: port to PlasmaComponents3 before release of KF6 PlasmaComponents.ListItem { id: activityItem separatorVisible: false enabled: true // enable mouse event handling - RowLayout { - id: activityView - width: (type == "announcement" ? announcementsListView : assignmentsListView).width - Layout.fillWidth: true + property bool expanded: false + ColumnLayout { + width: + (type == "announcement" + ? announcementsListView : assignmentsListView).width + - PlasmaCore.Units.gridUnit // HACK: clearance for scrollbar + Layout.fillWidth: true RowLayout { - Layout.fillWidth: true - PlasmaComponents3.CheckBox { - id: activityCheckbox - checkState: finished ? Qt.Checked : Qt.Unchecked - onToggled: () => { - finished = (checkState == Qt.Checked) - activityLabel.font.strikeout = (checkState == Qt.Checked) - - const configKeys = { - announcement: "finishedAnnouncements", - assignment: "finishedAssignments", - } + // "finished" checkbox and activity title + RowLayout { + PlasmaComponents3.CheckBox { + id: activityCheckbox + checkState: finished ? Qt.Checked : Qt.Unchecked + onToggled: () => { + finished = (checkState == Qt.Checked) + activityLabel.font.strikeout = (checkState == Qt.Checked) + + const configKeys = { + announcement: "finishedAnnouncements", + assignment: "finishedAssignments", + } - let finishedActivities = plasmoid.configuration[configKeys[type]] - if (finished) { - if (!finishedActivities.includes(activityId)) { - finishedActivities.push(activityId) + let finishedActivities = plasmoid.configuration[configKeys[type]] + if (finished) { + if (!finishedActivities.includes(activityId)) { + finishedActivities.push(activityId) + } + } else { + // remove activityId from list + finishedActivities.splice( + finishedActivities.indexOf(activityId), 1 + ) } - } else { - // remove activityId from list - finishedActivities.splice( - finishedActivities.indexOf(activityId), 1 - ) + // save config + plasmoid.configuration[configKeys[type]] = finishedActivities } - // save config - plasmoid.configuration[configKeys[type]] = finishedActivities } - } - ColumnLayout { - PlasmaComponents3.Label { - id: activityLabel - text: `[${course}] ${title}` - font.bold: important - font.strikeout: finished - color: important - ? PlasmaCore.Theme.negativeTextColor - : PlasmaCore.Theme.textColor - wrapMode: Text.WordWrap - Layout.fillWidth: true - } + ColumnLayout { + PlasmaComponents3.Label { + id: activityLabel + text: `[${course}] ${title}` + font.bold: important + font.strikeout: finished + color: important + ? PlasmaCore.Theme.negativeTextColor + : PlasmaCore.Theme.textColor + wrapMode: Text.WordWrap + Layout.fillWidth: true + } - PlasmaComponents3.Label { - id: dueLabel - visible: type == "assignment" - text: Activity.dueLabelText() - color: activityLabel.color - Layout.fillWidth: true - } + PlasmaComponents3.Label { + id: dueLabel + visible: type == "assignment" + text: Activity.dueLabelText() + color: activityLabel.color + Layout.fillWidth: true + } - MouseArea { - width: parent.width - height: parent.height - onClicked: () => { - activityCheckbox.toggle() // toggle checkbox - activityCheckbox.toggled() // and trigger the onToggled effects + MouseArea { + width: parent.width + height: parent.height + cursorShape: Qt.PointingHandCursor + onClicked: () => { + if (type == "announcement") { + expanded = !expanded + } else { + Qt.openUrlExternally(url) + } + } } } } - } + // buttons + RowLayout { + Layout.alignment: Qt.AlignRight + PlasmaComponents3.ToolButton { + icon.name: "emblem-important-symbolic" + checked: important + opacity: activityItem.containsMouse ? 1 : 0 - RowLayout { - Layout.alignment: Qt.AlignRight + onClicked: () => { + important = !important + activityLabel.font.bold = important + activityLabel.color = important + ? PlasmaCore.Theme.negativeTextColor + : PlasmaCore.Theme.textColor + + const configKeys = { + announcement: "importantAnnouncements", + assignment: "importantAssignments", + } - PlasmaComponents3.ToolButton { - icon.name: "view-visible" - // only show when mouse is hovering above this activity - opacity: activityItem.containsMouse ? 1 : 0 - onClicked: () => { - Qt.openUrlExternally(url) + let importantActivities = plasmoid.configuration[configKeys[type]] + if (important) { + if (!importantActivities.includes(activityId)) { + importantActivities.push(activityId) + } + } else { + // remove activityId from list + importantActivities.splice( + importantActivities.indexOf(activityId), 1 + ) + } + // save config + plasmoid.configuration[configKeys[type]] = importantActivities + } } } + } - PlasmaComponents3.ToolButton { - icon.name: "emblem-important-symbolic" - checked: important - opacity: activityItem.containsMouse ? 1 : 0 - - onClicked: () => { - important = !important - activityLabel.font.bold = important - activityLabel.color = important - ? PlasmaCore.Theme.negativeTextColor - : PlasmaCore.Theme.textColor - - const configKeys = { - announcement: "importantAnnouncements", - assignment: "importantAssignments", - } + // announcement message + PlasmaExtras.Paragraph { + Layout.fillWidth: true + visible: expanded + text: message + } - let importantActivities = plasmoid.configuration[configKeys[type]] - if (important) { - if (!importantActivities.includes(activityId)) { - importantActivities.push(activityId) - } - } else { - // remove activityId from list - importantActivities.splice( - importantActivities.indexOf(activityId), 1 - ) - } - // save config - plasmoid.configuration[configKeys[type]] = importantActivities - } + PlasmaComponents3.Button { + icon.name: "internet-web-browser" + visible: expanded + text: i18n("Open in browser") + onClicked: () => { + Qt.openUrlExternally(url) } } } diff --git a/contents/ui/configCanvas.qml b/contents/ui/configCanvas.qml index aed1a3e..26f611e 100644 --- a/contents/ui/configCanvas.qml +++ b/contents/ui/configCanvas.qml @@ -63,13 +63,13 @@ Kirigami.FormLayout { Button { icon.name: "download" - text: "Fetch courses" + text: i18n("Fetch courses") onClicked: fetchCourses() } Label { id: fetchCoursesStatus - text: "Fetching courses from Canvas will overwrite your current config." + text: i18n("Fetching courses from Canvas will overwrite your current config.") } } diff --git a/contents/ui/kanvas.js b/contents/ui/kanvas.js index dbd2526..a8a8f7c 100644 --- a/contents/ui/kanvas.js +++ b/contents/ui/kanvas.js @@ -83,6 +83,7 @@ function syncCourses(courses, courseIndices, showSubmittedAssignments, userId) { courseId: course.id, course: course.code, title: announcement.title, + message: announcement.message, url: announcement.html_url, important: plasmoid.configuration.importantAnnouncements .includes(announcement.id.toString()), @@ -133,6 +134,7 @@ function syncCourses(courses, courseIndices, showSubmittedAssignments, userId) { courseId: course.id, course: course.code, title: assignment.name, + message: "", // if null, use empty string to suppress errors dueAt: assignment.due_at || "", submitted: submitted, diff --git a/contents/ui/main.qml b/contents/ui/main.qml index 6fd20bc..4e3be19 100644 --- a/contents/ui/main.qml +++ b/contents/ui/main.qml @@ -11,6 +11,7 @@ import org.kde.plasma.networkmanagement 0.2 as PlasmaNM import "kanvas.js" as Kanvas +// TODO: change to PlasmoidItem on KF6 Item { width: PlasmaCore.Units.gridUnit * 20 height: PlasmaCore.Units.gridUnit * 40 @@ -43,12 +44,12 @@ Item { PlasmaExtras.Heading { level: 1 - text: "Kanvas" + text: i18n("Kanvas") } PlasmaExtras.Heading { level: 2 - text: "Announcements" + text: i18n("Announcements") } ListModel { @@ -58,6 +59,7 @@ Item { type: "announcement" course: "CS101" title: "Code quality" + message: "Code may be a little messy…" url: "https://xkcd.com/1513" important: true finished: false @@ -85,14 +87,14 @@ Item { width: parent.width - (PlasmaCore.Units.largeSpacing * 4) visible: announcementsModel.count == 0 iconName: "mail-read-symbolic" - text: "No announcements" + text: i18n("No announcements") } } } PlasmaExtras.Heading { level: 2 - text: "Assignments" + text: i18n("Assignments") } ListModel { @@ -131,7 +133,7 @@ Item { width: parent.width - (PlasmaCore.Units.largeSpacing * 4) visible: assignmentsModel.count == 0 iconName: "mail-read-symbolic" - text: "No assignments" + text: i18n("No assignments") } } } @@ -146,7 +148,7 @@ Item { PlasmaComponents3.Label { id: offlineLabel visible: networkStatus.networkStatus != "Connected" - text: "Network disconnected" + text: i18n("Network disconnected") color: PlasmaCore.Theme.negativeTextColor } } |