All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
MainLayout.cpp
Go to the documentation of this file.
1 /* Copyright (C) 2008 National Institute For Space Research (INPE) - Brazil.
2 
3  This file is part of the TerraLib - a Framework for building GIS enabled applications.
4 
5  TerraLib is free software: you can redistribute it and/or modify
6  it under the terms of the GNU Lesser General Public License as published by
7  the Free Software Foundation, either version 3 of the License,
8  or (at your option) any later version.
9 
10  TerraLib is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU Lesser General Public License
16  along with TerraLib. See COPYING. If not, write to
17  TerraLib Team at <terralib-team@terralib.org>.
18  */
19 
20 /*!
21  \file terralib/layout/MainLayout.cpp
22 
23  \brief A singleton
24 */
25 
26 // TerraLib
27 #include "MainLayout.h"
28 #include "../../../layout/qt/core/Scene.h"
29 #include "../../../color/RGBAColor.h"
30 #include "../../../geometry/Envelope.h"
31 #include "OutsideArea.h"
32 #include "DisplayDock.h"
33 #include "ProxyProject.h"
34 #include "../../../layout/core/pattern/singleton/Context.h"
35 
36 // Qt
37 #include <QGraphicsScene>
38 #include <QApplication>
39 #include <QDesktopWidget>
40 #include <QMainWindow>
41 #include <QString>
42 #include <QVBoxLayout>
43 
45  m_view(0),
46  m_dockLayoutDisplay(0),
47  m_groupBox(0),
48  m_statusBar(0),
49  m_buildContext(0),
50  m_outsideArea(0),
51  m_buildEnums(0),
52  m_proxyProject(0)
53 {
56 }
57 
59 {
60  if(m_outsideArea)
61  {
62  delete m_outsideArea;
63  m_outsideArea = 0;
64  }
65 
66  if(m_view)
67  {
68  delete m_view;
69  m_view = 0;
70  }
71 
72  finish();
73 
74  if(m_buildContext)
75  {
76  delete m_buildContext;
77  m_buildContext = 0;
78  }
79 
80  if(m_buildEnums)
81  {
82  delete m_buildEnums;
83  m_buildEnums = 0;
84  }
85 
86  if(m_proxyProject)
87  {
88  delete m_proxyProject;
89  m_proxyProject = 0;
90  }
91 }
92 
93 void te::qt::plugins::layout::MainLayout::init(QWidget* mainWindow, QMenu* mnuLayout)
94 {
95  bool create = false;
96 
97  QSize size(800, 600);
98  QRect screen = QApplication::desktop()->screen()->rect();
99 
100  if(mainWindow)
101  {
102  QMainWindow* mw = dynamic_cast<QMainWindow*>(mainWindow);
103  if(mw)
104  {
105  size = mw->centralWidget()->size();
106  screen = mw->centralWidget()->geometry();
107  }
108  }
109 
110  if(!m_view)
111  {
112  create = true;
113  m_view = new te::layout::View;
114  m_view->setScene(new te::layout::Scene(m_view));
115  }
116 
117  //Resize the dialog and put it in the screen center
118  m_view->move( screen.center() - m_view->rect().center() );
119 
120  createEnums();
121  createLayoutContext(size.width(), size.height());
122 
123  if(create)
124  {
125  //Calculate matrix and centralizes the scene
126  m_view->config();
127  }
128 
129  createDockLayoutDisplay(mainWindow, m_view);
130 
131  if(!m_outsideArea)
132  {
133  m_outsideArea = new OutsideArea(m_view, mainWindow, mnuLayout, m_statusBar);
134  m_outsideArea->connect(m_outsideArea, SIGNAL(exit()), m_dockLayoutDisplay, SLOT(onExit()));
135  }
136 
137  m_view->show();
138  m_outsideArea->openMainMenu();
139  m_outsideArea->openAllDocks();
140 }
141 
143 {
144  if(mainWindow)
145  {
146  QMainWindow* mw = dynamic_cast<QMainWindow*>(mainWindow);
147  if(!m_dockLayoutDisplay)
148  {
149  m_dockLayoutDisplay = new DisplayDock;
150 
151  m_statusBar = new QStatusBar;
152  m_statusBar->setMinimumSize(200, 10);
153  m_statusBar->showMessage("Map Layout - TerraLib 5");
154 
155  QVBoxLayout* vLayout = new QVBoxLayout;
156  vLayout->addWidget(view);
157  vLayout->addWidget(m_statusBar);
158 
159  m_groupBox = new QGroupBox(m_dockLayoutDisplay);
160  m_groupBox->setLayout(vLayout);
161  }
162 
163  m_dockLayoutDisplay->setWidget(m_groupBox);
164  m_dockLayoutDisplay->setPreviousCentralWidget(mw->centralWidget());
165  m_dockLayoutDisplay->setParent(mw);
166 
167  mw->setCentralWidget(m_dockLayoutDisplay);
168  m_dockLayoutDisplay->setVisible(true);
169  }
170 }
171 
173 {
174  if(!m_buildContext)
175  return;
176 
177  m_buildContext->createLayoutContext(width, height, m_view);
178  m_proxyProject = new ProxyProject;
179  if(!te::layout::Context::getInstance().getProxyProject())
180  {
181  te::layout::Context::getInstance().setProxyProject(m_proxyProject);
182  }
183 }
184 
186 {
187  if(m_dockLayoutDisplay)
188  {
189  m_dockLayoutDisplay->close();
190  delete m_dockLayoutDisplay;
191  m_dockLayoutDisplay = 0;
192  }
193 }
194 
196 {
197  if(!m_buildEnums)
198  return;
199 
200  m_buildEnums->build();
201 }
te::layout::BuildEnums * m_buildEnums
Definition: MainLayout.h:95
Provide a surrogate or placeholder for te::qt::af::Project to control access to it. A wrapper to access without complexity. This proxy is required because module not must have dependence te::qt::af. Useful to access the Layers belonging to the project.
Provide a surrogate or placeholder for te::qt::af::Project to control access to it. A wrapper to access without complexity. This proxy is required because module not must have dependence te::qt::af. Useful to access the Layers belonging to the project.
Definition: ProxyProject.h:59
te::layout::BuildContext * m_buildContext
Definition: MainLayout.h:93
void createDockLayoutDisplay(QWidget *mainWindow, te::layout::View *view)
Definition: MainLayout.cpp:142
void createLayoutContext(int width, int height)
Definition: MainLayout.cpp:172
static Context & getInstance()
It returns a reference to the singleton instance.
Class representing the view. This view is child of QGraphicsView, part of Graphics View Framework...
Definition: View.h:89
Class representing the scene. This scene is child of QGraphicsScene, part of Graphics View Framework...
Definition: Scene.h:80
A class.
virtual void init(QWidget *mainWindow=0, QMenu *mnuLayout=0)
Inializes.
Definition: MainLayout.cpp:93