diff --git a/examples/quick/dialogs/systemdialogs/FileDialogs.qml b/examples/quick/dialogs/systemdialogs/FileDialogs.qml index 6bdaf7bc631f728fc66bc9a1ef5a5ff7e0adac64..79a58b9825ce9097dd94aebff6c8b29633bc8af3 100644 --- a/examples/quick/dialogs/systemdialogs/FileDialogs.qml +++ b/examples/quick/dialogs/systemdialogs/FileDialogs.qml @@ -61,6 +61,7 @@ Item { selectFolder: fileDialogSelectFolder.checked nameFilters: [ "Image files (*.png *.jpg)", "All files (*)" ] selectedNameFilter: "All files (*)" + sidebarVisible: fileDialogSidebarVisible.checked onAccepted: { console.log("Accepted: " + fileUrls) if (fileDialogOpenFiles.checked) @@ -106,6 +107,12 @@ Item { id: fileDialogOpenFiles text: "Open Files After Accepting" } + CheckBox { + id: fileDialogSidebarVisible + text: "Show Sidebar" + checked: fileDialog.sidebarVisible + Binding on checked { value: fileDialog.sidebarVisible } + } CheckBox { id: fileDialogVisible text: "Visible" diff --git a/src/dialogs/DefaultFileDialog.qml b/src/dialogs/DefaultFileDialog.qml index 278ee9dbe4e0dacfc7dd8d6983be023307fb841d..7a91353f779951d1a8d64784a6d208382b363031 100644 --- a/src/dialogs/DefaultFileDialog.qml +++ b/src/dialogs/DefaultFileDialog.qml @@ -47,6 +47,7 @@ import QtQuick.Layouts 1.1 import QtQuick.Window 2.1 import Qt.labs.folderlistmodel 2.1 import Qt.labs.settings 1.0 +import "qml" AbstractFileDialog { id: root @@ -75,6 +76,7 @@ AbstractFileDialog { property alias height: root.height property alias sidebarWidth: sidebar.width property alias sidebarSplit: shortcuts.height + property alias sidebarVisible: root.sidebarVisible property variant favoriteFolders: [] } @@ -166,6 +168,7 @@ AbstractFileDialog { Component.onCompleted: if (width < 1) width = sidebarSplitter.maxShortcutWidth height: parent.height width: 0 // initial width only; settings and onCompleted will override it + visible: root.sidebarVisible SplitView { id: sidebarSplitter orientation: Qt.Vertical @@ -414,11 +417,23 @@ AbstractFileDialog { anchors.rightMargin: spacing anchors.verticalCenter: parent.verticalCenter spacing: 4 + Button { + id: toggleSidebarButton + checkable: true + style: IconButtonStyle { } + text: "\u25E7" + height: cancelButton.height + width: height + checked: root.sidebarVisible + onClicked: { + root.sidebarVisible = !root.sidebarVisible + } + } ComboBox { id: filterField model: root.nameFilters visible: !selectFolder - width: bottomBar.width - cancelButton.width - okButton.width - parent.spacing * 5 + width: bottomBar.width - toggleSidebarButton.width - cancelButton.width - okButton.width - parent.spacing * 6 anchors.verticalCenter: parent.verticalCenter onCurrentTextChanged: { root.selectNameFilter(currentText) diff --git a/src/dialogs/dialogs.pro b/src/dialogs/dialogs.pro index 4ad7888f5f753021301b8a00c234ef7e1bf383ea..c33fa7f78a6b2f03e5daff4203daaa037fef7dce 100644 --- a/src/dialogs/dialogs.pro +++ b/src/dialogs/dialogs.pro @@ -51,7 +51,9 @@ DIALOGS_QML_FILES += \ DefaultDialogWrapper.qml \ qml/ColorSlider.qml \ qml/DefaultWindowDecoration.qml \ + qml/IconButtonStyle.qml \ qml/qmldir \ + qml/icons.ttf \ images/critical.png \ images/information.png \ images/question.png \ diff --git a/src/dialogs/qml/IconButtonStyle.qml b/src/dialogs/qml/IconButtonStyle.qml new file mode 100644 index 0000000000000000000000000000000000000000..3af5b6cdffad09995b651238bb48b7cf989b0825 --- /dev/null +++ b/src/dialogs/qml/IconButtonStyle.qml @@ -0,0 +1,58 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the Qt Quick Controls module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names +** of its contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +import QtQuick 2.2 +import QtQuick.Controls 1.2 +import QtQuick.Controls.Private 1.0 +import QtQuick.Controls.Styles 1.1 + +ButtonStyle { + FontLoader { id: iconFont; source: "icons.ttf" } + + label: Text { + id: text + font.family: iconFont.name + font.pointSize: TextSingleton.font.pointSize * 1.5 + renderType: Text.NativeRendering + text: control.text + color: SystemPaletteSingleton.buttonText(control.enabled) + verticalAlignment: Text.AlignVCenter + horizontalAlignment: Text.AlignHCenter + } +} diff --git a/src/dialogs/qml/icons.ttf b/src/dialogs/qml/icons.ttf new file mode 100644 index 0000000000000000000000000000000000000000..e94078eb5e466582118b8068c3d8a2e25b03f752 Binary files /dev/null and b/src/dialogs/qml/icons.ttf differ diff --git a/src/dialogs/qml/qmldir b/src/dialogs/qml/qmldir index c2bf3e58e50bc22777414f5d48f27909ee7e09ed..184e80cecf693d6b1cdd563e2d4851a92938c897 100644 --- a/src/dialogs/qml/qmldir +++ b/src/dialogs/qml/qmldir @@ -1 +1,2 @@ ColorSlider 1.0 ColorSlider.qml +IconButtonStyle 1.0 IconButtonStyle.qml diff --git a/src/dialogs/qquickabstractfiledialog.cpp b/src/dialogs/qquickabstractfiledialog.cpp index 671f33f89fe81d5aaeaf93179a9d10d1c9c50560..e7df943251e20606dd6056b25f87bc4cf99938fc 100644 --- a/src/dialogs/qquickabstractfiledialog.cpp +++ b/src/dialogs/qquickabstractfiledialog.cpp @@ -48,6 +48,7 @@ QQuickAbstractFileDialog::QQuickAbstractFileDialog(QObject *parent) , m_selectExisting(true) , m_selectMultiple(false) , m_selectFolder(false) + , m_sidebarVisible(true) { updateModes(); connect(this, SIGNAL(accepted()), this, SIGNAL(selectionAccepted())); @@ -155,6 +156,13 @@ void QQuickAbstractFileDialog::setSelectedNameFilterIndex(int idx) selectNameFilter(nameFilters().at(idx)); } +void QQuickAbstractFileDialog::setSidebarVisible(bool s) +{ + if (s == m_sidebarVisible) return; + m_sidebarVisible = s; + emit sidebarVisibleChanged(); +} + QStringList QQuickAbstractFileDialog::selectedNameFilterExtensions() const { QString filterRaw = selectedNameFilter(); diff --git a/src/dialogs/qquickabstractfiledialog_p.h b/src/dialogs/qquickabstractfiledialog_p.h index 499b645d5caea2bf905fe522a0f06c75acb18de9..aa740b1207e693ea5caf66b4be3950fa2710e3dd 100644 --- a/src/dialogs/qquickabstractfiledialog_p.h +++ b/src/dialogs/qquickabstractfiledialog_p.h @@ -65,6 +65,7 @@ class QQuickAbstractFileDialog : public QQuickAbstractDialog Q_PROPERTY(int selectedNameFilterIndex READ selectedNameFilterIndex WRITE setSelectedNameFilterIndex NOTIFY filterSelected) Q_PROPERTY(QUrl fileUrl READ fileUrl NOTIFY selectionAccepted) Q_PROPERTY(QList<QUrl> fileUrls READ fileUrls NOTIFY selectionAccepted) + Q_PROPERTY(bool sidebarVisible READ sidebarVisible WRITE setSidebarVisible NOTIFY sidebarVisibleChanged) public: QQuickAbstractFileDialog(QObject *parent = 0); @@ -81,6 +82,7 @@ public: int selectedNameFilterIndex() const; QUrl fileUrl() const; virtual QList<QUrl> fileUrls() const; + bool sidebarVisible() const { return m_sidebarVisible; } public Q_SLOTS: void setVisible(bool v); @@ -92,6 +94,7 @@ public Q_SLOTS: void setNameFilters(const QStringList &f); void selectNameFilter(const QString &f); void setSelectedNameFilterIndex(int idx); + void setSidebarVisible(bool s); Q_SIGNALS: void folderChanged(); @@ -99,6 +102,7 @@ Q_SIGNALS: void filterSelected(); void fileModeChanged(); void selectionAccepted(); + void sidebarVisibleChanged(); protected: void updateModes(); @@ -109,6 +113,7 @@ protected: bool m_selectExisting; bool m_selectMultiple; bool m_selectFolder; + bool m_sidebarVisible; Q_DISABLE_COPY(QQuickAbstractFileDialog) }; diff --git a/src/dialogs/qquickplatformfiledialog.cpp b/src/dialogs/qquickplatformfiledialog.cpp index 4a52c485c8db26c73f4e07976f551349de849cd7..7ed4e3fbc28062e89dd02dc0ecd647ef28980514 100644 --- a/src/dialogs/qquickplatformfiledialog.cpp +++ b/src/dialogs/qquickplatformfiledialog.cpp @@ -329,4 +329,15 @@ QPlatformFileDialogHelper *QQuickPlatformFileDialog::helper() The list of file paths which were selected by the user. */ +/*! + \qmlproperty bool FileDialog::sidebarVisible + + This property holds whether the sidebar in the dialog containing shortcuts + and bookmarks is visible. By default it depends on the setting stored in + the \c QQControlsFileDialog section of the application's + \l {Qt.labs.settings::Settings} {Settings}. + + \since 5.4 +*/ + QT_END_NAMESPACE