52
52
#include " DockOverlay.h"
53
53
#include " DockAreaTabBar.h"
54
54
#include " DockSplitter.h"
55
+ #include " DockAreaTitleBar.h"
55
56
56
57
#include < iostream>
57
58
@@ -209,14 +210,9 @@ struct DockAreaWidgetPrivate
209
210
{
210
211
CDockAreaWidget* _this;
211
212
QBoxLayout* Layout;
212
- QFrame* TitleBar;
213
- QBoxLayout* TopLayout;
214
213
DockAreaLayout* ContentsLayout;
215
- CDockAreaTabBar* TabBar;
216
- QPushButton* TabsMenuButton;
217
- QPushButton* CloseButton;
214
+ CDockAreaTitleBar* TitleBar;
218
215
CDockManager* DockManager = nullptr ;
219
- bool MenuOutdated = true ;
220
216
221
217
/* *
222
218
* Private data constructor
@@ -226,7 +222,7 @@ struct DockAreaWidgetPrivate
226
222
/* *
227
223
* Creates the layout for top area with tabs and close button
228
224
*/
229
- void createTabBar ();
225
+ void createTitleBar ();
230
226
231
227
/* *
232
228
* Returns the dock widget with the given index
@@ -244,13 +240,6 @@ struct DockAreaWidgetPrivate
244
240
return dockWidgetAt (index)->tabWidget ();
245
241
}
246
242
247
- /* *
248
- * Adds a tabs menu entry for the given dock widget
249
- * If menu is 0, a menu entry is added to the menu of the TabsMenuButton
250
- * member. If menu is a valid menu pointer, the entry will be added to
251
- * the given menu
252
- */
253
- void addTabsMenuEntry (CDockWidget* DockWidget, int Index = -1 , QMenu* menu = 0 );
254
243
255
244
/* *
256
245
* Returns the tab action of the given dock widget
@@ -268,22 +257,19 @@ struct DockAreaWidgetPrivate
268
257
return DockWidget->property (INDEX_PROPERTY).toInt ();
269
258
}
270
259
271
- /* *
272
- * Update the tabs menu if dock widget order changed or if dock widget has
273
- * been removed
274
- */
275
- void markTabsMenuOutdated ();
276
-
277
- /* *
278
- * Updates the tabs menu if it is outdated
279
- */
280
- void updateTabsMenu ();
281
-
282
260
/* *
283
261
* Updates the tab bar visibility depending on the number of dock widgets
284
262
* in this area
285
263
*/
286
264
void updateTabBar ();
265
+
266
+ /* *
267
+ * Convenience function for tabbar access
268
+ */
269
+ CDockAreaTabBar* tabBar () const
270
+ {
271
+ return TitleBar->tabBar ();
272
+ }
287
273
};
288
274
// struct DockAreaWidgetPrivate
289
275
@@ -297,43 +283,14 @@ DockAreaWidgetPrivate::DockAreaWidgetPrivate(CDockAreaWidget* _public) :
297
283
298
284
299
285
// ============================================================================
300
- void DockAreaWidgetPrivate::createTabBar ()
286
+ void DockAreaWidgetPrivate::createTitleBar ()
301
287
{
302
- TitleBar = new QFrame (_this);
303
- TitleBar->setObjectName (" dockAreaTitleBar" );
304
- TopLayout = new QBoxLayout (QBoxLayout::LeftToRight);
305
- TopLayout->setContentsMargins (0 , 0 , 0 , 0 );
306
- TopLayout->setSpacing (0 );
307
- TitleBar->setLayout (TopLayout);
288
+ TitleBar = new CDockAreaTitleBar (_this);
308
289
Layout->addWidget (TitleBar);
309
- TitleBar->setSizePolicy (QSizePolicy::Expanding, QSizePolicy::Fixed);
310
-
311
- TabBar = new CDockAreaTabBar (_this);
312
- TopLayout->addWidget (TabBar, 1 );
313
- _this->connect (TabBar, SIGNAL (currentChanged (int )), SLOT (setCurrentIndex (int )));
314
- _this->connect (TabBar, SIGNAL (tabMoved (int , int )), SLOT (reorderDockWidget (int , int )));
315
-
316
- TabsMenuButton = new QPushButton ();
317
- TabsMenuButton->setObjectName (" tabsMenuButton" );
318
- TabsMenuButton->setFlat (true );
319
- TabsMenuButton->setIcon (_this->style ()->standardIcon (QStyle::SP_TitleBarUnshadeButton));
320
- TabsMenuButton->setMaximumWidth (TabsMenuButton->iconSize ().width ());
321
- QMenu* TabsMenu = new QMenu (TabsMenuButton);
322
- _this->connect (TabsMenu, SIGNAL (aboutToShow ()), SLOT (onTabsMenuAboutToShow ()));
323
- TabsMenuButton->setMenu (TabsMenu);
324
- TopLayout->addWidget (TabsMenuButton, 0 );
325
- TabsMenuButton->setSizePolicy (QSizePolicy::Expanding, QSizePolicy::Expanding);
326
- _this->connect (TabsMenuButton->menu (), SIGNAL (triggered (QAction*)),
327
- SLOT (onTabsMenuActionTriggered (QAction*)));
328
-
329
- CloseButton = new QPushButton ();
330
- CloseButton->setObjectName (" closeButton" );
331
- CloseButton->setFlat (true );
332
- CloseButton->setIcon (_this->style ()->standardIcon (QStyle::SP_TitleBarCloseButton));
333
- CloseButton->setToolTip (_this->tr (" Close" ));
334
- CloseButton->setSizePolicy (QSizePolicy::Expanding, QSizePolicy::Expanding);
335
- TopLayout->addWidget (CloseButton, 0 );
336
- _this->connect (CloseButton, SIGNAL (clicked ()), SLOT (onCloseButtonClicked ()));
290
+ _this->connect (tabBar (), SIGNAL (tabCloseRequested (int )),
291
+ SLOT (onTabCloseRequested (int )));
292
+ _this->connect (tabBar (), SIGNAL (tabBarClicked (int )),
293
+ SLOT (setCurrentIndex (int )));
337
294
}
338
295
339
296
@@ -350,57 +307,6 @@ void DockAreaWidgetPrivate::updateTabBar()
350
307
}
351
308
352
309
353
- // ============================================================================
354
- void DockAreaWidgetPrivate::addTabsMenuEntry (CDockWidget* DockWidget,
355
- int Index, QMenu* menu)
356
- {
357
- menu = menu ? menu : TabsMenuButton->menu ();
358
- QAction* Action;
359
- if (Index >= 0 && Index < menu->actions ().count ())
360
- {
361
- Action = new QAction (DockWidget->icon (), DockWidget->windowTitle ());
362
- menu->insertAction (menu->actions ().at (Index), Action);
363
- }
364
- else
365
- {
366
- Action = menu->addAction (DockWidget->icon (), DockWidget->windowTitle ());
367
- }
368
- Action->setProperty (DOCKWIDGET_PROPERTY, QVariant::fromValue (DockWidget));
369
- QVariant vAction = QVariant::fromValue (Action);
370
- DockWidget->setProperty (ACTION_PROPERTY, vAction);
371
- }
372
-
373
-
374
- // ============================================================================
375
- void DockAreaWidgetPrivate::markTabsMenuOutdated ()
376
- {
377
- MenuOutdated = true ;
378
- }
379
-
380
-
381
- // ============================================================================
382
- void DockAreaWidgetPrivate::updateTabsMenu ()
383
- {
384
- if (!MenuOutdated)
385
- {
386
- return ;
387
- }
388
-
389
- QMenu* menu = TabsMenuButton->menu ();
390
- menu->clear ();
391
- for (int i = 0 ; i < ContentsLayout->count (); ++i)
392
- {
393
- if (dockWidgetAt (i)->isClosed ())
394
- {
395
- continue ;
396
- }
397
- addTabsMenuEntry (dockWidgetAt (i), APPEND, menu);
398
- }
399
-
400
- MenuOutdated = false ;
401
- }
402
-
403
-
404
310
// ============================================================================
405
311
CDockAreaWidget::CDockAreaWidget (CDockManager* DockManager, CDockContainerWidget* parent) :
406
312
QFrame (parent),
@@ -412,7 +318,7 @@ CDockAreaWidget::CDockAreaWidget(CDockManager* DockManager, CDockContainerWidget
412
318
d->Layout ->setSpacing (0 );
413
319
setLayout (d->Layout );
414
320
415
- d->createTabBar ();
321
+ d->createTitleBar ();
416
322
d->ContentsLayout = new DockAreaLayout (d->Layout );
417
323
}
418
324
@@ -453,10 +359,9 @@ void CDockAreaWidget::insertDockWidget(int index, CDockWidget* DockWidget,
453
359
d->ContentsLayout ->insertWidget (index, DockWidget);
454
360
DockWidget->tabWidget ()->setDockAreaWidget (this );
455
361
auto TabWidget = DockWidget->tabWidget ();
456
- d->TabBar ->insertTab (index, TabWidget);
362
+ d->tabBar () ->insertTab (index, TabWidget);
457
363
TabWidget->setVisible (!DockWidget->isClosed ());
458
364
DockWidget->setProperty (INDEX_PROPERTY, index);
459
- d->markTabsMenuOutdated ();
460
365
if (Activate)
461
366
{
462
367
setCurrentIndex (index);
@@ -474,11 +379,10 @@ void CDockAreaWidget::removeDockWidget(CDockWidget* DockWidget)
474
379
d->ContentsLayout ->removeWidget (DockWidget);
475
380
auto TabWidget = DockWidget->tabWidget ();
476
381
TabWidget->hide ();
477
- d->TabBar ->removeTab (TabWidget);
382
+ d->tabBar () ->removeTab (TabWidget);
478
383
if (NextOpenDockWidget)
479
384
{
480
385
setCurrentDockWidget (NextOpenDockWidget);
481
- d->markTabsMenuOutdated ();
482
386
}
483
387
else if (d->ContentsLayout ->isEmpty ())
484
388
{
@@ -541,9 +445,10 @@ void CDockAreaWidget::hideAreaIfNoVisibleContent()
541
445
542
446
543
447
// ============================================================================
544
- void CDockAreaWidget::onCloseButtonClicked ( )
448
+ void CDockAreaWidget::onTabCloseRequested ( int Index )
545
449
{
546
- currentDockWidget ()->toggleView (false );
450
+ qDebug () << " CDockAreaWidget::onTabCloseRequested " << Index;
451
+ dockWidget (Index)->toggleView (false );
547
452
}
548
453
549
454
@@ -576,18 +481,15 @@ void CDockAreaWidget::setCurrentDockWidget(CDockWidget* DockWidget)
576
481
void CDockAreaWidget::setCurrentIndex (int index)
577
482
{
578
483
std::cout << " CDockAreaWidget::setCurrentIndex " << index << std::endl;
579
- if (index < 0 || index > (d->TabBar ->count () - 1 ))
484
+ auto TabBar = d->tabBar ();
485
+ if (index < 0 || index > (TabBar->count () - 1 ))
580
486
{
581
487
qWarning () << Q_FUNC_INFO << " Invalid index" << index;
582
488
return ;
583
489
}
584
490
585
491
emit currentChanging (index);
586
- d->TabBar ->setCurrentIndex (index);
587
- CDockWidgetTab* CurrentTab = d->TabBar ->currentTab ();
588
- auto Features = CurrentTab->dockWidget ()->features ();
589
- d->CloseButton ->setVisible (Features.testFlag (CDockWidget::DockWidgetClosable));
590
-
492
+ TabBar->setCurrentIndex (index);
591
493
d->ContentsLayout ->setCurrentIndex (index);
592
494
d->ContentsLayout ->currentWidget ()->show ();
593
495
emit currentChanged (index);
@@ -602,9 +504,9 @@ int CDockAreaWidget::currentIndex() const
602
504
603
505
604
506
// ============================================================================
605
- QRect CDockAreaWidget::titleAreaGeometry () const
507
+ QRect CDockAreaWidget::titleBarGeometry () const
606
508
{
607
- return d->TopLayout ->geometry ();
509
+ return d->TitleBar ->geometry ();
608
510
}
609
511
610
512
// ============================================================================
@@ -664,21 +566,6 @@ QList<CDockWidget*> CDockAreaWidget::openedDockWidgets() const
664
566
}
665
567
666
568
667
- // ============================================================================
668
- int CDockAreaWidget::indexOfContentByTitlePos (const QPoint& p, QWidget* exclude) const
669
- {
670
- for (int i = 0 ; i < d->ContentsLayout ->count (); ++i)
671
- {
672
- auto TabWidget = d->tabWidgetAt (i);
673
- if (TabWidget->isVisible () && TabWidget->geometry ().contains (p) && (!exclude || TabWidget != exclude))
674
- {
675
- return i;
676
- }
677
- }
678
- return -1 ;
679
- }
680
-
681
-
682
569
// ============================================================================
683
570
int CDockAreaWidget::dockWidgetsCount () const
684
571
{
@@ -716,16 +603,6 @@ void CDockAreaWidget::toggleDockWidgetView(CDockWidget* DockWidget, bool Open)
716
603
Q_UNUSED (DockWidget);
717
604
Q_UNUSED (Open);
718
605
updateTabBarVisibility ();
719
- d->markTabsMenuOutdated ();
720
- }
721
-
722
-
723
- // ============================================================================
724
- void CDockAreaWidget::onTabsMenuActionTriggered (QAction* Action)
725
- {
726
- QVariant vDockWidget = Action->property (DOCKWIDGET_PROPERTY);
727
- CDockWidget* DockWidget = vDockWidget.value <CDockWidget*>();
728
- setCurrentDockWidget (DockWidget);
729
606
}
730
607
731
608
@@ -777,13 +654,6 @@ CDockWidget* CDockAreaWidget::nextOpenDockWidget(CDockWidget* DockWidget) const
777
654
}
778
655
}
779
656
780
-
781
- // ============================================================================
782
- void CDockAreaWidget::onTabsMenuAboutToShow ()
783
- {
784
- d->updateTabsMenu ();
785
- }
786
-
787
657
} // namespace ads
788
658
789
659
// ---------------------------------------------------------------------------
0 commit comments