refactor common parts of conflict delegate into a separate component
authorMatthieu Gallien <matthieu.gallien@nextcloud.com>
Tue, 16 May 2023 07:37:45 +0000 (09:37 +0200)
committerMatthieu Gallien <matthieu_gallien@yahoo.fr>
Wed, 17 May 2023 06:43:54 +0000 (08:43 +0200)
Signed-off-by: Matthieu Gallien <matthieu.gallien@nextcloud.com>
resources.qrc
src/gui/ConflictDelegate.qml
src/gui/ConflictItemFileInfo.qml [new file with mode: 0644]

index 12ed9ae1d9229ec91aa9d4b1a95f6f594c7cbf50..fdd4bcf570e6306f83805c4bd91befb1ef90e5b8 100644 (file)
@@ -58,5 +58,6 @@
         <file>src/gui/tray/TrayFolderListItem.qml</file>
         <file>src/gui/ResolveConflictsDialog.qml</file>
         <file>src/gui/ConflictDelegate.qml</file>
+        <file>src/gui/ConflictItemFileInfo.qml</file>
     </qresource>
 </RCC>
index eeebc3f5011c7efd93ca27fbc48c4b3b12c88536..6786fb998c8dfcfbe068ac41475c7ff019438d95 100644 (file)
@@ -53,156 +53,33 @@ Item {
         anchors.right: parent.right
         anchors.bottomMargin: 8
 
-        Item {
+        ConflictItemFileInfo {
             Layout.fillWidth: true
             Layout.fillHeight: true
 
-            CheckBox {
-                id: selectExisting
+            itemSelected: root.existingSelected
+            itemPreviewUrl: root.existingPreviewUrl
+            itemVersionLabel: qsTr('Local version')
+            itemDateLabel: root.existingDate
+            itemFileSizeLabel: root.existingSize
 
-                anchors.left: parent.left
-                anchors.verticalCenter: parent.verticalCenter
-
-                leftPadding: 0
-                spacing: 0
-
-                checked: root.existingSelected
-
-                onToggled: function() {
-                    model.existingSelected = checked
-                }
-            }
-
-            Image {
-                id: existingPreview
-
-                anchors.left: selectExisting.right
-                anchors.verticalCenter: parent.verticalCenter
-
-                source: root.existingPreviewUrl
-                width: 48
-                height: 48
-                sourceSize.width: 48
-                sourceSize.height: 48
-            }
-
-            ColumnLayout {
-                anchors.top: parent.top
-                anchors.bottom: parent.bottom
-                anchors.left: existingPreview.right
-                anchors.right: parent.right
-                anchors.leftMargin: 10
-
-                spacing: 0
-
-                Item {
-                    Layout.fillHeight: true
-                }
-
-                EnforcedPlainTextLabel {
-                    Layout.fillWidth: true
-
-                    text: qsTr('Local version')
-
-                    font.pixelSize: 15
-                }
-
-                EnforcedPlainTextLabel {
-                    Layout.fillWidth: true
-
-                    text: root.existingDate
-
-                    font.pixelSize: 15
-                }
-
-                EnforcedPlainTextLabel {
-                    Layout.fillWidth: true
-
-                    text: existingSize
-
-                    font.pixelSize: 15
-                }
-
-                Item {
-                    Layout.fillHeight: true
-                }
+            onSelectedChanged: function() {
+                model.existingSelected = itemSelected
             }
         }
 
-        Item {
+        ConflictItemFileInfo {
             Layout.fillWidth: true
             Layout.fillHeight: true
 
-            CheckBox {
-                id: selectConflict
-
-                anchors.left: parent.left
-                anchors.verticalCenter: parent.verticalCenter
-                anchors.leftMargin: 0
-
-                leftPadding: 0
-                spacing: 0
-
-                checked: root.conflictSelected
-
-                onToggled: function() {
-                    model.conflictSelected = checked
-                }
-            }
-
-            Image {
-                id: conflictPreview
-
-                anchors.left: selectConflict.right
-                anchors.verticalCenter: parent.verticalCenter
-
-                source: root.conflictPreviewUrl
-                width: 48
-                height: 48
-                sourceSize.width: 48
-                sourceSize.height: 48
-            }
-
-            ColumnLayout {
-                anchors.top: parent.top
-                anchors.bottom: parent.bottom
-                anchors.left: conflictPreview.right
-                anchors.right: parent.right
-                anchors.leftMargin: 10
-
-                spacing: 0
-
-                Item {
-                    Layout.fillHeight: true
-                }
-
-                EnforcedPlainTextLabel {
-                    Layout.fillWidth: true
-
-                    text: qsTr('Server version')
-
-                    font.pixelSize: 15
-                }
-
-                EnforcedPlainTextLabel {
-                    Layout.fillWidth: true
-
-                    text: root.conflictDate
-
-                    font.pixelSize: 15
-                }
-
-                EnforcedPlainTextLabel {
-                    Layout.fillWidth: true
-
-                    text: conflictSize
-
-                    font.pixelSize: 15
-                }
+            itemSelected: root.conflictSelected
+            itemPreviewUrl: root.conflictPreviewUrl
+            itemVersionLabel: qsTr('Server version')
+            itemDateLabel: root.conflictDate
+            itemFileSizeLabel: root.conflictSize
 
-                Item {
-                    Layout.fillHeight: true
-                }
+            onSelectedChanged: function() {
+                model.conflictSelected = itemSelected
             }
         }
     }
diff --git a/src/gui/ConflictItemFileInfo.qml b/src/gui/ConflictItemFileInfo.qml
new file mode 100644 (file)
index 0000000..156f127
--- /dev/null
@@ -0,0 +1,98 @@
+/*
+ * Copyright (C) 2023 by Matthieu Gallien <matthieu.gallien@nextcloud.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * for more details.
+ */
+
+import QtQml 2.15
+import QtQuick 2.15
+import QtQuick.Layouts 1.15
+import QtQuick.Controls 2.15
+import Style 1.0
+import "./tray"
+
+Item {
+    property alias itemSelected: selectItem.checked
+    property alias itemPreviewUrl: itemPreview.source
+    property alias itemVersionLabel: versionLabel.text
+    property alias itemDateLabel: dateLabel.text
+    property alias itemFileSizeLabel: fileSizeLabel.text
+
+    signal selectedChanged()
+
+    CheckBox {
+        id: selectItem
+
+        anchors.left: parent.left
+        anchors.verticalCenter: parent.verticalCenter
+
+        leftPadding: 0
+        spacing: 0
+
+        onToggled: function() {
+            selectedChanged()
+        }
+    }
+
+    Image {
+        id: itemPreview
+
+        anchors.left: selectItem.right
+        anchors.verticalCenter: parent.verticalCenter
+
+        width: 48
+        height: 48
+        sourceSize.width: 48
+        sourceSize.height: 48
+    }
+
+    ColumnLayout {
+        anchors.top: parent.top
+        anchors.bottom: parent.bottom
+        anchors.left: itemPreview.right
+        anchors.right: parent.right
+        anchors.leftMargin: 10
+
+        spacing: 0
+
+        Item {
+            Layout.fillHeight: true
+        }
+
+        EnforcedPlainTextLabel {
+            id: versionLabel
+
+            Layout.fillWidth: true
+
+            font.pixelSize: 15
+        }
+
+        EnforcedPlainTextLabel {
+            id: dateLabel
+
+            Layout.fillWidth: true
+
+            font.pixelSize: 15
+        }
+
+        EnforcedPlainTextLabel {
+            id: fileSizeLabel
+
+            Layout.fillWidth: true
+
+            font.pixelSize: 15
+        }
+
+        Item {
+            Layout.fillHeight: true
+        }
+    }
+}