Improved detection of dock widget dragging - uses a distance now (half the height of dock area title bar)

This commit is contained in:
Uwe Kindler 2018-10-15 15:09:59 +02:00
parent ada3d6b3b5
commit 927be9a7d9
7 changed files with 26 additions and 7 deletions

View File

@ -186,7 +186,9 @@ void CDockAreaTabBar::mouseMoveEvent(QMouseEvent* ev)
return; return;
} }
if (!this->geometry().contains(ev->pos())) int DragDistanceY = qAbs(d->DragStartMousePos.y() - ev->pos().y());
int MinDragDistanceY = this->height() / 2;
if (DragDistanceY >= MinDragDistanceY)
{ {
qDebug() << "CTabsScrollArea::startFloating"; qDebug() << "CTabsScrollArea::startFloating";
startFloating(d->DragStartMousePos); startFloating(d->DragStartMousePos);

View File

@ -163,7 +163,7 @@ signals:
void currentChanged(int Index); void currentChanged(int Index);
/** /**
* This signal is emitted when user clicks on a tab at an index. * This signal is emitted when user clicks on a tab
*/ */
void tabBarClicked(int index); void tabBarClicked(int index);

View File

@ -84,7 +84,7 @@ void DockAreaTitleBarPrivate::createButtons()
_this->connect(TabsMenu, SIGNAL(aboutToShow()), SLOT(onTabsMenuAboutToShow())); _this->connect(TabsMenu, SIGNAL(aboutToShow()), SLOT(onTabsMenuAboutToShow()));
TabsMenuButton->setMenu(TabsMenu); TabsMenuButton->setMenu(TabsMenu);
TopLayout->addWidget(TabsMenuButton, 0); TopLayout->addWidget(TabsMenuButton, 0);
TabsMenuButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); TabsMenuButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding);
_this->connect(TabsMenuButton->menu(), SIGNAL(triggered(QAction*)), _this->connect(TabsMenuButton->menu(), SIGNAL(triggered(QAction*)),
SLOT(onTabsMenuActionTriggered(QAction*))); SLOT(onTabsMenuActionTriggered(QAction*)));
@ -93,7 +93,7 @@ void DockAreaTitleBarPrivate::createButtons()
CloseButton->setFlat(true); CloseButton->setFlat(true);
CloseButton->setIcon(_this->style()->standardIcon(QStyle::SP_TitleBarCloseButton)); CloseButton->setIcon(_this->style()->standardIcon(QStyle::SP_TitleBarCloseButton));
CloseButton->setToolTip(QObject::tr("Close")); CloseButton->setToolTip(QObject::tr("Close"));
CloseButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); CloseButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding);
TopLayout->addWidget(CloseButton, 0); TopLayout->addWidget(CloseButton, 0);
_this->connect(CloseButton, SIGNAL(clicked()), SLOT(onCloseButtonClicked())); _this->connect(CloseButton, SIGNAL(clicked()), SLOT(onCloseButtonClicked()));
} }
@ -110,6 +110,7 @@ void DockAreaTitleBarPrivate::createTabBar()
_this->connect(TabBar, SIGNAL(removingTab(int)), SLOT(markTabsMenuOutdated())); _this->connect(TabBar, SIGNAL(removingTab(int)), SLOT(markTabsMenuOutdated()));
_this->connect(TabBar, SIGNAL(tabMoved(int, int)), SLOT(markTabsMenuOutdated())); _this->connect(TabBar, SIGNAL(tabMoved(int, int)), SLOT(markTabsMenuOutdated()));
_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)));
} }
@ -192,6 +193,7 @@ void CDockAreaTitleBar::onTabsMenuActionTriggered(QAction* Action)
{ {
int Index = Action->data().toInt(); int Index = Action->data().toInt();
d->TabBar->setCurrentIndex(Index); d->TabBar->setCurrentIndex(Index);
emit tabBarClicked(Index);
} }

View File

@ -71,6 +71,13 @@ public:
* Returns the pointer to the tabBar() * Returns the pointer to the tabBar()
*/ */
CDockAreaTabBar* tabBar() const; CDockAreaTabBar* tabBar() const;
signals:
/**
* This signal is emitted if a tab in the tab bar is clicked by the user
* or if the user clicks on a tab item in the title bar tab menu.
*/
void tabBarClicked(int index);
}; // class name }; // class name
} }
// namespace ads // namespace ads

View File

@ -289,7 +289,7 @@ void DockAreaWidgetPrivate::createTitleBar()
Layout->addWidget(TitleBar); Layout->addWidget(TitleBar);
_this->connect(tabBar(), SIGNAL(tabCloseRequested(int)), _this->connect(tabBar(), SIGNAL(tabCloseRequested(int)),
SLOT(onTabCloseRequested(int))); SLOT(onTabCloseRequested(int)));
_this->connect(tabBar(), SIGNAL(tabBarClicked(int)), _this->connect(TitleBar, SIGNAL(tabBarClicked(int)),
SLOT(setCurrentIndex(int))); SLOT(setCurrentIndex(int)));
_this->connect(tabBar(), SIGNAL(tabMoved(int, int)), _this->connect(tabBar(), SIGNAL(tabMoved(int, int)),
SLOT(reorderDockWidget(int, int))); SLOT(reorderDockWidget(int, int)));

View File

@ -225,6 +225,12 @@ bool DockManagerPrivate::restoreState(const QByteArray &state, int version)
return false; return false;
} }
// Hide updates of floatingf widgets from use
for (auto FloatingWidget : FloatingWidgets)
{
FloatingWidget->hide();
}
for (auto DockWidget : DockWidgetsMap) for (auto DockWidget : DockWidgetsMap)
{ {
DockWidget->setProperty("dirty", true); DockWidget->setProperty("dirty", true);

View File

@ -279,8 +279,10 @@ void CDockWidgetTab::mouseMoveEvent(QMouseEvent* ev)
d->moveTab(ev); d->moveTab(ev);
} }
bool MouseInsideTitleArea = d->titleAreaGeometryContains(ev->globalPos()); // Maybe a fixed drag distance is better here ?
if (!MouseInsideTitleArea) int DragDistanceY = qAbs(d->DragStartMousePosition.y() - ev->pos().y());
int MinDragDistanceY = d->DockArea->titleBarGeometry().height() / 2;
if (DragDistanceY >= MinDragDistanceY)
{ {
// If this is the last dock area in a dock container with only // If this is the last dock area in a dock container with only
// one single dock widget it does not make sense to move it to a new // one single dock widget it does not make sense to move it to a new