Engauge Digitizer 2
Loading...
Searching...
No Matches
TutorialStateContext.cpp
Go to the documentation of this file.
1/******************************************************************************************************
2 * (C) 2014 markummitchell@github.com. This file is part of Engauge Digitizer, which is released *
3 * under GNU General Public License version 2 (GPLv2) or (at your option) any later version. See file *
4 * LICENSE or go to gnu.org/licenses for details. Distribution requires prior written permission. *
5 ******************************************************************************************************/
6
7#include "EngaugeAssert.h"
8#include "Logger.h"
9#include <QTimer>
10#include "TutorialDlg.h"
22
23const int TIMER_INTERVAL = 1;
24
26 m_tutorialDlg (tutorialDlg)
27{
28 createStates ();
29 createTimer ();
30}
31
33{
34 qDeleteAll (m_states);
35}
36
37void TutorialStateContext::createStates ()
38{
39 LOG4CPP_INFO_S ((*mainCat)) << "TutorialStateContext::createStates";
40
41 // These states follow the same order as the TutorialState enumeration
42 m_states.insert (TUTORIAL_STATE_AXIS_POINTS , new TutorialStateAxisPoints (*this));
45 m_states.insert (TUTORIAL_STATE_COLOR_FILTER , new TutorialStateColorFilter (*this));
46 m_states.insert (TUTORIAL_STATE_CURVE_SELECTION , new TutorialStateCurveSelection (*this));
47 m_states.insert (TUTORIAL_STATE_CURVE_TYPE , new TutorialStateCurveType (*this));
48 m_states.insert (TUTORIAL_STATE_INTRODUCTION , new TutorialStateIntroduction (*this));
49 m_states.insert (TUTORIAL_STATE_POINT_MATCH , new TutorialStatePointMatch (*this));
50 m_states.insert (TUTORIAL_STATE_SEGMENT_FILL , new TutorialStateSegmentFill (*this));
51 ENGAUGE_ASSERT (m_states.size () == NUM_TUTORIAL_STATES);
52
53 m_currentState = NUM_TUTORIAL_STATES; // Value that forces a transition right away;
55 completeRequestedStateTransitionIfExists ();
56}
57
58void TutorialStateContext::createTimer ()
59{
60 LOG4CPP_INFO_S ((*mainCat)) << "TutorialStateContext::createTimer";
61
62 m_timer = new QTimer ();
63 m_timer->setInterval (TIMER_INTERVAL);
64 m_timer->setSingleShot (true);
65 connect (m_timer, SIGNAL (timeout ()), this, SLOT (slotTimeout ()));
66}
67
68void TutorialStateContext::completeRequestedStateTransitionIfExists ()
69{
70 if (m_currentState != m_requestedState) {
71
72 // A transition is waiting so perform it
73
74 if (m_currentState != NUM_TUTORIAL_STATES) {
75
76 // This is not the first state so close the previous state
77 m_states [m_currentState]->end ();
78 }
79
80 // Start the new state
81 m_currentState = m_requestedState;
82 m_states [m_requestedState]->begin ();
83 }
84}
85
87{
88 LOG4CPP_INFO_S ((*mainCat)) << "TutorialStateContext::requestDelayedStateTransition";
89
90 m_requestedState = tutorialState;
91
92 m_timer->start ();
93}
94
96{
97 LOG4CPP_INFO_S ((*mainCat)) << "TutorialStateContext::requestImmediateStateTransition";
98
99 m_requestedState = tutorialState;
100}
101
102void TutorialStateContext::slotTimeout()
103{
104 LOG4CPP_INFO_S ((*mainCat)) << "TutorialStateContext::slotTimeout";
105
106 completeRequestedStateTransitionIfExists();
107}
108
110{
111 return m_tutorialDlg;
112}
#define ENGAUGE_ASSERT(cond)
Drop in replacement for Q_ASSERT.
log4cpp::Category * mainCat
Definition Logger.cpp:14
@ TUTORIAL_STATE_POINT_MATCH
@ TUTORIAL_STATE_AXIS_POINTS
@ TUTORIAL_STATE_CURVE_SELECTION
@ TUTORIAL_STATE_COLOR_FILTER
@ TUTORIAL_STATE_SEGMENT_FILL
@ TUTORIAL_STATE_CURVE_TYPE
@ TUTORIAL_STATE_CHECKLIST_WIZARD_POINTS
@ TUTORIAL_STATE_INTRODUCTION
@ TUTORIAL_STATE_CHECKLIST_WIZARD_LINES
const int TIMER_INTERVAL
Tutorial using a strategy like a comic strip with decision points deciding which panels appear.
Definition TutorialDlg.h:20
Axis points panel discusses axis point digitization.
Checklist wizard panel for lines discusses the checklist wizard, and returns to TRANSITION_STATE_SEGM...
Checklist wizard panel for points discusses the checklist wizard, and returns to TRANSITION_STATE_POI...
Color filter panel discusses the curve-specific color filtering.
void requestDelayedStateTransition(TutorialState tutorialState)
Request a transition to the specified state from the current state.
void requestImmediateStateTransition(TutorialState tutorialState)
Request a transition to the specified state from the current state.
TutorialStateContext(TutorialDlg &tutorialDlg)
Single constructor.
TutorialDlg & tutorialDlg()
Access to tutorial dialogs and its scene.
~TutorialStateContext()
Destructor deallocates memory.
Curve selection panel discusses how to select a curve, and perform setup on the selected curve.
Curve type state/panel lets user select the curve type (lines or points)
Introduction state/panel is the first panel the user sees.
Point match panel discusses the matching of points in curves without lines.
Segment fill panel discusses the digitization of points along curve lines.
#define LOG4CPP_INFO_S(logger)
Definition convenience.h:18