Engauge Digitizer  2
 All Classes Files Functions Variables Enumerations Enumerator Friends Pages
TutorialStateContext.cpp
1 #include "EngaugeAssert.h"
2 #include "Logger.h"
3 #include <QTimer>
4 #include "TutorialDlg.h"
5 #include "TutorialStateAbstractBase.h"
6 #include "TutorialStateAxisPoints.h"
7 #include "TutorialStateChecklistWizardLines.h"
8 #include "TutorialStateChecklistWizardPoints.h"
9 #include "TutorialStateColorFilter.h"
10 #include "TutorialStateContext.h"
11 #include "TutorialStateCurveSelection.h"
12 #include "TutorialStateCurveType.h"
13 #include "TutorialStateIntroduction.h"
14 #include "TutorialStatePointMatch.h"
15 #include "TutorialStateSegmentFill.h"
16 
17 const int TIMER_INTERVAL = 1;
18 
20  m_tutorialDlg (tutorialDlg)
21 {
22  createStates ();
23  createTimer ();
24 }
25 
26 void TutorialStateContext::createStates ()
27 {
28  LOG4CPP_INFO_S ((*mainCat)) << "TutorialStateContext::createStates";
29 
30  // These states follow the same order as the TutorialState enumeration
31  m_states.insert (TUTORIAL_STATE_AXIS_POINTS , new TutorialStateAxisPoints (*this));
32  m_states.insert (TUTORIAL_STATE_CHECKLIST_WIZARD_LINES , new TutorialStateChecklistWizardLines (*this));
33  m_states.insert (TUTORIAL_STATE_CHECKLIST_WIZARD_POINTS, new TutorialStateChecklistWizardPoints (*this));
34  m_states.insert (TUTORIAL_STATE_COLOR_FILTER , new TutorialStateColorFilter (*this));
35  m_states.insert (TUTORIAL_STATE_CURVE_SELECTION , new TutorialStateCurveSelection (*this));
36  m_states.insert (TUTORIAL_STATE_CURVE_TYPE , new TutorialStateCurveType (*this));
37  m_states.insert (TUTORIAL_STATE_INTRODUCTION , new TutorialStateIntroduction (*this));
38  m_states.insert (TUTORIAL_STATE_POINT_MATCH , new TutorialStatePointMatch (*this));
39  m_states.insert (TUTORIAL_STATE_SEGMENT_FILL , new TutorialStateSegmentFill (*this));
40  ENGAUGE_ASSERT (m_states.size () == NUM_TUTORIAL_STATES);
41 
42  m_currentState = NUM_TUTORIAL_STATES; // Value that forces a transition right away;
43  requestImmediateStateTransition (TUTORIAL_STATE_INTRODUCTION);
44  completeRequestedStateTransitionIfExists ();
45 }
46 
47 void TutorialStateContext::createTimer ()
48 {
49  LOG4CPP_INFO_S ((*mainCat)) << "TutorialStateContext::createTimer";
50 
51  m_timer = new QTimer ();
52  m_timer->setInterval (TIMER_INTERVAL);
53  m_timer->setSingleShot (true);
54  connect (m_timer, SIGNAL (timeout ()), this, SLOT (slotTimeout ()));
55 }
56 
57 void TutorialStateContext::completeRequestedStateTransitionIfExists ()
58 {
59  if (m_currentState != m_requestedState) {
60 
61  // A transition is waiting so perform it
62 
63  if (m_currentState != NUM_TUTORIAL_STATES) {
64 
65  // This is not the first state so close the previous state
66  m_states [m_currentState]->end ();
67  }
68 
69  // Start the new state
70  m_currentState = m_requestedState;
71  m_states [m_requestedState]->begin ();
72  }
73 }
74 
75 void TutorialStateContext::requestDelayedStateTransition (TutorialState tutorialState)
76 {
77  LOG4CPP_INFO_S ((*mainCat)) << "TutorialStateContext::requestDelayedStateTransition";
78 
79  m_requestedState = tutorialState;
80 
81  m_timer->start ();
82 }
83 
85 {
86  LOG4CPP_INFO_S ((*mainCat)) << "TutorialStateContext::requestImmediateStateTransition";
87 
88  m_requestedState = tutorialState;
89 }
90 
91 void TutorialStateContext::slotTimeout()
92 {
93  LOG4CPP_INFO_S ((*mainCat)) << "TutorialStateContext::slotTimeout";
94 
95  completeRequestedStateTransitionIfExists();
96 }
97 
99 {
100  return m_tutorialDlg;
101 }
Point match panel discusses the matching of points in curves without lines.
Curve type state/panel lets user select the curve type (lines or points)
void requestImmediateStateTransition(TutorialState tutorialState)
Request a transition to the specified state from the current state.
Checklist wizard panel for lines discusses the checklist wizard, and returns to TRANSITION_STATE_SEGM...
Color filter panel discusses the curve-specific color filtering.
Axis points panel discusses axis point digitization.
Tutorial using a strategy like a comic strip with decision points deciding which panels appear...
Definition: TutorialDlg.h:13
Curve selection panel discusses how to select a curve, and perform setup on the selected curve...
TutorialStateContext(TutorialDlg &tutorialDlg)
Single constructor.
Checklist wizard panel for points discusses the checklist wizard, and returns to TRANSITION_STATE_POI...
Segment fill panel discusses the digitization of points along curve lines.
Introduction state/panel is the first panel the user sees.
void requestDelayedStateTransition(TutorialState tutorialState)
Request a transition to the specified state from the current state.
TutorialDlg & tutorialDlg()
Access to tutorial dialogs and its scene.