All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
EditTemplateDock.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 EditTemplateDock.cpp
22 
23  \brief
24 
25  \ingroup layout
26 */
27 
28 // TerraLib
29 #include "EditTemplateDock.h"
30 #include "../../../layout/qt/outside/EditTemplateOutside.h"
31 #include "../../../layout/core/pattern/singleton/Context.h"
32 #include "../../../layout/qt/core/BuildGraphicsOutside.h"
33 #include "../../../layout/core/enum/Enums.h"
34 
35 // Qt
36 #include <QTabBar>
37 #include <QEvent>
38 #include <QSizePolicy>
39 #include <QString>
40 
41 te::qt::plugins::layout::EditTemplateDock::EditTemplateDock( QWidget * parent, Qt::WindowFlags flags ) :
42  QDockWidget(parent, flags),
43  m_editTemplate(0),
44  m_tab(0),
45  m_currentTab(-1),
46  m_tabHeight(0)
47 {
48  setVisible(false);
49  setAllowedAreas(Qt::RightDockWidgetArea);
50  setFeatures(QDockWidget::DockWidgetVerticalTitleBar);
51 
52  create();
53 
54  m_editTemplateSize.setWidth(m_editTemplate->geometry().width());
55  m_editTemplateSize.setHeight(m_editTemplate->geometry().height());
56 
57  m_tab = new QTabWidget(this);
58  m_tab->addTab(m_editTemplate, "Edit Template");
59  m_tab->setTabPosition(QTabWidget::East);
60 
61  connect(m_tab, SIGNAL(currentChanged(int)), this, SLOT(onCurrentChanged(int)));
62 
63  setWidget(m_tab);
64 
65  int h = getHeightTabBar();
66  m_tab->setFixedWidth(h);
67 
68  m_tabHeight = h;
69 
71 }
72 
74 {
75 
76 }
77 
79 {
80  te::layout::AbstractBuildGraphicsOutside* abstractBuildOutside = te::layout::Context::getInstance().getAbstractBuildGraphicsOutside();
81  if(!abstractBuildOutside)
82  {
83  return;
84  }
85 
86  te::layout::BuildGraphicsOutside* buildOutside = dynamic_cast<te::layout::BuildGraphicsOutside*>(abstractBuildOutside);
87  if(!buildOutside)
88  {
89  return;
90  }
91 
92  te::layout::EnumObjectType* objectType = te::layout::Enums::getInstance().getEnumObjectType();
93  if(!objectType)
94  {
95  return;
96  }
97 
98  QWidget* widget = buildOutside->createOuside(objectType->getEditTemplate());
99  if(!widget)
100  {
101  return;
102  }
103  m_editTemplate = dynamic_cast<te::layout::EditTemplateOutside*>(widget);
104 }
105 
107 {
108  return m_editTemplate;
109 }
110 
112 {
113 
114 }
115 
117 {
118  QList<QTabBar*> tabBar = m_tab->findChildren<QTabBar*>();
119  tabBar.at(0)->setCursor(Qt::PointingHandCursor);
120  int h = tabBar.at(0)->size().height();
121 
122  return h;
123 }
124 
126 {
127  QList<QTabBar*> tabBar = m_tab->findChildren<QTabBar*>();
128  for(int i = 0 ; i < tabBar.count() ; ++i)
129  tabBar.at(i)->installEventFilter(this);
130 }
131 
132 bool te::qt::plugins::layout::EditTemplateDock::eventFilter( QObject * watched, QEvent * event )
133 {
134  QList<QTabBar*> tabBar = m_tab->findChildren<QTabBar*>();
135  for(int i = 0 ; i < tabBar.count() ; ++i)
136  {
137  if (watched == tabBar.at(i) && event->type() == QEvent::MouseButtonPress)
138  {
139  if(m_editTemplate == m_tab->widget(i))
140  {
141  selectionEditTemplateTab(i);
142  break;
143  }
144  }
145  }
146 
147  return QDockWidget::eventFilter(watched, event);
148 }
149 
151 {
152  if(m_currentTab == index)
153  {
154  /* fixed size */
155  m_tab->setFixedWidth(m_tabHeight);
156  m_currentTab = -1;
157  return;
158  }
159 
160  m_currentTab = index;
161 
162  /* Remove fixed size */
163  m_tab->setMaximumSize(QWIDGETSIZE_MAX,QWIDGETSIZE_MAX);
164  int w = m_editTemplateSize.width();
165  int h = m_editTemplateSize.height();
166  m_tab->setMinimumSize(w,h);
167 }
virtual bool eventFilter(QObject *watched, QEvent *event)
Class to represent a graphic object (MVC component) and widget object (MVC widget) type enumeration...
te::layout::EditTemplateOutside * m_editTemplate
QWidget * createOuside(te::layout::EnumType *type)
Method to create a widget from the type.
EditTemplateDock(QWidget *parent=0, Qt::WindowFlags flags=0)
te::layout::EditTemplateOutside * getEditTemplateOutside()
Abstract class for build MVC widgets.
static Context & getInstance()
It returns a reference to the singleton instance.
Class responsible for creating or building widgets. All objects are children of Qwidget and OutsideOb...
virtual EnumType * getEditTemplate() const
Returns value that represents edit template widget (MVC widget) type belonging to enumeration...