FileDialog.qml 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. /****************************************************************************
  2. **
  3. ** Copyright (C) 2021 The Qt Company Ltd.
  4. ** Contact: http://www.qt.io/licensing/
  5. **
  6. ** This file is part of the Qt Quick Dialogs module of the Qt Toolkit.
  7. **
  8. ** $QT_BEGIN_LICENSE:LGPL3$
  9. ** Commercial License Usage
  10. ** Licensees holding valid commercial Qt licenses may use this file in
  11. ** accordance with the commercial license agreement provided with the
  12. ** Software or, alternatively, in accordance with the terms contained in
  13. ** a written agreement between you and The Qt Company. For licensing terms
  14. ** and conditions see http://www.qt.io/terms-conditions. For further
  15. ** information use the contact form at http://www.qt.io/contact-us.
  16. **
  17. ** GNU Lesser General Public License Usage
  18. ** Alternatively, this file may be used under the terms of the GNU Lesser
  19. ** General Public License version 3 as published by the Free Software
  20. ** Foundation and appearing in the file LICENSE.LGPLv3 included in the
  21. ** packaging of this file. Please review the following information to
  22. ** ensure the GNU Lesser General Public License version 3 requirements
  23. ** will be met: https://www.gnu.org/licenses/lgpl.html.
  24. **
  25. ** GNU General Public License Usage
  26. ** Alternatively, this file may be used under the terms of the GNU
  27. ** General Public License version 2.0 or later as published by the Free
  28. ** Software Foundation and appearing in the file LICENSE.GPL included in
  29. ** the packaging of this file. Please review the following information to
  30. ** ensure the GNU General Public License version 2.0 requirements will be
  31. ** met: http://www.gnu.org/licenses/gpl-2.0.html.
  32. **
  33. ** $QT_END_LICENSE$
  34. **
  35. ****************************************************************************/
  36. import Qt.labs.folderlistmodel
  37. import QtQuick
  38. import QtQuick.Controls
  39. import QtQuick.Controls.impl
  40. import QtQuick.Controls.Fusion
  41. import QtQuick.Controls.Fusion.impl
  42. import QtQuick.Dialogs
  43. import QtQuick.Dialogs.quickimpl
  44. import QtQuick.Layouts
  45. import QtQuick.Templates as T
  46. import "." as DialogsImpl
  47. FileDialogImpl {
  48. id: control
  49. implicitWidth: Math.max(implicitBackgroundWidth + leftInset + rightInset,
  50. contentWidth + leftPadding + rightPadding,
  51. implicitHeaderWidth,
  52. implicitFooterWidth)
  53. implicitHeight: Math.max(implicitBackgroundHeight + topInset + bottomInset,
  54. contentHeight + topPadding + bottomPadding
  55. + (implicitHeaderHeight > 0 ? implicitHeaderHeight + spacing : 0)
  56. + (implicitFooterHeight > 0 ? implicitFooterHeight + spacing : 0))
  57. padding: 6
  58. horizontalPadding: 12
  59. standardButtons: T.Dialog.Open | T.Dialog.Cancel
  60. /*
  61. We use attached properties because we want to handle logic in C++, and:
  62. - We can't assume the footer only contains a DialogButtonBox (which would allow us
  63. to connect up to it in QQuickFileDialogImpl); it also needs to hold a ComboBox
  64. and therefore the root footer item will be e.g. a layout item instead.
  65. - We don't want to create our own "FileDialogButtonBox" (in order to be able to handle the logic
  66. in C++) because we'd need to copy (and hence duplicate code in) DialogButtonBox.qml.
  67. */
  68. FileDialogImpl.buttonBox: buttonBox
  69. FileDialogImpl.nameFiltersComboBox: nameFiltersComboBox
  70. FileDialogImpl.fileDialogListView: fileDialogListView
  71. FileDialogImpl.breadcrumbBar: breadcrumbBar
  72. background: Rectangle {
  73. implicitWidth: 600
  74. implicitHeight: 400
  75. color: control.palette.window
  76. border.color: control.palette.mid
  77. radius: 2
  78. Rectangle {
  79. z: -1
  80. x: 1
  81. y: 1
  82. width: parent.width
  83. height: parent.height
  84. color: control.palette.shadow
  85. opacity: 0.2
  86. radius: 2
  87. }
  88. }
  89. header: ColumnLayout {
  90. spacing: 0
  91. Label {
  92. objectName: "dialogTitleBarLabel"
  93. text: control.title
  94. horizontalAlignment: Label.AlignHCenter
  95. elide: Label.ElideRight
  96. font.bold: true
  97. padding: 6
  98. Layout.fillWidth: true
  99. Layout.leftMargin: 12
  100. Layout.rightMargin: 12
  101. Layout.topMargin: control.title.length > 0 ? 0 : 12
  102. Layout.preferredHeight: control.title.length > 0 ? implicitHeight : 0
  103. }
  104. DialogsImpl.FolderBreadcrumbBar {
  105. id: breadcrumbBar
  106. fileDialog: control
  107. Layout.fillWidth: true
  108. Layout.leftMargin: 12
  109. Layout.rightMargin: 12
  110. KeyNavigation.tab: fileDialogListView
  111. }
  112. }
  113. contentItem: Frame {
  114. padding: 0
  115. verticalPadding: 1
  116. ListView {
  117. id: fileDialogListView
  118. objectName: "fileDialogListView"
  119. anchors.fill: parent
  120. clip: true
  121. focus: true
  122. boundsBehavior: Flickable.StopAtBounds
  123. ScrollBar.vertical: ScrollBar {}
  124. model: FolderListModel {
  125. folder: control.currentFolder
  126. nameFilters: control.selectedNameFilter.globs
  127. showDirsFirst: true
  128. sortCaseSensitive: false
  129. }
  130. delegate: DialogsImpl.FileDialogDelegate {
  131. objectName: "fileDialogDelegate" + index
  132. x: 1
  133. width: ListView.view.width - 2
  134. highlighted: ListView.isCurrentItem
  135. fileDialog: control
  136. fileDetailRowWidth: nameFiltersComboBox.width
  137. KeyNavigation.backtab: breadcrumbBar
  138. KeyNavigation.tab: nameFiltersComboBox
  139. }
  140. }
  141. }
  142. footer: RowLayout {
  143. id: rowLayout
  144. spacing: 12
  145. ComboBox {
  146. // OK to use IDs here, since users shouldn't be overriding this stuff.
  147. id: nameFiltersComboBox
  148. model: control.nameFilters
  149. Layout.leftMargin: 12
  150. Layout.fillWidth: true
  151. Layout.bottomMargin: 12
  152. }
  153. DialogButtonBox {
  154. id: buttonBox
  155. standardButtons: control.standardButtons
  156. spacing: 6
  157. horizontalPadding: 0
  158. verticalPadding: 0
  159. background: null
  160. Layout.rightMargin: 12
  161. Layout.bottomMargin: 12
  162. }
  163. }
  164. T.Overlay.modal: Rectangle {
  165. color: Fusion.topShadow
  166. }
  167. T.Overlay.modeless: Rectangle {
  168. color: Fusion.topShadow
  169. }
  170. }