37
37
#include < QScrollArea>
38
38
#include < QMouseEvent>
39
39
#include < QDebug>
40
+ #include < QPointer>
40
41
41
42
#include " ads_globals.h"
42
43
#include " FloatingDockContainer.h"
52
53
53
54
namespace ads
54
55
{
55
- using tTileBarButton = QToolButton;
56
+ using tTitleBarButton = QToolButton;
57
+
58
+ /* *
59
+ * Some kind of dummy button that is used if certain buttons are hidden
60
+ * by dock manager config flags (i.e CDockManager::DockAreaHasCloseButton is
61
+ * disabled)
62
+ */
63
+ class CInvisibleButton : public tTitleBarButton
64
+ {
65
+ public:
66
+ CInvisibleButton (QWidget* parent = nullptr )
67
+ : tTitleBarButton(parent)
68
+ {
69
+ this ->hide ();
70
+ }
71
+
72
+
73
+ virtual void setVisible (bool visible) override
74
+ {
75
+ Q_UNUSED (visible);
76
+ tTitleBarButton::setVisible (false );
77
+ }
78
+ };
79
+
80
+
56
81
/* *
57
82
* Private data class of CDockAreaTitleBar class (pimpl)
58
83
*/
59
84
struct DockAreaTitleBarPrivate
60
85
{
61
86
CDockAreaTitleBar* _this;
62
- tTileBarButton* TabsMenuButton;
63
- tTileBarButton* UndockButton;
64
- tTileBarButton* CloseButton;
87
+ QPointer<tTitleBarButton> TabsMenuButton;
88
+ QPointer<tTitleBarButton> UndockButton;
89
+ QPointer<tTitleBarButton> CloseButton;
65
90
QBoxLayout* TopLayout;
66
91
CDockAreaWidget* DockArea;
67
92
CDockAreaTabBar* TabBar;
@@ -106,7 +131,7 @@ struct DockAreaTitleBarPrivate
106
131
* If the global IconPovider of the dockmanager provides a custom
107
132
* Icon for the given CustomIconId, the this icon will be used.
108
133
*/
109
- void setTitleBarButtonIcon (tTileBarButton * Button, QStyle::StandardPixmap StandarPixmap,
134
+ void setTitleBarButtonIcon (tTitleBarButton * Button, QStyle::StandardPixmap StandarPixmap,
110
135
ads::eIcon CustomIconId)
111
136
{
112
137
// First we try to use custom icons if available
@@ -143,7 +168,7 @@ void DockAreaTitleBarPrivate::createButtons()
143
168
{
144
169
QSizePolicy ButtonSizePolicy (QSizePolicy::Fixed, QSizePolicy::Expanding);
145
170
// Tabs menu button
146
- TabsMenuButton = new tTileBarButton ();
171
+ TabsMenuButton = new tTitleBarButton ();
147
172
TabsMenuButton->setObjectName (" tabsMenuButton" );
148
173
TabsMenuButton->setAutoRaise (true );
149
174
TabsMenuButton->setPopupMode (QToolButton::InstantPopup);
@@ -164,40 +189,43 @@ void DockAreaTitleBarPrivate::createButtons()
164
189
165
190
166
191
// Undock button
167
- UndockButton = new tTileBarButton ();
192
+ UndockButton = new tTitleBarButton ();
168
193
UndockButton->setObjectName (" undockButton" );
169
194
UndockButton->setAutoRaise (true );
170
195
#ifndef QT_NO_TOOLTIP
171
196
UndockButton->setToolTip (QObject::tr (" Detach Group" ));
172
197
#endif
173
- setTitleBarButtonIcon (UndockButton, QStyle::SP_TitleBarNormalButton, ads::DockAreaUndockIcon);
174
- UndockButton->setSizePolicy (ButtonSizePolicy);
198
+ setTitleBarButtonIcon (UndockButton, QStyle::SP_TitleBarNormalButton, ads::DockAreaUndockIcon);
199
+ UndockButton->setSizePolicy (ButtonSizePolicy);
175
200
TopLayout->addWidget (UndockButton, 0 );
176
201
_this->connect (UndockButton, SIGNAL (clicked ()), SLOT (onUndockButtonClicked ()));
177
202
178
-
179
- // Close button
180
- CloseButton = new tTileBarButton ();
181
- CloseButton->setObjectName (" closeButton" );
182
- CloseButton->setAutoRaise (true );
183
- setTitleBarButtonIcon (CloseButton, QStyle::SP_TitleBarCloseButton, ads::DockAreaCloseIcon);
184
- #ifndef QT_NO_TOOLTIP
185
- if (testConfigFlag (CDockManager::DockAreaCloseButtonClosesTab))
203
+ if (testConfigFlag (CDockManager::DockAreaHasCloseButton))
186
204
{
187
- CloseButton->setToolTip (QObject::tr (" Close Active Tab" ));
205
+ // Close button
206
+ CloseButton = new tTitleBarButton ();
207
+ CloseButton->setObjectName (" closeButton" );
208
+ CloseButton->setAutoRaise (true );
209
+ setTitleBarButtonIcon (CloseButton, QStyle::SP_TitleBarCloseButton, ads::DockAreaCloseIcon);
210
+ #ifndef QT_NO_TOOLTIP
211
+ if (testConfigFlag (CDockManager::DockAreaCloseButtonClosesTab))
212
+ {
213
+ CloseButton->setToolTip (QObject::tr (" Close Active Tab" ));
214
+ }
215
+ else
216
+ {
217
+ CloseButton->setToolTip (QObject::tr (" Close Group" ));
218
+ }
219
+ #endif
220
+ CloseButton->setSizePolicy (ButtonSizePolicy);
221
+ CloseButton->setIconSize (QSize (16 , 16 ));
222
+ TopLayout->addWidget (CloseButton, 0 );
223
+ _this->connect (CloseButton, SIGNAL (clicked ()), SLOT (onCloseButtonClicked ()));
188
224
}
189
225
else
190
226
{
191
- CloseButton->setToolTip (QObject::tr (" Close Group" ));
192
- }
193
- #endif
194
- CloseButton->setSizePolicy (ButtonSizePolicy);
195
- CloseButton->setIconSize (QSize (16 , 16 ));
196
- if (testConfigFlag (CDockManager::DockAreaHasCloseButton))
197
- {
198
- TopLayout->addWidget (CloseButton, 0 );
227
+ CloseButton = new CInvisibleButton ();
199
228
}
200
- _this->connect (CloseButton, SIGNAL (clicked ()), SLOT (onCloseButtonClicked ()));
201
229
}
202
230
203
231
@@ -243,6 +271,20 @@ CDockAreaTitleBar::CDockAreaTitleBar(CDockAreaWidget* parent) :
243
271
// ============================================================================
244
272
CDockAreaTitleBar::~CDockAreaTitleBar ()
245
273
{
274
+ if (!d->CloseButton .isNull ())
275
+ {
276
+ delete d->CloseButton ;
277
+ }
278
+
279
+ if (!d->TabsMenuButton .isNull ())
280
+ {
281
+ delete d->TabsMenuButton ;
282
+ }
283
+
284
+ if (!d->UndockButton .isNull ())
285
+ {
286
+ delete d->UndockButton ;
287
+ }
246
288
delete d;
247
289
}
248
290
0 commit comments