1 | // Copyright (C) 2016 The Qt Company Ltd. |
2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 |
3 | |
4 | #include "default_container.h" |
5 | #include <QtCore/qdebug.h> |
6 | |
7 | QT_BEGIN_NAMESPACE |
8 | |
9 | template <class Container> |
10 | static inline void setCurrentContainerIndex(int index, Container *container) |
11 | { |
12 | const bool blocked = container->signalsBlocked(); |
13 | container->blockSignals(true); |
14 | container->setCurrentIndex(index); |
15 | container->blockSignals(blocked); |
16 | } |
17 | |
18 | static inline void ensureNoParent(QWidget *widget) |
19 | { |
20 | if (widget->parentWidget()) |
21 | widget->setParent(nullptr); |
22 | } |
23 | |
24 | static const char PageLabel[] = "Page" ; |
25 | |
26 | namespace qdesigner_internal { |
27 | |
28 | // --------- QStackedWidgetContainer |
29 | QStackedWidgetContainer::QStackedWidgetContainer(QStackedWidget *widget, QObject *parent) : |
30 | QObject(parent), |
31 | m_widget(widget) |
32 | { |
33 | } |
34 | |
35 | void QStackedWidgetContainer::setCurrentIndex(int index) |
36 | { |
37 | setCurrentContainerIndex(index, container: m_widget); |
38 | } |
39 | |
40 | void QStackedWidgetContainer::addWidget(QWidget *widget) |
41 | { |
42 | ensureNoParent(widget); |
43 | m_widget->addWidget(w: widget); |
44 | } |
45 | |
46 | void QStackedWidgetContainer::insertWidget(int index, QWidget *widget) |
47 | { |
48 | ensureNoParent(widget); |
49 | m_widget->insertWidget(index, w: widget); |
50 | } |
51 | |
52 | void QStackedWidgetContainer::remove(int index) |
53 | { |
54 | m_widget->removeWidget(w: widget(index)); |
55 | } |
56 | |
57 | // --------- QTabWidgetContainer |
58 | QTabWidgetContainer::QTabWidgetContainer(QTabWidget *widget, QObject *parent) : |
59 | QObject(parent), |
60 | m_widget(widget) |
61 | { |
62 | } |
63 | |
64 | void QTabWidgetContainer::setCurrentIndex(int index) |
65 | { |
66 | setCurrentContainerIndex(index, container: m_widget); |
67 | } |
68 | |
69 | void QTabWidgetContainer::addWidget(QWidget *widget) |
70 | { |
71 | ensureNoParent(widget); |
72 | m_widget->addTab(widget, QString::fromUtf8(utf8: PageLabel)); |
73 | } |
74 | |
75 | void QTabWidgetContainer::insertWidget(int index, QWidget *widget) |
76 | { |
77 | ensureNoParent(widget); |
78 | m_widget->insertTab(index, widget, QString::fromUtf8(utf8: PageLabel)); |
79 | } |
80 | |
81 | void QTabWidgetContainer::remove(int index) |
82 | { |
83 | m_widget->removeTab(index); |
84 | } |
85 | |
86 | // ------------------- QToolBoxContainer |
87 | QToolBoxContainer::QToolBoxContainer(QToolBox *widget, QObject *parent) : |
88 | QObject(parent), |
89 | m_widget(widget) |
90 | { |
91 | } |
92 | |
93 | void QToolBoxContainer::setCurrentIndex(int index) |
94 | { |
95 | setCurrentContainerIndex(index, container: m_widget); |
96 | } |
97 | |
98 | void QToolBoxContainer::addWidget(QWidget *widget) |
99 | { |
100 | ensureNoParent(widget); |
101 | m_widget->addItem(item: widget, text: QString::fromUtf8(utf8: PageLabel)); |
102 | } |
103 | |
104 | void QToolBoxContainer::insertWidget(int index, QWidget *widget) |
105 | { |
106 | ensureNoParent(widget); |
107 | m_widget->insertItem(index, item: widget, text: QString::fromUtf8(utf8: PageLabel)); |
108 | } |
109 | |
110 | void QToolBoxContainer::remove(int index) |
111 | { |
112 | m_widget->removeItem(index); |
113 | } |
114 | |
115 | // ------------------- QScrollAreaContainer |
116 | // We pass on active=true only if there are no children yet. |
117 | // If there are children, it is a legacy custom widget QScrollArea that has an internal, |
118 | // unmanaged child, in which case we deactivate the extension (otherwise we crash). |
119 | // The child will then not show up in the task menu |
120 | |
121 | QScrollAreaContainer::QScrollAreaContainer(QScrollArea *widget, QObject *parent) : |
122 | QObject(parent), |
123 | SingleChildContainer<QScrollArea>(widget, widget->widget() == nullptr) |
124 | { |
125 | } |
126 | // ------------------- QDockWidgetContainer |
127 | QDockWidgetContainer::QDockWidgetContainer(QDockWidget *widget, QObject *parent) : |
128 | QObject(parent), |
129 | SingleChildContainer<QDockWidget>(widget) |
130 | { |
131 | } |
132 | |
133 | } |
134 | |
135 | QT_END_NAMESPACE |
136 | |