Warning, /multimedia/kdenlive/src/qml/ZoomBar.qml is written in an unsupported language. File is not indexed.
0001 /* 0002 SPDX-FileCopyrightText: 2021 Jean-Baptiste Mardelle <jb@kdenlive.org> 0003 SPDX-FileCopyrightText: 2022 Julius Künzel <jk.kdedev@smartlab.uber.space> 0004 0005 SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL 0006 */ 0007 0008 import QtQuick 2.15 0009 import QtQuick.Controls 2.15 0010 0011 Rectangle { 0012 id: zoomContainer 0013 SystemPalette { id: barPalette; colorGroup: SystemPalette.Disabled } 0014 property bool hoveredBar: barArea.containsMouse || barArea.pressed || zoomStart.isActive || zoomEnd.isActive 0015 property int barMinWidth: 1 0016 required property real contentPos 0017 required property real zoomFactor 0018 required property bool fitsZoom 0019 property string toolTipText 0020 signal proposeContentPos(real proposedValue) 0021 signal proposeZoomFactor(real proposedValue) 0022 signal zoomByWheel(var wheel) 0023 signal fitZoom() 0024 color: hoveredBar || containerArea.containsMouse ? barPalette.text : activePalette.window 0025 radius: height / 2 0026 border { 0027 color: activePalette.window 0028 width: 1 0029 } 0030 MouseArea { 0031 id: containerArea 0032 anchors.fill: parent 0033 hoverEnabled: true 0034 onWheel: wheel => { 0035 if (wheel.modifiers & Qt.ControlModifier) { 0036 zoomByWheel(wheel) 0037 } else { 0038 var newPos = zoomBar.x 0039 if (wheel.angleDelta.y < 0) { 0040 newPos = Math.min(zoomHandleContainer.width - zoomBar.width, newPos + 10) 0041 } else { 0042 newPos = Math.max(0, newPos - 10) 0043 } 0044 proposeContentPos(newPos / zoomHandleContainer.width) 0045 } 0046 } 0047 onPressed: mouse => { 0048 if (mouse.buttons === Qt.LeftButton) { 0049 if (mouseX > zoomEnd.x + zoomEnd.width) { 0050 proposeContentPos((zoomBar.x + zoomBar.width) / zoomHandleContainer.width) 0051 } else if (mouseX < zoomBar.x) { 0052 proposeContentPos(Math.max(0, (zoomBar.x - zoomBar.width) / zoomHandleContainer.width)) 0053 } 0054 } 0055 } 0056 } 0057 Item { 0058 id: zoomHandleContainer 0059 anchors.fill: parent 0060 Item { 0061 id: zoomBar 0062 height: parent.height 0063 property int minWidth: barMinWidth + zoomEnd.width + zoomStart.width 0064 property int preferedWidth: zoomFactor * zoomHandleContainer.width 0065 width: !zoomStart.pressed && !zoomEnd.pressed && preferedWidth < minWidth ? minWidth : preferedWidth 0066 x: contentPos * zoomHandleContainer.width 0067 MouseArea { 0068 id: barArea 0069 anchors.fill: parent 0070 hoverEnabled: true 0071 cursorShape: Qt.PointingHandCursor 0072 property real previousPos: 0 0073 property real previousFactor: -1 0074 drag { 0075 target: zoomBar 0076 axis: Drag.XAxis 0077 smoothed: false 0078 minimumX: 0 0079 maximumX: zoomHandleContainer.width - zoomBar.width 0080 } 0081 onPositionChanged: mouse => { 0082 if (mouse.buttons === Qt.LeftButton) { 0083 proposeContentPos(zoomBar.x / zoomHandleContainer.width) 0084 } 0085 } 0086 onDoubleClicked: { 0087 // Switch between current zoom and fit whole content 0088 if (zoomBar.x == 0 && fitsZoom) { 0089 // Restore previous pos 0090 if (previousFactor > -1) { 0091 proposeZoomFactor(previousFactor) 0092 proposeContentPos(previousPos) 0093 } 0094 } else { 0095 previousPos = contentPos 0096 previousFactor = zoomFactor 0097 fitZoom() 0098 } 0099 } 0100 Rectangle { 0101 color: hoveredBar ? activePalette.highlight : containerArea.containsMouse ? activePalette.text : barPalette.text 0102 opacity: hoveredBar || containerArea.containsMouse ? 0.6 : 1 0103 x: parent.x + zoomStart.width 0104 height: parent.height 0105 width: parent.width - zoomStart.width - zoomEnd.width 0106 } 0107 } 0108 } 0109 //Start drag handle 0110 MouseArea { 0111 id: zoomStart 0112 property bool isActive: zoomStart.containsMouse || zoomStart.pressed 0113 anchors { 0114 right: pressed ? undefined : zoomBar.left 0115 rightMargin: -width 0116 bottom: zoomBar.bottom 0117 } 0118 width: zoomBar.height 0119 height: zoomBar.height 0120 hoverEnabled: true 0121 cursorShape: Qt.SizeHorCursor 0122 onPositionChanged: mouse => { 0123 if (mouse.buttons === Qt.LeftButton) { 0124 var updatedPos = Math.max(0, x + mouseX) 0125 updatedPos = Math.min(updatedPos, zoomEnd.x - width - 1) 0126 proposeZoomFactor((zoomBar.x + zoomBar.width + 0.5 - updatedPos) / zoomHandleContainer.width) 0127 proposeContentPos(updatedPos / zoomHandleContainer.width) 0128 startHandleRect.x = updatedPos - x 0129 } 0130 } 0131 Rectangle { 0132 id: startHandleRect 0133 anchors.fill: parent.pressed ? undefined : parent 0134 radius: height / 2 0135 color: zoomStart.isActive ? activePalette.highlight : hoveredBar || containerArea.containsMouse ? activePalette.text : barPalette.text 0136 Rectangle { 0137 anchors.fill: parent 0138 anchors.leftMargin: height / 2 0139 color: parent.color 0140 } 0141 } 0142 } 0143 //End drag handle 0144 MouseArea { 0145 id: zoomEnd 0146 property bool isActive: zoomEnd.containsMouse || zoomEnd.pressed 0147 anchors { 0148 left: pressed ? undefined : zoomBar.right 0149 leftMargin: -width 0150 bottom: zoomBar.bottom 0151 } 0152 width: zoomBar.height 0153 height: zoomBar.height 0154 hoverEnabled: true 0155 cursorShape: Qt.SizeHorCursor 0156 onPositionChanged: mouse => { 0157 if (mouse.buttons === Qt.LeftButton) { 0158 var updatedPos = Math.min(zoomHandleContainer.width, x + mouseX) 0159 updatedPos = Math.max(updatedPos, zoomBar.x + width * 2 + 1) 0160 var zoomBarX = zoomBar.x // we need to save the value before we change zoomFactor, but apply it afterwards 0161 proposeZoomFactor((updatedPos - zoomBar.x) / zoomHandleContainer.width) 0162 proposeContentPos(zoomBarX / zoomHandleContainer.width) 0163 endHandleRect.x = updatedPos - x - width 0164 } 0165 } 0166 Rectangle { 0167 id: endHandleRect 0168 anchors.fill: parent.pressed ? undefined : parent 0169 radius: height / 2 0170 color: zoomEnd.isActive ? activePalette.highlight : hoveredBar || containerArea.containsMouse ? activePalette.text : barPalette.text 0171 Rectangle { 0172 anchors { 0173 fill: parent 0174 rightMargin: height / 2 0175 } 0176 color: parent.color 0177 } 0178 } 0179 } 0180 } 0181 ToolTip { 0182 visible: barArea.containsMouse && toolTipText 0183 delay: 1000 0184 timeout: 5000 0185 background: Rectangle { 0186 color: activePalette.alternateBase 0187 border.color: activePalette.light 0188 } 0189 contentItem: Label { 0190 color: activePalette.text 0191 //font: fixedFont 0192 text: toolTipText 0193 } 0194 } 0195 }