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 "qquickbutton_p.h"
5#include "qquickbutton_p_p.h"
6
7#include <QtGui/qpa/qplatformtheme.h>
8
9QT_BEGIN_NAMESPACE
10
11/*!
12 \qmltype Button
13 \inherits AbstractButton
14//! \instantiates QQuickButton
15 \inqmlmodule QtQuick.Controls
16 \since 5.7
17 \ingroup qtquickcontrols-buttons
18 \brief Push-button that can be clicked to perform a command or answer a question.
19
20 \image qtquickcontrols-button.gif
21
22 Button presents a push-button control that can be pushed or clicked by
23 the user. Buttons are normally used to perform an action, or to answer
24 a question. Typical buttons are \e OK, \e Apply, \e Cancel, \e Close,
25 \e Yes, \e No, and \e Help.
26
27 Button inherits its API from AbstractButton. For instance, you can set
28 \l {AbstractButton::text}{text}, display an \l {Icons in Qt Quick Controls}{icon},
29 and react to \l {AbstractButton::clicked}{clicks} using the AbstractButton API.
30
31 A button emits the signal \l {AbstractButton::}{clicked()} when it is activated by the user.
32 Connect to this signal to perform the button's action. Buttons also
33 provide the signals \l {AbstractButton::}{canceled()}, \l {AbstractButton::}{doubleClicked()}, \l {AbstractButton::}{pressed()},
34 \l {AbstractButton::}{released()} and \l {AbstractButton::}{pressAndHold()} for long presses.
35
36 See the snippet below on how to connect to the button's signals.
37
38 \code
39 RowLayout {
40 Button {
41 text: "Ok"
42 onClicked: model.submit()
43 }
44 Button {
45 text: "Cancel"
46 onClicked: model.revert()
47 }
48 }
49 \endcode
50
51 \sa {Customizing Button}, {Button Controls}
52*/
53
54QQuickButton::QQuickButton(QQuickItem *parent)
55 : QQuickAbstractButton(*(new QQuickButtonPrivate), parent)
56{
57}
58
59QQuickButton::QQuickButton(QQuickButtonPrivate &dd, QQuickItem *parent)
60 : QQuickAbstractButton(dd, parent)
61{
62}
63
64QFont QQuickButton::defaultFont() const
65{
66 return QQuickTheme::font(scope: QQuickTheme::Button);
67}
68
69/*!
70 \qmlproperty bool QtQuick.Controls::Button::highlighted
71
72 This property holds whether the button is highlighted.
73
74 \image qtquickcontrols-button-highlighted.gif
75
76 A button can be highlighted in order to draw the user's attention towards
77 it. It has no effect on keyboard interaction.
78
79 The default value is \c false.
80*/
81bool QQuickButton::isHighlighted() const
82{
83 Q_D(const QQuickButton);
84 return d->highlighted;
85}
86
87void QQuickButton::setHighlighted(bool highlighted)
88{
89 Q_D(QQuickButton);
90 if (highlighted == d->highlighted)
91 return;
92
93 d->highlighted = highlighted;
94 emit highlightedChanged();
95}
96
97/*!
98 \qmlproperty bool QtQuick.Controls::Button::flat
99
100 This property holds whether the button is flat.
101
102 \image qtquickcontrols-button-flat.gif
103
104 A flat button typically does not draw a background unless it is pressed or checked.
105
106 The default value is \c false.
107*/
108bool QQuickButton::isFlat() const
109{
110 Q_D(const QQuickButton);
111 return d->flat;
112}
113
114void QQuickButton::setFlat(bool flat)
115{
116 Q_D(QQuickButton);
117 if (flat == d->flat)
118 return;
119
120 d->flat = flat;
121 emit flatChanged();
122}
123
124QPalette QQuickButtonPrivate::defaultPalette() const
125{
126 return QQuickTheme::palette(scope: QQuickTheme::Button);
127}
128
129QT_END_NAMESPACE
130
131#include "moc_qquickbutton_p.cpp"
132

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