Engauge Digitizer  2
TutorialDlg.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 "MainWindow.h"
10 #include <QGraphicsRectItem>
11 #include <QGraphicsScene>
12 #include <QGraphicsView>
13 #include <QVBoxLayout>
14 #include "TutorialDlg.h"
15 #include "TutorialStateContext.h"
16 
17 const int SCENE_WIDTH = 550;
18 const int SCENE_HEIGHT = 450;
19 
21  QDialog (mainWindow)
22 {
23  setWindowTitle ("Engauge Digitizer Tutorial");
24 
25  // Dialog size is determined by scene size
26  QVBoxLayout *layout = new QVBoxLayout;
27  layout->setSizeConstraint (QLayout::SetFixedSize);
28  setLayout (layout);
29 
30  createSceneAndView();
31  createContext();
32 }
33 
35 {
36  return QSize (SCENE_WIDTH,
37  SCENE_HEIGHT);
38 }
39 void TutorialDlg::createContext ()
40 {
41  m_context = new TutorialStateContext(*this);
42 }
43 
44 void TutorialDlg::createSceneAndView ()
45 {
46  LOG4CPP_INFO_S ((*mainCat)) << "TutorialDlg::createSceneAndView";
47 
48  m_scene = new QGraphicsScene (this);
49 
50  m_view = new QGraphicsView (m_scene, this);
51  m_view->setMouseTracking (true);
52  layout ()->addWidget(m_view);
53 
54  // Spacer is used to ensure view is the desired size. Directly setting the size of the view
55  // is ineffective since the view then get resized to the smallest rectangle fitting the added items
56  QGraphicsRectItem *spacer = new QGraphicsRectItem (0,
57  0,
58  backgroundSize().width (),
59  backgroundSize().height ());
60  spacer->setBrush (QBrush (Qt::NoBrush));
61  spacer->setPen (QPen (Qt::NoPen));
62  spacer->setZValue(-1); // Put behind everything else at the default z of zero
63  m_scene->addItem (spacer);
64 }
65 
66 QGraphicsScene &TutorialDlg::scene ()
67 {
68  ENGAUGE_CHECK_PTR (m_scene);
69 
70  return *m_scene;
71 }
72 
73 QGraphicsView &TutorialDlg::view ()
74 {
75  ENGAUGE_CHECK_PTR (m_view);
76 
77  return *m_view;
78 }
TutorialDlg(MainWindow *mainWindow)
Single constructor.
Definition: TutorialDlg.cpp:20
QGraphicsScene & scene()
Single scene the covers the entire tutorial dialog.
Definition: TutorialDlg.cpp:66
QSize backgroundSize() const
Make geometry available for layout.
Definition: TutorialDlg.cpp:34
Context class for tutorial state machine.
QGraphicsView & view()
Single view that displays the single scene.
Definition: TutorialDlg.cpp:73
Main window consisting of menu, graphics scene, status bar and optional toolbars as a Single Document...
Definition: MainWindow.h:89