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