GOFIGURE2  0.9.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
QGoToolBarStatus.cxx
Go to the documentation of this file.
1 /*=========================================================================
2  Authors: The GoFigure Dev. Team.
3  at Megason Lab, Systems biology, Harvard Medical school, 2009-11
4 
5  Copyright (c) 2009-11, President and Fellows of Harvard College.
6  All rights reserved.
7 
8  Redistribution and use in source and binary forms, with or without
9  modification, are permitted provided that the following conditions are met:
10 
11  Redistributions of source code must retain the above copyright notice,
12  this list of conditions and the following disclaimer.
13  Redistributions in binary form must reproduce the above copyright notice,
14  this list of conditions and the following disclaimer in the documentation
15  and/or other materials provided with the distribution.
16  Neither the name of the President and Fellows of Harvard College
17  nor the names of its contributors may be used to endorse or promote
18  products derived from this software without specific prior written
19  permission.
20 
21  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
23  THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24  PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
25  BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
26  OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
27  OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
28  OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
29  WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
30  OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
31  ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 
33 =========================================================================*/
34 
35 #include "QGoToolBarStatus.h"
36 
37 #include <iostream>
38 
40  QObject(iParent),
41  m_ToolBar(NULL), m_Menu(NULL), m_Area(Qt::TopToolBarArea),
42  m_DefaultArea(Qt::TopToolBarArea), m_Visibility(true), m_Attached(true),
43  m_Widget(NULL)
44 {
45 }
46 //--------------------------------------------------------------------------
47 
48 //--------------------------------------------------------------------------
50  m_ToolBar(iS.m_ToolBar), m_Menu(iS.m_Menu), m_Area(iS.m_Area),
51  m_DefaultArea(iS.m_Area), m_Visibility(iS.m_Visibility),
52  m_Attached(iS.m_Attached), m_VectorAction(iS.m_VectorAction),
53  m_Widget(iS.m_Widget)
54 {
55  this->setParent(iS.parent());
56 }
57 //--------------------------------------------------------------------------
58 
59 //--------------------------------------------------------------------------
60 QGoToolBarStatus::QGoToolBarStatus(Qt::ToolBarArea iArea,
61  const bool & iVisibility, const bool & iAttached,
62  QWidget* iParent) :
63  QObject(iParent),
64  m_ToolBar(NULL), m_Menu(NULL), m_Area(iArea),
65  m_DefaultArea(iArea), m_Visibility(iVisibility),
66  m_Attached(iAttached), m_Widget(NULL)
67 {
68 }
69 //--------------------------------------------------------------------------
70 
71 //--------------------------------------------------------------------------
73  Qt::ToolBarArea iArea,
74  const bool & iVisibility, const bool & iAttached, QWidget* iParent, QWidget* iWidget):
75  QObject(iParent), m_ToolBar(iToolBar), m_Menu(iMenu),
76  m_Area(iArea), m_Visibility(iVisibility), m_Attached(iAttached),
77  m_Widget(iWidget)
78 {
79  if(m_Widget && m_ToolBar)
80  {
81  QAction* Action = this->m_ToolBar->addWidget(iWidget);
82  Action->setVisible(true);
83  }
84 }
85 //--------------------------------------------------------------------------
86 
87 //--------------------------------------------------------------------------
90 {
91 }
92 //--------------------------------------------------------------------------
93 
94 //--------------------------------------------------------------------------
95 void
96 QGoToolBarStatus::SetArea(Qt::ToolBarArea iArea)
97 {
98  m_Area = iArea;
99 }
100 //--------------------------------------------------------------------------
101 
102 //--------------------------------------------------------------------------
103 void
105 {
106  m_Visibility = iVisibility;
107 }
108 //--------------------------------------------------------------------------
109 
110 //--------------------------------------------------------------------------
111 void
113 {
114  m_Attached = iAttached;
115 }
116 //--------------------------------------------------------------------------
117 
118 //--------------------------------------------------------------------------
119 void
121 {
122  //if (this->m_ToolBar)
123  // {
124  for ( std::vector< QAction * >::iterator it = this->m_VectorAction.begin();
125  it != this->m_VectorAction.end();
126  ++it )
127  {
128  if (this->m_ToolBar)
129  {
130  this->m_ToolBar->addAction(*it);
131  }
132  if (this->m_Menu)
133  {
134  this->m_Menu->addAction(*it);
135  }
136  }
137 
138  if (this->m_Widget)
139  {
140  QAction* Action = this->m_ToolBar->addWidget(this->m_Widget);
141  Action->setVisible(true);
142  }
143 
144  if(this->m_ToolBar)
145  {
146  this->m_ToolBar->setVisible(this->m_Visibility);
147  }
148 
149  if (!this->m_ToolBar && !this->m_Menu)
150  {
151  std::cout<<"initialize first the toolbar and/or the qmenu ";
152  std::cout << "Debug: In " << __FILE__ << ", line " << __LINE__;
153  std::cout << std::endl;
154  }
155 
156 }
157 //--------------------------------------------------------------------------
158 
159 //--------------------------------------------------------------------------
160 void
162 {
163  if (this->m_ToolBar)
164  {
165  //this->Disconnect();
166  this->m_Visibility = this->m_ToolBar->isVisible();
167  //this->m_Area = this->m_ToolBar->geometry();
168  this->m_Attached = this->m_ToolBar->isFloating();
169  this->m_ToolBar->clear();
170  }
171  if (this->m_Menu)
172  {
173  this->m_Menu->clear();
174  }
175  if (!this->m_ToolBar && !this->m_Menu)
176  {
177  std::cout<<"initialize first the toolbar and the qmenu ";
178  std::cout << "Debug: In " << __FILE__ << ", line " << __LINE__;
179  std::cout << std::endl;
180  }
181 }
182 //--------------------------------------------------------------------------
183 
184 //--------------------------------------------------------------------------
186 {
187  this->m_ToolBar = iToolBar;
188  this->m_Menu = iMenu;
189 }
190 
191 //--------------------------------------------------------------------------
192 
193 //--------------------------------------------------------------------------
194 /*void QGoToolBarStatus::Connect()
195 {
196  //QObject::connect( m_ToolBar, SIGNAL( dockLocationChanged(Qt::DockWidgetArea) ),
197  // this, SLOT( SetArea(Qt::DockWidgetArea) ) );
198 
199  // QObject::connect(m_ToolBar->toggleViewAction(), SIGNAL(toggled(bool) ),
200  // this, SLOT(SetVisibility(bool) ) );
201 
202  QObject::connect(m_ToolBar, SIGNAL(topLevelChanged (bool) ),
203  this, SLOT( SetAttached(bool) ) );
204 }
205 //--------------------------------------------------------------------------
206 
207 //--------------------------------------------------------------------------
208 void QGoToolBarStatus::Disconnect()
209 {
210  if (this->m_ToolBar)
211  {
212  this->m_ToolBar->disconnect(this);
213  this->m_ToolBar->toggleViewAction()->disconnect(this);
214  }
215  else
216  {
217  std::cout<<"initialize first the toolbar and the qmenu ";
218  std::cout << "Debug: In " << __FILE__ << ", line " << __LINE__;
219  std::cout << std::endl;
220  }
221 }*/
void SetArea(Qt::ToolBarArea iArea)
set the area of the m_ToolBar
virtual ~QGoToolBarStatus()
bool isFloating() const
void InitializeToolBarAndMenu(QToolBar *iToolBar, QMenu *iMenu)
void setVisible(bool)
void addAction(QAction *action)
virtual void setVisible(bool visible)
QAction * addWidget(QWidget *widget)
void ClearToolBar()
clear the toolbar and disconnect all the slots inside this class connected to the toolbar ...
QGoToolBarStatus(QWidget *iParent=0)
std::vector< QAction * > m_VectorAction
void clear()
Qt::ToolBarArea m_Area
Position.
bool m_Visibility
is Visible
void SetAttached(bool iAttached)
set the floated status of the m_ToolBar
QToolBar * m_ToolBar
void setParent(QObject *parent)
bool m_Attached
Attached to QGoMainWindow.
void SetUpToolBar()
add all the actions coontained in the m_VectorAction into the toolbar and connect the slots ...
void SetVisibility(bool iVisibility)
set the visibility of the m_ToolBar
QObject * parent() const
void addAction(QAction *action)
void clear()