Skip to content

Conversation

@JarbasAl
Copy link
Member

@JarbasAl JarbasAl commented Nov 17, 2024

avoid inconsistencies like

image

example above is from speedtest skill, in a mk2 it works as intended due to screen resolution, in x86 we get the above instead of a page replacing the previous one

by default a single page should be displayed, scenarios where this isnt desired should use their own QML not system templates

Summary by CodeRabbit

Release Notes

  • New Features

    • Introduced fillWidth property across several components to enhance layout responsiveness.
    • Improved image display and caption visibility in the SYSTEM_ImageFrame.
    • Enhanced web view functionality with better error handling and interaction in the SYSTEM_UrlFrame.
  • Bug Fixes

    • Corrected logical conditions in the onPageUrlChanged handler for URL validation in the SYSTEM_UrlFrame.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 17, 2024

Walkthrough

The changes introduce a new property fillWidth set to true in various components such as Mycroft.Delegate, Mycroft.CardDelegate, and Mycroft.AbstractDelegate across multiple QML files. This property is intended to enhance layout behavior by allowing components to utilize the full width of their parent containers. Additionally, modifications include the introduction of a fill property in image-related components, which adjusts the display mode based on session data. The changes also refine visibility conditions for caption elements and improve error handling and functionality within web view components.

Changes

File Path Change Summary
ovos_gui/res/gui/qt5/SYSTEM_AnimatedImageFrame.qml Added fillWidth in Mycroft.Delegate, added property var fill in AnimatedImage, updated onFillChanged signal handler.
ovos_gui/res/gui/qt5/SYSTEM_HtmlFrame.qml Added fillWidth in Mycroft.Delegate.
ovos_gui/res/gui/qt5/SYSTEM_ImageFrame.qml Added fillWidth in Mycroft.Delegate, added property var fill in Image, updated onFillChanged signal handler.
ovos_gui/res/gui/qt5/SYSTEM_TextFrame.qml Added fillWidth in Mycroft.CardDelegate, defined hasTitle property.
ovos_gui/res/gui/qt5/SYSTEM_UrlFrame.qml Added fillWidth in Mycroft.AbstractDelegate, modified onPageUrlChanged, updated web view settings and handlers.

Possibly related PRs

Suggested labels

fix

Suggested reviewers

  • j1nx

Poem

🐇 In the garden of code where the rabbits play,
New properties bloom, brightening the day.
fillWidth spreads wide, like the sun's gentle rays,
Captions now dance, in their own special way.
With images bright, and layouts so neat,
Our GUI's a wonder, a joyful treat! 🌼


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@github-actions github-actions bot added fix and removed fix labels Nov 17, 2024
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (9)
ovos_gui/res/gui/qt5/SYSTEM_TextFrame.qml (2)

Line range hint 8-14: Consider improvements to overlay colors and property definition

  1. The hardcoded overlay colors could limit theme flexibility.
  2. The hasTitle property could be simplified.

Consider these improvements:

 Mycroft.CardDelegate {
     id: systemTextFrame
-    skillBackgroundColorOverlay: "#000000"
-    cardBackgroundOverlayColor: "#000000"
+    skillBackgroundColorOverlay: Kirigami.Theme.backgroundColor
+    cardBackgroundOverlayColor: Kirigami.Theme.backgroundColor
     fillWidth: true
 
-    property bool hasTitle: sessionData.title.length > 0 ? true : false
+    property bool hasTitle: sessionData.title.length > 0

Line range hint 16-17: Remove debugging color from Rectangle

The Rectangle has a hardcoded "blue" color which appears to be a debugging artifact.

Apply this change:

     contentItem: Rectangle {
-        color: "blue"
+        color: "transparent"
ovos_gui/res/gui/qt5/SYSTEM_ImageFrame.qml (2)

Line range hint 41-53: Refactor the fillMode handling for better maintainability

The current implementation has several issues:

  1. Uses magic numbers instead of Qt.FillMode enum values
  2. Contains debug console.log statements
  3. Has redundant else-if branches

Consider this cleaner implementation:

             onFillChanged: {
-                console.log(fill)
-                if(fill == "PreserveAspectCrop"){
-                    systemImageDisplay.fillMode = 2
-                } else if (fill == "PreserveAspectFit"){
-                    console.log("inFit")
-                    systemImageDisplay.fillMode = 1
-                } else if (fill == "Stretch"){
-                    systemImageDisplay.fillMode = 0
-                } else {
-                    systemImageDisplay.fillMode = 0
-                }
+                systemImageDisplay.fillMode = {
+                    "PreserveAspectCrop": Image.PreserveAspectCrop,
+                    "PreserveAspectFit": Image.PreserveAspectFit,
+                    "Stretch": Image.Stretch
+                }[fill] || Image.Stretch
             }

This change:

  • Uses proper Qt enum values for clarity
  • Removes debug logging
  • Simplifies the logic using an object lookup
  • Maintains the same default behavior

Line range hint 34-34: Consider documenting the fill property

The fill property controls important layout behavior but lacks documentation about its expected values and purpose.

Add a documentation comment:

+            // Controls image scaling behavior. Accepted values: "PreserveAspectCrop", "PreserveAspectFit", "Stretch"
             property var fill: sessionData.fill
ovos_gui/res/gui/qt5/SYSTEM_AnimatedImageFrame.qml (1)

Line range hint 39-52: Enhance code clarity and remove debug statements

Several improvements can be made to the fill mode handling:

  1. Replace magic numbers with Qt.FillMode enum values
  2. Remove console.log statements from production code
  3. Document the default behavior

Apply this diff to improve the code:

             onFillChanged: {
-                console.log(fill)
                 if(fill == "PreserveAspectCrop"){
-                    systemImageDisplay.fillMode = 2
+                    systemImageDisplay.fillMode = Image.PreserveAspectCrop
                 } else if (fill == "PreserveAspectFit"){
-                    console.log("inFit")
-                    systemImageDisplay.fillMode = 1
+                    systemImageDisplay.fillMode = Image.PreserveAspectFit
                 } else if (fill == "Stretch"){
-                    systemImageDisplay.fillMode = 0
+                    systemImageDisplay.fillMode = Image.Stretch
                 } else {
-                    systemImageDisplay.fillMode = 0
+                    // Default to Stretch mode when fill type is not specified
+                    systemImageDisplay.fillMode = Image.Stretch
                 }
             }
ovos_gui/res/gui/qt5/SYSTEM_UrlFrame.qml (4)

Line range hint 14-16: Fix incorrect URL validation logic

The current condition will always evaluate to true because a value cannot be both undefined AND null simultaneously. This could lead to attempts to load invalid URLs.

Apply this fix:

-    if(typeof pageUrl !== "undefined" || typeof pageUrl !== null){
+    if(typeof pageUrl !== "undefined" && pageUrl !== null){
         webview.url = pageUrl
     }

Line range hint 65-77: Add error handling for full-screen transitions

The full-screen handling stores and restores dimensions but lacks error handling. This could lead to undefined behavior if the stored dimensions are invalid.

Consider adding error handling:

     onFullScreenRequested: function(request) {
         if (request.toggleOn) {
+            try {
                 flickable.storeCWidth = flickable.contentWidth
                 flickable.storeCHeight = flickable.contentHeight
                 flickable.contentWidth = flickable.width
                 flickable.contentHeight = flickable.height
+            } catch (e) {
+                console.error("Failed to store dimensions:", e)
+                request.reject()
+                return
+            }
         }
         else {
+            try {
                 flickable.contentWidth = flickable.storeCWidth
                 flickable.contentHeight = flickable.storeCHeight
+            } catch (e) {
+                console.error("Failed to restore dimensions:", e)
+                request.reject()
+                return
+            }
         }
         request.accept()
     }

Line range hint 79-90: Add error handling for JavaScript execution

The content height adjustment lacks error handling for JavaScript execution failures.

Add error handling:

     onLoadingChanged: {
         if (loadRequest.status !== WebEngineView.LoadSucceededStatus) {
+            console.warn("Page load failed:", loadRequest.errorString)
             return;
         }

         flickable.contentHeight = 0;
         flickable.contentWidth = flickable.width;

         runJavaScript (
             "document.documentElement.scrollHeight;",
-            function (actualPageHeight) {
+            function (actualPageHeight, error) {
+                if (error) {
+                    console.error("Failed to get page height:", error)
+                    return;
+                }
                 flickable.contentHeight = Math.max (
                     actualPageHeight, flickable.height);
             });
     }

Line range hint 127-156: Improve popup implementation robustness

The popup implementation has several areas that could be improved:

  1. Hardcoded dimensions relative to root
  2. No cleanup handling
  3. Limited error handling in popup web view

Consider these improvements:

     Popup {
         id: popuproot
         modal: true
         focus: true
-        width: root.width - Kirigami.Units.largeSpacing * 1.25
-        height: root.height - Kirigami.Units.largeSpacing * 1.25
+        width: Math.min(root.width * 0.9, Kirigami.Units.gridUnit * 45)
+        height: Math.min(root.height * 0.9, Kirigami.Units.gridUnit * 35)
         closePolicy: Popup.CloseOnEscape | Popup.CloseOnPressOutsideParent
         anchors.centerIn: parent
+        onClosed: {
+            popupwebview.url = "about:blank"
+        }

         WebEngineView {
             id: popupwebview
             anchors.fill: parent
             url: "about:blank"
             // ... existing settings ...

             onNewViewRequested: function(request) {
-                console.log(request.destination)
+                console.warn("Nested popups are not supported:", request.destination)
+                request.reject()
             }
+            
+            onLoadingChanged: {
+                if (loadRequest.status === WebEngineView.LoadFailedStatus) {
+                    console.error("Popup load failed:", loadRequest.errorString)
+                }
+            }
         }
     }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between c7bbc11 and b77ebcf.

📒 Files selected for processing (5)
  • ovos_gui/res/gui/qt5/SYSTEM_AnimatedImageFrame.qml (1 hunks)
  • ovos_gui/res/gui/qt5/SYSTEM_HtmlFrame.qml (1 hunks)
  • ovos_gui/res/gui/qt5/SYSTEM_ImageFrame.qml (1 hunks)
  • ovos_gui/res/gui/qt5/SYSTEM_TextFrame.qml (1 hunks)
  • ovos_gui/res/gui/qt5/SYSTEM_UrlFrame.qml (1 hunks)
🔇 Additional comments (6)
ovos_gui/res/gui/qt5/SYSTEM_HtmlFrame.qml (1)

11-11: LGTM! The fillWidth property addition aligns with the PR objectives.

The change correctly implements full-width behavior for HTML frames, consistent with the PR's goal of standardizing page display.

Let's verify this change is consistently applied across other similar frame components:

✅ Verification successful

The fillWidth: true property is consistently applied across all SYSTEM frame components

The verification confirms that the fillWidth: true property is properly set in all related SYSTEM frame components:

  • SYSTEM_AnimatedImageFrame.qml
  • SYSTEM_ImageFrame.qml
  • SYSTEM_HtmlFrame.qml
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify fillWidth property is consistently applied across all SYSTEM frame components
# Expected: All SYSTEM frame QML files should have the fillWidth property set to true

# Search for all SYSTEM frame QML files and check for fillWidth property
fd -e qml SYSTEM_ -x grep -l "Mycroft.Delegate" {} \; | while read -r file; do
    echo "=== Checking $file ==="
    grep -A 5 "Mycroft.Delegate {" "$file"
done

Length of output: 1532

ovos_gui/res/gui/qt5/SYSTEM_TextFrame.qml (2)

12-12: LGTM: fillWidth property addition

The addition of fillWidth: true aligns with the PR objectives to ensure consistent full-width page display.


Line range hint 7-42: Verify consistent behavior with other system templates

The implementation looks correct, but let's verify it maintains consistency with other system templates.

✅ Verification successful

Consistent fillWidth implementation confirmed across system templates

The verification shows that all system templates (SYSTEM_*Frame.qml) consistently use fillWidth: true and proper layout management:

  • All templates use fillWidth: true at the delegate level
  • Layout components (ColumnLayout, Image, etc.) properly use Layout.fillWidth: true
  • Anchor usage is consistent and complementary to width settings
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for consistent fillWidth property usage across system templates
# and verify no conflicting width settings

# Search for other system templates and their width-related properties
rg -l "SYSTEM_.*\.qml" | xargs rg -l "fillWidth|width:"

# Check for potential conflicting anchors that might affect fillWidth
rg -l "SYSTEM_.*\.qml" | xargs rg "anchors\.(left|right|horizontalCenter)"

Length of output: 134


Script:

#!/bin/bash
# Let's try a different approach to find system templates and their properties

# First, let's find all SYSTEM QML files
fd "SYSTEM.*\.qml$"

# Then let's examine their content specifically for width-related properties
fd "SYSTEM.*\.qml$" --exec cat {}

Length of output: 14201

ovos_gui/res/gui/qt5/SYSTEM_ImageFrame.qml (1)

13-13: LGTM: fillWidth property addition aligns with PR objectives

The addition of fillWidth: true to the Delegate component ensures consistent full-width display behavior, which directly addresses the PR's goal of fixing full-width page issues.

ovos_gui/res/gui/qt5/SYSTEM_AnimatedImageFrame.qml (1)

13-13: LGTM: fillWidth property addition aligns with PR objectives

The addition of fillWidth: true ensures consistent full-width display behavior, which directly addresses the PR's goal of fixing full-width page display issues.

ovos_gui/res/gui/qt5/SYSTEM_UrlFrame.qml (1)

11-11: LGTM: fillWidth property addition

The addition of fillWidth: true aligns with the PR objectives to ensure consistent full-width page display.

@JarbasAl JarbasAl merged commit 37726bc into dev Nov 19, 2024
@JarbasAl JarbasAl deleted the fix/full_width_pages branch November 19, 2024 15:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants