Debian Codegraph @

examples/hapticsquare/hapticsquare.cpp

raw symbols SCIP
1 /****************************************************************************
2 **
3 ** Copyright (C) 2017 The Qt Company Ltd.
4 ** Contact: https://www.qt.io/licensing/
5 **
6 ** This file is part of the examples of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:BSD$
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 https://www.qt.io/terms-conditions. For further
15 ** information use the contact form at https://www.qt.io/contact-us.
16 **
17 ** BSD License Usage
18 ** Alternatively, you may use this file under the terms of the BSD license
19 ** as follows:
20 **
21 ** "Redistribution and use in source and binary forms, with or without
22 ** modification, are permitted provided that the following conditions are
23 ** met:
24 ** * Redistributions of source code must retain the above copyright
25 ** notice, this list of conditions and the following disclaimer.
26 ** * Redistributions in binary form must reproduce the above copyright
27 ** notice, this list of conditions and the following disclaimer in
28 ** the documentation and/or other materials provided with the
29 ** distribution.
30 ** * Neither the name of The Qt Company Ltd nor the names of its
31 ** contributors may be used to endorse or promote products derived
32 ** from this software without specific prior written permission.
33 **
34 **
35 ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
36 ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
37 ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
38 ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
39 ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
40 ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
41 ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
42 ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
43 ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
44 ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
45 ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
46 **
47 ** $QT_END_LICENSE$
48 **
49 ****************************************************************************/
50
51 #include "hapticsquare.h"
52 #include "hapticbutton.h"
53
54 #include <QGridLayout>
55 #include <QDebug>
56
57 //! [0]
58 HapticSquare::HapticSquare()
59 {
60 m_rumble.setAttackIntensity(0.1);
61 m_rumble.setAttackTime(250);
62 m_rumble.setIntensity(1.0);
63 m_rumble.setDuration(1000);
64 m_rumble.setFadeTime(250);
65 m_rumble.setFadeIntensity(0.1);
66 //! [0]
67
68 //! [1]
69 m_ocean.setAttackIntensity(0.1);
70 m_ocean.setAttackTime(450);
71 m_ocean.setIntensity(0.8);
72 m_ocean.setDuration(6000);
73 m_ocean.setFadeTime(900);
74 m_ocean.setFadeIntensity(0.05);
75 m_ocean.setPeriod(1500);
76 //! [1]
77
78 //! [2]
79 m_btnRumble = new HapticButton(tr("Rumble!"));
80 m_btnOcean = new HapticButton(tr("Ocean"));
81 m_btnButtonClick = new HapticButton(tr("Click"));
82 m_btnNegativeEffect = new HapticButton(tr("Oops!"));
83 QGridLayout *topLayout = new QGridLayout(this);
84 topLayout->addWidget(m_btnRumble, 0, 0);
85 topLayout->addWidget(m_btnOcean, 0, 1);
86 topLayout->addWidget(m_btnButtonClick, 1, 0);
87 topLayout->addWidget(m_btnNegativeEffect, 1, 1);
88
89 connect(m_btnRumble, SIGNAL(clicked()), this, SLOT(playRumble()));
90 connect(m_btnOcean, SIGNAL(clicked()), this, SLOT(playOcean()));
91 connect(m_btnButtonClick, SIGNAL(clicked()), this, SLOT(playButtonClick()));
92 connect(m_btnNegativeEffect, SIGNAL(clicked()), this, SLOT(playNegativeEffect()));
93 }
94 //! [2]
95
96 HapticSquare::~HapticSquare()
97 {
98 delete m_btnRumble;
99 delete m_btnOcean;
100 delete m_btnButtonClick;
101 delete m_btnNegativeEffect;
102 }
103
104 //! [3]
105 void HapticSquare::playRumble()
106 {
107 m_rumble.start();
108 }
109
110 void HapticSquare::playOcean()
111 {
112 if (m_ocean.state() == QFeedbackEffect::Stopped) {
113 m_ocean.start();
114 } else {
115 m_ocean.stop();
116 }
117 }
118 //! [3]
119
120 //! [4]
121 void HapticSquare::playButtonClick()
122 {
123 QFeedbackEffect::playThemeEffect(QFeedbackEffect::ThemeBasicButton);
124 }
125
126 void HapticSquare::playNegativeEffect()
127 {
128 QFeedbackEffect::playThemeEffect(QFeedbackEffect::ThemeNegativeTacticon);
129 }
130 //! [4]
131
132 #include "moc_hapticsquare.cpp"