[vlc-devel] [PATCH 04/16] qml: factorize custom cover used in Networkview in separate file

Prince Gupta guptaprince8832 at gmail.com
Fri Dec 4 12:19:01 CET 2020


---
 modules/gui/qt/Makefile.am                    |  1 +
 .../gui/qt/network/qml/NetworkCustomCover.qml | 65 +++++++++++++++++++
 .../gui/qt/network/qml/NetworkGridItem.qml    | 38 +----------
 .../qt/network/qml/NetworkThumbnailItem.qml   | 36 ++--------
 modules/gui/qt/vlc.qrc                        |  1 +
 5 files changed, 73 insertions(+), 68 deletions(-)
 create mode 100644 modules/gui/qt/network/qml/NetworkCustomCover.qml

diff --git a/modules/gui/qt/Makefile.am b/modules/gui/qt/Makefile.am
index 35c8e6223d..3ff0e265df 100644
--- a/modules/gui/qt/Makefile.am
+++ b/modules/gui/qt/Makefile.am
@@ -652,6 +652,7 @@ libqt_plugin_la_QML = \
 	gui/qt/network/qml/DiscoverUrlDisplay.qml \
 	gui/qt/network/qml/NetworkAddressbar.qml \
 	gui/qt/network/qml/NetworkBrowseDisplay.qml \
+	gui/qt/network/qml/NetworkCustomCover.qml \
 	gui/qt/network/qml/NetworkDisplay.qml \
 	gui/qt/network/qml/NetworkGridItem.qml \
 	gui/qt/network/qml/NetworkHomeDisplay.qml \
diff --git a/modules/gui/qt/network/qml/NetworkCustomCover.qml b/modules/gui/qt/network/qml/NetworkCustomCover.qml
new file mode 100644
index 0000000000..9110f3861d
--- /dev/null
+++ b/modules/gui/qt/network/qml/NetworkCustomCover.qml
@@ -0,0 +1,65 @@
+/*****************************************************************************
+ * Copyright (C) 2020 VLC authors and VideoLAN
+ *
+ * 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.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ *****************************************************************************/
+import QtQuick 2.11
+import QtQuick.Controls 2.4
+import QtGraphicalEffects 1.0
+
+import org.videolan.vlc 0.1
+
+import "qrc:///widgets/" as Widgets
+import "qrc:///style/"
+
+Item {
+    property alias iconSize: custom_cover.width
+
+    Image {
+        id: custom_cover
+
+        anchors.centerIn: parent
+        visible: !model.artwork || model.artwork.toString() === ""
+        height: iconSize
+        mipmap: true
+        sourceSize: Qt.size(width, height)
+        source: {
+            switch (model.type) {
+            case NetworkMediaModel.TYPE_DISC:
+                return "qrc:///type/disc.svg"
+            case NetworkMediaModel.TYPE_CARD:
+                return "qrc:///type/capture-card.svg"
+            case NetworkMediaModel.TYPE_STREAM:
+                return "qrc:///type/stream.svg"
+            case NetworkMediaModel.TYPE_PLAYLIST:
+                return "qrc:///type/playlist.svg"
+            case NetworkMediaModel.TYPE_FILE:
+                return "qrc:///type/file_black.svg"
+            default:
+                return "qrc:///type/directory_black.svg"
+            }
+        }
+    }
+
+    ColorOverlay {
+        anchors.fill: custom_cover
+        source: custom_cover
+        color: VLCStyle.colors.text
+        visible: custom_cover.visible
+                 && model.type !== NetworkMediaModel.TYPE_DISC
+                 && model.type !== NetworkMediaModel.TYPE_CARD
+                 && model.type !== NetworkMediaModel.TYPE_STREAM
+    }
+}
diff --git a/modules/gui/qt/network/qml/NetworkGridItem.qml b/modules/gui/qt/network/qml/NetworkGridItem.qml
index 52e9fc0496..16cb12222f 100644
--- a/modules/gui/qt/network/qml/NetworkGridItem.qml
+++ b/modules/gui/qt/network/qml/NetworkGridItem.qml
@@ -40,42 +40,8 @@ Widgets.GridItem {
     subtitle: model.mrl || ""
     title: model.name || i18n.qtr("Unknown share")
 
-    pictureOverlay: Item {
-        Image {
-            id: custom_cover
-
-            x: (pictureWidth - this.width) / 2
-            y: (pictureHeight - this.height) / 2
-            width: VLCStyle.icon_normal
-            height: VLCStyle.icon_normal
-            visible: !model.artwork || model.artwork.toString() === ""
-            source: {
-                switch (model.type){
-                case NetworkMediaModel.TYPE_DISC:
-                    return  "qrc:///type/disc.svg"
-                case NetworkMediaModel.TYPE_CARD:
-                    return  "qrc:///type/capture-card.svg"
-                case NetworkMediaModel.TYPE_STREAM:
-                    return  "qrc:///type/stream.svg"
-                case NetworkMediaModel.TYPE_PLAYLIST:
-                    return  "qrc:///type/playlist.svg"
-                case NetworkMediaModel.TYPE_FILE:
-                    return  "qrc:///type/file_black.svg"
-                default:
-                    return "qrc:///type/directory_black.svg"
-                }
-            }
-        }
-
-        ColorOverlay {
-            anchors.fill: custom_cover
-            source: custom_cover
-            color: VLCStyle.colors.text
-            visible: custom_cover.visible
-                     && model.type !== NetworkMediaModel.TYPE_DISC
-                     && model.type !== NetworkMediaModel.TYPE_CARD
-                     && model.type !== NetworkMediaModel.TYPE_STREAM
-        }
+    pictureOverlay: NetworkCustomCover {
+        iconSize: VLCStyle.icon_normal
     }
 
 }
diff --git a/modules/gui/qt/network/qml/NetworkThumbnailItem.qml b/modules/gui/qt/network/qml/NetworkThumbnailItem.qml
index a031114080..4bcb624a04 100644
--- a/modules/gui/qt/network/qml/NetworkThumbnailItem.qml
+++ b/modules/gui/qt/network/qml/NetworkThumbnailItem.qml
@@ -45,39 +45,11 @@ Item {
         height: VLCStyle.listAlbumCover_height
         visible: !artwork.visible
 
-        Image {
-            id: custom_cover
+        NetworkCustomCover {
+            property var model: rowModel
 
-            anchors.centerIn: parent
-            sourceSize.height: VLCStyle.icon_small
-            sourceSize.width: VLCStyle.icon_small
-            fillMode: Image.PreserveAspectFit
-            mipmap: true
-            source: {
-                switch (rowModel.type) {
-                case NetworkMediaModel.TYPE_DISC:
-                    return "qrc:///type/disc.svg"
-                case NetworkMediaModel.TYPE_CARD:
-                    return "qrc:///type/capture-card.svg"
-                case NetworkMediaModel.TYPE_STREAM:
-                    return "qrc:///type/stream.svg"
-                case NetworkMediaModel.TYPE_PLAYLIST:
-                    return "qrc:///type/playlist.svg"
-                case NetworkMediaModel.TYPE_FILE:
-                    return "qrc:///type/file_black.svg"
-                default:
-                    return "qrc:///type/directory_black.svg"
-                }
-            }
-        }
-
-        ColorOverlay {
-            anchors.fill: custom_cover
-            source: custom_cover
-            color: VLCStyle.colors.text
-            visible: rowModel.type !== NetworkMediaModel.TYPE_DISC
-                     && rowModel.type !== NetworkMediaModel.TYPE_CARD
-                     && rowModel.type !== NetworkMediaModel.TYPE_STREAM
+            anchors.fill: parent
+            iconSize: VLCStyle.icon_small
         }
     }
 
diff --git a/modules/gui/qt/vlc.qrc b/modules/gui/qt/vlc.qrc
index fb470a9afa..88e183cce0 100644
--- a/modules/gui/qt/vlc.qrc
+++ b/modules/gui/qt/vlc.qrc
@@ -244,6 +244,7 @@
         <file alias="AddressbarButton.qml">network/qml/AddressbarButton.qml</file>
         <file alias="DiscoverDisplay.qml">network/qml/DiscoverDisplay.qml</file>
         <file alias="DiscoverUrlDisplay.qml">network/qml/DiscoverUrlDisplay.qml</file>
+        <file alias="NetworkCustomCover.qml">network/qml/NetworkCustomCover.qml</file>
         <file alias="NetworkDisplay.qml">network/qml/NetworkDisplay.qml</file>
         <file alias="NetworkHomeDeviceListView.qml">network/qml/NetworkHomeDeviceListView.qml</file>
         <file alias="NetworkHomeDisplay.qml">network/qml/NetworkHomeDisplay.qml</file>
-- 
2.25.1



More information about the vlc-devel mailing list