| 693 | } |
| 694 | |
| 695 | bool CodeEditor::eventFilter(QObject *, QEvent *ev) |
| 696 | { |
| 697 | if (ev->type() == QEvent::KeyPress) { |
| 698 | QKeyEvent *keyEvent = static_cast<QKeyEvent*>(ev); |
| 699 | if (keyEvent == QKeySequence::Copy) { |
| 700 | copy(); |
| 701 | return true; |
| 702 | } else if (keyEvent == QKeySequence::Cut) { |
| 703 | cut(); |
| 704 | return true; |
| 705 | } |
| 706 | } else if (ev->type() == QEvent::ToolTip) { |
| 707 | QHelpEvent* helpEvent = static_cast<QHelpEvent*>(ev); |
| 708 | QPoint evPos = helpEvent->pos(); |
| 709 | evPos = QPoint(evPos.x()-lineNumbersWidth(),evPos.y()); |
| 710 | if (evPos.x() >= 0) { |
| 711 | QTextCursor cursor = cursorForPosition(evPos); |
| 712 | bool foundError = false; |
| 713 | foreach (CodeEditorError cee, errors) { |
| 714 | if (cursor.position() >= cee.startPos && cursor.position() <= cee.endPos) { |
| 715 | QToolTip::showText(helpEvent->globalPos(), cee.msg); |
| 716 | foundError = true; |
| 717 | break; |
| 718 | } |
| 719 | } |
| 720 | if (!foundError) { |
| 721 | cursor.select(QTextCursor::WordUnderCursor); |
| 722 | QString loc(filename+":"); |
| 723 | loc += QString().number(cursor.block().blockNumber()+1); |
| 724 | loc += "."; |
| 725 | loc += QString().number(cursor.selectionStart()-cursor.block().position()+1); |
| 726 | QHash<QString,QString>::iterator idMapIt = idMap.find(loc); |
| 727 | if (idMapIt != idMap.end()) { |
| 728 | QToolTip::showText(helpEvent->globalPos(), idMapIt.value()); |
| 729 | } else { |
| 730 | QToolTip::hideText(); |
| 731 | } |
| 732 | } |
| 733 | } else { |
| 734 | QToolTip::hideText(); |
| 735 | } |
| 736 | return true; |
| 737 | } |
| 738 | return false; |
| 739 | } |
| 740 | |
| 741 | void CodeEditor::copy() |
| 742 | { |