FileDialog.qml 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  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.Templates as T
  39. import QtQuick.Controls.Imagine
  40. import QtQuick.Controls.Imagine.impl
  41. import QtQuick.Dialogs.quickimpl
  42. import QtQuick.Layouts
  43. import "." as DialogsImpl
  44. FileDialogImpl {
  45. id: control
  46. // Can't set implicitWidth of the NinePatchImage background, so we do it here.
  47. implicitWidth: Math.max(600,
  48. implicitBackgroundWidth + leftInset + rightInset,
  49. contentWidth + leftPadding + rightPadding,
  50. implicitHeaderWidth,
  51. implicitFooterWidth)
  52. implicitHeight: Math.max(400,
  53. implicitBackgroundHeight + topInset + bottomInset,
  54. contentHeight + topPadding + bottomPadding
  55. + (implicitHeaderHeight > 0 ? implicitHeaderHeight + spacing : 0)
  56. + (implicitFooterHeight > 0 ? implicitFooterHeight + spacing : 0))
  57. topPadding: background ? background.topPadding : 0
  58. leftPadding: background ? background.leftPadding : 0
  59. rightPadding: background ? background.rightPadding : 0
  60. bottomPadding: background ? background.bottomPadding : 0
  61. topInset: background ? -background.topInset || 0 : 0
  62. leftInset: background ? -background.leftInset || 0 : 0
  63. rightInset: background ? -background.rightInset || 0 : 0
  64. bottomInset: background ? -background.bottomInset || 0 : 0
  65. standardButtons: T.Dialog.Open | T.Dialog.Cancel
  66. FileDialogImpl.buttonBox: buttonBox
  67. FileDialogImpl.nameFiltersComboBox: nameFiltersComboBox
  68. FileDialogImpl.fileDialogListView: fileDialogListView
  69. FileDialogImpl.breadcrumbBar: breadcrumbBar
  70. background: NinePatchImage {
  71. source: Imagine.url + "dialog-background"
  72. NinePatchImageSelector on source {
  73. states: [
  74. {"modal": control.modal},
  75. {"dim": control.dim}
  76. ]
  77. }
  78. }
  79. header: ColumnLayout {
  80. spacing: 12
  81. Label {
  82. text: control.title
  83. elide: Label.ElideRight
  84. font.bold: true
  85. Layout.leftMargin: 16
  86. Layout.rightMargin: 16
  87. Layout.topMargin: 12
  88. Layout.fillWidth: true
  89. Layout.preferredHeight: control.title.length > 0 ? implicitHeight : 0
  90. background: NinePatchImage {
  91. width: parent.width
  92. height: parent.height
  93. source: Imagine.url + "dialog-title"
  94. NinePatchImageSelector on source {
  95. states: [
  96. {"modal": control.modal},
  97. {"dim": control.dim}
  98. ]
  99. }
  100. }
  101. }
  102. DialogsImpl.FolderBreadcrumbBar {
  103. id: breadcrumbBar
  104. fileDialog: control
  105. Layout.leftMargin: 16
  106. Layout.rightMargin: 16
  107. Layout.fillWidth: true
  108. Layout.maximumWidth: parent.width - 28
  109. }
  110. }
  111. contentItem: ListView {
  112. id: fileDialogListView
  113. objectName: "fileDialogListView"
  114. clip: true
  115. boundsBehavior: Flickable.StopAtBounds
  116. ScrollBar.vertical: ScrollBar {}
  117. model: FolderListModel {
  118. folder: control.currentFolder
  119. nameFilters: control.selectedNameFilter.globs
  120. showDirsFirst: true
  121. sortCaseSensitive: false
  122. }
  123. delegate: DialogsImpl.FileDialogDelegate {
  124. objectName: "fileDialogDelegate" + index
  125. width: ListView.view.width
  126. highlighted: ListView.isCurrentItem
  127. fileDialog: control
  128. fileDetailRowWidth: nameFiltersComboBox.width
  129. }
  130. }
  131. footer: RowLayout {
  132. id: rowLayout
  133. spacing: 20
  134. ComboBox {
  135. id: nameFiltersComboBox
  136. model: control.nameFilters
  137. Layout.leftMargin: 16
  138. Layout.bottomMargin: 16
  139. Layout.fillWidth: true
  140. }
  141. DialogButtonBox {
  142. id: buttonBox
  143. standardButtons: control.standardButtons
  144. spacing: 12
  145. Layout.bottomMargin: 16
  146. Layout.rightMargin: 16
  147. }
  148. }
  149. T.Overlay.modal: NinePatchImage {
  150. source: Imagine.url + "dialog-overlay"
  151. NinePatchImageSelector on source {
  152. states: [
  153. {"modal": true}
  154. ]
  155. }
  156. }
  157. T.Overlay.modeless: NinePatchImage {
  158. source: Imagine.url + "dialog-overlay"
  159. NinePatchImageSelector on source {
  160. states: [
  161. {"modal": false}
  162. ]
  163. }
  164. }
  165. }