Engauge Digitizer  2
TutorialStateCurveSelection.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 "TutorialStateCurveSelection.h"
16 #include "TutorialStateContext.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_text3 (nullptr),
26  m_previous (nullptr),
27  m_colorFilter (nullptr),
28  m_next (nullptr)
29 {
30  LOG4CPP_INFO_S ((*mainCat)) << "TutorialStateCurveSelection::TutorialStateCurveSelection";
31 }
32 
34 {
35  LOG4CPP_INFO_S ((*mainCat)) << "TutorialStateCurveSelection::begin ()";
36 
37  m_title = createTitle ("Curve Selection");
38  m_background = createPixmapItem (":/engauge/img/panel_curve_selection.png",
39  QPoint (0, 30));
40  m_text0 = createTextItem (tr ("After the axis points have been created, a\n"
41  "curve is selected to receive curve points.\n"
42  "Step 1 - click on Curve, Point Match, Color\n"
43  "Picker or Segment Fill buttons."),
44  QPoint (250, 40));
45  m_text1 = createTextItem (tr ("Step 2 - Select the desired curve name. If\n"
46  "that curve name has not been created yet,\n"
47  "use the menu option Settings / Curve Names\n"
48  "to create it."),
49  QPoint (250, 120));
50  m_text2 = createTextItem (tr ("Step 3 - Change the background from the\n"
51  "original image to the filtered image\n"
52  "produced for the current curve, using the\n"
53  "menu option View / Background / Filtered\n"
54  "Image. This filtering enables the powerful\n"
55  "automated algorithms discussed later in\n"
56  "the tutorial."),
57  QPoint (250, 200));
58  m_text3 = createTextItem (tr ("If the current curve is no longer visible\n"
59  "in the filtered image, then change the\n"
60  "current Color Filter settings. In the figure,\n"
61  "the orange points have disappeared."),
62  QPoint (250, 330));
63 
64  QSize backgroundSize = context().tutorialDlg().backgroundSize();
65 
66  m_previous = new TutorialButton (tr ("Previous"),
67  context().tutorialDlg().scene());
68  m_previous->setGeometry (QPoint (buttonMargin (),
69  backgroundSize.height() - buttonMargin() - m_previous->size().height()));
70  connect (m_previous, SIGNAL (signalTriggered ()), this, SLOT (slotPrevious ()));
71 
72  m_colorFilter = new TutorialButton (tr ("Color Filter Settings"),
73  context().tutorialDlg().scene());
74  m_colorFilter->setGeometry (QPoint (qFloor (backgroundSize.width () / 2.0 - m_colorFilter->size ().width () / 2),
75  qFloor (backgroundSize.height () - buttonMargin () - m_colorFilter->size ().height ())));
76  connect (m_colorFilter, SIGNAL (signalTriggered ()), this, SLOT (slotColorFilter ()));
77 
78  m_next = new TutorialButton (tr ("Next"),
79  context().tutorialDlg().scene());
80  m_next->setGeometry (QPoint (backgroundSize.width () - buttonMargin () - m_next->size ().width (),
81  backgroundSize.height () - buttonMargin () - m_next->size ().height ()));
82  connect (m_next, SIGNAL (signalTriggered ()), this, SLOT (slotNext ()));
83 }
84 
86 {
87  LOG4CPP_INFO_S ((*mainCat)) << "TutorialStateCurveSelection::end ()";
88 
89  context().tutorialDlg().scene().removeItem (m_title);
90  context().tutorialDlg().scene().removeItem (m_background);
91  context().tutorialDlg().scene().removeItem (m_text0);
92  context().tutorialDlg().scene().removeItem (m_text1);
93  context().tutorialDlg().scene().removeItem (m_text2);
94  context().tutorialDlg().scene().removeItem (m_text3);
95  // TutorialButtons removes themselves from the scene
96 
97  delete m_title;
98  delete m_background;
99  delete m_text0;
100  delete m_text1;
101  delete m_text2;
102  delete m_text3;
103  delete m_next;
104  delete m_colorFilter;
105  delete m_previous;
106 
107  m_title = nullptr;
108  m_background = nullptr;
109  m_text0 = nullptr;
110  m_text1 = nullptr;
111  m_text2 = nullptr;
112  m_text3 = nullptr;
113  m_next = nullptr;
114  m_colorFilter = nullptr;
115  m_previous = nullptr;
116 }
117 
119 {
120  LOG4CPP_INFO_S ((*mainCat)) << "TutorialStateCurveSelection::slotColorFilter";
121 
122  context().requestDelayedStateTransition (TUTORIAL_STATE_COLOR_FILTER);
123 }
124 
126 {
127  LOG4CPP_INFO_S ((*mainCat)) << "TutorialStateCurveSelection::slotNextCurves";
128 
129  context().requestDelayedStateTransition (TUTORIAL_STATE_CURVE_TYPE);
130 }
131 
133 {
134  LOG4CPP_INFO_S ((*mainCat)) << "TutorialStateCurveSelection::slotPrevious";
135 
136  context().requestDelayedStateTransition (TUTORIAL_STATE_AXIS_POINTS);
137 }
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 end()
Transition out of this state.
TutorialStateCurveSelection(TutorialStateContext &context)
Single constructor.
QGraphicsScene & scene()
Single scene the covers the entire tutorial dialog.
Definition: TutorialDlg.cpp:76
void slotPrevious()
Slot called to return to previous panel.
TutorialStateContext & context()
Context class for the tutorial state machine.
QGraphicsTextItem * createTextItem(const QString &text, const QPoint &pos)
Factory method for text items.
QGraphicsTextItem * createTitle(const QString &text)
Factory method for title items.
QGraphicsPixmapItem * createPixmapItem(const QString &resource, const QPoint &pos)
Factory method for pixmap items.
QSize backgroundSize() const
Make geometry available for layout.
Definition: TutorialDlg.cpp:44
void slotNext()
Slot called when next button is triggered.
Context class for tutorial state machine.
void slotColorFilter()
Slot called when settings button is triggered.
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.
virtual void begin()
Transition into this state.