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

source code of qtdeclarative/src/quicktemplates/qquicktoolbar.cpp