vlc | branch: master | Fatih Uzunoglu <[email protected]> | Mon Aug 10 16:40:31 2020 +0300| [d56e934c509cf3e1f80ba600dfe983db0c3423aa] | committer: Pierre Lamot
qml: add PointingTooltip as a general purpose pointing tooltip Signed-off-by: Pierre Lamot <[email protected]> > http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=d56e934c509cf3e1f80ba600dfe983db0c3423aa --- modules/gui/qt/Makefile.am | 1 + modules/gui/qt/vlc.qrc | 1 + modules/gui/qt/widgets/qml/PointingTooltip.qml | 146 +++++++++++++++++++++++++ 3 files changed, 148 insertions(+) diff --git a/modules/gui/qt/Makefile.am b/modules/gui/qt/Makefile.am index e718bdf3fe..0440020af5 100644 --- a/modules/gui/qt/Makefile.am +++ b/modules/gui/qt/Makefile.am @@ -707,6 +707,7 @@ libqt_plugin_la_QML = \ gui/qt/widgets/qml/VideoProgressBar.qml \ gui/qt/widgets/qml/VideoQualityLabel.qml \ gui/qt/widgets/qml/ListSubtitleLabel.qml \ + gui/qt/widgets/qml/PointingTooltip.qml \ gui/qt/widgets/qml/FrostedGlassEffect.qml EXTRA_DIST += gui/qt/vlc.qrc $(libqt_plugin_la_RES) diff --git a/modules/gui/qt/vlc.qrc b/modules/gui/qt/vlc.qrc index 97aa678d7d..3c565ded9f 100644 --- a/modules/gui/qt/vlc.qrc +++ b/modules/gui/qt/vlc.qrc @@ -223,6 +223,7 @@ <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> + <file alias="PointingTooltip.qml">widgets/qml/PointingTooltip.qml</file> <file alias="FrostedGlassEffect.qml">widgets/qml/FrostedGlassEffect.qml</file> </qresource> <qresource prefix="/util"> diff --git a/modules/gui/qt/widgets/qml/PointingTooltip.qml b/modules/gui/qt/widgets/qml/PointingTooltip.qml new file mode 100644 index 0000000000..f0d51d9e0e --- /dev/null +++ b/modules/gui/qt/widgets/qml/PointingTooltip.qml @@ -0,0 +1,146 @@ +/***************************************************************************** + * 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 QtGraphicalEffects 1.0 + +import "qrc:///style/" + +Item { + id: pointingTooltip + + // set parentWindow if you want to let tooltip not exceed window boundaries + // if it is not set, tooltip will use mouseArea as the bounding rect. + // Note that for now it only works with x axis. + property var parentWindow: undefined + + property var mouseArea: undefined + + property alias text: timeMetrics.text + + // set fixedY if you want to fix y position of the tooltip + property bool fixedY: true + + readonly property real position: xPos / mouseArea.width + readonly property real xPos: mouseArea.mouseX + readonly property real yPos: mouseArea.mouseY + + width: childrenRect.width + height: childrenRect.height + + function getX() { + var x = xPos - (pointingTooltip.width / 2) + var diff = (x + pointingTooltip.width) + + var windowMappedX = !!parentWindow ? parentWindow.mapFromItem(mouseArea, mouseArea.x, mouseArea.y).x : undefined + + var sliderRealX = 0 + + if (!!parentWindow) { + diff -= parentWindow.width - windowMappedX + sliderRealX = windowMappedX + } + else + diff -= mouseArea.width + + if (x < -sliderRealX) { + if (!!parentWindow) + arrow.diff = x + windowMappedX + else + arrow.diff = x + x = -sliderRealX + } + else if (diff > 0) { + arrow.diff = diff + x -= (diff) + } + else { + arrow.diff = 0 + } + + return x + } + + y: fixedY ? -(childrenRect.height) : yPos - childrenRect.height + x: getX() + + Item { + height: arrow.height * Math.sqrt(2) + width: timeIndicatorRect.width + + anchors.horizontalCenter: timeIndicatorRect.horizontalCenter + anchors.verticalCenter: timeIndicatorRect.bottom + anchors.verticalCenterOffset: height / 2 + + clip: true + + Rectangle { + id: arrow + width: VLCStyle.dp(10) + height: VLCStyle.dp(10) + + anchors.centerIn: parent + anchors.verticalCenterOffset: -(parent.height / 2) + anchors.horizontalCenterOffset: diff + + property int diff: 0 + + color: VLCStyle.colors.bgAlt + + rotation: 45 + + RectangularGlow { + anchors.fill: parent + glowRadius: VLCStyle.dp(2) + spread: 0.2 + color: VLCStyle.colors.glowColor + } + } + } + + Rectangle { + id: timeIndicatorRect + width: timeMetrics.width + VLCStyle.dp(10) + height: timeMetrics.height + VLCStyle.dp(5) + + color: VLCStyle.colors.bgAlt + radius: VLCStyle.dp(6) + + RectangularGlow { + anchors.fill: parent + + glowRadius: VLCStyle.dp(2) + cornerRadius: parent.radius + spread: 0.2 + + color: VLCStyle.colors.glowColor + } + + Text { + anchors.fill: parent + text: timeMetrics.text + color: VLCStyle.colors.text + + horizontalAlignment: Text.AlignHCenter + verticalAlignment: Text.AlignVCenter + + TextMetrics { + id: timeMetrics + } + } + } +} _______________________________________________ vlc-commits mailing list [email protected] https://mailman.videolan.org/listinfo/vlc-commits
