Qucs-GUI  0.0.18
 All Data Structures 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>
24 #include <QToolTip>
25 //Added by qt3to4:
26 #include <Q3VBoxLayout>
27 
28 VTabBar::VTabBar(VTabPosition p,QWidget* parent, const char* name): QWidget(parent, name)
29 {
30  m_position = p;
31  m_layout = new Q3VBoxLayout(this);
32  m_layout->addStretch(800); //HACK to avoid spaces b/w buttons
33  m_index = 0;
34  m_tabsOff = true;
35  m_tabs.setAutoDelete( false );
36  setSizePolicy( QSizePolicy::Fixed,QSizePolicy::MinimumExpanding);
37 }
38 
40 {}
41 
42 VTab* VTabBar::addTab(const QString& caption,int id)
43 {
44  VTab *tab = new VTab(m_position,id,this);
45  tab->setText(caption);
46  m_layout->insertWidget(m_index,tab);
47  m_tabs.append(tab);
48  m_index++;
49  connect(tab,SIGNAL(toggled(int, bool )),this,SLOT(setTabState(int, bool )));
50  updateGeometry();
51  return tab;
52 }
53 
55 {
56  VTab * c = m_tabs.first();
57  for ( ; c; c = m_tabs.next() )
58  {
59  if(c->id() == _id)
60  return c;
61  }
62  return 0l;
63 }
64 
65 void VTabBar::setTabToolTip(VTab *tab,const QString &tip)
66 {
67  QToolTip::add(tab,tip);
68 }
69 
70 void VTabBar::setTabToolTip(int id,const QString &tip)
71 {
72  VTab *tab = findTab(id);
73  if(tab)
74  QToolTip::add(tab,tip);
75 }
76 
78 {
79  VTab * c = m_tabs.first();
80  for ( ; c; c = m_tabs.next() )
81  {
82  if(c == tab)
83  {
84  m_tabs.remove(c);
85  return;
86  }
87  }
88 }
89 #include <iostream>
90 using namespace std;
91 void VTabBar::removeTab(int _id)
92 {
93  VTab * c = m_tabs.first();
94  for ( ; c; c = m_tabs.next() )
95  {
96  cout<<c->id()<<endl;
97  if(c->id() == _id)
98  {
99  m_tabs.remove(c);
100  return;
101  }
102  }
103 }
104 
106 {
107  setTabState(tab->id(),true);
108 }
109 
111 {
112  setTabState(id,true);
113 }
114 
115 void VTabBar::setTabState(int p_id,bool state)
116 {
117  VTab *c,*current;
118  c = current = 0l;
119  for ( c = m_tabs.first(); c; c = m_tabs.next() )
120  {
121  c->blockSignals(true);
122  if(c->id() == p_id && state == true)
123  {
124  current = c;
125  current->setOn(true);
126  }
127  else
128  c->setOn(false);
129  c->blockSignals(false);
130  }
131  if(current)
132  {
133  emit activatedTab( p_id);
134  emit activatedTab(current);
135  m_tabsOff = false;
136  }
137  else
138  {
139  m_tabsOff = true;
140  emit allTabsOff();
141  }
142 }
143 
145 {
146  return m_tabsOff;
147 }
148 
150 {
151  VTab *c = m_tabs.first();
152  for ( ; c; c = m_tabs.next() )
153  {
154  c->blockSignals(true);
155  c->setOn(false);
156  c->blockSignals(false);
157  }
158  m_tabsOff = true;
159  emit allTabsOff();
160 }
161 
163 {
164  if(m_position == p_pos)
165  return;
166  m_position = p_pos;
167  VTab * c = m_tabs.first();
168  while(c)
169  {
170  c->setPosition(m_position);
171  c = m_tabs.next();
172  }
173 }
bool isAllTabsOff()
Definition: vtabbar.cpp:144
void setTabToolTip(VTab *tab, const QString &tip)
Definition: vtabbar.cpp:65
void setCurrentTab(VTab *tab)
Definition: vtabbar.cpp:105
Q3VBoxLayout * m_layout
Definition: vtabbar.h:71
VTab * findTab(int id)
Definition: vtabbar.cpp:54
virtual void setText(const QString &s)
Definition: vtabbutton.cpp:106
void switchOffAllTabs()
Definition: vtabbar.cpp:149
void setTabState(int p_id, bool state)
Definition: vtabbar.cpp:115
void setPosition(VTabPosition p_pos)
Definition: vtabbutton.cpp:52
virtual ~VTabBar()
Definition: vtabbar.cpp:39
int id() const
Definition: vtabbutton.h:72
void setPosition(VTabPosition p_pos)
Definition: vtabbar.cpp:162
VTab * addTab(const QString &caption, int id=-1)
Definition: vtabbar.cpp:42
VTabPosition m_position
Definition: vtabbar.h:70
void removeTab(VTab *tab)
Definition: vtabbar.cpp:77
int m_index
Definition: vtabbar.h:68
Q3PtrList< VTab > m_tabs
Definition: vtabbar.h:72
VTabBar(VTabPosition p=TabLeft, QWidget *parent=0l, const char *name=0l)
Definition: vtabbar.cpp:28
bool m_tabsOff
Definition: vtabbar.h:69