Skip to content

Commit

Permalink
Modernize QML for Qt 6
Browse files Browse the repository at this point in the history
- Qt Quick Controls 1 are gone (required a bit of refactoring between
  FileContent and Attachment)
- Explicit signal handler parameters where needed
- Using inline components and required properties where it makes sense
  • Loading branch information
KitsuneRal committed Jun 27, 2023
1 parent 660ac10 commit e721aa4
Show file tree
Hide file tree
Showing 11 changed files with 106 additions and 108 deletions.
32 changes: 15 additions & 17 deletions client/qml/Attachment.qml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ Item {
width: parent.width
height: visible ? childrenRect.height : 0

property bool openOnFinished: false
required property bool openOnFinished
readonly property bool downloaded: progressInfo &&
!progressInfo.isUpload && progressInfo.completed
signal opened

onDownloadedChanged: {
if (downloaded && openOnFinished)
Expand All @@ -19,27 +20,24 @@ Item {
if (progressInfo.localPath.toString() || downloaded)
openLocalFile()
else
{
openOnFinished = true
room.downloadFile(eventId)
}
}

function openLocalFile()
{
if (Qt.openUrlExternally(progressInfo.localPath))
return;

controller.showStatusMessage(
"Couldn't determine how to open the file, " +
"opening its folder instead", 5000)

if (Qt.openUrlExternally(progressInfo.localDir))
return;

controller.showStatusMessage(
"Couldn't determine how to open the file or its folder.",
5000)
if (!Qt.openUrlExternally(progressInfo.localPath)) {
controller.showStatusMessage(
"Couldn't determine how to open the file, " +
"opening its folder instead", 5000)

if (!Qt.openUrlExternally(progressInfo.localDir)) {
controller.showStatusMessage(
"Couldn't determine how to open the file or its folder.",
5000)
return;
}
}
opened()
}

Connections {
Expand Down
5 changes: 3 additions & 2 deletions client/qml/AuthorInteractionArea.qml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
TimelineMouseArea {
property var authorId
required property var authorId

enabled: parent.visible
anchors.fill: parent
Expand All @@ -8,8 +8,9 @@ TimelineMouseArea {
hoverEnabled: true
onEntered: controller.showStatusMessage(authorId)
onExited: controller.showStatusMessage("")
onClicked:
onClicked: (mouse) => {
controller.resourceRequested(authorId,
mouse.button === Qt.LeftButton
? "mention" : "_interactive")
}
}
32 changes: 15 additions & 17 deletions client/qml/FileContent.qml
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
import QtQuick 2.0
import QtQuick.Controls 1.4
import QtQuick.Controls 2.15
import QtQuick.Layouts 1.1

Attachment {
openOnFinished: openButton.checked

TextEdit {
id: fileTransferInfo
width: parent.width

selectByMouse: true;
readOnly: true;
font: timelabel.font
color: textColor
color: foreground
renderType: settings.render_type
text: qsTr("Size: %1, declared type: %2")
.arg(content.info ? humanSize(content.info.size) : "")
Expand Down Expand Up @@ -59,35 +61,31 @@ Attachment {
width: parent.width
spacing: 2

CheckBox {
id: openOnFinishedFlag
text: qsTr("Open after downloading")
visible: progressInfo &&
!progressInfo.isUpload && transferProgress.visible
checked: openOnFinished
TimelineItemToolButton {
id: openButton
text: progressInfo &&
!progressInfo.isUpload && transferProgress.visible
? qsTr("Open after downloading") : qsTr("Open")
checkable: !downloaded && !(progressInfo && progressInfo.isUpload)
onClicked: { if (checked) openExternally() }
}
Button {
TimelineItemToolButton {
text: qsTr("Cancel")
visible: progressInfo && progressInfo.started
onClicked: room.cancelFileTransfer(eventId)
}
Button {
TimelineItemToolButton {
text: qsTr("Save as...")
visible: !progressInfo ||
(!progressInfo.isUpload && !progressInfo.started)
onClicked: controller.saveFileAs(eventId)
}

Button {
text: qsTr("Open")
visible: !openOnFinishedFlag.visible
onClicked: openExternally()
}
Button {
TimelineItemToolButton {
text: qsTr("Open folder")
visible: progressInfo && progressInfo.localDir
onClicked:
Qt.openUrlExternally(progressInfo.localDir)
}
}
onOpened: openButton.checked = false
}
14 changes: 9 additions & 5 deletions client/qml/ImageContent.qml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ import QtQuick 2.0
import QtQuick.Layouts 1.1

Attachment {
property var sourceSize
property url source
property var maxHeight
property bool autoload
required property var sourceSize
required property url source
required property var maxHeight
required property bool autoload
openOnFinished: false

Image {
id: imageContent
Expand All @@ -27,7 +28,10 @@ Attachment {
onContainsMouseChanged:
controller.showStatusMessage(containsMouse
? room.fileSource(eventId) : "")
onClicked: openExternally()
onClicked: {
openOnFinished = true
openExternally()
}
}

TimelineMouseArea {
Expand Down
23 changes: 0 additions & 23 deletions client/qml/ScrollToButton.qml

This file was deleted.

33 changes: 26 additions & 7 deletions client/qml/Timeline.qml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import QtQuick 2.10 // Qt 5.10
import QtQuick.Controls 2.2
import QtQuick.Layouts 1.1
import Quotient 1.0

Page {
Expand Down Expand Up @@ -181,7 +180,8 @@ Page {
onHoveredLinkChanged:
controller.showStatusMessage(hoveredLink)

onLinkActivated: controller.resourceRequested(link)
onLinkActivated:
(link) => { controller.resourceRequested(link) }
}
}
}
Expand All @@ -191,7 +191,7 @@ Page {
cursorShape: topicText.hoveredLink
? Qt.PointingHandCursor : Qt.IBeamCursor

onClicked: {
onClicked: (mouse) => {
if (topicText.hoveredLink)
controller.resourceRequested(topicText.hoveredLink,
"_interactive")
Expand Down Expand Up @@ -780,11 +780,32 @@ Page {
}
}

component ScrollToButton: RoundButton {
anchors.right: scrollerArea.left
anchors.rightMargin: 2
height: settings.fontHeight * 2
width: height
hoverEnabled: true
opacity: visible * (0.7 + hovered * 0.2)

display: Button.IconOnly
icon.color: defaultPalette.buttonText

AnimationBehavior on opacity {
NormalNumberAnimation {
easing.type: Easing.OutQuad
}
}
AnimationBehavior on anchors.bottomMargin {
NormalNumberAnimation {
easing.type: Easing.OutQuad
}
}
}

ScrollToButton {
id: scrollToBottomButton

anchors.right: scrollerArea.left
anchors.rightMargin: 2
anchors.bottom: parent.bottom
anchors.bottomMargin: visible ? 0.5 * height : -height

Expand All @@ -804,8 +825,6 @@ Page {
ScrollToButton {
id: scrollToReaderMarkerButton

anchors.right: scrollerArea.left
anchors.rightMargin: 2
anchors.bottom: scrollToBottomButton.top
anchors.bottomMargin: visible ? 0.5 * height : -3 * height

Expand Down
36 changes: 22 additions & 14 deletions client/qml/TimelineItem.qml
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ Item {
(-0.7*defaultPalette.window.hslLightness + 0.9),
defaultPalette.buttonText.a)

readonly property bool actionEvent: eventType == "state"
|| eventType == "emote"
readonly property bool actionEvent: eventType === "state"
|| eventType === "emote"

readonly property bool readMarkerHere: messageModel.readMarkerVisualIndex === index

Expand Down Expand Up @@ -367,7 +367,8 @@ Item {
onHoveredLinkChanged:
controller.showStatusMessage(hoveredLink)

onLinkActivated: controller.resourceRequested(link)
onLinkActivated:
(link) => { controller.resourceRequested(link) }

TimelineTextEditSelector {}

Expand All @@ -382,7 +383,7 @@ Item {
? Qt.PointingHandCursor : Qt.IBeamCursor
acceptedButtons: Qt.MiddleButton | Qt.RightButton

onClicked: {
onClicked: (mouse) => {
if (mouse.button === Qt.MiddleButton) {
if (textFieldImpl.hoveredLink)
controller.resourceRequested(
Expand All @@ -393,11 +394,11 @@ Item {
}
}

onWheel: {
if (wheel.angleDelta.x != 0 &&
onWheel: (wheel) => {
if (wheel.angleDelta.x !== 0 &&
textFieldImpl.width < textFieldImpl.contentWidth)
{
if (wheel.pixelDelta.x != 0)
if (wheel.pixelDelta.x !== 0)
textScrollBar.position -=
wheel.pixelDelta.x / width
else
Expand Down Expand Up @@ -425,7 +426,7 @@ Item {

Loader {
id: imageLoader
active: eventType == "image"
active: eventType === "image"

anchors.top: textField.bottom
anchors.left: textField.left
Expand Down Expand Up @@ -453,7 +454,7 @@ Item {
}
Loader {
id: fileLoader
active: eventType == "file"
active: eventType === "file"

anchors.top: textField.bottom
anchors.left: textField.left
Expand Down Expand Up @@ -552,15 +553,22 @@ Item {
id: buttonArea

Item {
TimelineItemToolButton {
component EventActionButton: TimelineItemToolButton {
anchors.top: parent.top
anchors.rightMargin: 2
width: visible * implicitWidth
height: visible * parent.height
}

EventActionButton {
id: resendButton
visible: failed
anchors.right: discardButton.left
text: qsTr("Resend")

onClicked: room.retryMessage(eventId)
}
TimelineItemToolButton {
EventActionButton {
id: discardButton
visible: pending && marks !== EventStatus.ReachedServer
&& marks !== EventStatus.Departed
Expand All @@ -569,7 +577,7 @@ Item {

onClicked: room.discardMessage(eventId)
}
TimelineItemToolButton {
EventActionButton {
id: goToPredecessorButton
visible: !pending && eventResolvedType == "m.room.create" && refId
anchors.right: parent.right
Expand All @@ -578,7 +586,7 @@ Item {
// TODO: Treat unjoined invite-only rooms specially
onClicked: controller.resourceRequested(refId, "join")
}
TimelineItemToolButton {
EventActionButton {
id: goToSuccessorButton
visible: !pending && eventResolvedType == "m.room.tombstone"
anchors.right: parent.right
Expand Down Expand Up @@ -637,7 +645,7 @@ Item {

width: parent.width

onLinkActivated: Qt.openUrlExternally(link)
onLinkActivated: (link) => { Qt.openUrlExternally(link) }

MouseArea {
anchors.fill: parent
Expand Down
Loading

0 comments on commit e721aa4

Please sign in to comment.