We need this to catch activation of views and tool views so that we can always tell what view and tool view is active. "Active" doesn't mean focused. It means that it is focused now or was focused before and no other view/tool view wasn't focused after that."*/ implementation is based upon KParts::PartManager::eventFilter
| 317 | after that."*/ |
| 318 | //implementation is based upon KParts::PartManager::eventFilter |
| 319 | bool Controller::eventFilter(QObject *obj, QEvent *ev) |
| 320 | { |
| 321 | Q_D(Controller); |
| 322 | |
| 323 | if (ev->type() != QEvent::MouseButtonPress && |
| 324 | ev->type() != QEvent::MouseButtonDblClick && |
| 325 | ev->type() != QEvent::FocusIn) |
| 326 | return false; |
| 327 | |
| 328 | //not a widget? - return |
| 329 | if (!obj->isWidgetType()) |
| 330 | return false; |
| 331 | |
| 332 | //is dialog or popup? - return |
| 333 | auto *w = static_cast<QWidget*>(obj); |
| 334 | if (((w->windowFlags().testFlag(Qt::Dialog)) && w->isModal()) || |
| 335 | (w->windowFlags().testFlag(Qt::Popup)) || (w->windowFlags().testFlag(Qt::Tool))) |
| 336 | return false; |
| 337 | |
| 338 | //not a mouse button that should activate the widget? - return |
| 339 | if (ev->type() == QEvent::MouseButtonPress || ev->type() == QEvent::MouseButtonDblClick) |
| 340 | { |
| 341 | auto* mev = static_cast<QMouseEvent*>(ev); |
| 342 | int activationButtonMask = Qt::LeftButton | Qt::MiddleButton | Qt::RightButton; |
| 343 | if ((mev->button() & activationButtonMask) == 0) |
| 344 | return false; |
| 345 | } |
| 346 | |
| 347 | while (w) |
| 348 | { |
| 349 | //not inside sublime mainwindow |
| 350 | auto *mw = qobject_cast<Sublime::MainWindow*>(w->topLevelWidget()); |
| 351 | if (!mw || !d->controlledWindows.contains(mw)) |
| 352 | return false; |
| 353 | |
| 354 | Area *area = mw->area(); |
| 355 | |
| 356 | ///@todo adymo: this is extra slow - optimize |
| 357 | //find this widget in views |
| 358 | WidgetFinder widgetFinder(w); |
| 359 | area->walkViews(widgetFinder, area->rootIndex()); |
| 360 | if (widgetFinder.view) { |
| 361 | if (widgetFinder.view != mw->activeView()) { |
| 362 | setActiveView(mw, widgetFinder.view); |
| 363 | } |
| 364 | ///@todo adymo: shall we filter out the event? |
| 365 | return false; |
| 366 | } |
| 367 | |
| 368 | //find this widget in tool views |
| 369 | ToolWidgetFinder toolFinder(w); |
| 370 | area->walkToolViews(toolFinder, Sublime::AllPositions); |
| 371 | if (toolFinder.view) { |
| 372 | setActiveToolView(mw, toolFinder.view); |
| 373 | ///@todo adymo: shall we filter out the event? |
| 374 | return false; |
| 375 | } |
| 376 |
nothing calls this directly
no test coverage detected