Skip to content

Commit 6b93ae9

Browse files
author
Uwe Kindler
committed
Some refactoring to improve code clarity, renamed DockWidgetTitleBar into DockWidgetTab because in the GUI it is a tab, created new class CDockAreaTabBar for the tabbar of a dock area
1 parent f5b3c05 commit 6b93ae9

14 files changed

+350
-209
lines changed

demo/MainWindow.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -174,13 +174,15 @@ void MainWindowPrivate::createContent()
174174
QMenu* ViewMenu = ui.menuView;
175175
auto DockWidget = createCalendarDockWidget(ViewMenu);
176176
DockWidget->setIcon(_this->style()->standardIcon(QStyle::SP_DialogOpenButton));
177-
DockWidget->setFeatures(DockWidget->features().setFlag(ads::CDockWidget::DockWidgetClosable, false));
177+
DockWidget->setFeature(ads::CDockWidget::DockWidgetClosable, false);
178178
DockManager->addDockWidget(ads::LeftDockWidgetArea, DockWidget);
179179
DockManager->addDockWidget(ads::LeftDockWidgetArea, createLongTextLabelDockWidget(ViewMenu));
180180
DockManager->addDockWidget(ads::BottomDockWidgetArea, createFileSystemTreeDockWidget(ViewMenu));
181-
auto TopDockArea = DockManager->addDockWidget(ads::TopDockWidgetArea, createFileSystemTreeDockWidget(ViewMenu));
181+
auto FileSystemWidget = createFileSystemTreeDockWidget(ViewMenu);
182+
FileSystemWidget->setFeature(ads::CDockWidget::DockWidgetMovable, false);
183+
auto TopDockArea = DockManager->addDockWidget(ads::TopDockWidgetArea, FileSystemWidget);
182184
DockWidget = createCalendarDockWidget(ViewMenu);
183-
DockWidget->setFeatures(DockWidget->features().setFlag(ads::CDockWidget::DockWidgetClosable, false));
185+
DockWidget->setFeature(ads::CDockWidget::DockWidgetClosable, false);
184186
DockManager->addDockWidget(ads::CenterDockWidgetArea, DockWidget, TopDockArea);
185187

186188
// Test dock area docking

src/DockAreaTabBar.cpp

Lines changed: 173 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,173 @@
1+
//============================================================================
2+
/// \file DockAreaTabBar.cpp
3+
/// \author Uwe Kindler
4+
/// \date 24.08.2018
5+
/// \brief Implementation of CDockAreaTabBar class
6+
//============================================================================
7+
8+
//============================================================================
9+
// INCLUDES
10+
//============================================================================
11+
#include "DockAreaTabBar.h"
12+
13+
#include <QMouseEvent>
14+
#include <QScrollBar>
15+
#include <QDebug>
16+
17+
#include "FloatingDockContainer.h"
18+
#include "DockAreaWidget.h"
19+
#include "DockOverlay.h"
20+
#include "DockManager.h"
21+
22+
namespace ads
23+
{
24+
/**
25+
* Private data class of CDockAreaTabBar class (pimpl)
26+
*/
27+
struct DockAreaTabBarPrivate
28+
{
29+
CDockAreaTabBar* _this;
30+
QPoint DragStartMousePos;
31+
CDockAreaWidget* DockArea;
32+
CFloatingDockContainer* FloatingWidget = nullptr;
33+
34+
/**
35+
* Private data constructor
36+
*/
37+
DockAreaTabBarPrivate(CDockAreaTabBar* _public);
38+
};
39+
// struct DockAreaTabBarPrivate
40+
41+
//============================================================================
42+
DockAreaTabBarPrivate::DockAreaTabBarPrivate(CDockAreaTabBar* _public) :
43+
_this(_public)
44+
{
45+
46+
}
47+
48+
//============================================================================
49+
CDockAreaTabBar::CDockAreaTabBar(CDockAreaWidget* parent) :
50+
QScrollArea(parent),
51+
d(new DockAreaTabBarPrivate(this))
52+
{
53+
d->DockArea = parent;
54+
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Ignored);
55+
setFrameStyle(QFrame::NoFrame);
56+
setWidgetResizable(true);
57+
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
58+
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
59+
}
60+
61+
//============================================================================
62+
CDockAreaTabBar::~CDockAreaTabBar()
63+
{
64+
delete d;
65+
}
66+
67+
68+
//============================================================================
69+
void CDockAreaTabBar::wheelEvent(QWheelEvent* Event)
70+
{
71+
Event->accept();
72+
const int direction = Event->angleDelta().y();
73+
if (direction < 0)
74+
{
75+
horizontalScrollBar()->setValue(horizontalScrollBar()->value() + 20);
76+
}
77+
else
78+
{
79+
horizontalScrollBar()->setValue(horizontalScrollBar()->value() - 20);
80+
}
81+
}
82+
83+
84+
//============================================================================
85+
void CDockAreaTabBar::mousePressEvent(QMouseEvent* ev)
86+
{
87+
if (ev->button() == Qt::LeftButton)
88+
{
89+
ev->accept();
90+
d->DragStartMousePos = ev->pos();
91+
return;
92+
}
93+
QScrollArea::mousePressEvent(ev);
94+
}
95+
96+
97+
//============================================================================
98+
void CDockAreaTabBar::mouseReleaseEvent(QMouseEvent* ev)
99+
{
100+
if (ev->button() == Qt::LeftButton)
101+
{
102+
qDebug() << "CTabsScrollArea::mouseReleaseEvent";
103+
ev->accept();
104+
d->FloatingWidget = nullptr;
105+
d->DragStartMousePos = QPoint();
106+
return;
107+
}
108+
QScrollArea::mouseReleaseEvent(ev);
109+
}
110+
111+
112+
//============================================================================
113+
void CDockAreaTabBar::mouseMoveEvent(QMouseEvent* ev)
114+
{
115+
QScrollArea::mouseMoveEvent(ev);
116+
if (ev->buttons() != Qt::LeftButton)
117+
{
118+
return;
119+
}
120+
121+
if (d->FloatingWidget)
122+
{
123+
d->FloatingWidget->moveFloating();
124+
return;
125+
}
126+
127+
// If this is the last dock area in a dock container it does not make
128+
// sense to move it to a new floating widget and leave this one
129+
// empty
130+
if (d->DockArea->dockContainer()->isFloating()
131+
&& d->DockArea->dockContainer()->visibleDockAreaCount() == 1)
132+
{
133+
return;
134+
}
135+
136+
if (!this->geometry().contains(ev->pos()))
137+
{
138+
qDebug() << "CTabsScrollArea::startFloating";
139+
startFloating(d->DragStartMousePos);
140+
auto Overlay = d->DockArea->dockManager()->containerOverlay();
141+
Overlay->setAllowedAreas(OuterDockAreas);
142+
}
143+
144+
return;
145+
}
146+
147+
148+
//============================================================================
149+
void CDockAreaTabBar::mouseDoubleClickEvent(QMouseEvent *event)
150+
{
151+
// If this is the last dock area in a dock container it does not make
152+
// sense to move it to a new floating widget and leave this one
153+
// empty
154+
if (d->DockArea->dockContainer()->isFloating() && d->DockArea->dockContainer()->dockAreaCount() == 1)
155+
{
156+
return;
157+
}
158+
startFloating(event->pos());
159+
}
160+
161+
162+
//============================================================================
163+
void CDockAreaTabBar::startFloating(const QPoint& Pos)
164+
{
165+
QSize Size = d->DockArea->size();
166+
CFloatingDockContainer* FloatingWidget = new CFloatingDockContainer(d->DockArea);
167+
FloatingWidget->startFloating(Pos, Size);
168+
d->FloatingWidget = FloatingWidget;
169+
}
170+
} // namespace ads
171+
172+
//---------------------------------------------------------------------------
173+
// EOF DockAreaTabBar.cpp

src/DockAreaTabBar.h

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
#ifndef DockAreaTabBarH
2+
#define DockAreaTabBarH
3+
//============================================================================
4+
/// \file DockAreaTabBar.h
5+
/// \author Uwe Kindler
6+
/// \date 24.08.2018
7+
/// \brief Declaration of CDockAreaTabBar class
8+
//============================================================================
9+
10+
//============================================================================
11+
// INCLUDES
12+
//============================================================================
13+
#include <QScrollArea>
14+
15+
namespace ads
16+
{
17+
class CDockAreaWidget;
18+
struct DockAreaTabBarPrivate;
19+
20+
/**
21+
* Custom scroll bar implementation for dock area tab bar
22+
* This scroll area enables floating of a whole dock area including all
23+
* dock widgets
24+
*/
25+
class CDockAreaTabBar : public QScrollArea
26+
{
27+
Q_OBJECT
28+
private:
29+
DockAreaTabBarPrivate* d; ///< private data (pimpl)
30+
friend class DockAreaTabBarPrivate;
31+
32+
protected:
33+
virtual void wheelEvent(QWheelEvent* Event) override;
34+
/**
35+
* Stores mouse position to detect dragging
36+
*/
37+
virtual void mousePressEvent(QMouseEvent* ev) override;
38+
39+
/**
40+
* Stores mouse position to detect dragging
41+
*/
42+
virtual void mouseReleaseEvent(QMouseEvent* ev) override;
43+
44+
/**
45+
* Starts floating the complete docking area including all dock widgets,
46+
* if it is not the last dock area in a floating widget
47+
*/
48+
virtual void mouseMoveEvent(QMouseEvent* ev) override;
49+
50+
/**
51+
* Double clicking the title bar also starts floating of the complete area
52+
*/
53+
virtual void mouseDoubleClickEvent(QMouseEvent *event) override;
54+
55+
/**
56+
* Starts floating
57+
*/
58+
void startFloating(const QPoint& Pos);
59+
60+
public:
61+
/**
62+
* Default Constructor
63+
*/
64+
CDockAreaTabBar(CDockAreaWidget* parent);
65+
66+
/**
67+
* Virtual Destructor
68+
*/
69+
virtual ~CDockAreaTabBar();
70+
}; // class CDockAreaTabBar
71+
} // namespace ads
72+
//-----------------------------------------------------------------------------
73+
#endif // DockAreaTabBarH
74+

0 commit comments

Comments
 (0)