All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
OutsideArea.cpp
Go to the documentation of this file.
1 /* Copyright (C) 2001-2014 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 OutsideArea.cpp
22 
23  \brief
24 
25  \ingroup layout
26 */
27 
28 // TerraLib
29 #include "OutsideArea.h"
30 #include "PropertiesOutside.h"
31 #include "PropertiesModel.h"
32 #include "PropertiesController.h"
33 #include "ObjectInspectorModel.h"
35 #include "ObjectInspectorOutside.h"
36 #include "ToolbarModel.h"
37 #include "ToolbarController.h"
38 #include "ToolbarOutside.h"
39 #include "LayoutConfig.h"
40 
41 // Qt
42 #include <QMainWindow>
43 #include <QMenu>
44 #include <QAction>
45 #include "Context.h"
46 
47 te::layout::OutsideArea::OutsideArea( QWidget* dockParent, QMenu* mnuLayout) :
48  m_dockParent(dockParent),
49  m_parentMenu(mnuLayout),
50  m_mainMenu(0),
51  m_dockInspector(0),
52  m_dockProperties(0),
53  m_dockToolbar(0),
54  m_optionNew("mnu_main_new"),
55  m_optionUpdate("mnu_main_update"),
56  m_optionImport("mnu_main_import"),
57  m_optionExport("mnu_main_export"),
58  m_optionPageConfig("mnu_main_page_config"),
59  m_optionPrint("mnu_main_print"),
60  m_optionExit("mnu_main_exit")
61 {
62  init();
63 }
64 
66 {
67  QMainWindow* win = (QMainWindow*)m_dockParent;
68 
69  if(!win)
70  return;
71 
72  if(m_dockProperties)
73  {
74  win->removeDockWidget(m_dockProperties);
75  m_dockProperties->close();
76  m_dockProperties->setParent(0);
77  delete m_dockProperties;
78  m_dockProperties = 0;
79  }
80 
81  if(m_dockInspector)
82  {
83  win->removeDockWidget(m_dockInspector);
84  m_dockInspector->close();
85  m_dockInspector->setParent(0);
86  delete m_dockInspector;
87  m_dockInspector = 0;
88  }
89 
90  if(m_dockToolbar)
91  {
92  win->removeDockWidget(m_dockToolbar);
93  m_dockToolbar->close();
94  m_dockToolbar->setParent(0);
95  delete m_dockToolbar;
96  m_dockToolbar = 0;
97  }
98 }
99 
101 {
102  createPropertiesDock();
103 
104  createInspectorDock();
105 
106  createToolbarDock();
107 
108  createMainMenu();
109 }
110 
112 {
113  //Use the Property Browser Framework for create Property Window
114  PropertiesModel* dockPropertyModel = new PropertiesModel();
115  PropertiesController* dockPropertyController = new PropertiesController(dockPropertyModel);
116  OutsideObserver* itemDockProperty = (OutsideObserver*)dockPropertyController->getView();
117  m_dockProperties = dynamic_cast<PropertiesOutside*>(itemDockProperty);
118 }
119 
121 {
122  //Use the Property Browser Framework for create Object Inspector Window
123  ObjectInspectorModel* dockInspectorModel = new ObjectInspectorModel();
124  ObjectInspectorController* dockInspectorController = new ObjectInspectorController(dockInspectorModel);
125  OutsideObserver* itemDockInspector = (OutsideObserver*)dockInspectorController->getView();
126  m_dockInspector = dynamic_cast<ObjectInspectorOutside*>(itemDockInspector);
127 }
128 
130 {
131  //Use the Property Browser Framework for create Object Inspector Window
132  ToolbarModel* dockToolbarModel = new ToolbarModel();
133  ToolbarController* dockToolbarController = new ToolbarController(dockToolbarModel);
134  OutsideObserver* itemDockToolbar = (OutsideObserver*)dockToolbarController->getView();
135  m_dockToolbar = dynamic_cast<ToolbarOutside*>(itemDockToolbar);
136 }
137 
139 {
140  m_mainMenu = new QMenu("Print Model");
141  connect(m_mainMenu, SIGNAL(triggered(QAction*)), this, SLOT(onMainMenuTriggered(QAction*)));
142 
143  QAction* actionNew = createAction("New", m_optionNew, "layout-new");
144  m_mainMenu->addAction(actionNew);
145 
146  QAction* actionSave = createAction("Update Template", m_optionUpdate, "layout-save");
147  m_mainMenu->addAction(actionSave);
148 
149  m_mainMenu->addSeparator();
150 
151  QAction* actionImport = createAction("Import Template", m_optionImport, "layout-import");
152  m_mainMenu->addAction(actionImport);
153 
154  QAction* actionExport = createAction("Export Template", m_optionExport, "layout-export");
155  m_mainMenu->addAction(actionExport);
156 
157  m_mainMenu->addSeparator();
158 
159  QAction* actionPageConfig = createAction("Page Config...", m_optionPageConfig, "layout-page-setup");
160  m_mainMenu->addAction(actionPageConfig);
161 
162  QAction* actionPrint = createAction("Print...", m_optionPrint, "layout-printer");
163  m_mainMenu->addAction(actionPrint);
164 
165  m_mainMenu->addSeparator();
166 
167  QAction* actionExit = createAction("Exit", m_optionExit, "close");
168  m_mainMenu->addAction(actionExit);
169 }
170 
172 {
173  if(action->objectName().compare(m_optionNew.c_str()) == 0)
174  {
175  changeAction(TypeNewTemplate);
176  }
177  else if(action->objectName().compare(m_optionUpdate.c_str()) == 0)
178  {
179  //changeAction(TypeSaveCurrentTemplate);
180  }
181  else if(action->objectName().compare(m_optionImport.c_str()) == 0)
182  {
183  changeAction(TypeImportJSONProps);
184  }
185  else if(action->objectName().compare(m_optionExport.c_str()) == 0)
186  {
187  changeAction(TypeExportPropsJSON);
188  }
189  else if(action->objectName().compare(m_optionPageConfig.c_str()) == 0)
190  {
191  //changeAction(TypeSaveCurrentTemplate);
192  }
193  else if(action->objectName().compare(m_optionPrint.c_str()) == 0)
194  {
195  changeAction(TypePrinter);
196  }
197  else if(action->objectName().compare(m_optionExit.c_str()) == 0)
198  {
199  changeAction(TypeExit);
200  }
201 }
202 
203 QAction* te::layout::OutsideArea::createAction( std::string text, std::string objName, std::string icon, std::string tooltip )
204 {
205  QAction *actionMenu = new QAction(text.c_str(), this);
206  actionMenu->setObjectName(objName.c_str());
207 
208  std::string icon_path = LAYOUT_IMAGES_PNG"/" + icon;
209  actionMenu->setIcon(QIcon::fromTheme(icon_path.c_str()));
210  actionMenu->setToolTip(tooltip.c_str());
211 
212  return actionMenu;
213 }
214 
216 {
217  bool result = true;
218  LayoutMode layoutMode = Context::getInstance()->getMode();
219 
220  if(mode != layoutMode)
221  {
222  Context::getInstance()->setMode(mode);
223  }
224  else
225  {
226  result = false;
227  }
228 
229  emit changeMenuContext(result);
230 }
231 
233 {
234  return m_dockProperties;
235 }
236 
238 {
239  return m_dockInspector;
240 }
241 
243 {
244  return m_dockToolbar;
245 }
246 
248 {
249  QMainWindow* win = (QMainWindow*)m_dockParent;
250 
251  if(!win)
252  return;
253 
254  if(m_dockProperties)
255  {
256  m_dockProperties->setParent(m_dockParent);
257  win->addDockWidget(Qt::LeftDockWidgetArea, m_dockProperties);
258  m_dockProperties->setVisible(true);
259  }
260  if(m_dockInspector)
261  {
262  m_dockInspector->setParent(m_dockParent);
263  win->addDockWidget(Qt::LeftDockWidgetArea, m_dockInspector);
264  m_dockInspector->setVisible(true);
265  }
266  if(m_dockToolbar)
267  {
268  m_dockToolbar->setParent(m_dockParent);
269  win->addDockWidget(Qt::TopDockWidgetArea, m_dockToolbar);
270  m_dockToolbar->setVisible(true);
271  }
272 }
273 
275 {
276  QMainWindow* win = (QMainWindow*)m_dockParent;
277 
278  if(!win)
279  return;
280 
281  if(m_dockProperties)
282  {
283  win->removeDockWidget(m_dockProperties);
284  m_dockProperties->close();
285  }
286  if(m_dockInspector)
287  {
288  win->removeDockWidget(m_dockInspector);
289  m_dockInspector->close();
290  }
291  if(m_dockToolbar)
292  {
293  win->removeDockWidget(m_dockToolbar);
294  m_dockToolbar->close();
295  }
296 }
297 
299 {
300  if(!m_parentMenu)
301  return;
302 
303  if(!m_mainMenu)
304  return;
305 
306  bool exist_menu = false;
307  QAction* action = m_mainMenu->menuAction();
308  QList<QAction*> acts = m_parentMenu->actions();
309  if(action)
310  {
311  foreach(QAction* act, acts)
312  {
313  if(act == action)
314  {
315  exist_menu = true;
316  }
317  }
318  }
319 
320  if(!exist_menu)
321  {
322  m_parentMenu->addSeparator();
323  m_parentMenu->addMenu(m_mainMenu);
324  }
325 }
326 
328 {
329  if(!m_parentMenu)
330  return;
331 
332  if(!m_mainMenu)
333  return;
334 
335  QAction* action = m_mainMenu->menuAction();
336  QList<QAction*> acts = m_parentMenu->actions();
337  if(action)
338  {
339  foreach(QAction* act, acts)
340  {
341  if(act == action)
342  {
343  m_parentMenu->removeAction(action);
344  }
345  }
346  }
347 }
virtual void changeAction(LayoutMode mode)
virtual void createInspectorDock()
virtual void openMainMenu()
void setMode(LayoutMode mode)
Definition: Context.cpp:66
virtual void openAllDocks()
ObjectInspectorOutside * getObjectInspectorOutside()
virtual QAction * createAction(std::string text, std::string objName, std::string icon, std::string tooltip="")
LayoutMode
Enum LayoutMode. This is the enumeration of the components types.
Definition: EnumMode.h:38
ToolbarOutside * getToolbarOutside()
virtual void closeMainMenu()
virtual void createToolbarDock()
virtual void createPropertiesDock()
virtual void onMainMenuTriggered(QAction *action)
OutsideArea(QWidget *dockParent=0, QMenu *mnuLayout=0)
Definition: OutsideArea.cpp:47
virtual void closeAllDocks()
static Context * getInstance()
This function is called to create an instance of the class.
Definition: Context.cpp:46
LayoutMode getMode()
Definition: Context.cpp:56
PropertiesOutside * getPropertiesOutside()
virtual void createMainMenu()