00001
00002
00003
00004
00005
00006
00007 #include "EngaugeAssert.h"
00008 #include "Logger.h"
00009 #include <QTimer>
00010 #include "TutorialDlg.h"
00011 #include "TutorialStateAbstractBase.h"
00012 #include "TutorialStateAxisPoints.h"
00013 #include "TutorialStateChecklistWizardLines.h"
00014 #include "TutorialStateChecklistWizardPoints.h"
00015 #include "TutorialStateColorFilter.h"
00016 #include "TutorialStateContext.h"
00017 #include "TutorialStateCurveSelection.h"
00018 #include "TutorialStateCurveType.h"
00019 #include "TutorialStateIntroduction.h"
00020 #include "TutorialStatePointMatch.h"
00021 #include "TutorialStateSegmentFill.h"
00022
00023 const int TIMER_INTERVAL = 1;
00024
00025 TutorialStateContext::TutorialStateContext (TutorialDlg &tutorialDlg) :
00026 m_tutorialDlg (tutorialDlg)
00027 {
00028 createStates ();
00029 createTimer ();
00030 }
00031
00032 void TutorialStateContext::createStates ()
00033 {
00034 LOG4CPP_INFO_S ((*mainCat)) << "TutorialStateContext::createStates";
00035
00036
00037 m_states.insert (TUTORIAL_STATE_AXIS_POINTS , new TutorialStateAxisPoints (*this));
00038 m_states.insert (TUTORIAL_STATE_CHECKLIST_WIZARD_LINES , new TutorialStateChecklistWizardLines (*this));
00039 m_states.insert (TUTORIAL_STATE_CHECKLIST_WIZARD_POINTS, new TutorialStateChecklistWizardPoints (*this));
00040 m_states.insert (TUTORIAL_STATE_COLOR_FILTER , new TutorialStateColorFilter (*this));
00041 m_states.insert (TUTORIAL_STATE_CURVE_SELECTION , new TutorialStateCurveSelection (*this));
00042 m_states.insert (TUTORIAL_STATE_CURVE_TYPE , new TutorialStateCurveType (*this));
00043 m_states.insert (TUTORIAL_STATE_INTRODUCTION , new TutorialStateIntroduction (*this));
00044 m_states.insert (TUTORIAL_STATE_POINT_MATCH , new TutorialStatePointMatch (*this));
00045 m_states.insert (TUTORIAL_STATE_SEGMENT_FILL , new TutorialStateSegmentFill (*this));
00046 ENGAUGE_ASSERT (m_states.size () == NUM_TUTORIAL_STATES);
00047
00048 m_currentState = NUM_TUTORIAL_STATES;
00049 requestImmediateStateTransition (TUTORIAL_STATE_INTRODUCTION);
00050 completeRequestedStateTransitionIfExists ();
00051 }
00052
00053 void TutorialStateContext::createTimer ()
00054 {
00055 LOG4CPP_INFO_S ((*mainCat)) << "TutorialStateContext::createTimer";
00056
00057 m_timer = new QTimer ();
00058 m_timer->setInterval (TIMER_INTERVAL);
00059 m_timer->setSingleShot (true);
00060 connect (m_timer, SIGNAL (timeout ()), this, SLOT (slotTimeout ()));
00061 }
00062
00063 void TutorialStateContext::completeRequestedStateTransitionIfExists ()
00064 {
00065 if (m_currentState != m_requestedState) {
00066
00067
00068
00069 if (m_currentState != NUM_TUTORIAL_STATES) {
00070
00071
00072 m_states [m_currentState]->end ();
00073 }
00074
00075
00076 m_currentState = m_requestedState;
00077 m_states [m_requestedState]->begin ();
00078 }
00079 }
00080
00081 void TutorialStateContext::requestDelayedStateTransition (TutorialState tutorialState)
00082 {
00083 LOG4CPP_INFO_S ((*mainCat)) << "TutorialStateContext::requestDelayedStateTransition";
00084
00085 m_requestedState = tutorialState;
00086
00087 m_timer->start ();
00088 }
00089
00090 void TutorialStateContext::requestImmediateStateTransition (TutorialState tutorialState)
00091 {
00092 LOG4CPP_INFO_S ((*mainCat)) << "TutorialStateContext::requestImmediateStateTransition";
00093
00094 m_requestedState = tutorialState;
00095 }
00096
00097 void TutorialStateContext::slotTimeout()
00098 {
00099 LOG4CPP_INFO_S ((*mainCat)) << "TutorialStateContext::slotTimeout";
00100
00101 completeRequestedStateTransitionIfExists();
00102 }
00103
00104 TutorialDlg &TutorialStateContext::tutorialDlg()
00105 {
00106 return m_tutorialDlg;
00107 }