Skip to content

Commit

Permalink
Add ListLink component to show either QR code or link button
Browse files Browse the repository at this point in the history
Part of #1811
  • Loading branch information
blammit committed Jan 7, 2025
1 parent 377aec8 commit 4092b36
Show file tree
Hide file tree
Showing 7 changed files with 100 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,7 @@ set (VENUS_QML_MODULE_SOURCES
components/listitems/ListFirmwareCheckButton.qml
components/listitems/ListFirmwareVersion.qml
components/listitems/ListGeneratorError.qml
components/listitems/ListLink.qml
components/listitems/ListMqttAccessSwitch.qml
components/listitems/ListMountStateButton.qml
components/listitems/ListPvInverterPositionRadioButtonGroup.qml
Expand Down Expand Up @@ -1049,6 +1050,7 @@ qt_add_resources(${PROJECT_NAME} "${PROJECT_NAME}_large_resources"
images/icon_hydraulic_oil_24.svg
images/icon_lng_24.svg
images/icon_lpg_24.svg
images/icon_open_link_32.svg
images/icon_to_grid.svg
images/fueltank.svg
images/gauge_intro_5_matte_black.gif
Expand Down
79 changes: 79 additions & 0 deletions components/listitems/ListLink.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/*
** Copyright (C) 2024 Victron Energy B.V.
** See LICENSE.txt for license information.
*/

import QtQuick
import QtQuick.Controls.impl as CP
import Victron.VenusOS

ListItem {
id: root

property string url
property string caption: root.mode === VenusOS.ListLink_Mode_LinkButton ? ""
//: %1 = url text
//% "Scan the QR code with your portable device.<br />Or insert the link: %1"
: qsTrId("listlink_scan_qr_code").arg(formattedUrl)
readonly property string formattedUrl: "<font color=\"%1\">%2</font>".arg(Theme.color_font_primary).arg(url)

readonly property int mode: Qt.platform.os == "wasm" ? VenusOS.ListLink_Mode_LinkButton : VenusOS.ListLink_Mode_QRCode

down: pressArea.containsPress

content.children: [
SecondaryListLabel {
visible: root.mode === VenusOS.ListLink_Mode_LinkButton
anchors.verticalCenter: parent.verticalCenter
width: Math.min(implicitWidth, root.maximumContentWidth - icon.width - root.content.spacing)
//% "Open link"
text: qsTrId("listlink_open_link")
},

CP.ColorImage {
id: icon

visible: root.mode === VenusOS.ListLink_Mode_LinkButton
anchors.verticalCenter: parent.verticalCenter
source: "qrc:/images/icon_open_link_32.svg"
rotation: 180
color: pressArea.containsPress ? Theme.color_listItem_down_forwardIcon : Theme.color_listItem_forwardIcon
},

Item {
visible: root.mode === VenusOS.ListLink_Mode_QRCode
width: Theme.geometry_listLink_qrCodeSize
height: Theme.geometry_listLink_qrCodeSize + (2 * Theme.geometry_listItem_content_verticalMargin)

Image {
anchors.centerIn: parent
source: root.mode === VenusOS.ListLink_Mode_QRCode
? "image://QZXing/encode/" + root.url + "?correctionLevel=M" + "&format=qrcode"
: ""
sourceSize.width: Theme.geometry_listLink_qrCodeSize
sourceSize.height: Theme.geometry_listLink_qrCodeSize
}
}
]

bottomContentChildren: [
PrimaryListLabel {
font.pixelSize: Theme.font_size_body1
horizontalAlignment: Text.AlignLeft
color: Theme.color_listItem_secondaryText
text: root.caption
visible: root.mode === VenusOS.ListLink_Mode_QRCode
}
]

ListPressArea {
id: pressArea

enabled: root.mode === VenusOS.ListLink_Mode_LinkButton
radius: backgroundRect.radius
anchors.fill: root.backgroundRect
onClicked: {
BackendConnection.openUrl(root.url)
}
}
}
4 changes: 4 additions & 0 deletions images/icon_open_link_32.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions pages/settings/debug/PageSettingsDemo.qml
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,11 @@ Page {
}
]
}

ListLink {
text: "Victron Energy"
url: "http://www.victronenergy.com"
}
}
}

Expand Down
6 changes: 6 additions & 0 deletions src/enums.h
Original file line number Diff line number Diff line change
Expand Up @@ -737,6 +737,12 @@ class Enums : public QObject
};
Q_ENUM(ListItem_BottomContentSizeMode)

enum ListLink_Mode {
ListLink_Mode_LinkButton,
ListLink_Mode_QRCode
};
Q_ENUM(ListLink_Mode)

Q_INVOKABLE QString battery_modeToText(Battery_Mode mode) const;
Q_INVOKABLE Battery_Mode battery_modeFromPower(qreal power) const;

Expand Down
2 changes: 2 additions & 0 deletions themes/geometry/FiveInch.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@
"geometry_listItem_textField_minimumWidth": 200,
"geometry_listItem_textField_maximumWidth": 376,

"geometry_listLink_qrCodeSize": 96,

"geometry_slider_groove_height": 8,
"geometry_slider_groove_radius": 8,

Expand Down
2 changes: 2 additions & 0 deletions themes/geometry/SevenInch.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@
"geometry_listItem_textField_minimumWidth": 236,
"geometry_listItem_textField_maximumWidth": 472,

"geometry_listLink_qrCodeSize": 96,

"geometry_slider_groove_height": 8,
"geometry_slider_groove_radius": 8,

Expand Down

0 comments on commit 4092b36

Please sign in to comment.