1 | /****************************************************************************
|
---|
2 | **
|
---|
3 | ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
|
---|
4 | ** All rights reserved.
|
---|
5 | ** Contact: Nokia Corporation ([email protected])
|
---|
6 | **
|
---|
7 | ** This file is part of the documentation of the Qt Toolkit.
|
---|
8 | **
|
---|
9 | ** $QT_BEGIN_LICENSE:FDL$
|
---|
10 | ** Commercial Usage
|
---|
11 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
---|
12 | ** accordance with the Qt Commercial License Agreement provided with the
|
---|
13 | ** Software or, alternatively, in accordance with the terms contained in a
|
---|
14 | ** written agreement between you and Nokia.
|
---|
15 | **
|
---|
16 | ** GNU Free Documentation License
|
---|
17 | ** Alternatively, this file may be used under the terms of the GNU Free
|
---|
18 | ** Documentation License version 1.3 as published by the Free Software
|
---|
19 | ** Foundation and appearing in the file included in the packaging of this
|
---|
20 | ** file.
|
---|
21 | **
|
---|
22 | ** If you have questions regarding the use of this file, please contact
|
---|
23 | ** Nokia at [email protected].
|
---|
24 | ** $QT_END_LICENSE$
|
---|
25 | **
|
---|
26 | ****************************************************************************/
|
---|
27 |
|
---|
28 | /*!
|
---|
29 | \example statemachine/twowaybutton
|
---|
30 | \title Two-way Button Example
|
---|
31 |
|
---|
32 | The Two-way button example shows how to use \l{The State Machine
|
---|
33 | Framework} to implement a simple state machine that toggles the current
|
---|
34 | state when a button is clicked.
|
---|
35 |
|
---|
36 | \snippet examples/statemachine/twowaybutton/main.cpp 0
|
---|
37 |
|
---|
38 | The application's main() function begins by constructing the application
|
---|
39 | object, a button and a state machine.
|
---|
40 |
|
---|
41 | \snippet examples/statemachine/twowaybutton/main.cpp 1
|
---|
42 |
|
---|
43 | The state machine has two states; \c on and \c off. When either state is
|
---|
44 | entered, the text of the button will be set accordingly.
|
---|
45 |
|
---|
46 | \snippet examples/statemachine/twowaybutton/main.cpp 2
|
---|
47 |
|
---|
48 | When the state machine is in the \c off state and the button is clicked,
|
---|
49 | it will transition to the \c on state; when the state machine is in the \c
|
---|
50 | on state and the button is clicked, it will transition to the \c off
|
---|
51 | state.
|
---|
52 |
|
---|
53 | \snippet examples/statemachine/twowaybutton/main.cpp 3
|
---|
54 |
|
---|
55 | The states are added to the state machine; they become top-level (sibling)
|
---|
56 | states.
|
---|
57 |
|
---|
58 | \snippet examples/statemachine/twowaybutton/main.cpp 4
|
---|
59 |
|
---|
60 | The initial state is \c off; this is the state the state machine will
|
---|
61 | immediately transition to once the state machine is started.
|
---|
62 |
|
---|
63 | \snippet examples/statemachine/twowaybutton/main.cpp 5
|
---|
64 |
|
---|
65 | Finally, the button is resized and made visible, and the application event
|
---|
66 | loop is entered.
|
---|
67 |
|
---|
68 | */
|
---|