From f5b4668fa5e990cef310d3b3034f916d57722081 Mon Sep 17 00:00:00 2001 From: Thomas Hartmann Date: Wed, 29 Sep 2010 16:58:30 +0200 Subject: [PATCH] QmlJsEditor: combine the Quick ToolBar with the toolTip 1000ms after a tooltip is shown we now also show the quick toolbar Reviewed-by: Erik Verbruggen --- src/plugins/qmljseditor/qmljseditor.cpp | 37 +++++++++++++++++++++++-- src/plugins/qmljseditor/qmljseditor.h | 4 +++ 2 files changed, 39 insertions(+), 2 deletions(-) diff --git a/src/plugins/qmljseditor/qmljseditor.cpp b/src/plugins/qmljseditor/qmljseditor.cpp index c983f50ec8d..8c4a1b08968 100644 --- a/src/plugins/qmljseditor/qmljseditor.cpp +++ b/src/plugins/qmljseditor/qmljseditor.cpp @@ -63,6 +63,7 @@ #include #include #include +#include #include #include #include @@ -82,7 +83,8 @@ enum { UPDATE_DOCUMENT_DEFAULT_INTERVAL = 100, UPDATE_USES_DEFAULT_INTERVAL = 150, - UPDATE_OUTLINE_INTERVAL = 500 // msecs after new semantic info has been arrived / cursor has moved + UPDATE_OUTLINE_INTERVAL = 500, // msecs after new semantic info has been arrived / cursor has moved + TOOLTIP_TIMER_INTERVAL = 1000 // delay after we show the Quick ToolBar after a tooltip }; using namespace QmlJS; @@ -678,7 +680,8 @@ QmlJSTextEditor::QmlJSTextEditor(QWidget *parent) : m_modelManager(0), m_contextPane(0), m_updateSelectedElements(false), - m_findReferences(new FindReferences(this)) + m_findReferences(new FindReferences(this)), + m_toolTipPosition(0) { qRegisterMetaType("QmlJSEditor::Internal::SemanticInfo"); @@ -725,6 +728,11 @@ QmlJSTextEditor::QmlJSTextEditor(QWidget *parent) : m_cursorPositionTimer->setSingleShot(true); connect(m_cursorPositionTimer, SIGNAL(timeout()), this, SLOT(updateCursorPositionNow())); + m_ToolTipTimer = new QTimer(this); + m_ToolTipTimer->setInterval(TOOLTIP_TIMER_INTERVAL); + m_ToolTipTimer->setSingleShot(true); + connect(m_ToolTipTimer, SIGNAL(timeout()), this, SLOT(updateToolTipNow())); + baseTextDocument()->setSyntaxHighlighter(new Highlighter(document())); m_modelManager = ExtensionSystem::PluginManager::instance()->getObject(); @@ -750,6 +758,9 @@ QmlJSTextEditor::QmlJSTextEditor(QWidget *parent) : connect(this, SIGNAL(refactorMarkerClicked(TextEditor::Internal::RefactorMarker)), SLOT(onRefactorMarkerClicked(TextEditor::Internal::RefactorMarker))); + connect(editableInterface(), SIGNAL(tooltipRequested(TextEditor::ITextEditor*, QPoint, int)), + SLOT(onTooltipRequested(TextEditor::ITextEditor*, QPoint, int))); + setRequestMarkEnabled(true); } @@ -1458,6 +1469,28 @@ void QmlJSTextEditor::performQuickFix(int index) op->perform(); } +void QmlJSTextEditor::onTooltipRequested(TextEditor::ITextEditor* /* editor */, QPoint /* point */, int position) +{ + m_toolTipPosition = position; + if (m_contextPane) { + m_ToolTipTimer->start(); + } +} + +void QmlJSTextEditor::updateToolTipNow() +{ + if (!TextEditor::ToolTip::instance()->isVisible()) + return; + + if (m_contextPane) { + Node *newNode = m_semanticInfo.declaringMemberNoProperties(m_toolTipPosition); + m_contextPane->apply(editableInterface(), m_semanticInfo.lookupContext(), newNode, false, true); + m_oldCursorPosition = m_toolTipPosition; + QList markers; + setRefactorMarkers(markers); + } +} + void QmlJSTextEditor::contextMenuEvent(QContextMenuEvent *e) { QMenu *menu = new QMenu(); diff --git a/src/plugins/qmljseditor/qmljseditor.h b/src/plugins/qmljseditor/qmljseditor.h index 8071dd03d80..83072329438 100644 --- a/src/plugins/qmljseditor/qmljseditor.h +++ b/src/plugins/qmljseditor/qmljseditor.h @@ -279,6 +279,8 @@ private slots: void onRefactorMarkerClicked(const TextEditor::Internal::RefactorMarker &marker); void performQuickFix(int index); + void onTooltipRequested(TextEditor::ITextEditor* editor, QPoint point, int position); + void updateToolTipNow(); protected: void contextMenuEvent(QContextMenuEvent *e); @@ -317,6 +319,7 @@ private: QTimer *m_updateOutlineTimer; QTimer *m_updateOutlineIndexTimer; QTimer *m_cursorPositionTimer; + QTimer *m_toolTipTimer; QComboBox *m_outlineCombo; QmlOutlineModel *m_outlineModel; QModelIndex m_outlineModelIndex; @@ -333,6 +336,7 @@ private: QmlJS::IContextPane *m_contextPane; int m_oldCursorPosition; bool m_updateSelectedElements; + int m_toolTipPosition; FindReferences *m_findReferences; };