#ifndef QT_CODE_AREA_H #define QT_CODE_AREA_H #include #include #include #include #include "data/location/LocationType.h" #include "qt/utility/QtScrollSpeedChangeListener.h" #include "utility/types.h" class QDragMoveEvent; class QPaintEvent; class QResizeEvent; class QSize; class QtCodeNavigator; class QtHighlighter; class QWidget; class TokenLocation; class TokenLocationFile; class MouseWheelOverScrollbarFilter : public QObject { Q_OBJECT public: MouseWheelOverScrollbarFilter(); protected: bool eventFilter(QObject* obj, QEvent* event); }; class QtCodeArea : public QPlainTextEdit { Q_OBJECT public: class LineNumberArea : public QWidget { public: LineNumberArea(QtCodeArea* codeArea); virtual ~LineNumberArea(); QSize sizeHint() const Q_DECL_OVERRIDE; protected: virtual void paintEvent(QPaintEvent* event) Q_DECL_OVERRIDE; private: QtCodeArea* m_codeArea; }; static void clearAnnotationColors(); QtCodeArea( uint startLineNumber, const std::string& code, std::shared_ptr locationFile, QtCodeNavigator* navigator, QWidget* parent = nullptr ); virtual ~QtCodeArea(); virtual QSize sizeHint() const Q_DECL_OVERRIDE; uint getStartLineNumber() const; uint getEndLineNumber() const; std::shared_ptr getTokenLocationFile() const; void lineNumberAreaPaintEvent(QPaintEvent* event); int lineNumberDigits() const; int lineNumberAreaWidth() const; void updateLineNumberAreaWidthForDigits(int digits); void updateContent(); void setIsActiveFile(bool isActiveFile); uint getLineNumberForLocationId(Id locationId) const; uint getStartLineNumberOfFirstActiveLocationOfTokenId(Id tokenId) const; Id getLocationIdOfFirstActiveLocationOfTokenId(Id tokenId) const; uint getActiveLocationCount() const; QRectF getLineRectForLineNumber(uint lineNumber) const; std::string getCode() const; void hideLineNumbers(); protected: virtual void resizeEvent(QResizeEvent* event) Q_DECL_OVERRIDE; virtual void showEvent(QShowEvent* event) Q_DECL_OVERRIDE; virtual void paintEvent(QPaintEvent* event) Q_DECL_OVERRIDE; virtual void enterEvent(QEvent* event) Q_DECL_OVERRIDE; virtual void leaveEvent(QEvent* event) Q_DECL_OVERRIDE; virtual void mouseReleaseEvent(QMouseEvent* event) Q_DECL_OVERRIDE; virtual void mousePressEvent(QMouseEvent* event) Q_DECL_OVERRIDE; virtual void mouseMoveEvent(QMouseEvent* event) Q_DECL_OVERRIDE; virtual void wheelEvent(QWheelEvent *event) Q_DECL_OVERRIDE; virtual void contextMenuEvent(QContextMenuEvent* event) Q_DECL_OVERRIDE; private slots: void updateLineNumberAreaWidth(int newBlockCount = 0); void updateLineNumberArea(const QRect&, int); void clearSelection(); void setNewTextCursor(const QTextCursor& cursor); void setIDECursorPosition(); private: struct Annotation { int startLine; int endLine; int startCol; int endCol; int start; int end; Id tokenId; Id locationId; LocationType locationType; bool isActive; bool isFocused; QColor oldTextColor; }; struct AnnotationColor { std::string border; std::string fill; std::string text; }; std::vector getInteractiveAnnotationsForPosition(int pos) const; void activateTokenLocations(const std::vector& annotations); void activateLocalSymbols(const std::vector& annotations); void activateErrors(const std::vector& annotations); void createAnnotations(std::shared_ptr locationFile); void annotateText(); void setHoveredAnnotations(const std::vector& annotations); int toTextEditPosition(int lineNumber, int columnNumber) const; std::pair toLineColumn(int textEditPosition) const; int startTextEditPosition() const; int endTextEditPosition() const; std::set getActiveLineNumbers() const; std::vector getCursorRectsForAnnotation(const Annotation& annotation) const; const AnnotationColor& getAnnotationColorForAnnotation(const Annotation& annotation); void setTextColorForAnnotation(Annotation& annotation, QColor color) const; void createActions(); void createLineLengthCache(); static std::vector s_annotationColors; QtCodeNavigator* m_navigator; QWidget* m_lineNumberArea; QtHighlighter* m_highlighter; const uint m_startLineNumber; const std::string m_code; std::shared_ptr m_locationFile; std::vector m_annotations; std::vector m_hoveredAnnotations; // Remove when annotations become unique regarding start and end, and store multiple tokenIds std::vector m_colorChangedAnnotations; int m_digits; bool m_isSelecting; bool m_isPanning; QPoint m_oldMousePosition; int m_panningDistance; QAction* m_setIDECursorPositionAction; QPoint m_eventPosition; // is needed for IDE cursor control via context menu // the position where the context menu is opened needs to be stored] bool m_isActiveFile; bool m_lineNumbersHidden; bool m_wasAnnotated; std::vector m_lineLengths; int m_endTextEditPosition; QtScrollSpeedChangeListener m_scrollSpeedChangeListener; }; #endif // QT_CODE_AREA_H