Porperly moved title bar context menu code from DockAreaTabBar into DockAreaTitleBar

This commit is contained in:
Uwe Kindler 2020-02-07 12:23:26 +01:00
parent b61f50982a
commit d10d59a8e2
2 changed files with 25 additions and 24 deletions

View File

@ -259,10 +259,6 @@ void DockAreaTitleBarPrivate::createTabBar()
_this->connect(TabBar, SIGNAL(currentChanged(int)), SLOT(onCurrentTabChanged(int))); _this->connect(TabBar, SIGNAL(currentChanged(int)), SLOT(onCurrentTabChanged(int)));
_this->connect(TabBar, SIGNAL(tabBarClicked(int)), SIGNAL(tabBarClicked(int))); _this->connect(TabBar, SIGNAL(tabBarClicked(int)), SIGNAL(tabBarClicked(int)));
_this->connect(TabBar, SIGNAL(elidedChanged(bool)), SLOT(markTabsMenuOutdated())); _this->connect(TabBar, SIGNAL(elidedChanged(bool)), SLOT(markTabsMenuOutdated()));
TabBar->setContextMenuPolicy(Qt::CustomContextMenu);
_this->connect(TabBar, SIGNAL(customContextMenuRequested(const QPoint&)),
SLOT(showContextMenu(const QPoint&)));
} }
@ -519,25 +515,6 @@ void CDockAreaTitleBar::setVisible(bool Visible)
} }
//============================================================================
void CDockAreaTitleBar::showContextMenu(const QPoint& pos)
{
if (d->DragState == DraggingFloatingWidget)
{
return;
}
QMenu Menu(this);
auto Action = Menu.addAction(tr("Detach Area"), this, SLOT(onUndockButtonClicked()));
Action->setEnabled(d->DockArea->features().testFlag(CDockWidget::DockWidgetFloatable));
Menu.addSeparator();
Action = Menu.addAction(tr("Close Area"), this, SLOT(onCloseButtonClicked()));
Action->setEnabled(d->DockArea->features().testFlag(CDockWidget::DockWidgetClosable));
Menu.addAction(tr("Close Other Areas"), d->DockArea, SLOT(closeOtherAreas()));
Menu.exec(mapToGlobal(pos));
}
//============================================================================ //============================================================================
void CDockAreaTitleBar::mousePressEvent(QMouseEvent* ev) void CDockAreaTitleBar::mousePressEvent(QMouseEvent* ev)
{ {
@ -637,6 +614,26 @@ void CDockAreaTitleBar::mouseDoubleClickEvent(QMouseEvent *event)
} }
//============================================================================
void CDockAreaTitleBar::contextMenuEvent(QContextMenuEvent* ev)
{
ev->accept();
if (d->isDraggingState(DraggingFloatingWidget))
{
return;
}
QMenu Menu(this);
auto Action = Menu.addAction(tr("Detach Area"), this, SLOT(onUndockButtonClicked()));
Action->setEnabled(d->DockArea->features().testFlag(CDockWidget::DockWidgetFloatable));
Menu.addSeparator();
Action = Menu.addAction(tr("Close Area"), this, SLOT(onCloseButtonClicked()));
Action->setEnabled(d->DockArea->features().testFlag(CDockWidget::DockWidgetClosable));
Menu.addAction(tr("Close Other Areas"), d->DockArea, SLOT(closeOtherAreas()));
Menu.exec(ev->globalPos());
}
} // namespace ads } // namespace ads
#include "DockAreaTitleBar.moc" #include "DockAreaTitleBar.moc"

View File

@ -60,7 +60,6 @@ private slots:
void onUndockButtonClicked(); void onUndockButtonClicked();
void onTabsMenuActionTriggered(QAction* Action); void onTabsMenuActionTriggered(QAction* Action);
void onCurrentTabChanged(int Index); void onCurrentTabChanged(int Index);
void showContextMenu(const QPoint& pos);
protected: protected:
/** /**
@ -84,6 +83,11 @@ protected:
*/ */
virtual void mouseDoubleClickEvent(QMouseEvent *event) override; virtual void mouseDoubleClickEvent(QMouseEvent *event) override;
/**
* Show context menu
*/
virtual void contextMenuEvent(QContextMenuEvent *event);
public slots: public slots:
/** /**
* Call this slot to tell the title bar that it should update the tabs menu * Call this slot to tell the title bar that it should update the tabs menu