Skip to content

Commit b61f509

Browse files
Moved title bar dragging code from DockAreaTabBar into DockAreaTitleBar
1 parent ae72f5e commit b61f509

File tree

6 files changed

+194
-200
lines changed

6 files changed

+194
-200
lines changed

src/DockAreaTabBar.cpp

Lines changed: 0 additions & 162 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,10 @@ namespace ads
5454
struct DockAreaTabBarPrivate
5555
{
5656
CDockAreaTabBar* _this;
57-
QPoint DragStartMousePos;
5857
CDockAreaWidget* DockArea;
59-
IFloatingWidget* FloatingWidget = nullptr;
6058
QWidget* TabsContainerWidget;
6159
QBoxLayout* TabsLayout;
6260
int CurrentIndex = -1;
63-
eDragState DragState = DraggingInactive;
6461

6562
/**
6663
* Private data constructor
@@ -72,14 +69,6 @@ struct DockAreaTabBarPrivate
7269
* The function reassigns the stylesheet to update the tabs
7370
*/
7471
void updateTabs();
75-
76-
/**
77-
* Test function for current drag state
78-
*/
79-
bool isDraggingState(eDragState dragState) const
80-
{
81-
return this->DragState == dragState;
82-
}
8372
};
8473
// struct DockAreaTabBarPrivate
8574

@@ -164,149 +153,6 @@ void CDockAreaTabBar::wheelEvent(QWheelEvent* Event)
164153
}
165154

166155

167-
//============================================================================
168-
void CDockAreaTabBar::mousePressEvent(QMouseEvent* ev)
169-
{
170-
if (ev->button() == Qt::LeftButton)
171-
{
172-
ev->accept();
173-
d->DragStartMousePos = ev->pos();
174-
d->DragState = DraggingMousePressed;
175-
return;
176-
}
177-
Super::mousePressEvent(ev);
178-
}
179-
180-
181-
//============================================================================
182-
void CDockAreaTabBar::mouseReleaseEvent(QMouseEvent* ev)
183-
{
184-
if (ev->button() == Qt::LeftButton)
185-
{
186-
ADS_PRINT("CDockAreaTabBar::mouseReleaseEvent");
187-
ev->accept();
188-
auto CurrentDragState = d->DragState;
189-
d->DragStartMousePos = QPoint();
190-
d->DragState = DraggingInactive;
191-
if (DraggingFloatingWidget == CurrentDragState)
192-
{
193-
d->FloatingWidget->finishDragging();
194-
}
195-
return;
196-
}
197-
Super::mouseReleaseEvent(ev);
198-
}
199-
200-
201-
//============================================================================
202-
void CDockAreaTabBar::mouseMoveEvent(QMouseEvent* ev)
203-
{
204-
Super::mouseMoveEvent(ev);
205-
if (!(ev->buttons() & Qt::LeftButton) || d->isDraggingState(DraggingInactive))
206-
{
207-
d->DragState = DraggingInactive;
208-
return;
209-
}
210-
211-
// move floating window
212-
if (d->isDraggingState(DraggingFloatingWidget))
213-
{
214-
d->FloatingWidget->moveFloating();
215-
return;
216-
}
217-
218-
// If this is the last dock area in a dock container it does not make
219-
// sense to move it to a new floating widget and leave this one
220-
// empty
221-
if (d->DockArea->dockContainer()->isFloating()
222-
&& d->DockArea->dockContainer()->visibleDockAreaCount() == 1)
223-
{
224-
return;
225-
}
226-
227-
// If one single dock widget in this area is not floatable then the whole
228-
// area is not floatable
229-
if (!d->DockArea->features().testFlag(CDockWidget::DockWidgetFloatable))
230-
{
231-
return;
232-
}
233-
234-
int DragDistance = (d->DragStartMousePos - ev->pos()).manhattanLength();
235-
if (DragDistance >= CDockManager::startDragDistance())
236-
{
237-
ADS_PRINT("CTabsScrollArea::startFloating");
238-
startFloating(d->DragStartMousePos);
239-
auto Overlay = d->DockArea->dockManager()->containerOverlay();
240-
Overlay->setAllowedAreas(OuterDockAreas);
241-
}
242-
243-
return;
244-
}
245-
246-
247-
//============================================================================
248-
void CDockAreaTabBar::mouseDoubleClickEvent(QMouseEvent *event)
249-
{
250-
// If this is the last dock area in a dock container it does not make
251-
// sense to move it to a new floating widget and leave this one
252-
// empty
253-
if (d->DockArea->dockContainer()->isFloating() && d->DockArea->dockContainer()->dockAreaCount() == 1)
254-
{
255-
return;
256-
}
257-
258-
if (!d->DockArea->features().testFlag(CDockWidget::DockWidgetFloatable))
259-
{
260-
return;
261-
}
262-
makeAreaFloating(event->pos(), DraggingInactive);
263-
}
264-
265-
266-
//============================================================================
267-
IFloatingWidget* CDockAreaTabBar::makeAreaFloating(const QPoint& Offset, eDragState DragState)
268-
{
269-
QSize Size = d->DockArea->size();
270-
d->DragState = DragState;
271-
bool OpaqueUndocking = CDockManager::configFlags().testFlag(CDockManager::OpaqueUndocking) ||
272-
(DraggingFloatingWidget != DragState);
273-
CFloatingDockContainer* FloatingDockContainer = nullptr;
274-
IFloatingWidget* FloatingWidget;
275-
if (OpaqueUndocking)
276-
{
277-
FloatingWidget = FloatingDockContainer = new CFloatingDockContainer(d->DockArea);
278-
}
279-
else
280-
{
281-
auto w = new CFloatingDragPreview(d->DockArea);
282-
connect(w, &CFloatingDragPreview::draggingCanceled, [=]()
283-
{
284-
d->DragState = DraggingInactive;
285-
});
286-
FloatingWidget = w;
287-
}
288-
289-
FloatingWidget->startFloating(Offset, Size, DragState, nullptr);
290-
if (FloatingDockContainer)
291-
{
292-
auto TopLevelDockWidget = FloatingDockContainer->topLevelDockWidget();
293-
if (TopLevelDockWidget)
294-
{
295-
TopLevelDockWidget->emitTopLevelChanged(true);
296-
}
297-
}
298-
299-
return FloatingWidget;
300-
}
301-
302-
303-
//============================================================================
304-
void CDockAreaTabBar::startFloating(const QPoint& Offset)
305-
{
306-
d->FloatingWidget = makeAreaFloating(Offset, DraggingFloatingWidget);
307-
}
308-
309-
310156
//============================================================================
311157
void CDockAreaTabBar::setCurrentIndex(int index)
312158
{
@@ -625,7 +471,6 @@ bool CDockAreaTabBar::isTabOpen(int Index) const
625471
QSize CDockAreaTabBar::minimumSizeHint() const
626472
{
627473
QSize Size = sizeHint();
628-
//Size.setWidth(Super::minimumSizeHint().width());// this defines the minimum width of a dock area
629474
Size.setWidth(10);
630475
return Size;
631476
}
@@ -637,13 +482,6 @@ QSize CDockAreaTabBar::sizeHint() const
637482
return d->TabsContainerWidget->sizeHint();
638483
}
639484

640-
641-
//===========================================================================
642-
eDragState CDockAreaTabBar::dragState() const
643-
{
644-
return d->DragState;
645-
}
646-
647485
} // namespace ads
648486

649487

src/DockAreaTabBar.h

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -67,42 +67,6 @@ private slots:
6767
protected:
6868
virtual void wheelEvent(QWheelEvent* Event) override;
6969

70-
/**
71-
* Stores mouse position to detect dragging
72-
*/
73-
virtual void mousePressEvent(QMouseEvent* ev) override;
74-
75-
/**
76-
* Stores mouse position to detect dragging
77-
*/
78-
virtual void mouseReleaseEvent(QMouseEvent* ev) override;
79-
80-
/**
81-
* Starts floating the complete docking area including all dock widgets,
82-
* if it is not the last dock area in a floating widget
83-
*/
84-
virtual void mouseMoveEvent(QMouseEvent* ev) override;
85-
86-
/**
87-
* Double clicking the title bar also starts floating of the complete area
88-
*/
89-
virtual void mouseDoubleClickEvent(QMouseEvent *event) override;
90-
91-
/**
92-
* Starts floating
93-
*/
94-
void startFloating(const QPoint& Offset);
95-
96-
/**
97-
* Makes the dock area floating
98-
*/
99-
IFloatingWidget* makeAreaFloating(const QPoint& Offset, eDragState DragState);
100-
101-
/**
102-
* Returns the current drag state
103-
*/
104-
eDragState dragState() const;
105-
10670

10771
public:
10872
using Super = QScrollArea;

0 commit comments

Comments
 (0)