1/****************************************************************************
2**
3** Copyright (C) 2017 The Qt Company Ltd.
4** Contact: http://www.qt.io/licensing/
5**
6** This file is part of the Qt Quick Templates 2 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
37#include "qquicktoolbar_p.h"
38#include "qquickpane_p_p.h"
39
40QT_BEGIN_NAMESPACE
41
42/*!
43 \qmltype ToolBar
44 \inherits Pane
45//! \instantiates QQuickToolBar
46 \inqmlmodule QtQuick.Controls
47 \since 5.7
48 \ingroup qtquickcontrols2-containers
49 \brief Container for context-sensitive controls.
50
51 ToolBar is a container of application-wide and context sensitive
52 actions and controls, such as navigation buttons and search fields.
53 ToolBar is commonly used as a \l {ApplicationWindow::header}{header}
54 or a \l {ApplicationWindow::footer}{footer} of an \l ApplicationWindow.
55
56 ToolBar does not provide a layout of its own, but requires you to
57 position its contents, for instance by creating a \l RowLayout. If only
58 a single item is used within the ToolBar, it will resize to fit the
59 implicit size of its contained item. This makes it particularly suitable
60 for use together with layouts.
61
62 \image qtquickcontrols2-toolbar.png
63
64 \code
65 ApplicationWindow {
66 visible:true
67
68 header: ToolBar {
69 RowLayout {
70 anchors.fill: parent
71 ToolButton {
72 text: qsTr("‹")
73 onClicked: stack.pop()
74 }
75 Label {
76 text: "Title"
77 elide: Label.ElideRight
78 horizontalAlignment: Qt.AlignHCenter
79 verticalAlignment: Qt.AlignVCenter
80 Layout.fillWidth: true
81 }
82 ToolButton {
83 text: qsTr("⋮")
84 onClicked: menu.open()
85 }
86 }
87 }
88
89 StackView {
90 id: stack
91 anchors.fill: parent
92 }
93 }
94 \endcode
95
96 \sa ApplicationWindow, ToolButton, {Customizing ToolBar}, {Container Controls}
97*/
98
99class QQuickToolBarPrivate : public QQuickPanePrivate
100{
101public:
102 QQuickToolBar::Position position = QQuickToolBar::Header;
103};
104
105QQuickToolBar::QQuickToolBar(QQuickItem *parent)
106 : QQuickPane(*(new QQuickToolBarPrivate), parent)
107{
108}
109
110/*!
111 \qmlproperty enumeration QtQuick.Controls::ToolBar::position
112
113 This property holds the position of the toolbar.
114
115 \note If the toolbar is assigned as a header or footer of \l ApplicationWindow
116 or \l Page, the appropriate position is set automatically.
117
118 Possible values:
119 \value ToolBar.Header The toolbar is at the top, as a window or page header.
120 \value ToolBar.Footer The toolbar is at the bottom, as a window or page footer.
121
122 The default value is style-specific.
123
124 \sa ApplicationWindow::header, ApplicationWindow::footer, Page::header, Page::footer
125*/
126QQuickToolBar::Position QQuickToolBar::position() const
127{
128 Q_D(const QQuickToolBar);
129 return d->position;
130}
131
132void QQuickToolBar::setPosition(Position position)
133{
134 Q_D(QQuickToolBar);
135 if (d->position == position)
136 return;
137
138 d->position = position;
139 emit positionChanged();
140}
141
142QFont QQuickToolBar::defaultFont() const
143{
144 return QQuickTheme::font(scope: QQuickTheme::ToolBar);
145}
146
147QPalette QQuickToolBar::defaultPalette() const
148{
149 return QQuickTheme::palette(scope: QQuickTheme::ToolBar);
150}
151
152#if QT_CONFIG(accessibility)
153QAccessible::Role QQuickToolBar::accessibleRole() const
154{
155 return QAccessible::ToolBar;
156}
157#endif
158
159QT_END_NAMESPACE
160

source code of qtquickcontrols2/src/quicktemplates2/qquicktoolbar.cpp