| 653 | } |
| 654 | |
| 655 | void ContextBrowserPlugin::showToolTip(KTextEditor::View* view, KTextEditor::Cursor position) |
| 656 | { |
| 657 | ContextBrowserView* contextView = browserViewForWidget(view); |
| 658 | if (contextView && contextView->isVisible() && !contextView->isLocked()) |
| 659 | return; // If the context-browser view is visible, it will care about updating by itself |
| 660 | |
| 661 | KTextEditor::Range itemRange = KTextEditor::Range::invalid(); |
| 662 | auto navigationWidget = navigationWidgetForPosition(view, position, itemRange); |
| 663 | if (navigationWidget) { |
| 664 | // If we have an invisible context-view, assign the tooltip navigation-widget to it. |
| 665 | // If the user makes the context-view visible, it will instantly contain the correct widget. |
| 666 | if (contextView && !contextView->isLocked()) |
| 667 | contextView->setNavigationWidget(navigationWidget); |
| 668 | |
| 669 | if (m_currentToolTip) { |
| 670 | m_currentToolTip->deleteLater(); |
| 671 | m_currentToolTip = nullptr; |
| 672 | m_currentNavigationWidget = nullptr; |
| 673 | } |
| 674 | |
| 675 | auto* tooltip = |
| 676 | new KDevelop::NavigationToolTip(view, view->mapToGlobal(view->cursorToCoordinate(position)) + QPoint(20, |
| 677 | 40), |
| 678 | navigationWidget); |
| 679 | if (!itemRange.isValid()) { |
| 680 | qCWarning(PLUGIN_CONTEXTBROWSER) << "Got navigationwidget with invalid itemrange"; |
| 681 | itemRange = KTextEditor::Range(position, 0); |
| 682 | } |
| 683 | |
| 684 | tooltip->setHandleRect(KTextEditorHelpers::itemBoundingRect(view, itemRange)); |
| 685 | tooltip->resize(navigationWidget->sizeHint() + QSize(10, 10)); |
| 686 | QObject::connect(view, &KTextEditor::View::verticalScrollPositionChanged, |
| 687 | this, &ContextBrowserPlugin::hideToolTip); |
| 688 | QObject::connect(view, &KTextEditor::View::horizontalScrollPositionChanged, |
| 689 | this, &ContextBrowserPlugin::hideToolTip); |
| 690 | qCDebug(PLUGIN_CONTEXTBROWSER) << "tooltip size" << tooltip->size(); |
| 691 | m_currentToolTip = tooltip; |
| 692 | m_currentNavigationWidget = navigationWidget; |
| 693 | ActiveToolTip::showToolTip(tooltip); |
| 694 | |
| 695 | if (!navigationWidget->property("DoNotCloseOnCursorMove").toBool()) { |
| 696 | connect(view, &View::cursorPositionChanged, |
| 697 | this, &ContextBrowserPlugin::hideToolTip, Qt::UniqueConnection); |
| 698 | } else { |
| 699 | disconnect(view, &View::cursorPositionChanged, |
| 700 | this, &ContextBrowserPlugin::hideToolTip); |
| 701 | } |
| 702 | } else { |
| 703 | qCDebug(PLUGIN_CONTEXTBROWSER) << "not showing tooltip, no navigation-widget"; |
| 704 | } |
| 705 | } |
| 706 | |
| 707 | void ContextBrowserPlugin::clearMouseHover() |
| 708 | { |