]> git.lyx.org Git - lyx.git/blob - src/frontends/kde/dlg/tabstack.C
FormDocument and various fixes.
[lyx.git] / src / frontends / kde / dlg / tabstack.C
1 /*
2  * tabstack.C
3  * (C) 2001 LyX Team
4  * John Levon, moz@compsoc.man.ac.uk
5  */
6
7 #include "tabstack.h"
8
9 #include "qlayout.h"
10 #include "qwidgetstack.h"
11 #include "qtabbar.h"
12 #include "qpainter.h"
13
14 /**
15  * A tab bar and a widget stack for storing related pages.
16  */
17
18 TabStack::TabStack(QWidget * parent, const char * name)
19         : QWidget(parent,name), tabs(0), stack(0), topLayout(0)
20 {
21         stack = new QWidgetStack(this, "stack");
22         tabs = new QTabBar(this, "tabbar");
23         connect(tabs, SIGNAL(selected(int)), this, SLOT(selected(int)));
24 }
25
26 TabStack::~TabStack()
27 {
28 }
29
30 void TabStack::show()
31 {
32         doLayout();
33         QWidget::show();
34 }
35
36 void TabStack::doLayout()
37 {
38         const int margin = 6;
39
40         delete topLayout;
41         topLayout = new QBoxLayout(this, QBoxLayout::Down);
42
43         topLayout->addSpacing(margin);
44
45         QBoxLayout * tmp = new QBoxLayout(QBoxLayout::LeftToRight);
46         topLayout->addLayout(tmp, 0);
47         tmp->addSpacing(margin);
48         tmp->addWidget(tabs, 0);
49         tmp->addStretch(1);
50         tmp->addSpacing(margin + 2);
51
52         tmp = new QBoxLayout(QBoxLayout::LeftToRight);
53         topLayout->addLayout(tmp, 1);
54         tmp->addSpacing(margin + 1);
55         tmp->addWidget(stack, 1);
56         tmp->addSpacing(margin + 2);
57
58         topLayout->addSpacing(margin);
59
60         topLayout->activate();
61 }
62
63 void TabStack::paintEvent(QPaintEvent *)
64 {
65         if (!tabs)
66                 return;
67
68         QPainter p;
69         p.begin(this);
70
71         QRect s(stack->geometry());
72
73         QCOORD t = s.top() - 1;
74         QCOORD b = s.bottom() + 2;
75         QCOORD r = s.right() + 2;
76         QCOORD l = s.left() - 1;
77
78         p.setPen(colorGroup().light());
79         p.drawLine(l, t, r - 1, t);
80         p.drawLine(l, t + 1, l, b);
81         p.setPen(black);
82         p.drawLine(r, b, l,b);
83         p.drawLine(r, b-1, r, t);
84         p.setPen(colorGroup().dark());
85         p.drawLine(l+1, b-1, r-1, b-1);
86         p.drawLine(r-1, b-2, r-1, t+1);
87
88         p.end();
89 }
90
91 int TabStack::addTabPage(QWidget *page, const char *label)
92 {
93         QTab *tab = new QTab();
94
95         tab->label = label;
96
97         int id = tabs->addTab(tab);
98         stack->addWidget(page, id);
99         tabs->setMinimumSize(tabs->sizeHint());
100         return id;
101 }
102
103 void TabStack::setTabPageEnabled(int id, bool enable)
104 {
105         tabs->setTabEnabled(id, enable);
106 }
107
108 bool TabStack::isTabPageEnabled(int id) const
109 {
110         return tabs->isTabEnabled(id);
111 }
112
113 void TabStack::setCurrentTabPage(int id)
114 {
115         selected(id);
116 }
117
118 int TabStack::currentTabPage() const
119 {
120         return tabs->currentTab();
121 }
122
123 void TabStack::selected(int id)
124 {
125         if (tabs->currentTab() != id)
126                 tabs->setCurrentTab(id);
127         stack->raiseWidget(id);
128 }