My Project  0.0.16
QUCS Mapping
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
vtabbar.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2006 by Gopala Krishna A <krishna.ggk@gmail.com> *
3  * *
4  * This is free software; you can redistribute it and/or modify *
5  * it under the terms of the GNU General Public License as published by *
6  * the Free Software Foundation; either version 2, or (at your option) *
7  * any later version. *
8  * *
9  * This software is distributed in the hope that it will be useful, *
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12  * GNU General Public License for more details. *
13  * *
14  * You should have received a copy of the GNU General Public License *
15  * along with this package; see the file COPYING. If not, write to *
16  * the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor, *
17  * Boston, MA 02110-1301, USA. *
18  ***************************************************************************/
19 
20 #include "vtabbutton.h"
21 #include "vtabbar.h"
22 
23 #include <qlayout.h>
24 #include <qtooltip.h>
25 
26 VTabBar::VTabBar(VTabPosition p,QWidget* parent, const char* name): QWidget(parent, name)
27 {
28  m_position = p;
29  m_layout = new QVBoxLayout(this);
30  m_layout->addStretch(800); //HACK to avoid spaces b/w buttons
31  m_index = 0;
32  m_tabsOff = true;
33  m_tabs.setAutoDelete( false );
34  setSizePolicy( QSizePolicy::Fixed,QSizePolicy::MinimumExpanding);
35 }
36 
38 {}
39 
40 VTab* VTabBar::addTab(const QString& caption,int id)
41 {
42  VTab *tab = new VTab(m_position,id,this);
43  tab->setText(caption);
44  m_layout->insertWidget(m_index,tab);
45  m_tabs.append(tab);
46  m_index++;
47  connect(tab,SIGNAL(toggled(int, bool )),this,SLOT(setTabState(int, bool )));
48  updateGeometry();
49  return tab;
50 }
51 
53 {
54  VTab * c = m_tabs.first();
55  for ( ; c; c = m_tabs.next() )
56  {
57  if(c->id() == _id)
58  return c;
59  }
60  return 0l;
61 }
62 
63 void VTabBar::setTabToolTip(VTab *tab,const QString &tip)
64 {
65  QToolTip::add(tab,tip);
66 }
67 
68 void VTabBar::setTabToolTip(int id,const QString &tip)
69 {
70  VTab *tab = findTab(id);
71  if(tab)
72  QToolTip::add(tab,tip);
73 }
74 
76 {
77  VTab * c = m_tabs.first();
78  for ( ; c; c = m_tabs.next() )
79  {
80  if(c == tab)
81  {
82  m_tabs.remove(c);
83  return;
84  }
85  }
86 }
87 
88 void VTabBar::removeTab(int _id)
89 {
90  VTab * c = m_tabs.first();
91  for ( ; c; c = m_tabs.next() )
92  {
93  if(c->id() == _id)
94  {
95  m_tabs.remove(c);
96  return;
97  }
98  }
99 }
100 
102 {
103  setTabState(tab->id(),true);
104 }
105 
107 {
108  setTabState(id,true);
109 }
110 
111 void VTabBar::setTabState(int p_id,bool state)
112 {
113  VTab *c,*current;
114  c = current = 0l;
115  for ( c = m_tabs.first(); c; c = m_tabs.next() )
116  {
117  c->blockSignals(true);
118  if(c->id() == p_id && state == true)
119  {
120  current = c;
121  current->setOn(true);
122  }
123  else
124  c->setOn(false);
125  c->blockSignals(false);
126  }
127  if(current)
128  {
129  emit activatedTab( p_id);
130  emit activatedTab(current);
131  m_tabsOff = false;
132  }
133  else
134  {
135  m_tabsOff = true;
136  emit allTabsOff();
137  }
138 }
139 
141 {
142  return m_tabsOff;
143 }
144 
146 {
147  VTab *c = m_tabs.first();
148  for ( ; c; c = m_tabs.next() )
149  {
150  c->blockSignals(true);
151  c->setOn(false);
152  c->blockSignals(false);
153  }
154  m_tabsOff = true;
155  emit allTabsOff();
156 }
157 
159 {
160  if(m_position == p_pos)
161  return;
162  m_position = p_pos;
163  VTab * c = m_tabs.first();
164  while(c)
165  {
166  c->setPosition(m_position);
167  c = m_tabs.next();
168  }
169 }