FileDialog.qml 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  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.Dialogs
  41. import QtQuick.Dialogs.quickimpl
  42. import QtQuick.Layouts
  43. import QtQuick.Templates as T
  44. import "." as DialogsImpl
  45. FileDialogImpl {
  46. id: control
  47. implicitWidth: Math.max(implicitBackgroundWidth + leftInset + rightInset,
  48. contentWidth + leftPadding + rightPadding,
  49. implicitHeaderWidth,
  50. implicitFooterWidth)
  51. implicitHeight: Math.max(implicitBackgroundHeight + topInset + bottomInset,
  52. contentHeight + topPadding + bottomPadding
  53. + (implicitHeaderHeight > 0 ? implicitHeaderHeight + spacing : 0)
  54. + (implicitFooterHeight > 0 ? implicitFooterHeight + spacing : 0))
  55. leftPadding: 20
  56. rightPadding: 20
  57. // Ensure that the background's border is visible.
  58. leftInset: -1
  59. rightInset: -1
  60. topInset: -1
  61. bottomInset: -1
  62. standardButtons: T.Dialog.Open | T.Dialog.Cancel
  63. /*
  64. We use attached properties because we want to handle logic in C++, and:
  65. - We can't assume the footer only contains a DialogButtonBox (which would allow us
  66. to connect up to it in QQuickFileDialogImpl); it also needs to hold a ComboBox
  67. and therefore the root footer item will be e.g. a layout item instead.
  68. - We don't want to create our own "FileDialogButtonBox" (in order to be able to handle the logic
  69. in C++) because we'd need to copy (and hence duplicate code in) DialogButtonBox.qml.
  70. */
  71. FileDialogImpl.buttonBox: buttonBox
  72. FileDialogImpl.nameFiltersComboBox: nameFiltersComboBox
  73. FileDialogImpl.fileDialogListView: fileDialogListView
  74. FileDialogImpl.breadcrumbBar: breadcrumbBar
  75. background: Rectangle {
  76. implicitWidth: 600
  77. implicitHeight: 400
  78. color: control.palette.window
  79. border.color: control.palette.dark
  80. }
  81. header: Pane {
  82. palette.window: control.palette.light
  83. padding: 20
  84. contentItem: Column {
  85. spacing: 12
  86. Label {
  87. objectName: "dialogTitleBarLabel"
  88. width: parent.width
  89. text: control.title
  90. visible: control.title.length > 0
  91. horizontalAlignment: Label.AlignHCenter
  92. elide: Label.ElideRight
  93. font.bold: true
  94. }
  95. DialogsImpl.FolderBreadcrumbBar {
  96. id: breadcrumbBar
  97. width: parent.width
  98. fileDialog: control
  99. KeyNavigation.tab: fileDialogListView
  100. }
  101. }
  102. }
  103. contentItem: ListView {
  104. id: fileDialogListView
  105. objectName: "fileDialogListView"
  106. clip: true
  107. focus: true
  108. boundsBehavior: Flickable.StopAtBounds
  109. ScrollBar.vertical: ScrollBar {}
  110. model: FolderListModel {
  111. folder: control.currentFolder
  112. nameFilters: control.selectedNameFilter.globs
  113. showDirsFirst: true
  114. sortCaseSensitive: false
  115. }
  116. delegate: DialogsImpl.FileDialogDelegate {
  117. objectName: "fileDialogDelegate" + index
  118. width: ListView.view.width
  119. highlighted: ListView.isCurrentItem
  120. fileDialog: control
  121. fileDetailRowWidth: nameFiltersComboBox.width
  122. KeyNavigation.backtab: breadcrumbBar
  123. KeyNavigation.tab: nameFiltersComboBox
  124. }
  125. }
  126. footer: Rectangle {
  127. color: control.palette.light
  128. implicitWidth: rowLayout.implicitWidth
  129. implicitHeight: rowLayout.implicitHeight
  130. RowLayout {
  131. id: rowLayout
  132. width: parent.width
  133. height: parent.height
  134. spacing: 20
  135. ComboBox {
  136. // OK to use IDs here, since users shouldn't be overriding this stuff.
  137. id: nameFiltersComboBox
  138. model: control.nameFilters
  139. Layout.leftMargin: 20
  140. Layout.fillWidth: true
  141. }
  142. DialogButtonBox {
  143. id: buttonBox
  144. standardButtons: control.standardButtons
  145. palette.window: control.palette.light
  146. spacing: 12
  147. horizontalPadding: 0
  148. verticalPadding: 20
  149. Layout.rightMargin: 20
  150. }
  151. }
  152. }
  153. Overlay.modal: Rectangle {
  154. color: Color.transparent(control.palette.shadow, 0.5)
  155. }
  156. Overlay.modeless: Rectangle {
  157. color: Color.transparent(control.palette.shadow, 0.12)
  158. }
  159. }