-
Notifications
You must be signed in to change notification settings - Fork 0
/
ttabwidget.cpp
88 lines (71 loc) · 2.14 KB
/
ttabwidget.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#include "ttabwidget.hpp"
bool TTabWidget::isTabVisible(int idx) const
{
return !hidden_idx.contains(idx);
}
void TTabWidget::setTabVisible(int idx, bool visible)
{
if (hidden_idx.contains(idx) != visible)
return;
int bar_idx = idx;
int vector_idx = 0;
while (vector_idx < hidden_idx.size() && hidden_idx.at(vector_idx) < idx) {
bar_idx--;
vector_idx++;
}
if (visible ? vector_idx >= hidden_idx.size() : bar_idx >= count())
return;
doing_stuff = true;
if (!visible) {
QWidget *wid = widget(bar_idx);
hidden_wid.insert(vector_idx, wid);
hidden_idx.insert(vector_idx, idx);
hidden_data.insert(vector_idx, qMakePair<QIcon, QString>(tabIcon(bar_idx), tabText(bar_idx)));
removeTab(bar_idx);
wid->setParent(this);
} else {
insertTab(bar_idx, hidden_wid.at(vector_idx), hidden_data.at(vector_idx).first, hidden_data.at(vector_idx).second);
hidden_wid.remove(vector_idx);
hidden_idx.remove(vector_idx);
hidden_data.remove(vector_idx);
}
doing_stuff = false;
}
void TTabWidget::tabInserted(int index)
{
if (tabBarAutoHide && count() > 1) {
tabBar()->show();
updateGeometry(); //notify layout
}
if (doing_stuff)
return;
int full_idx = index;
int vector_idx = 0;
while (vector_idx < hidden_idx.size() && hidden_idx.at(vector_idx) < full_idx) {
full_idx++;
vector_idx++;
}
while (vector_idx < hidden_idx.size()) {
hidden_idx[vector_idx]++;
vector_idx++;
}
}
void TTabWidget::tabRemoved(int index)
{
if (tabBarAutoHide && count() <= 1) {
tabBar()->hide();
updateGeometry(); //notify layout
}
if (doing_stuff)
return;
int full_idx = index;
int vector_idx = 0;
while (vector_idx < hidden_idx.size() && hidden_idx.at(vector_idx) < full_idx) {
full_idx++;
vector_idx++;
}
while (vector_idx < hidden_idx.size()) {
hidden_idx[vector_idx]--;
vector_idx++;
}
}