1 | // Copyright (C) 2017 The Qt Company Ltd. |
2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
3 | |
4 | #include "qquicktoolbar_p.h" |
5 | #include "qquickpane_p_p.h" |
6 | |
7 | QT_BEGIN_NAMESPACE |
8 | |
9 | /*! |
10 | \qmltype ToolBar |
11 | \inherits Pane |
12 | //! \instantiates QQuickToolBar |
13 | \inqmlmodule QtQuick.Controls |
14 | \since 5.7 |
15 | \ingroup qtquickcontrols-containers |
16 | \brief Container for context-sensitive controls. |
17 | |
18 | ToolBar is a container of application-wide and context sensitive |
19 | actions and controls, such as navigation buttons and search fields. |
20 | ToolBar is commonly used as a \l {ApplicationWindow::header}{header} |
21 | or a \l {ApplicationWindow::footer}{footer} of an \l ApplicationWindow. |
22 | |
23 | ToolBar does not provide a layout of its own, but requires you to |
24 | position its contents, for instance by creating a \l RowLayout. If only |
25 | a single item is used within the ToolBar, it will resize to fit the |
26 | implicit size of its contained item. This makes it particularly suitable |
27 | for use together with layouts. |
28 | |
29 | \image qtquickcontrols-toolbar.png |
30 | |
31 | \code |
32 | ApplicationWindow { |
33 | visible:true |
34 | |
35 | header: ToolBar { |
36 | RowLayout { |
37 | anchors.fill: parent |
38 | ToolButton { |
39 | text: qsTr("‹") |
40 | onClicked: stack.pop() |
41 | } |
42 | Label { |
43 | text: "Title" |
44 | elide: Label.ElideRight |
45 | horizontalAlignment: Qt.AlignHCenter |
46 | verticalAlignment: Qt.AlignVCenter |
47 | Layout.fillWidth: true |
48 | } |
49 | ToolButton { |
50 | text: qsTr("⋮") |
51 | onClicked: menu.open() |
52 | } |
53 | } |
54 | } |
55 | |
56 | StackView { |
57 | id: stack |
58 | anchors.fill: parent |
59 | } |
60 | } |
61 | \endcode |
62 | |
63 | \sa ApplicationWindow, ToolButton, {Customizing ToolBar}, {Container Controls} |
64 | */ |
65 | |
66 | class QQuickToolBarPrivate : public QQuickPanePrivate |
67 | { |
68 | public: |
69 | QPalette defaultPalette() const override { return QQuickTheme::palette(scope: QQuickTheme::ToolBar); } |
70 | |
71 | QQuickToolBar::Position position = QQuickToolBar::Header; |
72 | }; |
73 | |
74 | QQuickToolBar::QQuickToolBar(QQuickItem *parent) |
75 | : QQuickPane(*(new QQuickToolBarPrivate), parent) |
76 | { |
77 | } |
78 | |
79 | /*! |
80 | \qmlproperty enumeration QtQuick.Controls::ToolBar::position |
81 | |
82 | This property holds the position of the toolbar. |
83 | |
84 | \note If the toolbar is assigned as a header or footer of \l ApplicationWindow |
85 | or \l Page, the appropriate position is set automatically. |
86 | |
87 | Possible values: |
88 | \value ToolBar.Header The toolbar is at the top, as a window or page header. |
89 | \value ToolBar.Footer The toolbar is at the bottom, as a window or page footer. |
90 | |
91 | The default value is style-specific. |
92 | |
93 | \sa ApplicationWindow::header, ApplicationWindow::footer, Page::header, Page::footer |
94 | */ |
95 | QQuickToolBar::Position QQuickToolBar::position() const |
96 | { |
97 | Q_D(const QQuickToolBar); |
98 | return d->position; |
99 | } |
100 | |
101 | void QQuickToolBar::setPosition(Position position) |
102 | { |
103 | Q_D(QQuickToolBar); |
104 | if (d->position == position) |
105 | return; |
106 | |
107 | d->position = position; |
108 | emit positionChanged(); |
109 | } |
110 | |
111 | QFont QQuickToolBar::defaultFont() const |
112 | { |
113 | return QQuickTheme::font(scope: QQuickTheme::ToolBar); |
114 | } |
115 | |
116 | #if QT_CONFIG(accessibility) |
117 | QAccessible::Role QQuickToolBar::accessibleRole() const |
118 | { |
119 | return QAccessible::ToolBar; |
120 | } |
121 | #endif |
122 | |
123 | QT_END_NAMESPACE |
124 | |
125 | #include "moc_qquicktoolbar_p.cpp" |
126 | |