mirror of
https://github.com/githubuser0xFFFF/Qt-Advanced-Docking-System.git
synced 2024-12-24 07:21:32 +08:00
Properly implemented support for DockWidgetFloatable feature - now detaching a DockWidget or a DockAre that is not floatable is not possible (support for DockWidgetMovable feature is not implemented yet)
This commit is contained in:
parent
c45327aafd
commit
0de1a9ccae
@ -88,6 +88,32 @@ static ads::CDockWidget* createLongTextLabelDockWidget(QMenu* ViewMenu)
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Function returns a features string with closable (c), movable (m) and floatable (f)
|
||||
* features. i.e. The following string is for a not closable but movable and floatable
|
||||
* widget: c- m+ f+
|
||||
*/
|
||||
static QString featuresString(ads::CDockWidget* DockWidget)
|
||||
{
|
||||
auto f = DockWidget->features();
|
||||
return QString("c%1 m%2 f%3")
|
||||
.arg(f.testFlag(ads::CDockWidget::DockWidgetClosable) ? "+" : "-")
|
||||
.arg(f.testFlag(ads::CDockWidget::DockWidgetMovable) ? "+" : "-")
|
||||
.arg(f.testFlag(ads::CDockWidget::DockWidgetFloatable) ? "+" : "-");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Appends the string returned by featuresString() to the window title of
|
||||
* the given DockWidget
|
||||
*/
|
||||
static void appendFeaturStringToWindowTitle(ads::CDockWidget* DockWidget)
|
||||
{
|
||||
DockWidget->setWindowTitle(DockWidget->windowTitle()
|
||||
+ QString(" (%1)").arg(featuresString(DockWidget)));
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
static ads::CDockWidget* createCalendarDockWidget(QMenu* ViewMenu)
|
||||
{
|
||||
@ -110,7 +136,8 @@ static ads::CDockWidget* createFileSystemTreeDockWidget(QMenu* ViewMenu)
|
||||
QFileSystemModel* m = new QFileSystemModel(w);
|
||||
m->setRootPath(QDir::currentPath());
|
||||
w->setModel(m);
|
||||
ads::CDockWidget* DockWidget = new ads::CDockWidget(QString("Filesystem %1").arg(FileSystemCount++));
|
||||
ads::CDockWidget* DockWidget = new ads::CDockWidget(QString("Filesystem %1")
|
||||
.arg(FileSystemCount++));
|
||||
DockWidget->setWidget(w);
|
||||
ViewMenu->addAction(DockWidget->toggleViewAction());
|
||||
return DockWidget;
|
||||
@ -185,6 +212,8 @@ void MainWindowPrivate::createContent()
|
||||
ToolBar->addAction(ui.actionSaveState);
|
||||
ToolBar->addAction(ui.actionRestoreState);
|
||||
FileSystemWidget->setFeature(ads::CDockWidget::DockWidgetMovable, false);
|
||||
FileSystemWidget->setFeature(ads::CDockWidget::DockWidgetFloatable, false);
|
||||
appendFeaturStringToWindowTitle(FileSystemWidget);
|
||||
auto TopDockArea = DockManager->addDockWidget(ads::TopDockWidgetArea, FileSystemWidget);
|
||||
DockWidget = createCalendarDockWidget(ViewMenu);
|
||||
DockWidget->setFeature(ads::CDockWidget::DockWidgetClosable, false);
|
||||
|
@ -205,6 +205,13 @@ void CDockAreaTabBar::mouseMoveEvent(QMouseEvent* ev)
|
||||
return;
|
||||
}
|
||||
|
||||
// If one single dock widget in this area is not floatable then the whole
|
||||
// area is not floatable
|
||||
if (!d->DockArea->features().testFlag(CDockWidget::DockWidgetFloatable))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
int DragDistance = (d->DragStartMousePos - ev->pos()).manhattanLength();
|
||||
if (DragDistance >= CDockManager::startDragDistance())
|
||||
{
|
||||
@ -228,6 +235,11 @@ void CDockAreaTabBar::mouseDoubleClickEvent(QMouseEvent *event)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (!d->DockArea->features().testFlag(CDockWidget::DockWidgetFloatable))
|
||||
{
|
||||
return;
|
||||
}
|
||||
makeAreaFloating(event->pos(), DraggingInactive);
|
||||
}
|
||||
|
||||
|
@ -288,7 +288,10 @@ void CDockAreaTitleBar::onCloseButtonClicked()
|
||||
//============================================================================
|
||||
void CDockAreaTitleBar::onUndockButtonClicked()
|
||||
{
|
||||
d->TabBar->makeAreaFloating(mapFromGlobal(QCursor::pos()), DraggingInactive);
|
||||
if (d->DockArea->features().testFlag(CDockWidget::DockWidgetFloatable))
|
||||
{
|
||||
d->TabBar->makeAreaFloating(mapFromGlobal(QCursor::pos()), DraggingInactive);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -343,9 +346,10 @@ void CDockAreaTitleBar::setVisible(bool Visible)
|
||||
void CDockAreaTitleBar::showContextMenu(const QPoint& pos)
|
||||
{
|
||||
QMenu Menu(this);
|
||||
Menu.addAction(tr("Detach Area"), this, SLOT(onUndockButtonClicked()));
|
||||
auto Action = Menu.addAction(tr("Detach Area"), this, SLOT(onUndockButtonClicked()));
|
||||
Action->setEnabled(d->DockArea->features().testFlag(CDockWidget::DockWidgetFloatable));
|
||||
Menu.addSeparator();
|
||||
auto Action = Menu.addAction(tr("Close Area"), this, SLOT(onCloseButtonClicked()));
|
||||
Action = Menu.addAction(tr("Close Area"), this, SLOT(onCloseButtonClicked()));
|
||||
Action->setEnabled(d->DockArea->features().testFlag(CDockWidget::DockWidgetClosable));
|
||||
Menu.addAction(tr("Close Other Areas"), d->DockArea, SLOT(closeOtherAreas()));
|
||||
Menu.exec(mapToGlobal(pos));
|
||||
|
@ -241,7 +241,7 @@ struct DockAreaWidgetPrivate
|
||||
DockAreaLayout* ContentsLayout = nullptr;
|
||||
CDockAreaTitleBar* TitleBar = nullptr;
|
||||
CDockManager* DockManager = nullptr;
|
||||
bool UpdateCloseButton = false;
|
||||
bool UpdateTitleBarButtons = false;
|
||||
|
||||
/**
|
||||
* Private data constructor
|
||||
@ -295,9 +295,9 @@ struct DockAreaWidgetPrivate
|
||||
}
|
||||
|
||||
/**
|
||||
* Udpates the enable state of the close button
|
||||
* Udpates the enable state of the close and detach button
|
||||
*/
|
||||
void updateCloseButtonState();
|
||||
void updateTitleBarButtonStates();
|
||||
};
|
||||
// struct DockAreaWidgetPrivate
|
||||
|
||||
@ -322,17 +322,19 @@ void DockAreaWidgetPrivate::createTitleBar()
|
||||
|
||||
|
||||
//============================================================================
|
||||
void DockAreaWidgetPrivate::updateCloseButtonState()
|
||||
void DockAreaWidgetPrivate::updateTitleBarButtonStates()
|
||||
{
|
||||
if (_this->isHidden())
|
||||
{
|
||||
UpdateCloseButton = true;
|
||||
UpdateTitleBarButtons = true;
|
||||
return;
|
||||
}
|
||||
|
||||
TitleBar->button(TitleBarButtonClose)->setEnabled(
|
||||
_this->features().testFlag(CDockWidget::DockWidgetClosable));
|
||||
UpdateCloseButton = false;
|
||||
TitleBar->button(TitleBarButtonUndock)->setEnabled(
|
||||
_this->features().testFlag(CDockWidget::DockWidgetFloatable));
|
||||
UpdateTitleBarButtons = false;
|
||||
}
|
||||
|
||||
|
||||
@ -400,7 +402,7 @@ void CDockAreaWidget::insertDockWidget(int index, CDockWidget* DockWidget,
|
||||
setCurrentIndex(index);
|
||||
}
|
||||
DockWidget->setDockArea(this);
|
||||
d->updateCloseButtonState();
|
||||
d->updateTitleBarButtonStates();
|
||||
}
|
||||
|
||||
|
||||
@ -433,7 +435,7 @@ void CDockAreaWidget::removeDockWidget(CDockWidget* DockWidget)
|
||||
hideAreaWithNoVisibleContent();
|
||||
}
|
||||
|
||||
d->updateCloseButtonState();
|
||||
d->updateTitleBarButtonStates();
|
||||
updateTitleBarVisibility();
|
||||
auto TopLevelDockWidget = DockContainer->topLevelDockWidget();
|
||||
if (TopLevelDockWidget)
|
||||
@ -765,9 +767,9 @@ void CDockAreaWidget::toggleView(bool Open)
|
||||
void CDockAreaWidget::setVisible(bool Visible)
|
||||
{
|
||||
Super::setVisible(Visible);
|
||||
if (d->UpdateCloseButton)
|
||||
if (d->UpdateTitleBarButtons)
|
||||
{
|
||||
d->updateCloseButtonState();
|
||||
d->updateTitleBarButtonStates();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -141,7 +141,7 @@ public:
|
||||
enum DockWidgetFeature
|
||||
{
|
||||
DockWidgetClosable = 0x01,
|
||||
DockWidgetMovable = 0x02,
|
||||
DockWidgetMovable = 0x02,///< this feature is not properly implemented yet and is ignored
|
||||
DockWidgetFloatable = 0x04,
|
||||
AllDockWidgetFeatures = DockWidgetClosable | DockWidgetMovable | DockWidgetFloatable,
|
||||
NoDockWidgetFeatures = 0x00
|
||||
|
@ -327,7 +327,7 @@ void CDockWidgetTab::mouseMoveEvent(QMouseEvent* ev)
|
||||
}
|
||||
|
||||
// Floating is only allowed for widgets that are movable
|
||||
if (d->DockWidget->features().testFlag(CDockWidget::DockWidgetMovable))
|
||||
if (d->DockWidget->features().testFlag(CDockWidget::DockWidgetFloatable))
|
||||
{
|
||||
d->startFloating();
|
||||
}
|
||||
@ -351,9 +351,10 @@ void CDockWidgetTab::contextMenuEvent(QContextMenuEvent* ev)
|
||||
|
||||
d->DragStartMousePosition = ev->pos();
|
||||
QMenu Menu(this);
|
||||
Menu.addAction(tr("Detach"), this, SLOT(onDetachActionTriggered()));
|
||||
auto Action = Menu.addAction(tr("Detach"), this, SLOT(onDetachActionTriggered()));
|
||||
Action->setEnabled(d->DockWidget->features().testFlag(CDockWidget::DockWidgetFloatable));
|
||||
Menu.addSeparator();
|
||||
auto Action = Menu.addAction(tr("Close"), this, SIGNAL(closeRequested()));
|
||||
Action = Menu.addAction(tr("Close"), this, SIGNAL(closeRequested()));
|
||||
Action->setEnabled(isClosable());
|
||||
Menu.addAction(tr("Close Others"), this, SIGNAL(closeOtherTabsRequested()));
|
||||
Menu.exec(mapToGlobal(ev->pos()));
|
||||
@ -468,7 +469,8 @@ void CDockWidgetTab::mouseDoubleClickEvent(QMouseEvent *event)
|
||||
// If this is the last dock area in a dock container it does not make
|
||||
// sense to move it to a new floating widget and leave this one
|
||||
// empty
|
||||
if (!d->DockArea->dockContainer()->isFloating() || d->DockArea->dockWidgetsCount() > 1)
|
||||
if ((!d->DockArea->dockContainer()->isFloating() || d->DockArea->dockWidgetsCount() > 1)
|
||||
&& d->DockWidget->features().testFlag(CDockWidget::DockWidgetFloatable))
|
||||
{
|
||||
d->DragStartMousePosition = event->pos();
|
||||
d->startFloating(DraggingInactive);
|
||||
@ -504,13 +506,15 @@ bool CDockWidgetTab::isClosable() const
|
||||
//===========================================================================
|
||||
void CDockWidgetTab::onDetachActionTriggered()
|
||||
{
|
||||
if (!d->DockWidget->features().testFlag(CDockWidget::DockWidgetFloatable))
|
||||
{
|
||||
return;
|
||||
}
|
||||
d->DragStartMousePosition = mapFromGlobal(QCursor::pos());
|
||||
d->startFloating(DraggingInactive);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
//============================================================================
|
||||
bool CDockWidgetTab::event(QEvent *e)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user