35
35
#include < QDebug>
36
36
#include < QBoxLayout>
37
37
#include < QApplication>
38
+ #include < QtGlobal>
38
39
39
40
#include " FloatingDockContainer.h"
40
41
#include " DockAreaWidget.h"
@@ -69,6 +70,16 @@ struct DockAreaTabBarPrivate
69
70
* The function reassigns the stylesheet to update the tabs
70
71
*/
71
72
void updateTabs ();
73
+
74
+ /* *
75
+ * Convenience function to access first tab
76
+ */
77
+ CDockWidgetTab* firstTab () const {return _this->tab (0 );}
78
+
79
+ /* *
80
+ * Convenience function to access last tab
81
+ */
82
+ CDockWidgetTab* lastTab () const {return _this->tab (_this->count () - 1 );}
72
83
};
73
84
// struct DockAreaTabBarPrivate
74
85
@@ -366,6 +377,8 @@ void CDockAreaTabBar::onTabWidgetMoved(const QPoint& GlobalPos)
366
377
367
378
int fromIndex = d->TabsLayout ->indexOf (MovingTab);
368
379
auto MousePos = mapFromGlobal (GlobalPos);
380
+ MousePos.rx () = qMax (d->firstTab ()->geometry ().left (), MousePos.x ());
381
+ MousePos.rx () = qMin (d->lastTab ()->geometry ().right (), MousePos.x ());
369
382
int toIndex = -1 ;
370
383
// Find tab under mouse
371
384
for (int i = 0 ; i < count (); ++i)
@@ -381,38 +394,23 @@ void CDockAreaTabBar::onTabWidgetMoved(const QPoint& GlobalPos)
381
394
if (toIndex == fromIndex)
382
395
{
383
396
toIndex = -1 ;
384
- continue ;
385
- }
386
-
387
- if (toIndex < 0 )
388
- {
389
- toIndex = 0 ;
390
397
}
391
398
break ;
392
399
}
393
400
394
- // Now check if the mouse is behind the last tab
395
- if (toIndex < 0 )
396
- {
397
- if (MousePos.x () > tab (count () - 1 )->geometry ().right ())
398
- {
399
- ADS_PRINT (" after all tabs" );
400
- toIndex = count () - 1 ;
401
- }
402
- else
403
- {
404
- toIndex = fromIndex;
405
- }
406
- }
407
-
408
- d->TabsLayout ->removeWidget (MovingTab);
409
- d->TabsLayout ->insertWidget (toIndex, MovingTab);
410
- if (toIndex >= 0 )
401
+ if (toIndex > -1 )
411
402
{
403
+ d->TabsLayout ->removeWidget (MovingTab);
404
+ d->TabsLayout ->insertWidget (toIndex, MovingTab);
412
405
ADS_PRINT (" tabMoved from " << fromIndex << " to " << toIndex);
413
406
emit tabMoved (fromIndex, toIndex);
414
407
setCurrentIndex (toIndex);
415
408
}
409
+ else
410
+ {
411
+ // Ensure that the moved tab is reset to its start position
412
+ d->TabsLayout ->update ();
413
+ }
416
414
}
417
415
418
416
// ===========================================================================
0 commit comments