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) 2001-2013 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 "Scene.h"
29 #include "View.h"
30 #include "../../../../color/RGBAColor.h"
31 #include "../../../../geometry/Envelope.h"
32 #include "DisplayModel.h"
33 #include "DisplayController.h"
34 #include "OutsideObserver.h"
35 #include "DisplayOutside.h"
36 #include "Scene.h"
37 #include "Observer.h"
38 #include "BuildContext.h"
39 #include "OutsideArea.h"
40 
41 // Qt
42 #include <QGraphicsScene>
43 #include <QApplication>
44 #include <QDesktopWidget>
45 #include <QMainWindow>
46 #include <QString>
47 #include <QVBoxLayout>
48 #include <QStatusBar>
49 #include <QGroupBox>
50 
52  m_view(0),
53  m_dockLayoutDisplay(0),
54  m_buildContext(0),
55  m_outsideArea(0)
56 {
58 }
59 
61 {
62  if(m_outsideArea)
63  {
64  delete m_outsideArea;
65  m_outsideArea = 0;
66  }
67 
68  if(m_view)
69  {
70  delete m_view;
71  m_view = 0;
72  }
73 
74  finish();
75 
76  if(m_statusBar)
77  {
78  delete m_statusBar;
79  m_statusBar = 0;
80  }
81 
82  if(m_buildContext)
83  {
84  delete m_buildContext;
85  m_buildContext = 0;
86  }
87 }
88 
89 void te::layout::MainLayout::init(QWidget* mainWindow, QMenu* mnuLayout)
90 {
91  bool create = false;
92 
93  QSize size(800, 600);
94 
95  if(mainWindow)
96  {
97  QMainWindow* mw = dynamic_cast<QMainWindow*>(mainWindow);
98  size = mw->centralWidget()->size();
99  }
100 
101  if(!m_view)
102  {
103 
104  create = true;
105  m_view = new View();
106  m_view->setScene(new Scene());
107  }
108 
109  //Resize the dialog and put it in the screen center
110  const QRect screen = QApplication::desktop()->screenGeometry();
111  m_view->move( screen.center() - m_view->rect().center() );
112 
113  createLayoutContext(size.width(), size.height());
114  createDockLayoutDisplay(mainWindow, m_view);
115 
116  if(!m_outsideArea)
117  m_outsideArea = new OutsideArea(mainWindow, mnuLayout);
118 
119  if(create)
120  {
121  m_view->setOutsideArea(m_outsideArea);
122  //Set a new window size
123  m_view->config();
124  }
125 
126  m_view->show();
127  m_outsideArea->openMainMenu();
128  m_outsideArea->openAllDocks();
129 }
130 
132 {
133  if(mainWindow)
134  {
135  QMainWindow* mw = dynamic_cast<QMainWindow*>(mainWindow);
136  if(!m_dockLayoutDisplay)
137  {
138  //Use the Property Browser Framework for create Property Window
139  DisplayModel* dockDisplayModel = new DisplayModel();
140  DisplayController* dockDisplayController = new DisplayController(dockDisplayModel);
141  Observer* itemDockDisplay = (Observer*)dockDisplayController->getView();
142  m_dockLayoutDisplay = dynamic_cast<DisplayOutside*>(itemDockDisplay);
143 
144  m_statusBar = new QStatusBar;
145  m_statusBar->setMinimumSize(200, 10);
146  m_statusBar->showMessage("TerraPrint. Terralib 5 - Ready...");
147 
148  QVBoxLayout* vLayout = new QVBoxLayout;
149  vLayout->addWidget(view);
150  vLayout->addWidget(m_statusBar);
151 
152  m_groupBox = new QGroupBox(m_dockLayoutDisplay);
153  m_groupBox->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
154  m_groupBox->setLayout(vLayout);
155  }
156 
157  m_dockLayoutDisplay->setWidget(m_groupBox);
158  m_dockLayoutDisplay->setPreviousCentralWidget(mw->centralWidget());
159  mw->removeDockWidget((QDockWidget*)mw->centralWidget());
160  m_dockLayoutDisplay->setParent(mw);
161 
162  mw->setCentralWidget(m_dockLayoutDisplay);
163  m_dockLayoutDisplay->setVisible(true);
164  }
165 }
166 
168 {
169  if(!m_buildContext)
170  return;
171 
172  m_buildContext->createLayoutContext(width, height, m_view);
173 }
174 
176 {
177  if(m_dockLayoutDisplay)
178  {
179  //m_dockLayoutDisplay->removeDock();
180 
181  m_dockLayoutDisplay->close();
182  delete m_dockLayoutDisplay;
183  m_dockLayoutDisplay = 0;
184  }
185 }
void createLayoutContext(int width, int height)
Definition: MainLayout.cpp:167
~MainLayout()
Destructor.
Definition: MainLayout.cpp:60
BuildContext * m_buildContext
Definition: MainLayout.h:82
virtual void init(QWidget *mainWindow=0, QMenu *mnuLayout=0)
Inializes.
Definition: MainLayout.cpp:89
MainLayout()
Constructor.
Definition: MainLayout.cpp:51
A class.
void createDockLayoutDisplay(QWidget *mainWindow, View *view)
Definition: MainLayout.cpp:131