Debian Codegraph @

phoenix/qt/widget/tab-frame.cpp

raw
1 namespace phoenix {
2
3 void pTabFrame::append(string text, const image& image) {
4 unsigned selection = tabFrame.state.text.size() - 1;
5 qtTabFrame->addTab(new QWidget, QString::fromUtf8(text));
6 if(!image.empty()) setImage(selection, image);
7 }
8
9 QWidget* pTabFrame::container(Widget& widget) {
10 Layout* widgetLayout = GetParentWidgetLayout(&widget);
11 unsigned selection = 0;
12 for(auto& layout : tabFrame.state.layout) {
13 if(layout == widgetLayout) return qtTabFrame->widget(selection);
14 selection++;
15 }
16 return nullptr;
17 }
18
19 Position pTabFrame::displacement() {
20 return {5, 33};
21 }
22
23 void pTabFrame::remove(unsigned selection) {
24 qtTabFrame->removeTab(selection);
25 }
26
27 void pTabFrame::setEnabled(bool enabled) {
28 for(auto& layout : tabFrame.state.layout) {
29 if(layout) layout->setEnabled(layout->enabled());
30 }
31 pWidget::setEnabled(enabled);
32 }
33
34 void pTabFrame::setGeometry(Geometry geometry) {
35 pWidget::setGeometry(geometry);
36 geometry.x += 0, geometry.width -= 5;
37 geometry.y += 29, geometry.height -= 33;
38 for(auto& layout : tabFrame.state.layout) {
39 if(layout) layout->setGeometry(geometry);
40 }
41 synchronizeLayout();
42 }
43
44 void pTabFrame::setImage(unsigned selection, const image& image) {
45 qtTabFrame->setTabIcon(selection, CreateIcon(image));
46 }
47
48 void pTabFrame::setSelection(unsigned selection) {
49 locked = true;
50 qtTabFrame->setCurrentIndex(selection);
51 synchronizeLayout();
52 locked = false;
53 }
54
55 void pTabFrame::setText(unsigned selection, string text) {
56 qtTabFrame->setTabText(selection, QString::fromUtf8(text));
57 }
58
59 void pTabFrame::setVisible(bool visible) {
60 for(auto& layout : tabFrame.state.layout) {
61 if(layout) layout->setVisible(layout->visible());
62 }
63 pWidget::setVisible(visible);
64 }
65
66 void pTabFrame::constructor() {
67 qtWidget = qtTabFrame = new QTabWidget;
68 connect(qtTabFrame, SIGNAL(currentChanged(int)), SLOT(onChange(int)));
69
70 setSelection(tabFrame.state.selection);
71 }
72
73 void pTabFrame::destructor() {
74 delete qtTabFrame;
75 qtWidget = qtTabFrame = nullptr;
76 }
77
78 void pTabFrame::orphan() {
79 destructor();
80 constructor();
81 }
82
83 void pTabFrame::synchronizeLayout() {
84 unsigned selection = 0;
85 for(auto& layout : tabFrame.state.layout) {
86 if(layout) layout->setVisible(selection == tabFrame.state.selection);
87 selection++;
88 }
89 }
90
91 void pTabFrame::onChange(int selection) {
92 tabFrame.state.selection = selection;
93 synchronizeLayout();
94 if(!locked && tabFrame.onChange) tabFrame.onChange();
95 }
96
97 }