diff options
author | Karsten Heimrich <karsten.heimrich@qt.io> | 2020-08-18 14:26:50 +0200 |
---|---|---|
committer | Karsten Heimrich <karsten.heimrich@qt.io> | 2020-08-24 20:10:25 +0200 |
commit | a735038376e1c229c293c36bd67800851323baf1 (patch) | |
tree | 4b0621b9a0b322ecb45e3843b3d7c3bacd90296f /examples/widgets/doc/src | |
parent | 43f01ec2e5bc52b290098d0fca1dd4ae40f2c6d3 (diff) |
Move QStateMachine from QtCore to QtScxml
Task-number: QTBUG-80316
Change-Id: I2ee74110fd55e94d86321d3b3dc5bb8297424ed4
Reviewed-by: Maurice Kalinowski <maurice.kalinowski@qt.io>
Diffstat (limited to 'examples/widgets/doc/src')
-rw-r--r-- | examples/widgets/doc/src/animatedtiles.qdoc | 36 | ||||
-rw-r--r-- | examples/widgets/doc/src/eventtransitions.qdoc | 85 | ||||
-rw-r--r-- | examples/widgets/doc/src/factorial.qdoc | 88 | ||||
-rw-r--r-- | examples/widgets/doc/src/moveblocks.qdoc | 214 | ||||
-rw-r--r-- | examples/widgets/doc/src/padnavigator.qdoc | 586 | ||||
-rw-r--r-- | examples/widgets/doc/src/pingpong.qdoc | 93 | ||||
-rw-r--r-- | examples/widgets/doc/src/rogue.qdoc | 208 | ||||
-rw-r--r-- | examples/widgets/doc/src/states.qdoc | 36 | ||||
-rw-r--r-- | examples/widgets/doc/src/stickman.qdoc | 102 | ||||
-rw-r--r-- | examples/widgets/doc/src/sub-attaq.qdoc | 41 | ||||
-rw-r--r-- | examples/widgets/doc/src/trafficlight.qdoc | 85 | ||||
-rw-r--r-- | examples/widgets/doc/src/twowaybutton.qdoc | 68 |
12 files changed, 0 insertions, 1642 deletions
diff --git a/examples/widgets/doc/src/animatedtiles.qdoc b/examples/widgets/doc/src/animatedtiles.qdoc deleted file mode 100644 index 9f1d912b0d..0000000000 --- a/examples/widgets/doc/src/animatedtiles.qdoc +++ /dev/null @@ -1,36 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the documentation of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:FDL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Free Documentation License Usage -** Alternatively, this file may be used under the terms of the GNU Free -** Documentation License version 1.3 as published by the Free Software -** Foundation and appearing in the file included in the packaging of -** this file. Please review the following information to ensure -** the GNU Free Documentation License version 1.3 requirements -** will be met: https://www.gnu.org/licenses/fdl-1.3.html. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -/*! - \example animation/animatedtiles - \title Animated Tiles Example - - \brief The Animated Tiles example animates items in a graphics scene. - - \image animatedtiles-example.png -*/ - diff --git a/examples/widgets/doc/src/eventtransitions.qdoc b/examples/widgets/doc/src/eventtransitions.qdoc deleted file mode 100644 index e74831b14b..0000000000 --- a/examples/widgets/doc/src/eventtransitions.qdoc +++ /dev/null @@ -1,85 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the documentation of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:FDL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Free Documentation License Usage -** Alternatively, this file may be used under the terms of the GNU Free -** Documentation License version 1.3 as published by the Free Software -** Foundation and appearing in the file included in the packaging of -** this file. Please review the following information to ensure -** the GNU Free Documentation License version 1.3 requirements -** will be met: https://www.gnu.org/licenses/fdl-1.3.html. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -/*! - \example statemachine/eventtransitions - \title Event Transitions Example - - \brief The Event Transitions example shows how to use event transitions, - a feature of \l{The State Machine Framework}. - - The Event Transitions Example illustrates how states change when a - user enters or leaves the area of a button. The states are handled by - a QStateMachine object. The screen consists of a QVBoxLayout with a - central button. - - When the mouse is outside the button, the text in the button displays - "Outside". When the mouse enters the button, it displays "Inside". - - \borderedimage transitions.png - - \snippet statemachine/eventtransitions/main.cpp 0 - - The \c Window class's constructors begins by creating a button. - This button is added to \c layout, which is a QVBoxLayout object. - Then two states are created: \c s1 is the state - "Outside", and \c s2 is the state "Inside". - - \snippet statemachine/eventtransitions/main.cpp 1 - - State \c s1 is the state "Outside" and state \c s2 is state "Inside". - - \snippet statemachine/eventtransitions/main.cpp 2 - - When the button receives an event of type QEvent::Enter and the state - machine is in state \c s1, the machine will transition to state \c s2. - - \snippet statemachine/eventtransitions/main.cpp 3 - - When the button receives an event of type QEvent::Leave and the state - machine is in state \c s2, the machine will transition back to state \c - s1. - - \snippet statemachine/eventtransitions/main.cpp 4 - - Next, state \c s3 is created. \c s3 will be entered when the button - receives an event of type QEvent::MouseButtonPress and the state machine - is in state \c s2. When the button receives an event of type - QEvent::MouseButtonRelease and the state machine is in state \c s3, the - machine will revert to state \c s2. - - \snippet statemachine/eventtransitions/main.cpp 5 - - Finally, the states are added to the machine as top-level states, the - initial state is set to be \c s1 ("Outside"), and the machine is started. - - \snippet statemachine/eventtransitions/main.cpp 6 - - The main() function constructs a Window object that displays the QVBoxLayout - object \c layout with its \c button. - -*/ diff --git a/examples/widgets/doc/src/factorial.qdoc b/examples/widgets/doc/src/factorial.qdoc deleted file mode 100644 index a0ace96cd3..0000000000 --- a/examples/widgets/doc/src/factorial.qdoc +++ /dev/null @@ -1,88 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the documentation of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:FDL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Free Documentation License Usage -** Alternatively, this file may be used under the terms of the GNU Free -** Documentation License version 1.3 as published by the Free Software -** Foundation and appearing in the file included in the packaging of -** this file. Please review the following information to ensure -** the GNU Free Documentation License version 1.3 requirements -** will be met: https://www.gnu.org/licenses/fdl-1.3.html. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -/*! - \example statemachine/factorial - \title Factorial States Example - - \brief The Factorial States example shows how to use \l{The State Machine - Framework} to calculate the factorial of an integer. - - The statechart for calculating the factorial looks as follows: - - \image factorial-example.png - \omit - \caption This is a caption - \endomit - - In other words, the state machine calculates the factorial of 6 and prints - the result. - - \snippet statemachine/factorial/main.cpp 0 - - The Factorial class is used to hold the data of the computation, \c x and - \c fac. It also provides a signal that's emitted whenever the value of \c - x changes. - - \snippet statemachine/factorial/main.cpp 1 - - The FactorialLoopTransition class implements the guard (\c x > 1) and - calculations (\c fac = \c x * \c fac; \c x = \c x - 1) of the factorial - loop. - - \snippet statemachine/factorial/main.cpp 2 - - The FactorialDoneTransition class implements the guard (\c x <= 1) that - terminates the factorial computation. It also prints the final result to - standard output. - - \snippet statemachine/factorial/main.cpp 3 - - The application's main() function first creates the application object, a - Factorial object and a state machine. - - \snippet statemachine/factorial/main.cpp 4 - - The \c compute state is created, and the initial values of \c x and \c fac - are defined. A FactorialLoopTransition object is created and added to the - state. - - \snippet statemachine/factorial/main.cpp 5 - - A final state, \c done, is created, and a FactorialDoneTransition object - is created with \c done as its target state. The transition is then added - to the \c compute state. - - \snippet statemachine/factorial/main.cpp 6 - - The machine's initial state is set to be the \c compute state. We connect - the QStateMachine::finished() signal to the QCoreApplication::quit() slot, - so the application will quit when the state machine's work is - done. Finally, the state machine is started, and the application's event - loop is entered. - - */ diff --git a/examples/widgets/doc/src/moveblocks.qdoc b/examples/widgets/doc/src/moveblocks.qdoc deleted file mode 100644 index 64045f1c4f..0000000000 --- a/examples/widgets/doc/src/moveblocks.qdoc +++ /dev/null @@ -1,214 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the documentation of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:FDL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Free Documentation License Usage -** Alternatively, this file may be used under the terms of the GNU Free -** Documentation License version 1.3 as published by the Free Software -** Foundation and appearing in the file included in the packaging of -** this file. Please review the following information to ensure -** the GNU Free Documentation License version 1.3 requirements -** will be met: https://www.gnu.org/licenses/fdl-1.3.html. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -/*! - \example animation/moveblocks - \title Move Blocks Example - - \brief The Move Blocks example shows how to animate items in a - QGraphicsScene using a QStateMachine with a custom transition. - - \image moveblocks-example.png - - The example animates the blue blocks that you can see in the image - above. The animation moves the blocks between four preset positions. - - The example consists of the following classes: - - \list - \li \c StateSwitcher inherits QState and can add - \c {StateSwitchTransition}s to other states. - When entered, it will randomly transition to one of these - states. - \li \c StateSwitchTransition is a custom transition that - triggers on \c{StateSwitchEvent}s. - \li \c StateSwitchEvent is a QEvent that triggers \c{StateSwitchTransition}s. - \li \c QGraphicsRectWidget is a QGraphicsWidget that simply - paints its background in a solid \l{Qt::}{blue} color. - \endlist - - The blocks are instances of \c QGraphicsRectWidget and are - animated in a QGraphicsScene. We do this by building a state - graph, which we insert animations into. The graph is then executed - in a QStateMachine. All this is done in \c main(). - Let's look at the \c main() function first. - - \section1 The \c main() Function - - After QApplication has been initialized, we set up the - QGraphicsScene with its \c{QGraphicsRectWidget}s. - - \snippet animation/moveblocks/main.cpp 1 - - After adding the scene to a QGraphicsView, it is time to build the - state graph. Let's first look at a statechart of what we are - trying to build. - - \image move-blocks-chart.png - - Note that the \c group has seven sub states, but we have only - included three of them in the diagram. The code that builds this - graph will be examined line-by-line, and will show how the graph - works. First off, we construct the \c group state: - - \snippet animation/moveblocks/main.cpp 2 - - The timer is used to add a delay between each time the blocks are - moved. The timer is started when \c group is entered. As we will - see later, \c group has a transition back to the \c StateSwitcher - when the timer times out. \c group is the initial state in the - machine, so an animation will be scheduled when the example is - started. - - \snippet animation/moveblocks/main.cpp 3 - \dots - \snippet animation/moveblocks/main.cpp 4 - - \c createGeometryState() returns a QState that will set the - geometry of our items upon entry. It also assigns \c group as the - parent of this state. - - A QPropertyAnimation inserted into a transition will use the - values assigned to a QState (with QState::assignProperty()), i.e., - the animation will interpolate between the current values of the - properties and the values in the target state. We add animated - transitions to the state graph later. - - \snippet animation/moveblocks/main.cpp 5 - - We move the items in parallel. Each item is added to \c - animationGroup, which is the animation that is inserted into the - transitions. - - \snippet animation/moveblocks/main.cpp 6 - - The sequential animation group, \c subGroup, helps us insert a - delay between the animation of each item. - - \snippet animation/moveblocks/main.cpp 7 - \dots - \snippet animation/moveblocks/main.cpp 8 - - A StateSwitchTransition is added to the state switcher - in \c StateSwitcher::addState(). We also add the animation in this - function. Since QPropertyAnimation uses the values from the - states, we can insert the same QPropertyAnimation instance in all - \c {StateSwitchTransition}s. - - As mentioned previously, we add a transition to the state switcher - that triggers when the timer times out. - - \snippet animation/moveblocks/main.cpp 9 - - Finally, we can create the state machine, add our initial state, - and start execution of the state graph. - - \section2 The \c createGeometryState() Function - - In \c createGeometryState(), we set up the geometry for each - graphics item. - - \snippet animation/moveblocks/main.cpp 13 - - As mentioned before, QAbstractTransition will set up an animation - added with \l{QAbstractTransition::}{addAnimation()} using - property values set with \l{QState::}{assignProperty()}. - - \section1 The StateSwitcher Class - - \c StateSwitcher has state switch transitions to each \l{QState}s - we created with \c createGeometryState(). Its job is to transition - to one of these states at random when it is entered. - - All functions in \c StateSwitcher are inlined. We'll step through - its definition. - - \snippet animation/moveblocks/main.cpp 10 - - \c StateSwitcher is a state designed for a particular purpose and - will always be a top-level state. We use \c m_stateCount to keep - track of how many states we are managing, and \c m_lastIndex to - remember which state was the last state to which we transitioned. - - \snippet animation/moveblocks/main.cpp 11 - - We select the next state we are going to transition to, and post a - \c StateSwitchEvent, which we know will trigger the \c - StateSwitchTransition to the selected state. - - \snippet animation/moveblocks/main.cpp 12 - - This is where the magic happens. We assign a number to each state - added. This number is given to both a StateSwitchTransition and to - StateSwitchEvents. As we have seen, state switch events will - trigger a transition with the same number. - - \section1 The StateSwitchTransition Class - - \c StateSwitchTransition inherits QAbstractTransition and triggers - on \c{StateSwitchEvent}s. It contains only inline functions, so - let's take a look at its \l{QAbstractTransition::}{eventTest()} - function, which is the only function that we define.. - - \snippet animation/moveblocks/main.cpp 14 - - \c eventTest is called by QStateMachine when it checks whether a - transition should be triggered--a return value of true means that - it will. We simply check if our assigned number is equal to the - event's number (in which case we fire away). - - \section1 The StateSwitchEvent Class - - \c StateSwitchEvent inherits QEvent, and holds a number that has - been assigned to a state and state switch transition by - \c StateSwitcher. We have already seen how it is used to trigger - \c{StateSwitchTransition}s in \c StateSwitcher. - - \snippet animation/moveblocks/main.cpp 15 - - We only have inlined functions in this class, so a look at its - definition will do. - - \section1 The QGraphicsRectWidget Class - - QGraphicsRectWidget inherits QGraphicsWidget and simply paints its - \l{QWidget::}{rect()} blue. We inline \l{QWidget::}{paintEvent()}, - which is the only function we define. Here is the - QGraphicsRectWidget class definition: - - \snippet animation/moveblocks/main.cpp 16 - - \section1 Moving On - - The technique shown in this example works equally well for all - \l{QPropertyAnimation}s. As long as the value to be animated is a - Qt property, you can insert an animation of it into a state graph. - - QState::addAnimation() takes a QAbstractAnimation, so any type - of animation can be inserted into the graph. -*/ - diff --git a/examples/widgets/doc/src/padnavigator.qdoc b/examples/widgets/doc/src/padnavigator.qdoc deleted file mode 100644 index 31440b650f..0000000000 --- a/examples/widgets/doc/src/padnavigator.qdoc +++ /dev/null @@ -1,586 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the documentation of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:FDL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Free Documentation License Usage -** Alternatively, this file may be used under the terms of the GNU Free -** Documentation License version 1.3 as published by the Free Software -** Foundation and appearing in the file included in the packaging of -** this file. Please review the following information to ensure -** the GNU Free Documentation License version 1.3 requirements -** will be met: https://www.gnu.org/licenses/fdl-1.3.html. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -/*! - \example graphicsview/padnavigator - \title Pad Navigator Example - \ingroup examples-graphicsview - \brief Demonstrates how to create animated user interface. - - The Pad Navigator Example shows how you can use Graphics View together with - embedded widgets and Qt's \l{The State Machine Framework}{state machine - framework} to create a simple but useful, dynamic, animated user interface. - - \image padnavigator-example.png - - The interface consists of a flippable, rotating pad with icons that can be - selected using the arrow keys on your keyboard or keypad. Pressing enter - will flip the pad around and reveal its back side, which has a form - embedded into a QGraphicsProxyWidget. You can interact with the form, and - press the enter key to flip back to the front side of the pad at any time. - - Graphics View provides the QGraphicsScene class for managing and - interacting with a large number of custom-made 2D graphical items derived - from the QGraphicsItem class, and a QGraphicsView widget for visualizing - the items, with support for zooming and rotation. - - This example consists of a \c RoundRectItem class, a \c FlippablePad class, - a \c PadNavigator class, a \c SplashItem class, and a \c main() function. - - \section1 RoundRectItem Class Definition - - The \c RoundRectItem class is used by itself to display the icons on the - pad, and as a base class for \c FlippablePad, the class for the pad itself. - The role of the class is to paint a round rectangle of a specified size and - gradient color, and optionally to paint a pixmap icon on top. To support \c - FlippablePad it also allows filling its contents with a plain window - background color. - - Let's start by reviewing the \c RoundRectItem class declaration. - - \snippet graphicsview/padnavigator/roundrectitem.h 0 - - \c RoundRectItem inherits QGraphicsObject, which makes it easy to control - its properties using QPropertyAnimation. Its constructor takes a rectangle - to determine its bounds, and a color. - - Besides implementing the mandatory \l{QGraphicsItem::paint()}{paint()} and - \l{QGraphicsItem::boundingRect()}{boundingRect()} pure virtual functions, - it also provides the \c pixmap and \c fill properties. - - The \c pixmap property sets an optional pixmap that is drawn on top of the - round rectangle. The \c fill property will, when true, fill the round - rectangle contents with a fixed QPalette::Window background color. - Otherwise the contents are filled using a gradient based on the color - passed to \c RoundRectItem's constructor. - - \snippet graphicsview/padnavigator/roundrectitem.h 1 - - The private data members are: - - \list - \li \c pix: The optional pixmap that is drawn on top of the rectangle. - \li \c fillRect: Corresponds to the \c fill property. - \li \c color: The configurable gradient color fill of the rectangle. - \li \c bounds: The bounds of the rectangle. - \li \c gradient: A precalculated gradient used to fill the rectangle. - \endlist - - We will now review the \c RoundRectItem implementation. Let's start by - looking at its constructor: - - \snippet graphicsview/padnavigator/roundrectitem.cpp 0 - - The constructor initializes its member variables and forwards the \c parent - argument to QGraphicsObject's constructor. It then constructs the linear - gradient that is used in \l{QGraphicsItem::paint()}{paint()} to draw the - round rectangle's gradient background. The linear gradient's starting point - is at the top-left corner of the bounds, and the end is at the bottom-left - corner. The start color is identical to the color passed as an argument, - and a slightly darker color is chosen for the final stop. - - We store this gradient as a member variable to avoid having to recreate the - gradient every time the item is repainted. - - Finally we set the cache mode - \l{QGraphicsItem::ItemCoordinateCache}{ItemCoordinateCache}. This mode - causes the item's rendering to be cached into an off-screen pixmap that - remains persistent as we move and transform the item. This mode is ideal - for this example, and works particularly well with OpenGL and OpenGL ES. - - \snippet graphicsview/padnavigator/roundrectitem.cpp 1 - - The \c pixmap property implementation simple returns the member pixmap, or - sets it and then calls \l{QGraphicsItem::update()}{update()}. - - \snippet graphicsview/padnavigator/roundrectitem.cpp 2 - - As the \l{QGraphicsItem::paint()}{paint()} implementation below draws a - simple drop shadow down and to the right of the item, we return a slightly - adjusted rectangle from \l{QGraphicsItem::boundingRect()}{boundingRect()}. - - \snippet graphicsview/padnavigator/roundrectitem.cpp 3 - - The \l{QGraphicsItem::paint()}{paint()} implementation starts by rendering - a semi transparent black round rectangle drop shadow, two units down and to - the right of the main item. - - \snippet graphicsview/padnavigator/roundrectitem.cpp 4 - - We then draw the "foreground" round rectangle itself. The fill depends on - the \c fill property; if true, we will with a plain QPalette::Window color. - We get the current brush from QApplication::palette(). We assign a single - unit wide pen for the stroke, assign the brush, and then draw the - rectangle. - - \snippet graphicsview/padnavigator/roundrectitem.cpp 5 - - If a pixmap has been assigned to the \e pixmap property, we draw this - pixmap in the center of the rectangle item. The pixmaps are scaled to match - the size of the icons; in arguably a better approach would have been to - store the icons with the right size in the first places. - - \snippet graphicsview/padnavigator/roundrectitem.cpp 6 - - Finally, for completeness we include the \c fill property implementation. - It returns the \c fill member variable's value, and when assigned to, it - calls \l{QGraphicsItem::update()}{update()}. - - As mentioned already, \c RoundRectItem is the base class for \c - FlippablePad, which is the class representing the tilting pad itself. We - will proceed to reviewing \c FlippablePad. - - \section1 FlippablePad Class Definition - - \c FlippablePad is, in addition to its inherited \c RoundRectItem - responsibilities, responsible for creating and managing a grid of icons. - - \snippet graphicsview/padnavigator/flippablepad.h 0 - - Its declaration is very simple: It inherits \c RoundRectItem and does not - need any special polymorphic behavior. It's suitable to declare its own - constructor, and a getter-function that allows \c PadNavigator to access - the icons in the grid by (row, column). - - The example has no "real" behavior or logic of any kind, and because of - that, the icons do not need to provide any \e behavior or special - interactions management. In a real application, however, it would be - natural for the \c FlippablePad and its icons to handle more of the - navigation logic. In this example, we have chosen to leave this to - the \c PadNavigator class, which we will get back to below. - - We will now review the \c FlippablePad implementation. This implementation - starts with two helper functions: \c boundsFromSize() and \c - posForLocation(): - - \snippet graphicsview/padnavigator/flippablepad.cpp 0 - - \c boundsForSize() takes a QSize argument, and returns the bounding - rectangle of the flippable pad item. The QSize determines how many rows and - columns the icon grid should have. Each icon is given 150x150 units of - space, and this determines the bounds. - - \snippet graphicsview/padnavigator/flippablepad.cpp 1 - - \c posForLocation() returns the position of an icon given its row and - column position. Like \c boundsForSize(), the function assumes each icon is - given 150x150 units of space, and that all icons are centered around the - flippable pad item's origin (0, 0). - - \snippet graphicsview/padnavigator/flippablepad.cpp 2 - - The \c FlippablePad constructor passes suitable bounds (using \c - boundsForSize()) and specific color to \c RoundRectItem's constructor. - - \snippet graphicsview/padnavigator/flippablepad.cpp 3 - - It then loads pixmaps from compiled-in resources to use for its icons. - QDirIterator is very useful in this context, as it allows us to fetch all - resource "*.png" files inside the \c :/images directory without explicitly - naming the files. - - We also make sure not to load more pixmaps than we need. - - \snippet graphicsview/padnavigator/flippablepad.cpp 4 - - Now that we have the pixmaps, we can create icons, position then and assign - pixmaps. We start by finding a suitable size and color for the icons, and - initializing a convenient grid structure for storing the icons. This \c - iconGrid is also used later to find the icon for a specific (column, row) - location. - - For each row and column in our grid, we proceed to constructing each icon - as an instance of \c RoundRectItem. The item is placed by using the \c - posForLocation() helper function. To make room for the slip-behind - selection item, we give each icon a \l{QGraphicsItem::zValue()}{Z-value} of - 1. The pixmaps are distributed to the icons in round-robin fasion. - - Again, this approach is only suitable for example purposes. In a real-life - application where each icon represents a specific action, it would be more - natural to assign the pixmaps directly, or that the icons themselves - provide suitable pixmaps. - - \snippet graphicsview/padnavigator/flippablepad.cpp 5 - - Finally, the \c iconAt() function returns a pointer to the icon at a - specific row and column. It makes a somewhat bold assumption that the input - is valid, which is fair because the \c PadNavigator class only calls this - function with correct input. - - We will now review the \c SplashItem class. - - \section1 SplashItem Class Definition - - The \c SplashItem class represents the "splash window", a semitransparent - white overlay with text that appears immediately after the application has - started, and disappears after pressing any key. The animation is controlled - by \c PadNavigator; this class is very simple by itself. - - \snippet graphicsview/padnavigator/splashitem.h 0 - - The class declaration shows that \c SplashItem inherits QGraphicsObject to - allow it to be controlled by QPropertyAnimation. It reimplements the - mandatory \l{QGraphicsItem::paint()}{paint()} and - \l{QGraphicsItem::boundingRect()}{boundingRect()} pure virtual functions, - and keeps a \c text member variable which will contain the information text - displayed on this splash item. - - Let's look at its implementation. - - \snippet graphicsview/padnavigator/splashitem.cpp 0 - - The constructor forwards to QGraphicsObject as expected, assigns a text - message to the \c text member variable, and enables - \l{QGraphicsItem::DeviceCoordinateCache}{DeviceCoordinateCache}. This cache - mode is suitable because the splash item only moves and is never - transformed, and because it contains text, it's important that it has a - pixel perfect visual appearance (in constrast to - \l{QGraphicsItem::ItemCoordinateCache}{ItemCoordinateCache}, where the - visual appearance is not as good). - - We use caching to avoid having to relayout and rerender the text for each - frame. An alterative approach would be to use the new QStaticText class. - - \snippet graphicsview/padnavigator/splashitem.cpp 1 - - \c SplashItem's bounding rectangle is fixed at (400x175). - - \snippet graphicsview/padnavigator/splashitem.cpp 2 - - The \l{QGraphicsItem::paint()}{paint()} implementation draws a clipped - round rectangle with a thick 2-unit border and a semi-transparent white - background. It proceeds to finding a suitable text area by adjusting the - splash item's bounding rectangle with 10 units in each side. The text is - rendered inside this rectangle, with top-left alignment, and with word - wrapping enabled. - - The main class now remains. We will proceed to reviewing \c PadNavigator. - - \section1 PadNavigator Class Definition - - \c PadNavigator represents the main window of our Pad Navigator Example - application. It creates and controls a somewhat complex state machine, and - several animations. Its class declaration is very simple: - - \snippet graphicsview/padnavigator/padnavigator.h 0 - - It inherits QGraphicsView and reimplements only one function: - \l{QGraphicsView::resizeEvent()}{resizeEvent()}, to ensure the scene is - scaled to fit inside the view when resizing the main window. - - The \c PadNavigator constructor takes a QSize argument that determines the - number or rows and columns in the grid. - - It also keeps a private member instance, \c form, which is the generated - code for the pad's back side item's QGraphicsProxyWidget-embedded form. - - \snippet graphicsview/padnavigator/padnavigator.cpp 0 - - \c PadNavigator's constructor is a bit long. In short, its job is to create - all items, including the \c FlippablePad, the \c SplashItem and the - QGraphicsProxyWidget \c backItem, and then to set up all animations, states - and transitions that control the behavior of the application. - - It starts out simple, by forwarding to QGraphicsView's constructor. - - \snippet graphicsview/padnavigator/padnavigator.cpp 1 - - The first item to be created is \c SplashItem. This is going to be a top-level - item in the scene, next to \c FlippablePad, and stacked on top of it, so we - assign it a \l{QGraphicsItem::zValue()}{Z-value} of 1. - - \snippet graphicsview/padnavigator/padnavigator.cpp 2 - - Now we construct the \c FlippablePad item, passing its column-row count to - its constructor. - - The pad is controlled by three transformations, and we create one - QGraphicsRotation object for each of these. - - \list - \li \c flipRotation: Rotates the grid around its Qt::YAxis. This rotation is - animated from 0 to 180, and eventually back, when enter is pressed on the - keyboard, flipping the pad around. - \li \c xRotation: Rotates the grid around its Qt::XAxis. This is used to - tilt the pad vertically corresponding to which item is currently selected. - This way, the selected item is always kept in front. - \li \c yRotation: Rotates the grid around its Qt::YAxis. This is used to - tilt the pad horizontally corresponding to which item is selected. This - way, the selected item is always kept in front. - \endlist - - The combination of all three rotations is assigned via - QGraphicsItem::setTransformations(). - - \snippet graphicsview/padnavigator/padnavigator.cpp 3 - - Now we construct the QGraphicsProxyWidget-embedded \c backItem. The proxy - widget is created as a child of the pad. We create a new QWidget and - populate it with the \c form member. To ensure the \c hostName line edit is - the first to receive input focus when this item is shown, we call - \l{QWidget::setFocus()}{setFocus()} immediately. This will not give the - widget focus right away; it will only prepare the item to automatically - receive focus once it is shown. - - The QWidget based form is embedded into the proxy widget. The proxy is - hidden initially; we only want to show it when the pad is rotated at least - 90 degrees, and we also rotate the proxy itself by 180 degrees. This way we - give the impression that the proxy widget is "behind" the flipped pad, when - in fact, it's actually \e{on top of it}. - - We enable \l{QGraphicsItem::ItemCoordinateCache}{ItemCoordinateCache} to - ensure the flip animation can run smoothly. - - \snippet graphicsview/padnavigator/padnavigator.cpp 4 - - We now create the selection item. This is simply another instance of \c - RoundRectItem that is slightly larger than the icons on the pad. We create - it as an immediate child of the \c FlippablePad, so the selection item is a - sibling to all the icons. By giving it a - \l{QGraphicsItem::zValue()}{Z-value} of 0.5 we ensure it will slide between - the pad and its icons. - - What follows now is a series of animation initializations. - - \snippet graphicsview/padnavigator/padnavigator.cpp 5 - - We begin with the animations that apply to the splash item. The first - animation, \c smoothSplashMove, ensures that the "y" property of \c splash - will be animated with a 250-millisecond duration - \l{QEasingCurve::InQuad}{InQuad} easing function. \c smoothSplashOpacity - ensures the opacity of \c splash eases in and out in 250 milliseconds. - - The values are assigned by \c PadNavigator's state machine, which is - created later. - - \snippet graphicsview/padnavigator/padnavigator.cpp 6 - - These are the animations that control the selection item's movement and the - \c xRotation and \c yRotation QGraphicsRotation objects that tilt the pad. - All animations have a duration of 125 milliseconds, and they all use the - \l{QEasingCurve::InOutQuad}{InOutQuad} easing function. - - \snippet graphicsview/padnavigator/padnavigator.cpp 7 - - We now create the animations that control the flip-effect when you press - the enter key. The main goal is to rotate the pad by 180 degrees or back. - - \list - \li \c smoothFlipRotation: Animates the main 180 degree rotation of the pad. - \li \c smoothFlipScale: Scales the pad out and then in again while the pad is rotating. - \li \c flipAnimation: A parallel animation group that ensures the above animations are run in parallel. - \endlist - - All animations are given a 500 millisecond duration and an - \l{QEasingCurve::InOutQuad}{InOutQuad} easing function. - - It's worth taking a close look at \c smoothFlipScale. This animation's - start and end values are both 1.0, but at animation step 0.5 the - animation's value is 0.7. This means that after 50% of the animation's - duration, or 250 milliseconds, the pad will be scaled down to 0.7x of its - original size, which gives a great visual effect while flipping. - - \snippet graphicsview/padnavigator/padnavigator.cpp 8 - - This section uses a trick to ensure that certain properties are assigned - precisely when the flip animation passes 50%, or 90 degrees, rotation. In - short, the pad's icons and selection item are all hidden, the pad's \c fill - property is enabled, and \c backItem is shown when flipping over. When - flipping back, the reverse properties are applied. - - The way this is achieved is by running a sequential animation in parallel - to the other animations. This sequence, dubbed \c setVariablesSequence, - starts with a 250 millisecond pause, and then executes several animations - with a duration of 0. Each animation will ensure that properties are set - immediate at this point. - - This approach can also be used to call functions or set any other - properties at a specific time while an animation is running. - - \snippet graphicsview/padnavigator/padnavigator.cpp 9 - - We will now create the state machine. The whole \c PadNavigator state - machinery is controlled by one single state machine that has a - straight-forward state structure. The state engine itself is created - as a child of the \c PadNavigator itself. We then create three top level - states: - - \list - \li \c splashState: The initial state where the splash item is visible. - \li \c frontState: The base state where the splash is gone and we can see - the front side of the pad, and navigate the selection item. - \li \c backState: The flipped state where the \c backItem is visible, and we - can interact with the QGraphicsProxyWidget-embedded form. - \endlist - - \snippet graphicsview/padnavigator/padnavigator.cpp 10 - - Each state assigns specific properties to objects on entry. Most - interesting perhaps is the assignment of the value 0.0 to the pad's \c - flipRotation angle property when in \c frontState, and 180.0 when in \c - backState. - - At the end of this section we register default animations with the state - engine; these animations will apply to their respective objects and - properties for any state transition. Otherwise it's common to assign - animations to specific transitions. - - Specifically, we use default animations to control the selection item's - movement and tilt rotations. The tilt rotations are set to 0 when the pad - is flipped, and restored back to their original values when flipped back. - - The \c splashState state is set as the initial state. This is required - before we start the state engine. We proceed with creating some - transitions. - - \snippet graphicsview/padnavigator/padnavigator.cpp 11 - - QEventTransition defines a very flexible transition type. You can use this - class to trigger a transition based on an object receiving an event of a - specific type. In this case, we would like to transition from \c - splashState into \c frontState if \c PadNavigator receives any key press - event (QEvent::KeyPress). - - We register the \c splashItem's animations to this transition to ensure they - are used to animate the item's movement and opacity. - - \snippet graphicsview/padnavigator/padnavigator.cpp 12 - - We use QKeyEventTransition to capture specific key events. In this case, we - detect that the user presses Qt::Key_Return or Qt::Key_Enter, and use this - to trigger transitions between \c frontState and backState. We register \c - flipAnimation, our complex parallel animation group, with these - transitions. - - We continue by defining the states for each of the icons in the grid. - - \snippet graphicsview/padnavigator/padnavigator.cpp 13 - - We will use state groups to control transitions between icons. Each icon - represents a \e substate of \c frontState. We will then define transitions - between the states by detecting key presses, using QKeyEventTransition. - - We start by creating all the substates, and at the same time we create a - temporary grid structure for the states to make it easier to find which - states represents icons that are up, down, left and to the right each - other. - - Once the first substate is known, we set this up as the initial substate of - \c frontState. We will use the (0, 0), or top-left, icon for the initial - substate. We initialze the selection item's position to be exactly where - the top-left icon is. - - \snippet graphicsview/padnavigator/padnavigator.cpp 14 - - We can now create four transitions for each icon. Each transition ensures - that we move to the state corresponding to which arrow key has been - pressed. It's clear from this techinique that we could design any other - specific transitions to and from each of the sub states depending on these - and other keys. - - \snippet graphicsview/padnavigator/padnavigator.cpp 15 - - Also, for each of the icons, we assign suitable values to the \c xRotation - and \c yRotation objects' "angle"-properties. If you recall, these - properties "tilt" the pad corresponding to which item is currently - selected. We ensure each icon is invisible when the pad is flipped, and - visible when the pad is not flipped. To ensure the visible property is - assigned at the right time, we add property-controlling animations to the - \c setVariableSequence animation defined earlier. - - \snippet graphicsview/padnavigator/padnavigator.cpp 16 - - We are now finished with all states, transitions, and animations. We now - create the scene that will contain all our items. The scene gets a defined - background pixmap, and we disable item indexing (as most items in this - scene are animated). We add our \c pad item to the scene, and use its - bounding rectangle to fixate the scene rectangle. This rectangle is used by - the view to find a suitable size for the application window. - - Then the scene is assigned to the view, or in our case, \c PadNavigator - itself. - - \snippet graphicsview/padnavigator/padnavigator.cpp 17 - - Now that the scene has received its final size, we can position the splash - item at the very top, find its fade-out position, and add it to the scene. - - \snippet graphicsview/padnavigator/padnavigator.cpp 18 - - The view toggles a few necessary properties: - - \list - \li It disables its scroll bars - this application has no use for scroll bars. - \li It assigns a minimum size. This is necessary to avoid numerical errors - in our fit-in-view \c resizeEvent() implementation. - \li It sets \l{QGraphicsView::FullViewportUpdate}{FullViewportUpdate}, to - ensure QGraphicsView doesn't spend time figuring out precisely what needs - to be redrawn. This application is very simple - if anything changes, - everything is updated. - \li It enables background caching - this makes no performance difference - with OpenGL, but without OpenGL it avoids unnecessary re-scaling of the - background pixmap. - \li It sets render hints that increase rendering quality. - \li If OpenGL is supported, a QOpenGLWidget viewport is assigned to the view. - \endlist - - Finally, we start the state engine. - - \snippet graphicsview/padnavigator/padnavigator.cpp 19 - - The \l{QGraphicsView::resizeEvent()}{resizeEvent()} implementation calls - the base implementation, and then calls QGraphicsView::fitInView() to scale - the scene so that it fits perfectly inside the view. - - By resizing the main application window, you can see this effect yourself. - The scene contents grow when you make the window larger, and shrink when - you make it smaller, while keeping the aspect ratio intact. - - \section1 The main() Function - - \snippet graphicsview/padnavigator/main.cpp 0 - - The \c main function creates the QApplication instance, uses - Q_INIT_RESOURCE to ensure our compiled-in resources aren't removed by the - linker, and then creates a 3x3 \c PadNavigator instance and shows it. - - Our flippable pad shows up with a suitable splash item once control returns - to the event loop. - - \section1 Performance Notes - - The example uses OpenGL if this is available, to achieve optimal - performance; otherwise perspective tranformations can be quite costly. - - Although this example does use QGraphicsProxyWidget to demonstrate - integration of Qt widget components integrated into Graphics View, using - QGraphicsProxyWidget comes with a performance penalty, and is therefore not - recommended for embedded development. - - This example uses extensive item caching to avoid rerendering of static - elements, at the expense of graphics memory. -*/ diff --git a/examples/widgets/doc/src/pingpong.qdoc b/examples/widgets/doc/src/pingpong.qdoc deleted file mode 100644 index 9545058500..0000000000 --- a/examples/widgets/doc/src/pingpong.qdoc +++ /dev/null @@ -1,93 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the documentation of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:FDL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Free Documentation License Usage -** Alternatively, this file may be used under the terms of the GNU Free -** Documentation License version 1.3 as published by the Free Software -** Foundation and appearing in the file included in the packaging of -** this file. Please review the following information to ensure -** the GNU Free Documentation License version 1.3 requirements -** will be met: https://www.gnu.org/licenses/fdl-1.3.html. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -/*! - \example statemachine/pingpong - \title Ping Pong States Example - - \brief The Ping Pong States example shows how to use parallel states together - with custom events and transitions in \l{The State Machine Framework}. - - This example implements a statechart where two states communicate by - posting events to the state machine. The state chart looks as follows: - - \image pingpong-example.png - \omit - \caption This is a caption - \endomit - - The \c pinger and \c ponger states are parallel states, i.e. they are - entered simultaneously and will take transitions independently of - eachother. - - The \c pinger state will post the first \c ping event upon entry; the \c - ponger state will respond by posting a \c pong event; this will cause the - \c pinger state to post a new \c ping event; and so on. - - \snippet statemachine/pingpong/main.cpp 0 - - Two custom events are defined, \c PingEvent and \c PongEvent. - - \snippet statemachine/pingpong/main.cpp 1 - - The \c Pinger class defines a state that posts a \c PingEvent to the state - machine when the state is entered. - - \snippet statemachine/pingpong/main.cpp 2 - - The \c PingTransition class defines a transition that is triggered by - events of type \c PingEvent, and that posts a \c PongEvent (with a delay - of 500 milliseconds) to the state machine when the transition is - triggered. - - \snippet statemachine/pingpong/main.cpp 3 - - The \c PongTransition class defines a transition that is triggered by - events of type \c PongEvent, and that posts a \c PingEvent (with a delay - of 500 milliseconds) to the state machine when the transition is - triggered. - - \snippet statemachine/pingpong/main.cpp 4 - - The main() function begins by creating a state machine and a parallel - state group. - - \snippet statemachine/pingpong/main.cpp 5 - - Next, the \c pinger and \c ponger states are created, with the parallel - state group as their parent state. Note that the transitions are \e - targetless. When such a transition is triggered, the source state won't be - exited and re-entered; only the transition's onTransition() function will - be called, and the state machine's configuration will remain the same, - which is precisely what we want in this case. - - \snippet statemachine/pingpong/main.cpp 6 - - Finally, the group is added to the state machine, the machine is started, - and the application event loop is entered. - - */ diff --git a/examples/widgets/doc/src/rogue.qdoc b/examples/widgets/doc/src/rogue.qdoc deleted file mode 100644 index b8b7cb15d6..0000000000 --- a/examples/widgets/doc/src/rogue.qdoc +++ /dev/null @@ -1,208 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the documentation of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:FDL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Free Documentation License Usage -** Alternatively, this file may be used under the terms of the GNU Free -** Documentation License version 1.3 as published by the Free Software -** Foundation and appearing in the file included in the packaging of -** this file. Please review the following information to ensure -** the GNU Free Documentation License version 1.3 requirements -** will be met: https://www.gnu.org/licenses/fdl-1.3.html. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -/*! - \example statemachine/rogue - \title Rogue Example - - \brief The Rogue example shows how to use the Qt state machine for event - handling. - - \image rogue-example.png - - This example implements a simple text based game. Do you see the - \c{@} in the screenshot? That's you, the rogue. The \c{#} - characters are walls, and the dots represent floor. In a real - game, other ASCII characters would represent all kinds of objects - and creatures, for instance, ancient dragons (\c{D}s) or food - rations (\c{%}s). But let's not get carried away. In this game, - the rogue is simply running around in an empty room. - - The rogue is moved with the keypad (2, 4, 8, 6). That aside, we - have implemented a \c quit command that triggers if the player - types \c {q}. The player is then asked if he/she really wants to - quit. - - Most games have commands that need more than one key press (we - think of consecutive presses, i.e., not of several keys being - pressed at the same time). In this game, only the \c quit command - falls under this category, but for the sake of argument, let's - imagine a fully-fledged game with a rich set of commands. If we - were to implement these by catching key events in - \l{QWidget::}{keyPressEvent()}, we would have to keep a lot of - class member variables to track the sequence of keys already typed - (or find some other way of deducing the current state of a - command). This can easily lead to spaghetti, which is--as we all - well know, I'm sure--unpleasant. With a state machine, on the - other hand, separate states can wait for a single key press, and - that makes our lives a lot simpler. - - The example consists of two classes: - - \list - \li \c Window draws the text display of the game and sets - up the state machine. The window also has a status bar - above the area in which the rouge moves. - \li \c MovementTransition is a transition that carries out - a single move of the rogue. - \endlist - - Before we embark on a code walkthrough, it is necessary to take a - closer look at the design of the machine. Here is a state chart - that shows what we want to achieve: - - \image rogue-statechart.png - - The input state waits for a key press to start a new command. - When receiving a key it recognizes, it transitions to one of the - two commands of the game; though, as we will see, movement is - handled by the transition itself. The quit state waits for the - player to answer yes or no (by typing \c y or \c n) when asked - whether he/she really wants to quit the game. - - The chart demonstrates how we use one state to wait for a single - key press. The press received may trigger one of the transitions - connected to the state. - - \section1 Window Class Definition - - The \c Window class is a widget that draws the text display of the - game. It also sets up the state machine, i.e., creates and - connects the states in the machine. It is the key events from this - widget that are used by the machine. - - \snippet statemachine/rogue/window.h 0 - - \c Direction specifies the direction in which the rogue is to - move. We use this in \c movePlayer(), which moves the rogue and - repaints the window. The game has a status line above the area in - which the rogue moves. The \c status property contains the text of - this line. We use a property because the QState class allows - setting any Qt \l{Qt's Property System}{property} when entered. - More on this later. - - \snippet statemachine/rogue/window.h 1 - - The \c map is an array with the characters that are currently - displayed. We set up the array in \c setupMap(), and update it - when the rogue is moved. \c pX and \c pY is the current position - of the rogue. \c WIDTH and \c HEIGHT are macros specifying the - dimensions of the map. - - The \c paintEvent() function is left out of this walkthrough. We - also do not discuss other code that does not concern the state - machine (the \c setupMap(), \c status(), \c setStatus(), \c - movePlayer(), and \c sizeHint() functions). If you wish to take a - look at the code, click on the link for the \c window.cpp file at - the top of this page. - - \section1 Window Class Implementation - - Here is the constructor of \c Window: - - \snippet statemachine/rogue/window.cpp 0 - \dots - \snippet statemachine/rogue/window.cpp 1 - - The player starts off at position (5, 5). We then set up the map - and statemachine. Let's proceed with the \c buildMachine() - function: - - \snippet statemachine/rogue/window.cpp 2 - - We enter \c inputState when the machine is started and from the \c - quitState if the user wants to continue playing. We then set the - status to a helpful reminder of how to play the game. - - First, the \c Movement transition is added to the input state. - This will enable the rogue to be moved with the keypad. Notice - that we don't set a target state for the movement transition. This - will cause the transition to be triggered (and the - \l{QAbstractTransition::}{onTransition()} function to be invoked), - but the machine will not leave the \c inputState. If we had set \c - inputState as the target state, we would first have left and then - entered the \c inputState again. - - \snippet statemachine/rogue/window.cpp 3 - - When we enter \c quitState, we update the status bar of the - window. - - \c QKeyEventTransition is a utility class that removes the hassle - of implementing transitions for \l{QKeyEvent}s. We simply need to - specify the key on which the transition should trigger and the - target state of the transition. - - \snippet statemachine/rogue/window.cpp 4 - - The transition from \c inputState allows triggering the quit state - when the player types \c {q}. - - \snippet statemachine/rogue/window.cpp 5 - - The machine is set up, so it's time to start it. - - \section1 The MovementTransition Class - - \c MovementTransition is triggered when the player request the - rogue to be moved (by typing 2, 4, 6, or 8) when the machine is in - the \c inputState. - - \snippet statemachine/rogue/movementtransition.h 0 - - In the constructor, we tell QEventTransition to only send - \l{QEvent::}{KeyPress} events to the - \l{QAbstractTransition::}{eventTest()} function: - - \snippet statemachine/rogue/movementtransition.h 1 - - The KeyPress events come wrapped in \l{QStateMachine::WrappedEvent}s. \c event - must be confirmed to be a wrapped event because Qt uses other - events internally. After that, it is simply a matter of checking - which key has been pressed. - - Let's move on to the \c onTransition() function: - - \snippet statemachine/rogue/movementtransition.h 2 - - When \c onTransition() is invoked, we know that we have a - \l{QEvent::}{KeyPress} event with 2, 4, 6, or 8, and can ask \c - Window to move the player. - - \section1 The Roguelike Tradition - - You might have been wondering why the game features a rogue. Well, - these kinds of text based dungeon exploration games date back to a - game called, yes, "Rogue". Although outflanked by the technology - of modern 3D computer games, roguelikes have a solid community of - hard-core, devoted followers. - - Playing these games can be surprisingly addictive (despite the - lack of graphics). Angband, the perhaps most well-known rougelike, - is found here: \l{http://rephial.org/}. -*/ - diff --git a/examples/widgets/doc/src/states.qdoc b/examples/widgets/doc/src/states.qdoc deleted file mode 100644 index 1ae379f918..0000000000 --- a/examples/widgets/doc/src/states.qdoc +++ /dev/null @@ -1,36 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the documentation of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:FDL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Free Documentation License Usage -** Alternatively, this file may be used under the terms of the GNU Free -** Documentation License version 1.3 as published by the Free Software -** Foundation and appearing in the file included in the packaging of -** this file. Please review the following information to ensure -** the GNU Free Documentation License version 1.3 requirements -** will be met: https://www.gnu.org/licenses/fdl-1.3.html. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -/*! - \example animation/states - \title States Example - - \brief The States example shows how to use the Qt state machine to play - animations. - - \image states-example.png -*/ diff --git a/examples/widgets/doc/src/stickman.qdoc b/examples/widgets/doc/src/stickman.qdoc deleted file mode 100644 index ffc736674b..0000000000 --- a/examples/widgets/doc/src/stickman.qdoc +++ /dev/null @@ -1,102 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the documentation of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:FDL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Free Documentation License Usage -** Alternatively, this file may be used under the terms of the GNU Free -** Documentation License version 1.3 as published by the Free Software -** Foundation and appearing in the file included in the packaging of -** this file. Please review the following information to ensure -** the GNU Free Documentation License version 1.3 requirements -** will be met: https://www.gnu.org/licenses/fdl-1.3.html. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -/*! - \example animation/stickman - \title Stickman Example - - \brief The Stickman example shows how to animate transitions in a state - machine to implement key frame animations. - - \image stickman-example.png - - In this example, we will write a small application which animates the joints in a skeleton and - projects a stickman figure on top. The stickman can be either "alive" or "dead", and when in the - "alive" state, he can be performing different actions defined by key frame animations. - - Animations are implemented as composite states. Each child state of the animation state - represents a frame in the animation by setting the position of each joint in the stickman's - skeleton to the positions defined for the particular frame. The frames are then bound together - with animated transitions that trigger on the source state's propertiesAssigned() signal. Thus, - the machine will enter the state representing the next frame in the animation immediately after - it has finished animating into the previous frame. - - \image stickman-example1.png - - The states for an animation is constructed by reading a custom animation file format and - creating states that assign values to the "position" properties of each of the nodes in the - skeleton graph. - - \snippet animation/stickman/lifecycle.cpp 1 - - The states are then bound together with signal transitions that listen to the - propertiesAssigned() signal. - - \snippet animation/stickman/lifecycle.cpp 2 - - The last frame state is given a transition to the first one, so that the animation will loop - until it is interrupted when a transition out from the animation state is taken. To get smooth - animations between the different key frames, we set a default animation on the state machine. - This is a parallel animation group which contains animations for all the "position" properties - and will be selected by default when taking any transition that leads into a state that assigns - values to these properties. - - \snippet animation/stickman/lifecycle.cpp 3 - - Several such animation states are constructed, and are placed together as children of a top - level "alive" state which represents the stickman life cycle. Transitions go from the parent - state to the child state to ensure that each of the child states inherit them. - - \image stickman-example2.png - - This saves us the effort of connect every state to every state with identical transitions. The - state machine makes sure that transitions between the key frame animations are also smooth by - applying the default animation when interrupting one and starting another. - - Finally, there is a transition out from the "alive" state and into the "dead" state. This is - a custom transition type called LightningSrikesTransition which samples every second and - triggers at random (one out of fifty times on average.) - - \snippet animation/stickman/lifecycle.cpp 4 - - When it triggers, the machine will first enter a "lightningBlink" state which uses a timer to - pause for a brief period of time while the background color of the scene is white. This gives us - a flash effect when the lightning strikes. - - \snippet animation/stickman/lifecycle.cpp 5 - - We start and stop a QTimer object when entering and exiting the state. Then we transition into - the "dead" state when the timer times out. - - \snippet animation/stickman/lifecycle.cpp 0 - - When the machine is in the "dead" state, it will be unresponsive. This is because the "dead" - state has no transitions leading out. - - \image stickman-example3.png - -*/ diff --git a/examples/widgets/doc/src/sub-attaq.qdoc b/examples/widgets/doc/src/sub-attaq.qdoc deleted file mode 100644 index 994e9d6f90..0000000000 --- a/examples/widgets/doc/src/sub-attaq.qdoc +++ /dev/null @@ -1,41 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the documentation of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:FDL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Free Documentation License Usage -** Alternatively, this file may be used under the terms of the GNU Free -** Documentation License version 1.3 as published by the Free Software -** Foundation and appearing in the file included in the packaging of -** this file. Please review the following information to ensure -** the GNU Free Documentation License version 1.3 requirements -** will be met: https://www.gnu.org/licenses/fdl-1.3.html. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -/*! - \example animation/sub-attaq - \title Sub-Attaq - \ingroup examples-layout - - \brief This example shows Qt's ability to combine \l{The Animation Framework}{the animation framework} - and \l{The State Machine Framework}{the state machine framework} to create a game. - - \image sub-attaq-demo.png - - The purpose of the game is to destroy all submarines to win the current level. - The boat can be controlled using left and right keys. To fire a bomb you can press - up and down keys. -*/ diff --git a/examples/widgets/doc/src/trafficlight.qdoc b/examples/widgets/doc/src/trafficlight.qdoc deleted file mode 100644 index 50c0944101..0000000000 --- a/examples/widgets/doc/src/trafficlight.qdoc +++ /dev/null @@ -1,85 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the documentation of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:FDL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Free Documentation License Usage -** Alternatively, this file may be used under the terms of the GNU Free -** Documentation License version 1.3 as published by the Free Software -** Foundation and appearing in the file included in the packaging of -** this file. Please review the following information to ensure -** the GNU Free Documentation License version 1.3 requirements -** will be met: https://www.gnu.org/licenses/fdl-1.3.html. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -/*! - \example statemachine/trafficlight - \title Traffic Light Example - - \brief The Traffic Light example shows how to use \l{The State Machine Framework} - to implement the control flow of a traffic light. - - \image trafficlight-example.png - - In this example we write a TrafficLightWidget class. The traffic light has - three lights: Red, yellow and green. The traffic light transitions from - one light to another (red to yellow to green to yellow to red again) at - certain intervals. - - \snippet statemachine/trafficlight/main.cpp 0 - - The LightWidget class represents a single light of the traffic light. It - provides an \c on property and two slots, turnOn() and turnOff(), to turn - the light on and off, respectively. The widget paints itself in the color - that's passed to the constructor. - - \snippet statemachine/trafficlight/main.cpp 1 - - The TrafficLightWidget class represents the visual part of the traffic - light; it's a widget that contains three lights arranged vertically, and - provides accessor functions for these. - - \snippet statemachine/trafficlight/main.cpp 2 - - The createLightState() function creates a state that turns a light on when - the state is entered, and off when the state is exited. The state uses a - timer, and as we shall see the timeout is used to transition from one - LightState to another. Here is the statechart for the light state: - - \image trafficlight-example1.png - \omit - \caption This is a caption - \endomit - - \snippet statemachine/trafficlight/main.cpp 3 - - The TrafficLight class combines the TrafficLightWidget with a state - machine. The state graph has four states: red-to-yellow, yellow-to-green, - green-to-yellow and yellow-to-red. The initial state is red-to-yellow; - when the state's timer times out, the state machine transitions to - yellow-to-green. The same process repeats through the other states. - This is what the statechart looks like: - - \image trafficlight-example2.png - \omit - \caption This is a caption - \endomit - - \snippet statemachine/trafficlight/main.cpp 4 - - The main() function constructs a TrafficLight and shows it. - -*/ diff --git a/examples/widgets/doc/src/twowaybutton.qdoc b/examples/widgets/doc/src/twowaybutton.qdoc deleted file mode 100644 index 2e1c29199d..0000000000 --- a/examples/widgets/doc/src/twowaybutton.qdoc +++ /dev/null @@ -1,68 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the documentation of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:FDL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Free Documentation License Usage -** Alternatively, this file may be used under the terms of the GNU Free -** Documentation License version 1.3 as published by the Free Software -** Foundation and appearing in the file included in the packaging of -** this file. Please review the following information to ensure -** the GNU Free Documentation License version 1.3 requirements -** will be met: https://www.gnu.org/licenses/fdl-1.3.html. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -/*! - \example statemachine/twowaybutton - \title Two-way Button Example - - \brief The Two-way button example shows how to use \l{The State Machine - Framework} to implement a simple state machine that toggles the current - state when a button is clicked. - - \snippet statemachine/twowaybutton/main.cpp 0 - - The application's main() function begins by constructing the application - object, a button and a state machine. - - \snippet statemachine/twowaybutton/main.cpp 1 - - The state machine has two states; \c on and \c off. When either state is - entered, the text of the button will be set accordingly. - - \snippet statemachine/twowaybutton/main.cpp 2 - - When the state machine is in the \c off state and the button is clicked, - it will transition to the \c on state; when the state machine is in the \c - on state and the button is clicked, it will transition to the \c off - state. - - \snippet statemachine/twowaybutton/main.cpp 3 - - The states are added to the state machine; they become top-level (sibling) - states. - - \snippet statemachine/twowaybutton/main.cpp 4 - - The initial state is \c off; this is the state the state machine will - immediately transition to once the state machine is started. - - \snippet statemachine/twowaybutton/main.cpp 5 - - Finally, the button is resized and made visible, and the application event - loop is entered. - -*/ |