16
16
#include < QPointer>
17
17
#include < QApplication>
18
18
#include < QAbstractButton>
19
+ #include < QWindow>
19
20
20
21
#include " DockWidget.h"
21
22
#include " DockAreaWidget.h"
@@ -115,6 +116,11 @@ void DockFocusControllerPrivate::updateDockWidgetFocus(CDockWidget* DockWidget)
115
116
return ;
116
117
}
117
118
119
+ auto Window = DockWidget->dockContainer ()->window ()->windowHandle ();
120
+ if (Window)
121
+ {
122
+ Window->setProperty (" FocusedDockWidget" , QVariant::fromValue<CDockWidget*>(DockWidget));
123
+ }
118
124
CDockAreaWidget* NewFocusedDockArea = nullptr ;
119
125
if (FocusedDockWidget)
120
126
{
@@ -206,6 +212,8 @@ CDockFocusController::CDockFocusController(CDockManager* DockManager) :
206
212
d->DockManager = DockManager;
207
213
connect (QApplication::instance (), SIGNAL (focusChanged (QWidget*, QWidget*)),
208
214
this , SLOT (onApplicationFocusChanged (QWidget*, QWidget*)));
215
+ connect (QApplication::instance (), SIGNAL (focusWindowChanged (QWindow*)),
216
+ this , SLOT (onFocusWindowChanged (QWindow*)));
209
217
connect (d->DockManager , SIGNAL (stateRestored ()), SLOT (onStateRestored ()));
210
218
}
211
219
@@ -216,64 +224,46 @@ CDockFocusController::~CDockFocusController()
216
224
}
217
225
218
226
219
- // ===========================================================================
220
- void CDockFocusController::onApplicationFocusChanged (QWidget* focusedOld, QWidget* focusedNow )
227
+ // ============================================================================
228
+ void CDockFocusController::onFocusWindowChanged (QWindow *focusWindow )
221
229
{
222
- if (d-> DockManager -> isRestoringState () )
230
+ if (!focusWindow )
223
231
{
224
232
return ;
225
233
}
226
234
227
- ADS_PRINT (" CDockFocusController::onApplicationFocusChanged "
228
- << " old: " << focusedOld << " new: " << focusedNow);
229
- if (!focusedNow)
235
+ auto vDockWidget = focusWindow->property (" FocusedDockWidget" );
236
+ if (!vDockWidget.isValid ())
230
237
{
231
238
return ;
232
239
}
233
240
234
- /*
235
- // If the close button in another tab steals the focus from the current
236
- // active dock widget content, i.e. if the user clicks its close button,
237
- // then we immediately give the focus back to the previous focused widget
238
- // focusedOld
239
- if (CDockManager::testConfigFlag(CDockManager::AllTabsHaveCloseButton))
241
+ auto DockWidget = vDockWidget.value <CDockWidget*>();
242
+ if (!DockWidget)
240
243
{
241
- auto OtherDockWidgetTab = internal::findParent<CDockWidgetTab*>(focusedNow);
242
- if (OtherDockWidgetTab && focusedOld)
243
- {
244
- auto OldFocusedDockWidget = internal::findParent<CDockWidget*>(focusedOld);
245
- if (OldFocusedDockWidget)
246
- {
247
- //focusedOld->setFocus();
248
- }
249
- return;
250
- }
251
- }*/
244
+ return ;
245
+ }
252
246
253
- CDockWidget* DockWidget = nullptr ;
254
- /* auto DockWidgetTab = qobject_cast<CDockWidgetTab*>(focusedNow);
255
- if (DockWidgetTab)
256
- {
257
- DockWidget = DockWidgetTab->dockWidget();
247
+ d->updateDockWidgetFocus (DockWidget);
248
+ }
258
249
259
- // If the DockWidgetTab "steals" the focus from a widget in the same
260
- // DockWidget, then we immediately give the focus back to the previous
261
- // focused widget focusedOld
262
- if (focusedOld)
263
- {
264
- auto OldFocusedDockWidget = internal::findParent<CDockWidget*>(focusedOld);
265
- if (OldFocusedDockWidget && OldFocusedDockWidget == DockWidget)
266
- {
267
- //focusedOld->setFocus();
268
- }
269
- }
270
- }*/
271
250
272
- if (!DockWidget)
251
+ // ===========================================================================
252
+ void CDockFocusController::onApplicationFocusChanged (QWidget* focusedOld, QWidget* focusedNow)
253
+ {
254
+ if (d->DockManager ->isRestoringState ())
273
255
{
274
- DockWidget = qobject_cast<CDockWidget*>(focusedNow) ;
256
+ return ;
275
257
}
276
258
259
+ ADS_PRINT (" CDockFocusController::onApplicationFocusChanged "
260
+ << " old: " << focusedOld << " new: " << focusedNow);
261
+ if (!focusedNow)
262
+ {
263
+ return ;
264
+ }
265
+
266
+ CDockWidget* DockWidget = qobject_cast<CDockWidget*>(focusedNow);
277
267
if (!DockWidget)
278
268
{
279
269
DockWidget = internal::findParent<CDockWidget*>(focusedNow);
@@ -298,7 +288,6 @@ void CDockFocusController::onApplicationFocusChanged(QWidget* focusedOld, QWidge
298
288
// ===========================================================================
299
289
void CDockFocusController::setDockWidgetTabFocused (CDockWidgetTab* Tab)
300
290
{
301
- std::cout << " setDockWidgetTabFocused " << Tab->text ().toStdString () << std::endl;
302
291
auto DockWidget = Tab->dockWidget ();
303
292
if (DockWidget)
304
293
{
@@ -334,7 +323,7 @@ void CDockFocusController::onFocusedDockAreaViewToggled(bool Open)
334
323
return ;
335
324
}
336
325
337
- CDockManager::setWidgetFocus (OpenedDockAreas[0 ]->currentDockWidget ()-> tabWidget ());
326
+ d-> updateDockWidgetFocus (OpenedDockAreas[0 ]->currentDockWidget ());
338
327
}
339
328
340
329
@@ -362,7 +351,7 @@ void CDockFocusController::notifyWidgetOrAreaRelocation(QWidget* DroppedWidget)
362
351
}
363
352
364
353
d->ForceFocusChangedSignal = true ;
365
- CDockManager::setWidgetFocus (DockWidget-> tabWidget () );
354
+ CDockManager::setWidgetFocus (DockWidget);
366
355
}
367
356
368
357
@@ -383,9 +372,15 @@ void CDockFocusController::notifyFloatingWidgetDrop(CFloatingDockContainer* Floa
383
372
auto DockWidget = vDockWidget.value <CDockWidget*>();
384
373
if (DockWidget)
385
374
{
375
+ /* auto Window = DockWidget->dockContainer()->window()->windowHandle();
376
+ DockWidget->dockContainer()->window()->clearFocus();
377
+ if (Window)
378
+ {
379
+ Window->setProperty("FocusedDockWidget", QVariant::fromValue<CDockWidget*>(DockWidget));
380
+ }*/
386
381
d->FocusedDockWidget = nullptr ;
387
382
DockWidget->dockAreaWidget ()->setCurrentDockWidget (DockWidget);
388
- CDockManager::setWidgetFocus (DockWidget-> tabWidget () );
383
+ CDockManager::setWidgetFocus (DockWidget);
389
384
}
390
385
}
391
386
0 commit comments