4 * John Levon, moz@compsoc.man.ac.uk
7 /***************************************************************************
9 * This program is free software; you can redistribute it and/or modify *
10 * it under the terms of the GNU General Public License as published by *
11 * the Free Software Foundation; either version 2 of the License, or *
12 * (at your option) any later version. *
14 ***************************************************************************/
19 #include "qwidgetstack.h"
24 * A tab bar and a widget stack for storing related pages.
27 TabStack::TabStack(QWidget * parent = 0, const char * name = 0)
28 : QWidget(parent,name), tabs(0), stack(0)
30 stack = new QWidgetStack(this, "stack");
31 tabs = new QTabBar(this, "tabbar");
32 connect(tabs, SIGNAL(selected(int)), this, SLOT(selected(int)));
34 topLayout = new QHBoxLayout(this, 1);
36 layout = new QVBoxLayout();
37 topLayout->addLayout(layout);
38 layout->addWidget(tabs, 0);
39 layout->addWidget(stack, 1);
46 int TabStack::addTabPage(QWidget *page, const char *label)
48 QTab *tab = new QTab();
52 int id = tabs->addTab(tab);
53 stack->addWidget(page, id);
54 tabs->setMinimumSize(tabs->sizeHint());
58 void TabStack::setTabPageEnabled(int id, bool enable)
60 tabs->setTabEnabled(id, enable);
63 bool TabStack::isTabPageEnabled(int id) const
65 return tabs->isTabEnabled(id);
68 void TabStack::setCurrentTabPage(int id)
73 int TabStack::currentTabPage() const
75 return tabs->currentTab();
78 void TabStack::selected(int id)
80 if (tabs->currentTab() != id)
81 tabs->setCurrentTab(id);
82 stack->raiseWidget(id);
85 void TabStack::paintEvent(QPaintEvent *)
92 QRect geom(stack->geometry());
94 QCOORD top = geom.top() - 1;
95 QCOORD bottom = geom.bottom() + 2;
96 QCOORD right = geom.right() + 2;
97 QCOORD left = geom.left() - 1;
100 p.drawLine(left, top, right - 1, top);
101 p.drawLine(left, top + 1, left, bottom);
103 p.drawLine(right, bottom, left, bottom);
104 p.drawLine(right, bottom-1, right, top);
105 p.setPen(colorGroup().dark());
106 p.drawLine(left+1, bottom-1, right-1, bottom-1);
107 p.drawLine(right-1, bottom-2, right-1, top+1);
111 // FIXME: do this better ?