Qucs-GUI  0.0.18
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
vtabwidget.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 #include "vtabwidget.h"
23 
24 #include <QLayout>
25 #include <Q3WidgetStack>
26 //Added by qt3to4:
27 #include <Q3HBoxLayout>
28 
29 VTabWidget::VTabWidget(VTabPosition p,QWidget* parent, const char* name): QWidget(parent, name)
30 {
31  m_position = p;
32  Q3HBoxLayout *layout = new Q3HBoxLayout(this);
33  m_bar = new VTabBar(p,this);
34  m_wStack = new Q3WidgetStack(this);
35  layout->addWidget(m_bar,0);
36  layout->addWidget(m_wStack,5);
37  m_autoIndexer = 0;
38  m_wStack->hide();
39  connect(m_bar,SIGNAL(allTabsOff()),m_wStack,SLOT(hide()));
40  connect(m_bar, SIGNAL(activatedTab(int)), this, SLOT(setCurrentPage(int)));
41 
42  connect(m_bar,SIGNAL(allTabsOff()),this,SIGNAL(widgetStackHidden()));
43  connect(m_bar,SIGNAL(activatedTab(int)),this,SIGNAL(widgetStackShown()));
44 }
45 
47 {}
48 
49 void VTabWidget::addPage(QWidget *w,const QString& tabCap)
50 {
51  m_bar->addTab(tabCap,m_autoIndexer);
52  m_wStack->addWidget(w,m_autoIndexer);
53  m_autoIndexer++;
54 }
55 
56 QWidget* VTabWidget::page(int id)
57 {
58  return m_wStack->widget(id);
59 }
60 
62 {
63  if(m_bar->isAllTabsOff())
64  return 0l;
65  return m_wStack->visibleWidget();
66 }
67 
68 void VTabWidget::setTabToolTip(int id,const QString &tip)
69 {
70  m_bar->setTabToolTip(id,tip);
71 }
72 
73 void VTabWidget::removePage(QWidget *w)
74 {
75  int _id = m_wStack->id(w);
76  if(_id == -1)
77  return;
78  m_bar->removeTab(_id);
79  m_wStack->removeWidget(w);
80 }
81 
83 {
84  QWidget *w = m_wStack->widget(id);
85  if(!w)
86  return;
87  removePage(w);
88 }
89 
90 int VTabWidget::id(QWidget *w)
91 {
92  return m_wStack->id(w);
93 }
94 
95 QSize VTabWidget::sizeHint() const
96 {
97  if(m_wStack->isHidden())
98  return m_bar->sizeHint();
99  int width = m_bar->sizeHint().width();
100  int height = m_bar->sizeHint().height();
101  width += m_wStack->sizeHint().width();
102  height = QMAX(height,m_wStack->sizeHint().height());
103  return QSize(width,height);
104 }
105 
107 {
108  if(!m_wStack->isShown())
109  {
110  m_wStack->setShown(true);
111  emit widgetStackShown();
112  }
113  m_wStack->raiseWidget(id);
114  QWidget *w = m_wStack->widget(id);
115  if(w)
116  emit activatedPage(w);
117  VTab *const t = m_bar->findTab(id);
118  if(t == 0l)
119  {
120  qWarning("BUG: Tab id and widget id mismatch");
121  return;
122  }
123  if(t->isOn())
124  return;
125  //else programatically called
126  m_bar->blockSignals(true);
127  m_bar->setCurrentTab(id);
128  m_bar->blockSignals(false);
129 }
130 
132 {
133  int _id = m_wStack->id(w);
134  if(_id != -1)
135  setCurrentPage(_id);
136 }
137 
138 
140 {
141  if(m_position == p)
142  return;
143  m_position = p;
144  Q3HBoxLayout *l = (Q3HBoxLayout*)layout();
145  if(!l)
146  {
147  qWarning( "Error layout is null");
148  return;
149  }
150  l->remove(m_wStack);
151  l->remove(m_bar);
152 
153  m_bar->setPosition(p);
154  if(p == TabLeft)
155  {
156  l->addWidget(m_bar,0);
157  l->addWidget(m_wStack,5);
158  }
159  else
160  {
161  l->addWidget(m_wStack,5);
162  l->addWidget(m_bar,0);
163  }
164 }
void widgetStackShown()
bool isAllTabsOff()
Definition: vtabbar.cpp:144
void setTabToolTip(int id, const QString &tip)
Definition: vtabwidget.cpp:68
VTabPosition m_position
Definition: vtabwidget.h:60
void activatedPage(QWidget *w)
VTabBar * m_bar
Definition: vtabwidget.h:61
void widgetStackHidden()
void setTabToolTip(VTab *tab, const QString &tip)
Definition: vtabbar.cpp:65
void setCurrentTab(VTab *tab)
Definition: vtabbar.cpp:105
int m_autoIndexer
Definition: vtabwidget.h:63
void setCurrentPage(int id)
Definition: vtabwidget.cpp:106
VTab * findTab(int id)
Definition: vtabbar.cpp:54
QWidget * currentPage()
Definition: vtabwidget.cpp:61
int id(QWidget *w)
Definition: vtabwidget.cpp:90
virtual ~VTabWidget()
Definition: vtabwidget.cpp:46
void setPosition(VTabPosition p_pos)
Definition: vtabbar.cpp:162
VTab * addTab(const QString &caption, int id=-1)
Definition: vtabbar.cpp:42
QWidget * page(int id)
Definition: vtabwidget.cpp:56
virtual QSize sizeHint() const
Definition: vtabwidget.cpp:95
void removeTab(VTab *tab)
Definition: vtabbar.cpp:77
void setPosition(VTabPosition p)
Definition: vtabwidget.cpp:139
void removePage(QWidget *w)
Definition: vtabwidget.cpp:73
VTabWidget(VTabPosition p=TabLeft, QWidget *parent=0l, const char *name=0l)
Definition: vtabwidget.cpp:29
Q3WidgetStack * m_wStack
Definition: vtabwidget.h:62
void addPage(QWidget *w, const QString &tabCap)
Definition: vtabwidget.cpp:49