1/************************************************************************** 2 ** ** 3 ** Copyright (C) 2018 Lukas Spies ** 4 ** Contact: http://photoqt.org ** 5 ** ** 6 ** This file is part of PhotoQt. ** 7 ** ** 8 ** PhotoQt is free software: you can redistribute it and/or modify ** 9 ** it under the terms of the GNU General Public License as published by ** 10 ** the Free Software Foundation, either version 2 of the License, or ** 11 ** (at your option) any later version. ** 12 ** ** 13 ** PhotoQt is distributed in the hope that it will be useful, ** 14 ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** 15 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** 16 ** GNU General Public License for more details. ** 17 ** ** 18 ** You should have received a copy of the GNU General Public License ** 19 ** along with PhotoQt. If not, see <http://www.gnu.org/licenses/>. ** 20 ** ** 21 **************************************************************************/ 22 23import QtQuick 2.5 24import QtQuick.Controls 1.4 25import QtQuick.Controls.Styles 1.4 26import PContextMenu 1.0 27 28import "../elements" 29import "handlestuff.js" as Handle 30 31Rectangle { 32 33 id: breadcrumbs_top 34 35 anchors.left: parent.left 36 anchors.top: parent.top 37 anchors.right: parent.right 38 height: 50 39 40 property int contextMenuCurrentIndex: -1 41 42 property alias modelForCrumbs: crumbsmodel 43 property alias viewForCrumbs: crumbsview 44 45 property int settingsQuickInfoCloseXSize: Math.max(5, Math.min(25, settings.quickInfoCloseXSize)) 46 47 color: "#44000000" 48 49 // Two buttons to go backwards/forwards in history 50 Rectangle { 51 52 id: hist_but 53 54 // Positioning and styling 55 color: "transparent" 56 anchors.left: parent.left 57 anchors.leftMargin: 10 58 anchors.top: parent.top 59 anchors.bottom: parent.bottom 60 width: toleft.width+toright.width 61 62 // Backwards 63 CustomButton { 64 65 id: toleft 66 67 anchors.left: parent.left 68 anchors.top: parent.top 69 anchors.bottom: parent.bottom 70 width: 40 71 72 enabled: (openvariables.historypos > 0 && openvariables.history.length > 1) 73 74 text: "<" 75 fontsize: 30 76 overrideFontColor: "white" 77 overrideBackgroundColor: "transparent" 78 79 opacity: enabled ? 1 : 0.4 80 81 //: The history is the list of visited folders in the element for opening files 82 tooltip: em.pty+qsTr("Go backwards in history") 83 84 onClickedButton: Handle.goBackInHistory() 85 onRightClickedButton: toleftcontext.popup() 86 87 PContextMenu { 88 id: toleftcontext 89 Component.onCompleted: { 90 addItem(em.pty+qsTr("Go backwards in history")) 91 addItem(em.pty+qsTr("Go forwards in history")) 92 } 93 onSelectedIndexChanged: { 94 if(index == 0) 95 Handle.goBackInHistory() 96 else 97 Handle.goForwardsInHistory() 98 } 99 } 100 101 } 102 103 // Forwards 104 CustomButton { 105 106 id: toright 107 108 anchors.right: parent.right 109 anchors.top: parent.top 110 anchors.bottom: parent.bottom 111 width: 40 112 113 enabled: (openvariables.historypos < openvariables.history.length-1 && openvariables.historypos > 0) 114 115 text: ">" 116 fontsize: 30 117 overrideFontColor: "white" 118 overrideBackgroundColor: "transparent" 119 120 opacity: enabled ? 1 : 0.4 121 122 //: The history is the list of visited folders in the element for opening files 123 tooltip: em.pty+qsTr("Go forwards in history") 124 125 onClickedButton: Handle.goForwardsInHistory() 126 onRightClickedButton: torightcontext.popup() 127 128 PContextMenu { 129 id: torightcontext 130 Component.onCompleted: { 131 addItem(em.pty+qsTr("Go backwards in history")) 132 addItem(em.pty+qsTr("Go forwards in history")) 133 } 134 onSelectedIndexChanged: { 135 if(index == 0) 136 Handle.goBackInHistory() 137 else 138 Handle.goForwardsInHistory() 139 } 140 } 141 142 } 143 144 } 145 146 // This button closes the OpenFile dialog -> it is displayed to the RIGHT of the ListView below, in the top right corner 147 Image { 148 149 id: closeopenfile 150 151 anchors.right: parent.right 152 anchors.top: parent.top 153 154 source: "qrc:/img/closingx.png" 155 sourceSize: Qt.size(3*settingsQuickInfoCloseXSize, 3*settingsQuickInfoCloseXSize) 156 157 ToolTip { 158 anchors.fill: parent 159 hoverEnabled: true 160 cursorShape: Qt.PointingHandCursor 161 onClicked: openfile_top.hide() 162 //: The element in this case is the element for opening files 163 text: em.pty+qsTr("Close element") 164 } 165 166 } 167 168 ListView { 169 170 id: crumbsview 171 172 spacing: 0 173 174 anchors.left: hist_but.right 175 anchors.right: closeopenfile.left 176 height: parent.height 177 178 orientation: ListView.Horizontal 179 interactive: false 180 clip: true 181 182 model: ListModel { id: crumbsmodel; } 183 184 property var menuitems: [] 185 186 delegate: Button { 187 id: delegButton 188 y: 7 189 height: parent.height-15 190 property bool hovered: false 191 192 property bool clicked: false 193 194 property var folders: getanddostuff.getFoldersIn(partialpath, false, settings.openShowHiddenFilesFolders) 195 196 Connections { 197 target: contextmenu 198 onOpenedChanged: 199 delegButton.clicked = (contextmenu.opened&&index==contextmenu.parentIndex) 200 } 201 202 style: ButtonStyle { 203 background: Rectangle { 204 id: bg 205 anchors.fill: parent 206 color: (hovered||delegButton.clicked) ? "#44ffffff" : "#00000000" 207 radius: 5 208 } 209 210 label: Text { 211 id: txt 212 horizontalAlignment: Text.AlignHCenter 213 color: "white" 214 font.bold: true 215 font.pointSize: 15 216 text: type=="folder" ? " " + location + " " : " / " 217 } 218 219 } 220 221 MouseArea { 222 anchors.fill: parent 223 hoverEnabled: true 224 cursorShape: Qt.PointingHandCursor 225 onClicked: { 226 if(type == "folder") 227 openvariables.currentDirectory = partialpath 228 else { 229 delegButton.clicked = true 230 var pos = delegButton.parent.mapToItem(mainwindow, delegButton.x, delegButton.y) 231 contextmenu.popup(Qt.point(pos.x+variables.windowXY.x, pos.y+delegButton.height+variables.windowXY.y)) 232 } 233 } 234 onEntered: 235 if(!contextmenu.opened) 236 parent.hovered = true 237 onExited: 238 parent.hovered = false 239 } 240 241 PContextMenu { 242 id: contextmenu 243 property int parentIndex: -1 244 onSelectedIndexChanged: 245 openvariables.currentDirectory = userData + folders[index-1] 246 } 247 248 Component.onCompleted: { 249 //: Used as in "Go directly to subfolder of '/path/to/somewhere'" 250 contextmenu.addItem(em.pty+qsTr("Go directly to subfolder of") + " '" + getanddostuff.getDirectoryDirName(partialpath) + "'") 251 contextmenu.setEnabled(0, false) 252 for(var i = 0; i < folders.length; ++i) 253 contextmenu.addItem(folders[i]) 254 contextmenu.parentIndex = index 255 if(partialpath != undefined) 256 contextmenu.userData = partialpath 257 } 258 259 } 260 261 } 262 263} 264