Display syntax error help message as when hovering over incorrect ASM line
MODIFY
src/codeeditor.cpp
src/codeeditor.cpp
#include <QMenu>
#include <QPainter>
#include <QTextBlock>
+#include <QToolTip>
#include <QWheelEvent>
#include <iterator>
@@ -40,6 +41,9 @@ CodeEditor::CodeEditor(QWidget* parent) : QPlainTextEdit(parent) {
// Set syntax highlighter
m_highlighter = new AsmHighlighter(document());
+ // needed for instant tooltip displaying
+ setMouseTracking(true);
+
setWordWrapMode(QTextOption::NoWrap);
}
@@ -86,6 +90,23 @@ bool CodeEditor::eventFilter(QObject* /*observed*/, QEvent* event) {
return false;
}
+bool CodeEditor::event(QEvent* event) {
+ // Override event handler for receiving tool tips
+ if (event->type() == QEvent::ToolTip) {
+ QHelpEvent* helpEvent = static_cast<QHelpEvent*>(event);
+ QTextCursor textAtCursor = cursorForPosition(helpEvent->pos());
+ QString syntaxCheck = m_highlighter->checkSyntax(textAtCursor.block().text().trimmed());
+ if (!syntaxCheck.isEmpty()) {
+ QToolTip::showText(helpEvent->globalPos(), syntaxCheck);
+ } else {
+ QToolTip::hideText();
+ event->ignore();
+ }
+ return true;
+ }
+ return QPlainTextEdit::event(event);
+}
+
void CodeEditor::updateSidebar(const QRect& rect, int dy) {
if (dy) {
m_lineNumberArea->scroll(0, dy);

MODIFY
src/codeeditor.h
src/codeeditor.h
@@ -29,6 +29,7 @@ public:
protected:
void resizeEvent(QResizeEvent* event) override;
+ bool event(QEvent* e) override;
private slots:
void updateSidebarWidth(int newBlockCount);

Display syntax error help message as when hovering over incorrect ASM line