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

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