[vlc-commits] [Git][videolan/vlc][master] 3 commits: qml: implement Helpers.contains
Jean-Baptiste Kempf (@jbk)
gitlab at videolan.org
Mon Apr 4 15:32:18 UTC 2022
Jean-Baptiste Kempf pushed to branch master at VideoLAN / VLC
Commits:
c29b1a25 by Prince Gupta at 2022-04-04T15:08:03+05:30
qml: implement Helpers.contains
- - - - -
33f6aef5 by Prince Gupta at 2022-04-04T15:18:40+05:30
qml: handle mouse hover and tooltip directly in ScrollingText widget
- - - - -
db1abbe0 by Prince Gupta at 2022-04-04T15:18:43+05:30
qml: add tooltip to subtitle of GridItem
- - - - -
6 changed files:
- modules/gui/qt/util/qml/Helpers.js
- modules/gui/qt/widgets/qml/DragItem.qml
- modules/gui/qt/widgets/qml/GridItem.qml
- modules/gui/qt/widgets/qml/KeyNavigableTableView.qml
- modules/gui/qt/widgets/qml/ScrollingText.qml
- modules/gui/qt/widgets/qml/TableColumns.qml
Changes:
=====================================
modules/gui/qt/util/qml/Helpers.js
=====================================
@@ -66,3 +66,9 @@ function enforceFocus(item, reason) {
function pointInRadius(x, y, radius) {
return (x * x + y * y < radius * radius)
}
+
+// checks if point `pos` lies in rect `rect`
+function contains(rect, pos) {
+ return (clamp(pos.x, rect.x, rect.x + rect.width) === pos.x)
+ && (clamp(pos.y, rect.y, rect.y + rect.height) === pos.y)
+}
=====================================
modules/gui/qt/widgets/qml/DragItem.qml
=====================================
@@ -318,10 +318,10 @@ Item {
ScrollingText {
label: titleLabel
- scroll: true
+ forceScroll: true
height: titleLabel.height
width: parent.width
- clip: animationRunning
+ clip: scrolling
T.Label {
id: titleLabel
=====================================
modules/gui/qt/widgets/qml/GridItem.qml
=====================================
@@ -16,6 +16,7 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
import QtQuick 2.11
+import QtQuick.Controls 2.4
import QtQuick.Templates 2.4 as T
import QtQuick.Layouts 1.11
import QtQml.Models 2.2
@@ -23,6 +24,7 @@ import QtGraphicalEffects 1.0
import org.videolan.vlc 0.1
import "qrc:///widgets/" as Widgets
+import "qrc:///util/Helpers.js" as Helpers
import "qrc:///style/"
T.Control {
@@ -243,10 +245,11 @@ T.Control {
}
}
- Column {
+ ColumnLayout {
id: layout
anchors.centerIn: parent
+ spacing: 0
Widgets.MediaCover {
id: picture
@@ -264,19 +267,19 @@ T.Control {
id: titleTextRect
label: titleLabel
- scroll: highlighted
- height: titleLabel.height
- width: titleLabel.width
+ forceScroll: highlighted
visible: root.title !== ""
- clip: animationRunning
+ clip: scrolling
+
+ Layout.preferredWidth: Math.min(titleLabel.implicitWidth, pictureWidth)
+ Layout.preferredHeight: titleLabel.height
+ Layout.topMargin: root.titleMargin
+ Layout.alignment: root.textAlignHCenter ? Qt.AlignCenter : Qt.AlignLeft
Widgets.ListLabel {
id: titleLabel
- elide: titleTextRect.scroll ? Text.ElideNone : Text.ElideRight
- width: pictureWidth
- horizontalAlignment: root.textAlignHCenter && titleLabel.contentWidth <= titleLabel.width ? Text.AlignHCenter : Text.AlignLeft
- topPadding: root.titleMargin
+ height: implicitHeight
color: background.foregroundColor
}
}
@@ -286,15 +289,26 @@ T.Control {
visible: text !== ""
text: root.subtitle
- width: pictureWidth
- topPadding: VLCStyle.margin_xsmall
elide: Text.ElideRight
- horizontalAlignment: root.textAlignHCenter && subtitleTxt.contentWidth <= subtitleTxt.width ? Text.AlignHCenter : Text.AlignLeft
color: background.foregroundColor
+ Layout.preferredWidth: Math.min(pictureWidth, implicitWidth)
+ Layout.alignment: root.textAlignHCenter ? Qt.AlignCenter : Qt.AlignLeft
+ Layout.topMargin: VLCStyle.margin_xsmall
+
// this is based on that MenuCaption.color.a == .6, color of this component is animated (via binding with background.foregroundColor),
// to save operation during animation, directly set the opacity
opacity: .6
+
+ ToolTip.delay: VLCStyle.delayToolTipAppear
+ ToolTip.text: subtitleTxt.text
+ ToolTip.visible: {
+ if (!mouseArea.containsMouse)
+ return false
+
+ var pos = mouseArea.mapToItem(subtitleTxt, mouseArea.mouseX, mouseArea.mouseY)
+ return Helpers.contains(Qt.rect(0, 0, width, height), pos)
+ }
}
}
}
=====================================
modules/gui/qt/widgets/qml/KeyNavigableTableView.qml
=====================================
@@ -42,9 +42,9 @@ FocusScope {
property color foregroundColor: parent.foregroundColor
label: text
- scroll: hoverArea.containsMouse || parent.currentlyFocused
+ forceScroll: parent.currentlyFocused
width: parent.width
- clip: animationRunning
+ clip: scrolling
Widgets.ListLabel {
id: text
@@ -52,16 +52,6 @@ FocusScope {
anchors.verticalCenter: parent.verticalCenter
text: !rowModel ? "" : (rowModel[model.criteria] || "")
color: textRect.foregroundColor
- elide: textRect.scroll ? Text.ElideNone : Text.ElideRight
- width: parent.width
- }
-
- MouseArea {
- id: hoverArea
-
- anchors.fill: parent
- hoverEnabled: true
- acceptedButtons: Qt.NoButton
}
}
=====================================
modules/gui/qt/widgets/qml/ScrollingText.qml
=====================================
@@ -23,17 +23,39 @@ import "qrc:///style/"
Item {
id: control
- readonly property alias animationRunning: scrollAnimation.running
+ readonly property alias scrolling: scrollAnimation.running
property Text label: undefined
- property bool scroll: false
+ property bool forceScroll: false
+ property alias hoverScroll: hoverArea.enabled
readonly property bool _needsToScroll: (label.width < label.contentWidth)
+ ToolTip.delay: VLCStyle.delayToolTipAppear
+ ToolTip.visible: scrolling && hoverArea.containsMouse
+ ToolTip.text: label.text
+
+ onLabelChanged: {
+ label.width = Qt.binding(function () { return Math.min(label.implicitWidth, control.width) })
+
+ label.elide = Qt.binding(function () {
+ return (control.forceScroll || hoverArea.containsMouse) ? Text.ElideNone : Text.ElideRight
+ })
+ }
+
+ MouseArea {
+ id: hoverArea
+
+ anchors.fill: parent
+ acceptedButtons: Qt.NoButton
+ cursorShape: undefined
+ hoverEnabled: true
+ }
+
SequentialAnimation {
id: scrollAnimation
- running: control.scroll && control._needsToScroll
+ running: (control.forceScroll || hoverArea.containsMouse) && control._needsToScroll
loops: Animation.Infinite
onStopped: {
@@ -64,6 +86,5 @@ Item {
value: 0
}
}
-
}
=====================================
modules/gui/qt/widgets/qml/TableColumns.qml
=====================================
@@ -91,8 +91,8 @@ Item {
id: textRect
label: text
- scroll: textHoverArea.containsMouse || parent.currentlyFocused
- clip: animationRunning
+ forceScroll: parent.currentlyFocused
+ clip: scrolling
visible: root.showTitleText
Layout.fillHeight: true
@@ -104,16 +104,6 @@ Item {
anchors.verticalCenter: parent.verticalCenter
text: (!rowModel || !root.showTitleText) ? "" : (rowModel[model.criteria] || I18n.qtr("Unknown Title"))
color: foregroundColor
- elide: textRect.scroll ? Text.ElideNone : Text.ElideRight
- width: parent.width
- }
-
- MouseArea {
- id: textHoverArea
-
- anchors.fill: parent
- hoverEnabled: true
- acceptedButtons: Qt.NoButton
}
}
}
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/030c3045f471397bd43a9aad46c06eb2edc541bf...db1abbe0311fb62a11feef9a57080d14357e0cf9
--
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/030c3045f471397bd43a9aad46c06eb2edc541bf...db1abbe0311fb62a11feef9a57080d14357e0cf9
You're receiving this email because of your account on code.videolan.org.
VideoLAN code repository instance
More information about the vlc-commits
mailing list