Enabled ClickFocus for CDockWidget to support focussing in case the content does not support it

Renamed FocusStyling to FocusHighlighting
This commit is contained in:
Uwe Kindler 2020-06-06 14:59:03 +02:00
parent 2fc8bbe9c9
commit 312a8cf500
9 changed files with 60 additions and 9 deletions

View File

@ -196,6 +196,9 @@ static ads::CDockWidget* createFileSystemTreeDockWidget(QMenu* ViewMenu)
.arg(FileSystemCount++));
DockWidget->setWidget(w);
ViewMenu->addAction(DockWidget->toggleViewAction());
// We disable focus to test focus highlighting if the dock widget content
// does not support focus
w->setFocusPolicy(Qt::NoFocus);
return DockWidget;
}
@ -572,7 +575,7 @@ CMainWindow::CMainWindow(QWidget *parent) :
// CDockManager::setConfigFlag(CDockManager::HideSingleCentralWidgetTitleBar, true);
//CDockManager::setConfigFlag(CDockManager::AlwaysShowTabs, true);
CDockManager::setConfigFlag(CDockManager::FocusStyling, true);
CDockManager::setConfigFlag(CDockManager::FocusHighlighting, true);
// Now create the dock manager and its content
d->DockManager = new CDockManager(this);
@ -659,6 +662,7 @@ void CMainWindow::onViewToggled(bool Open)
//============================================================================
void CMainWindow::onViewVisibilityChanged(bool Visible)
{
Q_UNUSED(Visible);
auto DockWidget = qobject_cast<ads::CDockWidget*>(sender());
if (!DockWidget)
{

View File

@ -10,7 +10,7 @@ int main(int argc, char *argv[])
QApplication a(argc, argv);
QMainWindow w;
ads::CDockManager::setConfigFlag(ads::CDockManager::FocusStyling, true);
ads::CDockManager::setConfigFlag(ads::CDockManager::FocusHighlighting, true);
auto dockManager = new ads::CDockManager(&w);
QAction *action = new QAction("New Delete On Close", &w);

View File

@ -465,6 +465,11 @@ void CDockAreaTitleBar::mousePressEvent(QMouseEvent* ev)
ev->accept();
d->DragStartMousePos = ev->pos();
d->DragState = DraggingMousePressed;
if (CDockManager::configFlags().testFlag(CDockManager::FocusHighlighting))
{
d->TabBar->currentTab()->setFocus(Qt::OtherFocusReason);
}
return;
}
Super::mousePressEvent(ev);
@ -485,6 +490,7 @@ void CDockAreaTitleBar::mouseReleaseEvent(QMouseEvent* ev)
{
d->FloatingWidget->finishDragging();
}
return;
}
Super::mouseReleaseEvent(ev);

View File

@ -202,7 +202,13 @@ void CDockFocusController::onApplicationFocusChanged(QWidget* focusedOld, QWidge
{
DockWidget = DockWidgetTab->dockWidget();
}
else
if (!DockWidget)
{
DockWidget = qobject_cast<CDockWidget*>(focusedNow);
}
if (!DockWidget)
{
DockWidget = internal::findParent<CDockWidget*>(focusedNow);
}
@ -226,6 +232,13 @@ void CDockFocusController::onApplicationFocusChanged(QWidget* focusedOld, QWidge
}
//===========================================================================
void CDockFocusController::setDockWidgetFocused(CDockWidget* focusedNow)
{
d->updateDockWidgetFocus(focusedNow);
}
//===========================================================================
void CDockFocusController::onFocusedDockAreaViewToggled(bool Open)
{

View File

@ -54,7 +54,7 @@ public:
template <class QWidgetPtr>
static void setWidgetFocus(QWidgetPtr widget)
{
if (!CDockManager::configFlags().testFlag(CDockManager::FocusStyling))
if (!CDockManager::configFlags().testFlag(CDockManager::FocusHighlighting))
{
return;
}
@ -75,6 +75,12 @@ public:
* are already inserted into its new position
*/
void notifyFloatingWidgetDrop(CFloatingDockContainer* FloatingWidget);
public slots:
/**
* Request a focus change to the given dock widget
*/
void setDockWidgetFocused(CDockWidget* focusedNow);
}; // class DockFocusController
}
// namespace ads

View File

@ -467,7 +467,7 @@ CDockManager::CDockManager(QWidget *parent) :
d->Containers.append(this);
d->loadStylesheet();
if (CDockManager::configFlags().testFlag(CDockManager::FocusStyling))
if (CDockManager::configFlags().testFlag(CDockManager::FocusHighlighting))
{
d->FocusController = new CDockFocusController(this);
}
@ -926,6 +926,16 @@ void CDockManager::notifyFloatingWidgetDrop(CFloatingDockContainer* FloatingWidg
}
//===========================================================================
void CDockManager::setDockWidgetFocused(CDockWidget* DockWidget)
{
if (d->FocusController)
{
d->FocusController->setDockWidgetFocused(DockWidget);
}
}
} // namespace ads
//---------------------------------------------------------------------------

View File

@ -178,7 +178,7 @@ public:
FloatingContainerHasWidgetIcon = 0x80000, //!< If set, the Floating Widget icon reflects the icon of the current dock widget otherwise it displays application icon
HideSingleCentralWidgetTitleBar = 0x100000, //!< If there is only one single visible dock widget in the main dock container (the dock manager) and if this flag is set, then the titlebar of this dock widget will be hidden
//!< this only makes sense for non draggable and non floatable widgets and enables the creation of some kind of "central" widget
FocusStyling = 0x200000, //!< enables styling of focused dock widget tabs or floating widget titlebar
FocusHighlighting = 0x200000, //!< enables styling of focused dock widget tabs or floating widget titlebar
DefaultDockAreaButtons = DockAreaHasCloseButton
| DockAreaHasUndockButton
@ -434,7 +434,7 @@ public:
template <class QWidgetPtr>
static void setWidgetFocus(QWidgetPtr widget)
{
if (!CDockManager::configFlags().testFlag(CDockManager::FocusStyling))
if (!CDockManager::configFlags().testFlag(CDockManager::FocusHighlighting))
{
return;
}
@ -448,6 +448,13 @@ public slots:
*/
void openPerspective(const QString& PerspectiveName);
/**
* Request a focus change to the given dock widget.
* This function only has an effect, if the flag CDockManager::FocusStyling
* is enabled
*/
void setDockWidgetFocused(CDockWidget* DockWidget);
signals:
/**
* This signal is emitted if the list of perspectives changed

View File

@ -235,6 +235,11 @@ CDockWidget::CDockWidget(const QString &title, QWidget *parent) :
connect(d->ToggleViewAction, SIGNAL(triggered(bool)), this,
SLOT(toggleView(bool)));
setToolbarFloatingStyle(false);
if (CDockManager::configFlags().testFlag(CDockManager::FocusHighlighting))
{
setFocusPolicy(Qt::ClickFocus);
}
}
//============================================================================

View File

@ -285,7 +285,7 @@ CDockWidgetTab::CDockWidgetTab(CDockWidget* DockWidget, QWidget *parent) :
setAttribute(Qt::WA_NoMousePropagation, true);
d->DockWidget = DockWidget;
d->createLayout();
if (CDockManager::configFlags().testFlag(CDockManager::FocusStyling))
if (CDockManager::configFlags().testFlag(CDockManager::FocusHighlighting))
{
setFocusPolicy(Qt::ClickFocus);
}
@ -468,7 +468,7 @@ void CDockWidgetTab::setActiveTab(bool active)
d->CloseButton->setVisible(DockWidgetClosable && TabHasCloseButton);
// Focus related stuff
if (CDockManager::configFlags().testFlag(CDockManager::FocusStyling) && !d->DockWidget->dockManager()->isRestoringState())
if (CDockManager::configFlags().testFlag(CDockManager::FocusHighlighting) && !d->DockWidget->dockManager()->isRestoringState())
{
bool UpdateFocusStyle = false;
if (active && !hasFocus())