Engauge Digitizer  2
TutorialStateContext.cpp
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"
11 #include "TutorialStateAbstractBase.h"
12 #include "TutorialStateAxisPoints.h"
13 #include "TutorialStateChecklistWizardLines.h"
14 #include "TutorialStateChecklistWizardPoints.h"
15 #include "TutorialStateColorFilter.h"
16 #include "TutorialStateContext.h"
17 #include "TutorialStateCurveSelection.h"
18 #include "TutorialStateCurveType.h"
19 #include "TutorialStateIntroduction.h"
20 #include "TutorialStatePointMatch.h"
21 #include "TutorialStateSegmentFill.h"
22 
23 const int TIMER_INTERVAL = 1;
24 
26  m_tutorialDlg (tutorialDlg)
27 {
28  createStates ();
29  createTimer ();
30 }
31 
32 void TutorialStateContext::createStates ()
33 {
34  LOG4CPP_INFO_S ((*mainCat)) << "TutorialStateContext::createStates";
35 
36  // These states follow the same order as the TutorialState enumeration
37  m_states.insert (TUTORIAL_STATE_AXIS_POINTS , new TutorialStateAxisPoints (*this));
38  m_states.insert (TUTORIAL_STATE_CHECKLIST_WIZARD_LINES , new TutorialStateChecklistWizardLines (*this));
39  m_states.insert (TUTORIAL_STATE_CHECKLIST_WIZARD_POINTS, new TutorialStateChecklistWizardPoints (*this));
40  m_states.insert (TUTORIAL_STATE_COLOR_FILTER , new TutorialStateColorFilter (*this));
41  m_states.insert (TUTORIAL_STATE_CURVE_SELECTION , new TutorialStateCurveSelection (*this));
42  m_states.insert (TUTORIAL_STATE_CURVE_TYPE , new TutorialStateCurveType (*this));
43  m_states.insert (TUTORIAL_STATE_INTRODUCTION , new TutorialStateIntroduction (*this));
44  m_states.insert (TUTORIAL_STATE_POINT_MATCH , new TutorialStatePointMatch (*this));
45  m_states.insert (TUTORIAL_STATE_SEGMENT_FILL , new TutorialStateSegmentFill (*this));
46  ENGAUGE_ASSERT (m_states.size () == NUM_TUTORIAL_STATES);
47 
48  m_currentState = NUM_TUTORIAL_STATES; // Value that forces a transition right away;
49  requestImmediateStateTransition (TUTORIAL_STATE_INTRODUCTION);
50  completeRequestedStateTransitionIfExists ();
51 }
52 
53 void TutorialStateContext::createTimer ()
54 {
55  LOG4CPP_INFO_S ((*mainCat)) << "TutorialStateContext::createTimer";
56 
57  m_timer = new QTimer ();
58  m_timer->setInterval (TIMER_INTERVAL);
59  m_timer->setSingleShot (true);
60  connect (m_timer, SIGNAL (timeout ()), this, SLOT (slotTimeout ()));
61 }
62 
63 void TutorialStateContext::completeRequestedStateTransitionIfExists ()
64 {
65  if (m_currentState != m_requestedState) {
66 
67  // A transition is waiting so perform it
68 
69  if (m_currentState != NUM_TUTORIAL_STATES) {
70 
71  // This is not the first state so close the previous state
72  m_states [m_currentState]->end ();
73  }
74 
75  // Start the new state
76  m_currentState = m_requestedState;
77  m_states [m_requestedState]->begin ();
78  }
79 }
80 
81 void TutorialStateContext::requestDelayedStateTransition (TutorialState tutorialState)
82 {
83  LOG4CPP_INFO_S ((*mainCat)) << "TutorialStateContext::requestDelayedStateTransition";
84 
85  m_requestedState = tutorialState;
86 
87  m_timer->start ();
88 }
89 
91 {
92  LOG4CPP_INFO_S ((*mainCat)) << "TutorialStateContext::requestImmediateStateTransition";
93 
94  m_requestedState = tutorialState;
95 }
96 
97 void TutorialStateContext::slotTimeout()
98 {
99  LOG4CPP_INFO_S ((*mainCat)) << "TutorialStateContext::slotTimeout";
100 
101  completeRequestedStateTransitionIfExists();
102 }
103 
105 {
106  return m_tutorialDlg;
107 }
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:19
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.