Tiroirs

Les tiroirs permettent aux applications d'accéder rapidement aux contrôles et aux pages de votre application.

Les tiroirs sont des panneaux coulissant sur les côtés de la fenêtre de l'application. Ils peuvent être remplis d'éléments interactifs tels que des actions de Kirigami, des boutons, du texte, etc.

Les tiroirs sont proposés avec différents types, différentes formes et différents modèles. Dans cette page, nous allons passer en revue chaque type et donner un aperçu de leurs caractéristiques.

Tiroir global

Le tiroir global est une fonctionnalité standard dans les applications mobiles de KDE et peut parfois être aussi présent dans leurs versions de bureau. Il contient un menu principal d'une application. Ce qui est inclus sont toutes les fonctions qui ne sont pas spécifiques à la page en cours, mais qui sont importantes pour la navigation ou l'interaction générale au sein de l'application.

It can be activated by tapping the hamburger menu or by swiping from the left edge to the middle of the screen in Left to Right mode or from the right edge in Right to Left mode.

Kirigami.GlobalDrawer components are what we use to create such drawers. These are set to the globalDrawer property of the Kirigami.ApplicationWindow that forms the basis of our Kirigami application.

Kirigami.ApplicationWindow {

    globalDrawer: Kirigami.GlobalDrawer {
        actions: [
            Kirigami.Action {
                text: "Kirigami Action 1"
            },
            Kirigami.Action {
                text: "Kirigami Action 2"
            },
            Kirigami.Action {
                text: i18n("Quit")
                icon.name: "gtk-quit"
                shortcut: StandardKey.Quit
                onTriggered: Qt.quit()
            }
        ]
    }
    ...
}
Screenshot of a global drawer in desktop mode that looks like a sidebar

En-tête

Les en-têtes peuvent être utilisés pour placer des composants collants en haut de votre tiroir global. Les composants d'en-tête resteront en place même si votre tiroir global contient des actions de Kirigami imbriquées qui remplacent la couche actuelle du tiroir global.

Le composant d'en-tête que vous avez choisi peut être défini avec la propriété « header » du tiroir global.

globalDrawer: Kirigami.GlobalDrawer {

    header: Kirigami.AbstractApplicationHeader {

        contentItem: Kirigami.SearchField {
            id: searchField
            Layout.fillWidth: true
        }
    }

    actions: [
        Kirigami.Action {
            text: "Kirigami Action 1"
        },
        Kirigami.Action {
            text: "Kirigami Action 2"
        },
        Kirigami.Action {
            text: i18n("Quit")
            icon.name: "application-exit"
            shortcut: StandardKey.Quit
            onTriggered: Qt.quit()
        }
    ]
}
Our global drawer now shows the search bar component we set as the header

Our global drawer now shows the search bar component we set as the header

Adaptation au bureau

Si les tiroirs globaux de type panneau peuvent être utiles dans les environnements mobiles, ils peuvent être trop grands sur le bureau.

Thankfully, Kirigami global drawers provide an isMenu property. When set to true, they turn into more traditional menus only on the desktop.

globalDrawer: Kirigami.GlobalDrawer {
    isMenu: true

    actions: [
        Kirigami.Action {
            text: "Kirigami Action 1"
        },
        Kirigami.Action {
            text: "Kirigami Action 2"
        },
        Kirigami.Action {
            text: i18n("Quit")
            icon.name: "application-exit"
            shortcut: StandardKey.Quit
            onTriggered: Qt.quit()
        }
    ]
}
Global drawer in menu mode, without a header or banner

Global drawer in menu mode, without a header or banner

Bannières

Les bannières vous permettent d'afficher un titre et une icône en haut de votre tiroir global (même au-dessus de l'en-tête).

By default, banners are only visible on mobile environments. You can change this by setting the global drawer component's bannerVisible property to true.

Titles, set with the title property, can be used to pretty up your global drawer and make it seem less sparse. More importantly, it can remind your users that this is a global and app-wide drawer rather than a local drawer.

There is also a titleIcon property, which can be paired with your title to make the global drawer even more aesthetically pleasing. This icon will be placed to the left of the title.

globalDrawer: Kirigami.GlobalDrawer {
    title: "My Global Drawer"
    titleIcon: "kde"
    bannerVisible: true
    actions: [
        Kirigami.Action {
            text: "Kirigami Action 1"
        },
        Kirigami.Action {
            text: "Kirigami Action 2"
        },
        Kirigami.Action {
            text: i18n("Quit")
            icon.name: "application-exit"
            shortcut: StandardKey.Quit
            onTriggered: Qt.quit()
        }
    ]
}
Global drawer with title and icon in banner

Global drawer with title and icon in banner

Context Drawers

While a Kirigami.GlobalDrawer displays global actions available throughout your application, a Kirigami.ContextDrawer should be used to display actions that are only relevant in certain contexts. This is usually used in separate pages.

A context drawer will only show up if any contextualActions have been created as part of the Page.actions group . It also behaves differently depending on whether it is being used on a mobile platform or on a desktop.

On a desktop, when a window has enough space, contextual actions show up as part of the actions group in the top toolbar. When space is limited, such as on a mobile device or in a narrow window, contextual actions are hidden behind a hamburger menu on the right side. This is different from other actions in the actions group, namely actions.main, actions.left and actions.right; these do not get hidden in space-constrained windows, and are instead collapsed into their respective icons.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import org.kde.kirigami 2.20 as Kirigami

Kirigami.ApplicationWindow {
    height: 600
    width: 1200
    minimumWidth: 500

    globalDrawer: Kirigami.GlobalDrawer {}
    contextDrawer: Kirigami.ContextDrawer {}

    pageStack.initialPage: [ emptyPage, contextDrawerPage ]

    Kirigami.Page {
        title: "Empty page"
        id: emptyPage
    }

    Kirigami.Page {
        id: contextDrawerPage
        title: "Context Drawer page"

        actions {
            main: Kirigami.Action {
                icon.name: "media-record"
            }
            left: Kirigami.Action {
                icon.name: "arrow-left"
            }
            right: Kirigami.Action {
                icon.name: "arrow-right"
            }
            contextualActions: [
                Kirigami.Action {
                    text: "Contextual Action 1"
                    icon.name: "media-playback-start"
                },
                Kirigami.Action {
                    text: "Contextual Action 2"
                    icon.name: "media-playback-stop"
                }
            ]
        }
    }
}
Context drawer with contextual actions hidden

Context drawer with contextual actions hidden

Context drawer showing all contextual actions

Context drawer showing all contextual actions

On mobile, the drawer always consists of actions hidden behind a hamburger menu. It can be activated by tapping the hamburger menu or by swiping from the right edge to the middle of the screen in Left to Right mode or from the left edge in Right to Left mode. If you are on a desktop and want to test the mobile interface, you can run your application with the environment variable QT_QUICK_CONTROLS_MOBILE=1.

Même exemple ci-dessus, en exécution en mode mobile

Même exemple ci-dessus, en exécution en mode mobile

Context drawer open in mobile mode

Context drawer open in mobile mode

Tiroirs modaux et intégrés

Kirigami propose deux autres types de tiroirs, les tiroirs modaux et les tiroirs intégrés. Ils sont assez semblables l'un à l'autre. Tous deux s'étendent sur toute la largeur ou la hauteur de l'application et peuvent être placés sur les bords de la fenêtre de l'application. Cependant, ils réagissent différemment lors d'une interaction avec l'utilisateur.

  • Modal drawers darken the rest of the application and, like overlay sheets , will be dismissed when clicking on a darkened area.
  • Les tiroirs intégrés permettent à l'utilisateur de continuer à interagir avec le reste de l'application sans être renvoyé et n'assombrissent pas les autres zones.

These two drawers are so similar because they can, in fact, be implemented using the same Kirigami component: Kirigami.OverlayDrawer . Here are a few important inherited properties of this component to keep in mind:

  • Popup.modal controls whether the drawer will be modal or inline depending on a boolean value
  • Drawer.edge controls which edge of the application window the drawer will appear on; options for this property are part of the Edge enum , namely Qt.TopEdge, Qt.RightEdge, Qt.BottomEdge, and Qt.LeftEdge
  • Popup.contentItem contains the component that will form the content of your drawer
import QtQuick.Controls 2.15 as Controls

Kirigami.Page {

    Kirigami.OverlayDrawer {
        id: bottomDrawer
        edge: Qt.BottomEdge
        // Définissez le paramètre « modal » à « False » pour que ce tiroir soit en ligne !
        modal: true

        contentItem: RowLayout {
            Layout.fillWidth: true

            Controls.Label {
                Layout.fillWidth: true
                text: "Say hello to my little drawer!"
            }
            Controls.Button {
                text: "Close"
                onClicked: bottomDrawer.close()
            }
        }
    }

    Controls.Button {
        text: "Open bottomDrawer"
        onClicked: bottomDrawer.open()
    }
}
Modal drawer on the bottom edge of the screen

Modal drawer on the bottom edge of the screen

Inline drawer on the bottom edge of the screen

Inline drawer on the bottom edge of the screen

A use case for bottom overlay drawers: NeoChat

NeoChat uses bottom overlay drawers to provide the user with a number of actions they can perform on a message they have long pressed. Here is a simplified example of what that looks like:

Kirigami.Page {

    ListView {
        model: App.MessageModel
        delegate: MessageDelegate {
            onPressAndHold: bottomDrawer.open()
        }
    }

   Kirigami.OverlayDrawer {
       id: bottomDrawer
       height: popupContent.implicitHeight
       edge: Qt.BottomEdge
       padding: 0
       leftPadding: 0
       rightPadding: 0
       bottomPadding: 0
       topPadding: 0

       parent: applicationWindow().overlay

       ColumnLayout {
           id: popupContent
           width: parent.width
           spacing: 0
           
           // Informations sur le message
           ...
           
           // Actions de messages
           Kirigami.BasicListItem {
               text: "Reply"
               onClicked: {
                   bottomDrawer.close();
               }
           }
           ...
       }
    }
}