From d1486dfb2e7f46940ac544276877ce21c7eef6dc Mon Sep 17 00:00:00 2001 From: Frederick Yin Date: Wed, 26 Jul 2023 15:09:10 +0800 Subject: Make list item expandable --- contents/ui/ActivityView.qml | 191 +++++++++++++++++++++++-------------------- 1 file changed, 102 insertions(+), 89 deletions(-) diff --git a/contents/ui/ActivityView.qml b/contents/ui/ActivityView.qml index 0e74a99..3f82325 100644 --- a/contents/ui/ActivityView.qml +++ b/contents/ui/ActivityView.qml @@ -14,118 +14,131 @@ PlasmaComponents.ListItem { id: activityItem separatorVisible: false enabled: true // enable mouse event handling - RowLayout { - id: activityView + property bool expanded: false + + ColumnLayout { width: (type == "announcement" ? announcementsListView : assignmentsListView).width 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", - } + 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 + onClicked: () => { + activityCheckbox.toggle() // toggle checkbox + activityCheckbox.toggled() // and trigger the onToggled effects + } } } } - } + RowLayout { + Layout.alignment: Qt.AlignRight - RowLayout { - Layout.alignment: Qt.AlignRight - - PlasmaComponents3.ToolButton { - icon.name: "view-visible" - // only show when mouse is hovering above this activity - opacity: activityItem.containsMouse ? 1 : 0 - onClicked: () => { - Qt.openUrlExternally(url) + PlasmaComponents3.ToolButton { + icon.name: "expand" + // only show when mouse is hovering above this activity + opacity: activityItem.containsMouse ? 1 : 0 + onClicked: () => { + expanded = !expanded + } } - } - 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", + PlasmaComponents3.ToolButton { + icon.name: "view-visible" + opacity: activityItem.containsMouse ? 1 : 0 + onClicked: () => { + Qt.openUrlExternally(url) } + } - let importantActivities = plasmoid.configuration[configKeys[type]] - if (important) { - if (!importantActivities.includes(activityId)) { - importantActivities.push(activityId) + 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", + } + + 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 + ) } - } else { - // remove activityId from list - importantActivities.splice( - importantActivities.indexOf(activityId), 1 - ) + // save config + plasmoid.configuration[configKeys[type]] = importantActivities } - // save config - plasmoid.configuration[configKeys[type]] = importantActivities } } } + + PlasmaExtras.Paragraph { + visible: expanded + text: "Hello world!" + } } } -- cgit v1.2.3 From 668732f0188d9f98ac63bae368d4ecbff4cf571c Mon Sep 17 00:00:00 2001 From: Frederick Yin Date: Wed, 26 Jul 2023 15:34:07 +0800 Subject: Fetch and display announcement message --- contents/ui/ActivityView.qml | 4 +++- contents/ui/kanvas.js | 2 ++ contents/ui/main.qml | 1 + 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/contents/ui/ActivityView.qml b/contents/ui/ActivityView.qml index 3f82325..38b92f1 100644 --- a/contents/ui/ActivityView.qml +++ b/contents/ui/ActivityView.qml @@ -86,6 +86,7 @@ PlasmaComponents.ListItem { PlasmaComponents3.ToolButton { icon.name: "expand" + visible: type == "announcement" // only show when mouse is hovering above this activity opacity: activityItem.containsMouse ? 1 : 0 onClicked: () => { @@ -137,8 +138,9 @@ PlasmaComponents.ListItem { } PlasmaExtras.Paragraph { + Layout.fillWidth: true visible: expanded - text: "Hello world!" + text: message } } } 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..0fb0b64 100644 --- a/contents/ui/main.qml +++ b/contents/ui/main.qml @@ -58,6 +58,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 -- cgit v1.2.3 From b2555cb09aa6f1b92cb41746ab546303ed6da38d Mon Sep 17 00:00:00 2001 From: Frederick Yin Date: Wed, 26 Jul 2023 18:15:35 +0800 Subject: Set clearance for scrollbar --- contents/ui/ActivityView.qml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/contents/ui/ActivityView.qml b/contents/ui/ActivityView.qml index 38b92f1..2f11db9 100644 --- a/contents/ui/ActivityView.qml +++ b/contents/ui/ActivityView.qml @@ -17,7 +17,10 @@ PlasmaComponents.ListItem { property bool expanded: false ColumnLayout { - width: (type == "announcement" ? announcementsListView : assignmentsListView).width + width: + (type == "announcement" + ? announcementsListView : assignmentsListView).width + - PlasmaCore.Units.gridUnit // clearance for scrollbar Layout.fillWidth: true RowLayout { RowLayout { -- cgit v1.2.3 From a3ce413e6bdbd119e5079e5e6edf98ed0a3c97a7 Mon Sep 17 00:00:00 2001 From: Frederick Yin Date: Wed, 26 Jul 2023 18:37:11 +0800 Subject: Add a bunch of comments --- contents/ui/ActivityView.qml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/contents/ui/ActivityView.qml b/contents/ui/ActivityView.qml index 2f11db9..ff27a14 100644 --- a/contents/ui/ActivityView.qml +++ b/contents/ui/ActivityView.qml @@ -10,6 +10,7 @@ import org.kde.plasma.extras 2.0 as PlasmaExtras import "activity.js" as Activity +// container for one single activity PlasmaComponents.ListItem { id: activityItem separatorVisible: false @@ -20,9 +21,10 @@ PlasmaComponents.ListItem { width: (type == "announcement" ? announcementsListView : assignmentsListView).width - - PlasmaCore.Units.gridUnit // clearance for scrollbar + - PlasmaCore.Units.gridUnit // HACK: clearance for scrollbar Layout.fillWidth: true RowLayout { + // "finished" checkbox and activity title RowLayout { PlasmaComponents3.CheckBox { id: activityCheckbox @@ -84,6 +86,7 @@ PlasmaComponents.ListItem { } } + // buttons RowLayout { Layout.alignment: Qt.AlignRight @@ -140,6 +143,7 @@ PlasmaComponents.ListItem { } } + // announcement message PlasmaExtras.Paragraph { Layout.fillWidth: true visible: expanded -- cgit v1.2.3 From d6e5294daece7e56b271f53a5d496f5edd620916 Mon Sep 17 00:00:00 2001 From: Frederick Yin Date: Wed, 26 Jul 2023 18:47:56 +0800 Subject: Clicking title opens activity instead of toggling finished --- contents/ui/ActivityView.qml | 30 +++++++++--------------------- 1 file changed, 9 insertions(+), 21 deletions(-) diff --git a/contents/ui/ActivityView.qml b/contents/ui/ActivityView.qml index ff27a14..febc4e0 100644 --- a/contents/ui/ActivityView.qml +++ b/contents/ui/ActivityView.qml @@ -78,9 +78,16 @@ PlasmaComponents.ListItem { MouseArea { width: parent.width height: parent.height + cursorShape: + type == "announcement" + ? Qt.ArrowCursor + : Qt.PointingHandCursor onClicked: () => { - activityCheckbox.toggle() // toggle checkbox - activityCheckbox.toggled() // and trigger the onToggled effects + if (type == "announcement") { + expanded = !expanded + } else { + Qt.openUrlExternally(url) + } } } } @@ -89,25 +96,6 @@ PlasmaComponents.ListItem { // buttons RowLayout { Layout.alignment: Qt.AlignRight - - PlasmaComponents3.ToolButton { - icon.name: "expand" - visible: type == "announcement" - // only show when mouse is hovering above this activity - opacity: activityItem.containsMouse ? 1 : 0 - onClicked: () => { - expanded = !expanded - } - } - - PlasmaComponents3.ToolButton { - icon.name: "view-visible" - opacity: activityItem.containsMouse ? 1 : 0 - onClicked: () => { - Qt.openUrlExternally(url) - } - } - PlasmaComponents3.ToolButton { icon.name: "emblem-important-symbolic" checked: important -- cgit v1.2.3 From db589d8f552e6ddaf80712fbbddfe2f296b135b4 Mon Sep 17 00:00:00 2001 From: Frederick Yin Date: Wed, 26 Jul 2023 19:10:25 +0800 Subject: Add open in browser button in expanded view --- contents/ui/ActivityView.qml | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/contents/ui/ActivityView.qml b/contents/ui/ActivityView.qml index febc4e0..1407e64 100644 --- a/contents/ui/ActivityView.qml +++ b/contents/ui/ActivityView.qml @@ -137,5 +137,14 @@ PlasmaComponents.ListItem { visible: expanded text: message } + + PlasmaComponents3.Button { + icon.name: "internet-web-browser" + visible: expanded + text: "Open in browser" + onClicked: () => { + Qt.openUrlExternally(url) + } + } } } -- cgit v1.2.3 From 119255ee7c0e76edbc9a43e4550ccb664d0baea3 Mon Sep 17 00:00:00 2001 From: Frederick Yin Date: Thu, 27 Jul 2023 10:35:58 +0800 Subject: Add missing i18n()s --- contents/ui/ActivityView.qml | 2 +- contents/ui/configCanvas.qml | 4 ++-- contents/ui/main.qml | 12 ++++++------ 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/contents/ui/ActivityView.qml b/contents/ui/ActivityView.qml index 1407e64..c8ec3c9 100644 --- a/contents/ui/ActivityView.qml +++ b/contents/ui/ActivityView.qml @@ -141,7 +141,7 @@ PlasmaComponents.ListItem { PlasmaComponents3.Button { icon.name: "internet-web-browser" visible: expanded - text: "Open in browser" + 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/main.qml b/contents/ui/main.qml index 0fb0b64..7e4b3ba 100644 --- a/contents/ui/main.qml +++ b/contents/ui/main.qml @@ -43,12 +43,12 @@ Item { PlasmaExtras.Heading { level: 1 - text: "Kanvas" + text: i18n("Kanvas") } PlasmaExtras.Heading { level: 2 - text: "Announcements" + text: i18n("Announcements") } ListModel { @@ -86,14 +86,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 { @@ -132,7 +132,7 @@ Item { width: parent.width - (PlasmaCore.Units.largeSpacing * 4) visible: assignmentsModel.count == 0 iconName: "mail-read-symbolic" - text: "No assignments" + text: i18n("No assignments") } } } @@ -147,7 +147,7 @@ Item { PlasmaComponents3.Label { id: offlineLabel visible: networkStatus.networkStatus != "Connected" - text: "Network disconnected" + text: i18n("Network disconnected") color: PlasmaCore.Theme.negativeTextColor } } -- cgit v1.2.3 From 8a01f6d979e3d452dbec10be7f8f0fab82d7fbb6 Mon Sep 17 00:00:00 2001 From: Frederick Yin Date: Thu, 27 Jul 2023 11:41:09 +0800 Subject: Use pointing hand cursor for announcements too --- contents/ui/ActivityView.qml | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/contents/ui/ActivityView.qml b/contents/ui/ActivityView.qml index c8ec3c9..6eb7e26 100644 --- a/contents/ui/ActivityView.qml +++ b/contents/ui/ActivityView.qml @@ -78,10 +78,7 @@ PlasmaComponents.ListItem { MouseArea { width: parent.width height: parent.height - cursorShape: - type == "announcement" - ? Qt.ArrowCursor - : Qt.PointingHandCursor + cursorShape: Qt.PointingHandCursor onClicked: () => { if (type == "announcement") { expanded = !expanded -- cgit v1.2.3 From c82c7b64b82657693a9e2b466a2d8803ce393f07 Mon Sep 17 00:00:00 2001 From: Frederick Yin Date: Sat, 29 Jul 2023 15:14:16 +0800 Subject: Add reminder to migrate to KF6 --- README.md | 1 + contents/ui/ActivityView.qml | 1 + contents/ui/main.qml | 1 + 3 files changed, 3 insertions(+) diff --git a/README.md b/README.md index b91e3b7..7a3860a 100644 --- a/README.md +++ b/README.md @@ -38,6 +38,7 @@ add the widget to your desktop it has to be configured again. - [ ] More friendly course list in config dialog - [ ] Ignore activity and undo ignore - [ ] Show announcement details +- [ ] Migrate to KF6 when it replaces KF5 (see [Porting guide](https://develop.kde.org/docs/plasma/widget/porting_kf6/)) ## Contributing diff --git a/contents/ui/ActivityView.qml b/contents/ui/ActivityView.qml index 6eb7e26..4b32cf4 100644 --- a/contents/ui/ActivityView.qml +++ b/contents/ui/ActivityView.qml @@ -11,6 +11,7 @@ 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 diff --git a/contents/ui/main.qml b/contents/ui/main.qml index 7e4b3ba..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 -- cgit v1.2.3