diff --git a/demo/main.cpp b/demo/main.cpp index 7e887f6..1a2bd47 100644 --- a/demo/main.cpp +++ b/demo/main.cpp @@ -42,7 +42,7 @@ int main(int argc, char *argv[]) std::shared_ptr b; QApplication a(argc, argv); a.setQuitOnLastWindowClosed(true); - //qInstallMessageHandler(myMessageOutput); + qInstallMessageHandler(myMessageOutput); qDebug() << "Message handler test"; CMainWindow mw; diff --git a/src/DockAreaTabBar.cpp b/src/DockAreaTabBar.cpp index 0baf839..33ade65 100644 --- a/src/DockAreaTabBar.cpp +++ b/src/DockAreaTabBar.cpp @@ -33,7 +33,6 @@ #include #include #include -#include #include #include "FloatingDockContainer.h" @@ -43,6 +42,8 @@ #include "DockWidget.h" #include "DockWidgetTab.h" +#include + namespace ads { @@ -288,7 +289,8 @@ void CDockAreaTabBar::insertTab(int Index, CDockWidgetTab* Tab) { d->TabsLayout->insertWidget(Index, Tab); connect(Tab, SIGNAL(clicked()), this, SLOT(onTabClicked())); - connect(Tab, SIGNAL(closeButtonClicked()), this, SLOT(onTabCloseButtonClicked())); + connect(Tab, SIGNAL(closeRequested()), this, SLOT(onTabCloseRequested())); + connect(Tab, SIGNAL(closeOtherTabsRequested()), this, SLOT(onCloseOtherTabsRequested())); connect(Tab, SIGNAL(moved(const QPoint&)), this, SLOT(onTabWidgetMoved(const QPoint&))); Tab->installEventFilter(this); emit tabInserted(Index); @@ -402,9 +404,26 @@ void CDockAreaTabBar::onTabClicked() //=========================================================================== -void CDockAreaTabBar::onTabCloseButtonClicked() +void CDockAreaTabBar::onTabCloseRequested() { - closeTab(currentIndex()); + CDockWidgetTab* Tab = qobject_cast(sender()); + int Index = d->TabsLayout->indexOf(Tab); + closeTab(Index); +} + + +//=========================================================================== +void CDockAreaTabBar::onCloseOtherTabsRequested() +{ + auto Sender = qobject_cast(sender()); + for (int i = 0; i < count(); ++i) + { + auto Tab = tab(i); + if (Tab->isClosable() && !Tab->isHidden() && Tab != Sender) + { + closeTab(i); + } + } } @@ -532,6 +551,7 @@ bool CDockAreaTabBar::isTabOpen(int Index) const return !tab(Index)->isHidden(); } + } // namespace ads //--------------------------------------------------------------------------- diff --git a/src/DockAreaTabBar.h b/src/DockAreaTabBar.h index 53e9d18..e7f815d 100644 --- a/src/DockAreaTabBar.h +++ b/src/DockAreaTabBar.h @@ -54,7 +54,8 @@ private: private slots: void onTabClicked(); - void onTabCloseButtonClicked(); + void onTabCloseRequested(); + void onCloseOtherTabsRequested(); void onTabWidgetMoved(const QPoint& GlobalPos); protected: diff --git a/src/DockAreaTitleBar.cpp b/src/DockAreaTitleBar.cpp index 699a19c..33ec304 100644 --- a/src/DockAreaTitleBar.cpp +++ b/src/DockAreaTitleBar.cpp @@ -120,6 +120,7 @@ void DockAreaTitleBarPrivate::createButtons() QMenu* TabsMenu = new QMenu(TabsMenuButton); _this->connect(TabsMenu, SIGNAL(aboutToShow()), SLOT(onTabsMenuAboutToShow())); TabsMenuButton->setMenu(TabsMenu); + TabsMenuButton->setToolTip(QObject::tr("List all tabs")); TabsMenuButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding); TopLayout->addWidget(TabsMenuButton, 0); _this->connect(TabsMenuButton->menu(), SIGNAL(triggered(QAction*)), @@ -129,6 +130,7 @@ void DockAreaTitleBarPrivate::createButtons() UndockButton = new tTileBarButton(); UndockButton->setObjectName("undockButton"); UndockButton->setAutoRaise(true); + UndockButton->setToolTip(QObject::tr("Detach Group")); UndockButton->setIcon(_this->style()->standardIcon(QStyle::SP_TitleBarNormalButton)); UndockButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding); TopLayout->addWidget(UndockButton, 0); @@ -145,7 +147,14 @@ void DockAreaTitleBarPrivate::createButtons() CloseIcon.addPixmap(disabledPixmap, QIcon::Disabled); CloseButton->setIcon(CloseIcon); - CloseButton->setToolTip(QObject::tr("Close all tabs")); + if (testConfigFlag(CDockManager::DockAreaCloseButtonClosesTab)) + { + CloseButton->setToolTip(QObject::tr("Close Active Tab")); + } + else + { + CloseButton->setToolTip(QObject::tr("Close Group")); + } CloseButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding); TopLayout->addWidget(CloseButton, 0); _this->connect(CloseButton, SIGNAL(clicked()), SLOT(onCloseButtonClicked())); diff --git a/src/DockAreaWidget.cpp b/src/DockAreaWidget.cpp index e2f7732..a31b035 100644 --- a/src/DockAreaWidget.cpp +++ b/src/DockAreaWidget.cpp @@ -336,10 +336,6 @@ void DockAreaWidgetPrivate::updateCloseButtonState() return; } - if (!UpdateCloseButton) - { - return; - } TitleBar->button(TitleBarButtonClose)->setEnabled( _this->features().testFlag(CDockWidget::DockWidgetClosable)); UpdateCloseButton = false; @@ -768,7 +764,10 @@ void CDockAreaWidget::toggleView(bool Open) void CDockAreaWidget::setVisible(bool Visible) { Super::setVisible(Visible); - d->updateCloseButtonState(); + if (d->UpdateCloseButton) + { + d->updateCloseButtonState(); + } } diff --git a/src/DockWidgetTab.cpp b/src/DockWidgetTab.cpp index 8fdec2f..00cba2e 100644 --- a/src/DockWidgetTab.cpp +++ b/src/DockWidgetTab.cpp @@ -40,6 +40,7 @@ #include #include #include +#include #include "ads_globals.h" #include "DockWidget.h" @@ -163,7 +164,7 @@ void DockWidgetTabPrivate::createLayout() CloseButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); CloseButton->setVisible(false); CloseButton->setToolTip(QObject::tr("Close Tab")); - _this->connect(CloseButton, SIGNAL(clicked()), SIGNAL(closeButtonClicked())); + _this->connect(CloseButton, SIGNAL(clicked()), SIGNAL(closeRequested())); QFontMetrics fm(TitleLabel->font()); int Spacing = qRound(fm.height() / 4.0); @@ -345,6 +346,23 @@ void CDockWidgetTab::mouseMoveEvent(QMouseEvent* ev) } +//============================================================================ +void CDockWidgetTab::contextMenuEvent(QContextMenuEvent* ev) +{ + ev->accept(); + std::cout << "CDockAreaTabBar::onTabContextMenuRequested" << std::endl; + + d->DragStartMousePosition = ev->pos(); + QMenu Menu(this); + Menu.addAction(tr("Detach"), this, SLOT(onDetachActionTriggered())); + Menu.addSeparator(); + auto Action = Menu.addAction(tr("Close"), this, SIGNAL(closeRequested())); + Action->setEnabled(isClosable()); + Menu.addAction(tr("Close Others"), this, SIGNAL(closeOtherTabsRequested())); + Menu.exec(mapToGlobal(ev->pos())); +} + + //============================================================================ bool CDockWidgetTab::isActiveTab() const { @@ -433,6 +451,7 @@ void CDockWidgetTab::mouseDoubleClickEvent(QMouseEvent *event) // empty if (!d->DockArea->dockContainer()->isFloating() || d->DockArea->dockWidgetsCount() > 1) { + d->DragStartMousePosition = event->pos(); d->startFloating(); } @@ -448,6 +467,20 @@ void CDockWidgetTab::setVisible(bool visible) } +//============================================================================ +bool CDockWidgetTab::isClosable() const +{ + return d->DockWidget && d->DockWidget->features().testFlag(CDockWidget::DockWidgetClosable); +} + + +//=========================================================================== +void CDockWidgetTab::onDetachActionTriggered() +{ + d->DragStartMousePosition = mapFromGlobal(QCursor::pos()); + d->startFloating(); +} + } // namespace ads //--------------------------------------------------------------------------- diff --git a/src/DockWidgetTab.h b/src/DockWidgetTab.h index e1ffa6e..692d940 100644 --- a/src/DockWidgetTab.h +++ b/src/DockWidgetTab.h @@ -54,10 +54,14 @@ private: DockWidgetTabPrivate* d; ///< private data (pimpl) friend struct DockWidgetTabPrivate; +private slots: + void onDetachActionTriggered(); + protected: virtual void mousePressEvent(QMouseEvent* ev) override; virtual void mouseReleaseEvent(QMouseEvent* ev) override; virtual void mouseMoveEvent(QMouseEvent* ev) override; + virtual void contextMenuEvent(QContextMenuEvent* ev) override; /** * Double clicking the tab widget makes the assigned dock widget floating @@ -121,13 +125,19 @@ public: */ QString text() const; + /** + * This function returns true if the assigned dock widget is closeable + */ + bool isClosable() const; + public slots: virtual void setVisible(bool visible); signals: void activeTabChanged(); void clicked(); - void closeButtonClicked(); + void closeRequested(); + void closeOtherTabsRequested(); void moved(const QPoint& GlobalPos); }; // class DockWidgetTab }