Engauge Digitizer  2
TutorialStateCurveType.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 "Logger.h"
8 #include <qdebug.h>
9 #include <QGraphicsPixmapItem>
10 #include <QGraphicsScene>
11 #include <QGraphicsView>
12 #include <qmath.h>
13 #include "TutorialButton.h"
14 #include "TutorialDlg.h"
15 #include "TutorialStateContext.h"
16 #include "TutorialStateCurveType.h"
17 
19  TutorialStateAbstractBase (context),
20  m_title (nullptr),
21  m_background (nullptr),
22  m_text0 (nullptr),
23  m_text1 (nullptr),
24  m_text2 (nullptr),
25  m_previous (nullptr),
26  m_nextLines (nullptr),
27  m_nextPoints (nullptr)
28 {
29  LOG4CPP_INFO_S ((*mainCat)) << "TutorialStateCurveType::TutorialStateCurveType";
30 }
31 
33 {
34  LOG4CPP_INFO_S ((*mainCat)) << "TutorialStateCurveType::begin ()";
35 
36  m_title = createTitle (tr ("Curve Type"));
37  m_background = createPixmapItem (":/engauge/img/panel_lines_points.png",
38  QPoint (0, 0));
39  m_text0 = createTextItem (tr ("The next steps depend on how the curves\n"
40  "are drawn, in terms of lines and points."),
41  QPoint (240, 40));
42  m_text1 = createTextItem (tr ("If the curves are drawn\n"
43  "with lines (with or without\n"
44  "points) then click on\n"
45  "Next (Lines)."),
46  QPoint (265, 110));
47  m_text2 = createTextItem (tr ("If the curves are drawn\n"
48  "without lines and only\n"
49  "with points, then click on\n"
50  "Next (Points)."),
51  QPoint (265, 270));
52 
53  QSize backgroundSize = context().tutorialDlg().backgroundSize();
54 
55  m_previous = new TutorialButton (tr ("Previous"),
56  context().tutorialDlg().scene());
57  m_previous->setGeometry (QPoint (buttonMargin (),
58  backgroundSize.height () - buttonMargin() - m_previous->size().height()));
59  connect (m_previous, SIGNAL (signalTriggered ()), this, SLOT (slotPrevious ()));
60 
61  m_nextLines = new TutorialButton (tr ("Next (Lines)"),
62  context().tutorialDlg().scene());
63  m_nextLines->setGeometry (QPoint (qFloor (backgroundSize.width () - buttonMargin () - m_nextLines->size ().width ()),
64  qFloor (backgroundSize.height () / 3.0 - m_nextLines->size ().height () / 2.0)));
65  connect (m_nextLines, SIGNAL (signalTriggered ()), this, SLOT (slotNextCurves ()));
66 
67  m_nextPoints = new TutorialButton (tr ("Next (Points)"),
68  context().tutorialDlg().scene());
69  m_nextPoints->setGeometry (QPoint (qFloor (backgroundSize.width () - buttonMargin () - m_nextPoints->size ().width ()),
70  qFloor (backgroundSize.height () * 2.0 / 3.0 - m_nextPoints->size ().height () / 2.0)));
71  connect (m_nextPoints, SIGNAL (signalTriggered ()), this, SLOT (slotNextLines ()));
72 }
73 
75 {
76  LOG4CPP_INFO_S ((*mainCat)) << "TutorialStateCurveType::end ()";
77 
78  context().tutorialDlg().scene().removeItem (m_title);
79  context().tutorialDlg().scene().removeItem (m_background);
80  context().tutorialDlg().scene().removeItem (m_text0);
81  context().tutorialDlg().scene().removeItem (m_text1);
82  context().tutorialDlg().scene().removeItem (m_text2);
83  // TutorialButtons removes themselves from the scene
84 
85  delete m_title;
86  delete m_background;
87  delete m_text0;
88  delete m_text1;
89  delete m_text2;
90  delete m_nextLines;
91  delete m_nextPoints;
92  delete m_previous;
93 
94  m_title = nullptr;
95  m_background = nullptr;
96  m_text0 = nullptr;
97  m_text1 = nullptr;
98  m_text2 = nullptr;
99  m_nextLines = nullptr;
100  m_nextPoints = nullptr;
101  m_previous = nullptr;
102 }
103 
105 {
106  LOG4CPP_INFO_S ((*mainCat)) << "TutorialStateCurveType::slotNextCurves";
107 
108  context().requestDelayedStateTransition (TUTORIAL_STATE_SEGMENT_FILL);
109 }
110 
112 {
113  LOG4CPP_INFO_S ((*mainCat)) << "TutorialStateCurveType::slotNextLines";
114 
115  context().requestDelayedStateTransition (TUTORIAL_STATE_POINT_MATCH);
116 }
117 
119 {
120  LOG4CPP_INFO_S ((*mainCat)) << "TutorialStateCurveType::slotNextCurves";
121 
122  context().requestDelayedStateTransition (TUTORIAL_STATE_CURVE_SELECTION);
123 }
One state manages one panel of the tutorial.
QSize size() const
Size of this button.
void setGeometry(const QPoint &pos)
Set the position. This is called after creation so screen extent is available for positioning calcula...
Show a button with text for clicking ion. The button is implemented using layering of two graphics it...
virtual void begin()
Transition into this state.
QGraphicsScene & scene()
Single scene the covers the entire tutorial dialog.
Definition: TutorialDlg.cpp:76
void slotNextCurves()
Slot called when next button for curves is triggered.
TutorialStateContext & context()
Context class for the tutorial state machine.
void slotNextLines()
Slot called when next button for lines is triggered.
QGraphicsTextItem * createTextItem(const QString &text, const QPoint &pos)
Factory method for text items.
virtual void end()
Transition out of this state.
QGraphicsTextItem * createTitle(const QString &text)
Factory method for title items.
void slotPrevious()
Slot called to return to previous panel.
QGraphicsPixmapItem * createPixmapItem(const QString &resource, const QPoint &pos)
Factory method for pixmap items.
TutorialStateCurveType(TutorialStateContext &context)
Single constructor.
QSize backgroundSize() const
Make geometry available for layout.
Definition: TutorialDlg.cpp:44
Context class for tutorial state machine.
int buttonMargin() const
Buttons are placed up against bottom side, and left or right side, separated by this margin.
void requestDelayedStateTransition(TutorialState tutorialState)
Request a transition to the specified state from the current state.
TutorialDlg & tutorialDlg()
Access to tutorial dialogs and its scene.