Engauge Digitizer  2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
TutorialDlg.cpp
Go to the documentation of this file.
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 = 580;
18 const int SCENE_HEIGHT = 480;
19 
21  QDialog (mainWindow),
22  m_context (nullptr),
23  m_scene (nullptr),
24  m_view (nullptr)
25 {
26  setWindowTitle ("Engauge Digitizer Tutorial");
27 
28  // Dialog size is determined by scene size
29  QVBoxLayout *layout = new QVBoxLayout;
30  layout->setSizeConstraint (QLayout::SetMinimumSize);
31  setLayout (layout);
32 
33  createSceneAndView();
34  createContext();
35 }
36 
38 {
39  delete m_view;
40  delete m_scene;
41  delete m_context;
42 }
43 
45 {
46  return QSize (SCENE_WIDTH,
47  SCENE_HEIGHT);
48 }
49 void TutorialDlg::createContext ()
50 {
51  m_context = new TutorialStateContext(*this);
52 }
53 
54 void TutorialDlg::createSceneAndView ()
55 {
56  LOG4CPP_INFO_S ((*mainCat)) << "TutorialDlg::createSceneAndView";
57 
58  m_scene = new QGraphicsScene (this);
59 
60  m_view = new QGraphicsView (m_scene, this);
61  m_view->setMouseTracking (true);
62  layout ()->addWidget(m_view);
63 
64  // Spacer is used to ensure view is the desired size. Directly setting the size of the view
65  // is ineffective since the view then get resized to the smallest rectangle fitting the added items
66  QGraphicsRectItem *spacer = new QGraphicsRectItem (0,
67  0,
68  backgroundSize().width (),
69  backgroundSize().height ());
70  spacer->setBrush (QBrush (Qt::NoBrush));
71  spacer->setPen (QPen (Qt::NoPen));
72  spacer->setZValue(-1); // Put behind everything else at the default z of zero
73  m_scene->addItem (spacer);
74 }
75 
76 QGraphicsScene &TutorialDlg::scene ()
77 {
78  ENGAUGE_CHECK_PTR (m_scene);
79 
80  return *m_scene;
81 }
82 
83 QGraphicsView &TutorialDlg::view ()
84 {
85  ENGAUGE_CHECK_PTR (m_view);
86 
87  return *m_view;
88 }
TutorialDlg(MainWindow *mainWindow)
Single constructor.
Definition: TutorialDlg.cpp:20
const int SCENE_WIDTH
Definition: TutorialDlg.cpp:17
#define LOG4CPP_INFO_S(logger)
Definition: convenience.h:18
const int SCENE_HEIGHT
Definition: TutorialDlg.cpp:18
QGraphicsScene & scene()
Single scene the covers the entire tutorial dialog.
Definition: TutorialDlg.cpp:76
#define ENGAUGE_CHECK_PTR(ptr)
#endif
Definition: EngaugeAssert.h:27
QSize backgroundSize() const
Make geometry available for layout.
Definition: TutorialDlg.cpp:44
log4cpp::Category * mainCat
Definition: Logger.cpp:14
Context class for tutorial state machine.
QGraphicsView & view()
Single view that displays the single scene.
Definition: TutorialDlg.cpp:83
Main window consisting of menu, graphics scene, status bar and optional toolbars as a Single Document...
Definition: MainWindow.h:91