Skip to content

Commit 35c1b04

Browse files
author
Uwe Kindler
committed
Merge branch 'refs/heads/master' into linux_experimental
2 parents 8853c75 + 0de1a9c commit 35c1b04

File tree

8 files changed

+84
-34
lines changed

8 files changed

+84
-34
lines changed

demo/MainWindow.cpp

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,32 @@ static ads::CDockWidget* createLongTextLabelDockWidget(QMenu* ViewMenu)
8888
}
8989

9090

91+
/**
92+
* Function returns a features string with closable (c), movable (m) and floatable (f)
93+
* features. i.e. The following string is for a not closable but movable and floatable
94+
* widget: c- m+ f+
95+
*/
96+
static QString featuresString(ads::CDockWidget* DockWidget)
97+
{
98+
auto f = DockWidget->features();
99+
return QString("c%1 m%2 f%3")
100+
.arg(f.testFlag(ads::CDockWidget::DockWidgetClosable) ? "+" : "-")
101+
.arg(f.testFlag(ads::CDockWidget::DockWidgetMovable) ? "+" : "-")
102+
.arg(f.testFlag(ads::CDockWidget::DockWidgetFloatable) ? "+" : "-");
103+
}
104+
105+
106+
/**
107+
* Appends the string returned by featuresString() to the window title of
108+
* the given DockWidget
109+
*/
110+
static void appendFeaturStringToWindowTitle(ads::CDockWidget* DockWidget)
111+
{
112+
DockWidget->setWindowTitle(DockWidget->windowTitle()
113+
+ QString(" (%1)").arg(featuresString(DockWidget)));
114+
}
115+
116+
91117
//============================================================================
92118
static ads::CDockWidget* createCalendarDockWidget(QMenu* ViewMenu)
93119
{
@@ -110,7 +136,8 @@ static ads::CDockWidget* createFileSystemTreeDockWidget(QMenu* ViewMenu)
110136
QFileSystemModel* m = new QFileSystemModel(w);
111137
m->setRootPath(QDir::currentPath());
112138
w->setModel(m);
113-
ads::CDockWidget* DockWidget = new ads::CDockWidget(QString("Filesystem %1").arg(FileSystemCount++));
139+
ads::CDockWidget* DockWidget = new ads::CDockWidget(QString("Filesystem %1")
140+
.arg(FileSystemCount++));
114141
DockWidget->setWidget(w);
115142
ViewMenu->addAction(DockWidget->toggleViewAction());
116143
return DockWidget;
@@ -185,6 +212,8 @@ void MainWindowPrivate::createContent()
185212
ToolBar->addAction(ui.actionSaveState);
186213
ToolBar->addAction(ui.actionRestoreState);
187214
FileSystemWidget->setFeature(ads::CDockWidget::DockWidgetMovable, false);
215+
FileSystemWidget->setFeature(ads::CDockWidget::DockWidgetFloatable, false);
216+
appendFeaturStringToWindowTitle(FileSystemWidget);
188217
auto TopDockArea = DockManager->addDockWidget(ads::TopDockWidgetArea, FileSystemWidget);
189218
DockWidget = createCalendarDockWidget(ViewMenu);
190219
DockWidget->setFeature(ads::CDockWidget::DockWidgetClosable, false);

src/DockAreaTabBar.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,13 @@ void CDockAreaTabBar::mouseMoveEvent(QMouseEvent* ev)
205205
return;
206206
}
207207

208+
// If one single dock widget in this area is not floatable then the whole
209+
// area is not floatable
210+
if (!d->DockArea->features().testFlag(CDockWidget::DockWidgetFloatable))
211+
{
212+
return;
213+
}
214+
208215
int DragDistance = (d->DragStartMousePos - ev->pos()).manhattanLength();
209216
if (DragDistance >= CDockManager::startDragDistance())
210217
{
@@ -228,6 +235,11 @@ void CDockAreaTabBar::mouseDoubleClickEvent(QMouseEvent *event)
228235
{
229236
return;
230237
}
238+
239+
if (!d->DockArea->features().testFlag(CDockWidget::DockWidgetFloatable))
240+
{
241+
return;
242+
}
231243
makeAreaFloating(event->pos(), DraggingInactive);
232244
}
233245

src/DockAreaTitleBar.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,10 @@ void CDockAreaTitleBar::onCloseButtonClicked()
291291
//============================================================================
292292
void CDockAreaTitleBar::onUndockButtonClicked()
293293
{
294-
d->TabBar->makeAreaFloating(mapFromGlobal(QCursor::pos()), DraggingInactive);
294+
if (d->DockArea->features().testFlag(CDockWidget::DockWidgetFloatable))
295+
{
296+
d->TabBar->makeAreaFloating(mapFromGlobal(QCursor::pos()), DraggingInactive);
297+
}
295298
}
296299

297300

@@ -346,9 +349,10 @@ void CDockAreaTitleBar::setVisible(bool Visible)
346349
void CDockAreaTitleBar::showContextMenu(const QPoint& pos)
347350
{
348351
QMenu Menu(this);
349-
Menu.addAction(tr("Detach Area"), this, SLOT(onUndockButtonClicked()));
352+
auto Action = Menu.addAction(tr("Detach Area"), this, SLOT(onUndockButtonClicked()));
353+
Action->setEnabled(d->DockArea->features().testFlag(CDockWidget::DockWidgetFloatable));
350354
Menu.addSeparator();
351-
auto Action = Menu.addAction(tr("Close Area"), this, SLOT(onCloseButtonClicked()));
355+
Action = Menu.addAction(tr("Close Area"), this, SLOT(onCloseButtonClicked()));
352356
Action->setEnabled(d->DockArea->features().testFlag(CDockWidget::DockWidgetClosable));
353357
Menu.addAction(tr("Close Other Areas"), d->DockArea, SLOT(closeOtherAreas()));
354358
Menu.exec(mapToGlobal(pos));

src/DockAreaWidget.cpp

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ struct DockAreaWidgetPrivate
241241
DockAreaLayout* ContentsLayout = nullptr;
242242
CDockAreaTitleBar* TitleBar = nullptr;
243243
CDockManager* DockManager = nullptr;
244-
bool UpdateCloseButton = false;
244+
bool UpdateTitleBarButtons = false;
245245

246246
/**
247247
* Private data constructor
@@ -295,9 +295,9 @@ struct DockAreaWidgetPrivate
295295
}
296296

297297
/**
298-
* Udpates the enable state of the close button
298+
* Udpates the enable state of the close and detach button
299299
*/
300-
void updateCloseButtonState();
300+
void updateTitleBarButtonStates();
301301
};
302302
// struct DockAreaWidgetPrivate
303303

@@ -322,17 +322,19 @@ void DockAreaWidgetPrivate::createTitleBar()
322322

323323

324324
//============================================================================
325-
void DockAreaWidgetPrivate::updateCloseButtonState()
325+
void DockAreaWidgetPrivate::updateTitleBarButtonStates()
326326
{
327327
if (_this->isHidden())
328328
{
329-
UpdateCloseButton = true;
329+
UpdateTitleBarButtons = true;
330330
return;
331331
}
332332

333333
TitleBar->button(TitleBarButtonClose)->setEnabled(
334334
_this->features().testFlag(CDockWidget::DockWidgetClosable));
335-
UpdateCloseButton = false;
335+
TitleBar->button(TitleBarButtonUndock)->setEnabled(
336+
_this->features().testFlag(CDockWidget::DockWidgetFloatable));
337+
UpdateTitleBarButtons = false;
336338
}
337339

338340

@@ -400,7 +402,7 @@ void CDockAreaWidget::insertDockWidget(int index, CDockWidget* DockWidget,
400402
setCurrentIndex(index);
401403
}
402404
DockWidget->setDockArea(this);
403-
d->updateCloseButtonState();
405+
d->updateTitleBarButtonStates();
404406
}
405407

406408

@@ -433,7 +435,7 @@ void CDockAreaWidget::removeDockWidget(CDockWidget* DockWidget)
433435
hideAreaWithNoVisibleContent();
434436
}
435437

436-
d->updateCloseButtonState();
438+
d->updateTitleBarButtonStates();
437439
updateTitleBarVisibility();
438440
auto TopLevelDockWidget = DockContainer->topLevelDockWidget();
439441
if (TopLevelDockWidget)
@@ -765,9 +767,9 @@ void CDockAreaWidget::toggleView(bool Open)
765767
void CDockAreaWidget::setVisible(bool Visible)
766768
{
767769
Super::setVisible(Visible);
768-
if (d->UpdateCloseButton)
770+
if (d->UpdateTitleBarButtons)
769771
{
770-
d->updateCloseButtonState();
772+
d->updateTitleBarButtonStates();
771773
}
772774
}
773775

src/DockManager.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -340,8 +340,9 @@ void DockManagerPrivate::emitTopLevelEvents()
340340

341341

342342
//============================================================================
343-
bool DockManagerPrivate::restoreState(const QByteArray &state, int version)
343+
bool DockManagerPrivate::restoreState(const QByteArray& State, int version)
344344
{
345+
QByteArray state = State.startsWith("<?xml") ? State : qUncompress(State);
345346
if (!checkFormat(state, version))
346347
{
347348
qDebug() << "checkFormat: Error checking format!!!!!!!";
@@ -493,11 +494,11 @@ unsigned int CDockManager::zOrderIndex() const
493494

494495

495496
//============================================================================
496-
QByteArray CDockManager::saveState(eXmlMode XmlMode, int version) const
497+
QByteArray CDockManager::saveState(int version) const
497498
{
498499
QByteArray xmldata;
499500
QXmlStreamWriter s(&xmldata);
500-
s.setAutoFormatting(XmlAutoFormattingEnabled == XmlMode);
501+
s.setAutoFormatting(d->ConfigFlags.testFlag(XmlAutoFormattingEnabled));
501502
s.writeStartDocument();
502503
s.writeStartElement("QtAdvancedDockingSystem");
503504
s.writeAttribute("Version", QString::number(version));
@@ -510,7 +511,7 @@ QByteArray CDockManager::saveState(eXmlMode XmlMode, int version) const
510511
s.writeEndElement();
511512
s.writeEndDocument();
512513

513-
return xmldata;
514+
return d->ConfigFlags.testFlag(XmlCompressionEnabled) ? qCompress(xmldata, 9) : xmldata;
514515
}
515516

516517

src/DockManager.h

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,9 @@ struct DockWidgetTabPrivate;
5151
struct DockAreaWidgetPrivate;
5252

5353
/**
54-
* The central dock manager that maintains the complete docking system
54+
* The central dock manager that maintains the complete docking system.
55+
* With the configuration flags you can globally control the functionality
56+
* of the docking system.
5557
**/
5658
class ADS_EXPORT CDockManager : public CDockContainerWidget
5759
{
@@ -108,12 +110,6 @@ class ADS_EXPORT CDockManager : public CDockContainerWidget
108110
MenuAlphabeticallySorted
109111
};
110112

111-
enum eXmlMode
112-
{
113-
XmlAutoFormattingDisabled,
114-
XmlAutoFormattingEnabled
115-
};
116-
117113
/**
118114
* These global configuration flags configure some global dock manager
119115
* settings.
@@ -124,7 +120,9 @@ class ADS_EXPORT CDockManager : public CDockContainerWidget
124120
DockAreaHasCloseButton = 0x02, //!< If the flag is set each dock area has a close button
125121
DockAreaCloseButtonClosesTab = 0x04,//!< If the flag is set, the dock area close button closes the active tab, if not set, it closes the complete cock area
126122
OpaqueSplitterResize = 0x08, //!< See QSplitter::setOpaqueResize() documentation
127-
DefaultConfig = ActiveTabHasCloseButton | DockAreaHasCloseButton | OpaqueSplitterResize, ///< the default configuration
123+
XmlAutoFormattingEnabled = 0x10,//!< If enabled, the XML writer automatically adds line-breaks and indentation to empty sections between elements (ignorable whitespace).
124+
XmlCompressionEnabled = 0x20,//!< If enabled, the XML output will be compressed and is not human readable anymore
125+
DefaultConfig = ActiveTabHasCloseButton | DockAreaHasCloseButton | OpaqueSplitterResize | XmlCompressionEnabled, ///< the default configuration
128126
};
129127
Q_DECLARE_FLAGS(ConfigFlags, eConfigFlag)
130128

@@ -228,7 +226,7 @@ class ADS_EXPORT CDockManager : public CDockContainerWidget
228226
* The XmlMode XmlAutoFormattingDisabled is better if you would like to have
229227
* a more compact XML output - i.e. for storage in ini files.
230228
*/
231-
QByteArray saveState(eXmlMode XmlMode = XmlAutoFormattingDisabled, int version = 0) const;
229+
QByteArray saveState(int version = 0) const;
232230

233231
/**
234232
* Restores the state of this dockmanagers dockwidgets.

src/DockWidget.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ private slots:
141141
enum DockWidgetFeature
142142
{
143143
DockWidgetClosable = 0x01,
144-
DockWidgetMovable = 0x02,
144+
DockWidgetMovable = 0x02,///< this feature is not properly implemented yet and is ignored
145145
DockWidgetFloatable = 0x04,
146146
AllDockWidgetFeatures = DockWidgetClosable | DockWidgetMovable | DockWidgetFloatable,
147147
NoDockWidgetFeatures = 0x00

src/DockWidgetTab.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ void CDockWidgetTab::mouseMoveEvent(QMouseEvent* ev)
328328
}
329329

330330
// Floating is only allowed for widgets that are movable
331-
if (d->DockWidget->features().testFlag(CDockWidget::DockWidgetMovable))
331+
if (d->DockWidget->features().testFlag(CDockWidget::DockWidgetFloatable))
332332
{
333333
d->startFloating();
334334
}
@@ -352,9 +352,10 @@ void CDockWidgetTab::contextMenuEvent(QContextMenuEvent* ev)
352352

353353
d->DragStartMousePosition = ev->pos();
354354
QMenu Menu(this);
355-
Menu.addAction(tr("Detach"), this, SLOT(onDetachActionTriggered()));
355+
auto Action = Menu.addAction(tr("Detach"), this, SLOT(onDetachActionTriggered()));
356+
Action->setEnabled(d->DockWidget->features().testFlag(CDockWidget::DockWidgetFloatable));
356357
Menu.addSeparator();
357-
auto Action = Menu.addAction(tr("Close"), this, SIGNAL(closeRequested()));
358+
Action = Menu.addAction(tr("Close"), this, SIGNAL(closeRequested()));
358359
Action->setEnabled(isClosable());
359360
Menu.addAction(tr("Close Others"), this, SIGNAL(closeOtherTabsRequested()));
360361
Menu.exec(mapToGlobal(ev->pos()));
@@ -469,7 +470,8 @@ void CDockWidgetTab::mouseDoubleClickEvent(QMouseEvent *event)
469470
// If this is the last dock area in a dock container it does not make
470471
// sense to move it to a new floating widget and leave this one
471472
// empty
472-
if (!d->DockArea->dockContainer()->isFloating() || d->DockArea->dockWidgetsCount() > 1)
473+
if ((!d->DockArea->dockContainer()->isFloating() || d->DockArea->dockWidgetsCount() > 1)
474+
&& d->DockWidget->features().testFlag(CDockWidget::DockWidgetFloatable))
473475
{
474476
d->DragStartMousePosition = event->pos();
475477
d->startFloating(DraggingInactive);
@@ -505,13 +507,15 @@ bool CDockWidgetTab::isClosable() const
505507
//===========================================================================
506508
void CDockWidgetTab::onDetachActionTriggered()
507509
{
510+
if (!d->DockWidget->features().testFlag(CDockWidget::DockWidgetFloatable))
511+
{
512+
return;
513+
}
508514
d->DragStartMousePosition = mapFromGlobal(QCursor::pos());
509515
d->startFloating(DraggingInactive);
510516
}
511517

512518

513-
514-
515519
//============================================================================
516520
bool CDockWidgetTab::event(QEvent *e)
517521
{

0 commit comments

Comments
 (0)