[vlc-devel] [PATCH 1/3] qml: introduce HorizontalResizehandle

Prince Gupta guptaprince8832 at gmail.com
Mon Aug 24 17:16:12 CEST 2020


---
 modules/gui/qt/Makefile.am                    |  1 +
 modules/gui/qt/vlc.qrc                        |  1 +
 .../qt/widgets/qml/HorizontalResizeHandle.qml | 55 +++++++++++++++++++
 3 files changed, 57 insertions(+)
 create mode 100644 modules/gui/qt/widgets/qml/HorizontalResizeHandle.qml

diff --git a/modules/gui/qt/Makefile.am b/modules/gui/qt/Makefile.am
index 53fd5ded18..e47303e0a0 100644
--- a/modules/gui/qt/Makefile.am
+++ b/modules/gui/qt/Makefile.am
@@ -671,6 +671,7 @@ libqt_plugin_la_QML = \
 	gui/qt/widgets/qml/ExpandGridView.qml \
 	gui/qt/widgets/qml/FocusBackground.qml \
 	gui/qt/widgets/qml/GridItem.qml \
+	gui/qt/widgets/qml/HorizontalResizeHandle.qml \
 	gui/qt/widgets/qml/IconLabel.qml \
 	gui/qt/widgets/qml/IconToolButton.qml \
 	gui/qt/widgets/qml/ImageToolButton.qml \
diff --git a/modules/gui/qt/vlc.qrc b/modules/gui/qt/vlc.qrc
index b545e1b8dd..fc0c5be020 100644
--- a/modules/gui/qt/vlc.qrc
+++ b/modules/gui/qt/vlc.qrc
@@ -221,6 +221,7 @@
         <file alias="MediaCover.qml">widgets/qml/MediaCover.qml</file>
         <file alias="MenuLabel.qml">widgets/qml/MenuLabel.qml</file>
         <file alias="ListSubtitleLabel.qml">widgets/qml/ListSubtitleLabel.qml</file>
+        <file alias="HorizontalResizeHandle.qml">widgets/qml/HorizontalResizeHandle.qml</file>
     </qresource>
     <qresource prefix="/util">
         <file alias="SelectableDelegateModel.qml">util/qml/SelectableDelegateModel.qml</file>
diff --git a/modules/gui/qt/widgets/qml/HorizontalResizeHandle.qml b/modules/gui/qt/widgets/qml/HorizontalResizeHandle.qml
new file mode 100644
index 0000000000..c86cbefa8e
--- /dev/null
+++ b/modules/gui/qt/widgets/qml/HorizontalResizeHandle.qml
@@ -0,0 +1,55 @@
+/*****************************************************************************
+ * 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 "qrc:///style/"
+
+// targetWidth: concerned widget's current width
+// sourceWidth: target's width is bounded by this value (parent's width?)
+// HorizontalResizeHandle actually doesn't resizes target
+// you have to assign target's width manually using widthFactor property
+// the idea behind using widthFactor is to maintain scale ratio when source itself resizes
+// e.g target.width: resizeHandle.clamp(sourceWidth / resizeHandle.widthFactor, minimumWidth, maximumWidth)
+MouseArea {
+    id: root
+
+    // provided by parent, this widget don't modify these properties
+    property int sourceWidth
+    property int targetWidth
+
+    property double widthFactor: 4
+    property bool atRight: true
+
+    property int _previousX
+
+    cursorShape: Qt.SplitHCursor
+    width: VLCStyle.dp(8)
+    acceptedButtons: Qt.LeftButton
+
+    onPressed: _previousX = mouseX
+
+    onPositionChanged: {
+        var f = atRight ? -1 : 1
+        var delta = mouseX + _previousX * f
+        root.widthFactor = root.sourceWidth / (root.targetWidth + (delta * - f))
+    }
+
+    function clamp(num, min, max) {
+      return num <= min ? min : num >= max ? max : num;
+    }
+}
-- 
2.25.1



More information about the vlc-devel mailing list