mirror of
https://github.com/epasveer/seer.git
synced 2026-08-29 16:40:42 +08:00
Only add syntax highlighying for C/C++ files.
This commit is contained in:
+105
-106
@@ -19,161 +19,161 @@ class SeerEditorWidgetSourceArea : public QPlainTextEdit {
|
||||
public:
|
||||
SeerEditorWidgetSourceArea (QWidget* parent = 0);
|
||||
|
||||
void enableLineNumberArea (bool flag);
|
||||
bool lineNumberAreaEnabled () const;
|
||||
void enableLineNumberArea (bool flag);
|
||||
bool lineNumberAreaEnabled () const;
|
||||
|
||||
void enableBreakPointArea (bool flag);
|
||||
bool breakPointAreaEnabled () const;
|
||||
void enableBreakPointArea (bool flag);
|
||||
bool breakPointAreaEnabled () const;
|
||||
|
||||
void enableMiniMapArea (bool flag);
|
||||
bool miniMapAreaEnabled () const;
|
||||
void enableMiniMapArea (bool flag);
|
||||
bool miniMapAreaEnabled () const;
|
||||
|
||||
void lineNumberAreaPaintEvent (QPaintEvent* event);
|
||||
int lineNumberAreaWidth ();
|
||||
void lineNumberAreaPaintEvent (QPaintEvent* event);
|
||||
int lineNumberAreaWidth ();
|
||||
|
||||
void breakPointAreaPaintEvent (QPaintEvent* event);
|
||||
int breakPointAreaWidth ();
|
||||
void breakPointAreaPaintEvent (QPaintEvent* event);
|
||||
int breakPointAreaWidth ();
|
||||
|
||||
void miniMapAreaPaintEvent (QPaintEvent* event);
|
||||
int miniMapAreaWidth ();
|
||||
void miniMapAreaPaintEvent (QPaintEvent* event);
|
||||
int miniMapAreaWidth ();
|
||||
|
||||
bool isOpen () const;
|
||||
void open (const QString& fullname, const QString& file);
|
||||
const QString& fullname () const;
|
||||
const QString& file () const;
|
||||
void close ();
|
||||
void setCurrentLine (int lineno);
|
||||
void scrollToLine (int lineno);
|
||||
bool isOpen () const;
|
||||
void open (const QString& fullname, const QString& file);
|
||||
const QString& fullname () const;
|
||||
const QString& file () const;
|
||||
void close ();
|
||||
void setCurrentLine (int lineno);
|
||||
void scrollToLine (int lineno);
|
||||
|
||||
void clearCurrentLines ();
|
||||
void addCurrentLine (int lineno);
|
||||
void clearCurrentLines ();
|
||||
void addCurrentLine (int lineno);
|
||||
|
||||
void clearBreakpoints ();
|
||||
void addBreakpoint (int number, int lineno, bool enabled);
|
||||
bool hasBreakpointNumber (int number) const;
|
||||
bool hasBreakpointLine (int lineno) const;
|
||||
const QVector<int>& breakpointNumbers () const;
|
||||
const QVector<int>& breakpointLines () const;
|
||||
const QVector<bool>& breakpointEnableds () const;
|
||||
int breakpointLineToNumber (int lineno) const;
|
||||
bool breakpointLineEnabled (int lineno) const;
|
||||
void clearBreakpoints ();
|
||||
void addBreakpoint (int number, int lineno, bool enabled);
|
||||
bool hasBreakpointNumber (int number) const;
|
||||
bool hasBreakpointLine (int lineno) const;
|
||||
const QVector<int>& breakpointNumbers () const;
|
||||
const QVector<int>& breakpointLines () const;
|
||||
const QVector<bool>& breakpointEnableds () const;
|
||||
int breakpointLineToNumber (int lineno) const;
|
||||
bool breakpointLineEnabled (int lineno) const;
|
||||
|
||||
void showContextMenu (QMouseEvent* event);
|
||||
void showContextMenu (QContextMenuEvent* event);
|
||||
void showContextMenu (const QPoint& pos, const QPoint& globalPos);
|
||||
void setQuickBreakpoint (QMouseEvent* event);
|
||||
void showContextMenu (QMouseEvent* event);
|
||||
void showContextMenu (QContextMenuEvent* event);
|
||||
void showContextMenu (const QPoint& pos, const QPoint& globalPos);
|
||||
void setQuickBreakpoint (QMouseEvent* event);
|
||||
|
||||
void clearExpression ();
|
||||
void clearExpression ();
|
||||
|
||||
signals:
|
||||
void insertBreakpoint (QString breakpoint);
|
||||
void deleteBreakpoints (QString breakpoints);
|
||||
void enableBreakpoints (QString breakpoints);
|
||||
void disableBreakpoints (QString breakpoints);
|
||||
void runToLine (QString fullname, int lineno);
|
||||
void addVariableExpression (QString expression);
|
||||
void refreshVariableValues ();
|
||||
void evaluateVariableExpression (int expressionid, QString expression);
|
||||
void addMemoryVisualize (QString expression);
|
||||
void showSearchBar (bool flag);
|
||||
void insertBreakpoint (QString breakpoint);
|
||||
void deleteBreakpoints (QString breakpoints);
|
||||
void enableBreakpoints (QString breakpoints);
|
||||
void disableBreakpoints (QString breakpoints);
|
||||
void runToLine (QString fullname, int lineno);
|
||||
void addVariableExpression (QString expression);
|
||||
void refreshVariableValues ();
|
||||
void evaluateVariableExpression (int expressionid, QString expression);
|
||||
void addMemoryVisualize (QString expression);
|
||||
void showSearchBar (bool flag);
|
||||
|
||||
public slots:
|
||||
void handleText (const QString& text);
|
||||
void handleText (const QString& text);
|
||||
|
||||
protected:
|
||||
void resizeEvent (QResizeEvent* event);
|
||||
void contextMenuEvent (QContextMenuEvent* event);
|
||||
void keyPressEvent (QKeyEvent* event);
|
||||
void mouseReleaseEvent (QMouseEvent* event);
|
||||
bool event (QEvent* event);
|
||||
void resizeEvent (QResizeEvent* event);
|
||||
void contextMenuEvent (QContextMenuEvent* event);
|
||||
void keyPressEvent (QKeyEvent* event);
|
||||
void mouseReleaseEvent (QMouseEvent* event);
|
||||
bool event (QEvent* event);
|
||||
|
||||
private slots:
|
||||
void highlightCurrentLines ();
|
||||
void highlightCurrentLine ();
|
||||
void unhighlightCurrentLine ();
|
||||
void highlightCurrentLines ();
|
||||
void highlightCurrentLine ();
|
||||
void unhighlightCurrentLine ();
|
||||
|
||||
void updateMarginAreasWidth (int newBlockCount);
|
||||
void updateLineNumberArea (const QRect& rect, int dy);
|
||||
void updateBreakPointArea (const QRect& rect, int dy);
|
||||
void updateMiniMapArea (const QRect& rect, int dy);
|
||||
void updateMarginAreasWidth (int newBlockCount);
|
||||
void updateLineNumberArea (const QRect& rect, int dy);
|
||||
void updateBreakPointArea (const QRect& rect, int dy);
|
||||
void updateMiniMapArea (const QRect& rect, int dy);
|
||||
|
||||
private:
|
||||
QString _fullname;
|
||||
QString _file;
|
||||
bool _enableLineNumberArea;
|
||||
bool _enableBreakPointArea;
|
||||
bool _enableMiniMapArea;
|
||||
QVector<int> _breakpointsNumbers;
|
||||
QVector<int> _breakpointsLineNumbers;
|
||||
QVector<bool> _breakpointsEnableds;
|
||||
QVector<QTextCursor> _currentLineCursors;
|
||||
QString _fullname;
|
||||
QString _file;
|
||||
bool _enableLineNumberArea;
|
||||
bool _enableBreakPointArea;
|
||||
bool _enableMiniMapArea;
|
||||
QVector<int> _breakpointsNumbers;
|
||||
QVector<int> _breakpointsLineNumbers;
|
||||
QVector<bool> _breakpointsEnableds;
|
||||
QVector<QTextCursor> _currentLineCursors;
|
||||
|
||||
QTextCursor _selectedExpressionCursor;
|
||||
int _selectedExpressionId;
|
||||
QString _selectedExpressionName;
|
||||
QString _selectedExpressionValue;
|
||||
bool _ctrlKeyPressed;
|
||||
QTextCursor _selectedExpressionCursor;
|
||||
int _selectedExpressionId;
|
||||
QString _selectedExpressionName;
|
||||
QString _selectedExpressionValue;
|
||||
bool _ctrlKeyPressed;
|
||||
|
||||
QWidget* _lineNumberArea;
|
||||
QWidget* _breakPointArea;
|
||||
QWidget* _miniMapArea;
|
||||
QWidget* _lineNumberArea;
|
||||
QWidget* _breakPointArea;
|
||||
QWidget* _miniMapArea;
|
||||
|
||||
QPixmap* _miniMapPixmap;
|
||||
SeerCppSourceHighlighter* _sourceHighlighter;
|
||||
QPixmap* _miniMapPixmap;
|
||||
SeerCppSourceHighlighter* _sourceHighlighter;
|
||||
};
|
||||
|
||||
class SeerEditorWidgetLineNumberArea : public QWidget {
|
||||
public:
|
||||
SeerEditorWidgetLineNumberArea (SeerEditorWidgetSourceArea* editorWidget);
|
||||
|
||||
QSize sizeHint () const override;
|
||||
QSize sizeHint () const override;
|
||||
|
||||
protected:
|
||||
void paintEvent (QPaintEvent* event) override;
|
||||
void mouseDoubleClickEvent (QMouseEvent* event) override;
|
||||
void mouseMoveEvent (QMouseEvent* event) override;
|
||||
void mousePressEvent (QMouseEvent* event) override;
|
||||
void mouseReleaseEvent (QMouseEvent* event) override;
|
||||
void paintEvent (QPaintEvent* event) override;
|
||||
void mouseDoubleClickEvent (QMouseEvent* event) override;
|
||||
void mouseMoveEvent (QMouseEvent* event) override;
|
||||
void mousePressEvent (QMouseEvent* event) override;
|
||||
void mouseReleaseEvent (QMouseEvent* event) override;
|
||||
|
||||
|
||||
private:
|
||||
SeerEditorWidgetSourceArea* _editorWidget;
|
||||
SeerEditorWidgetSourceArea* _editorWidget;
|
||||
};
|
||||
|
||||
class SeerEditorWidgetBreakPointArea : public QWidget {
|
||||
public:
|
||||
SeerEditorWidgetBreakPointArea (SeerEditorWidgetSourceArea* editorWidget);
|
||||
|
||||
QSize sizeHint () const override;
|
||||
QSize sizeHint () const override;
|
||||
|
||||
protected:
|
||||
void paintEvent (QPaintEvent* event) override;
|
||||
void mouseDoubleClickEvent (QMouseEvent* event) override;
|
||||
void mouseMoveEvent (QMouseEvent* event) override;
|
||||
void mousePressEvent (QMouseEvent* event) override;
|
||||
void mouseReleaseEvent (QMouseEvent* event) override;
|
||||
void paintEvent (QPaintEvent* event) override;
|
||||
void mouseDoubleClickEvent (QMouseEvent* event) override;
|
||||
void mouseMoveEvent (QMouseEvent* event) override;
|
||||
void mousePressEvent (QMouseEvent* event) override;
|
||||
void mouseReleaseEvent (QMouseEvent* event) override;
|
||||
|
||||
|
||||
private:
|
||||
SeerEditorWidgetSourceArea* _editorWidget;
|
||||
SeerEditorWidgetSourceArea* _editorWidget;
|
||||
};
|
||||
|
||||
class SeerEditorWidgetMiniMapArea : public QWidget {
|
||||
public:
|
||||
SeerEditorWidgetMiniMapArea (SeerEditorWidgetSourceArea* editorWidget);
|
||||
|
||||
QSize sizeHint () const override;
|
||||
QSize sizeHint () const override;
|
||||
|
||||
protected:
|
||||
void paintEvent (QPaintEvent* event) override;
|
||||
void mouseDoubleClickEvent (QMouseEvent* event) override;
|
||||
void mouseMoveEvent (QMouseEvent* event) override;
|
||||
void mousePressEvent (QMouseEvent* event) override;
|
||||
void mouseReleaseEvent (QMouseEvent* event) override;
|
||||
void paintEvent (QPaintEvent* event) override;
|
||||
void mouseDoubleClickEvent (QMouseEvent* event) override;
|
||||
void mouseMoveEvent (QMouseEvent* event) override;
|
||||
void mousePressEvent (QMouseEvent* event) override;
|
||||
void mouseReleaseEvent (QMouseEvent* event) override;
|
||||
|
||||
|
||||
private:
|
||||
SeerEditorWidgetSourceArea* _editorWidget;
|
||||
SeerEditorWidgetSourceArea* _editorWidget;
|
||||
};
|
||||
|
||||
#include "ui_SeerEditorWidget.h"
|
||||
@@ -186,16 +186,15 @@ class SeerEditorWidget : public QWidget, protected Ui::SeerEditorWidgetForm {
|
||||
explicit SeerEditorWidget (QWidget* parent = 0);
|
||||
~SeerEditorWidget ();
|
||||
|
||||
SeerEditorWidgetSourceArea* sourceArea ();
|
||||
SeerEditorWidgetSourceArea* sourceArea ();
|
||||
|
||||
void handleLineNumberLineEdit ();
|
||||
void handleSearchTextLineEdit ();
|
||||
void handleSearchDownToolButton ();
|
||||
void handleSearchUpToolButton ();
|
||||
void handleCloseToolButton ();
|
||||
void handleLineNumberLineEdit ();
|
||||
void handleSearchTextLineEdit ();
|
||||
void handleSearchDownToolButton ();
|
||||
void handleSearchUpToolButton ();
|
||||
void handleCloseToolButton ();
|
||||
|
||||
public slots:
|
||||
void showSearchBar (bool flag);
|
||||
void showSearchBar (bool flag);
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
#include <QtCore/QString>
|
||||
#include <QtCore/QTextStream>
|
||||
#include <QtCore/QFile>
|
||||
#include <QtCore/QRegExp>
|
||||
#include <QtCore/QDebug>
|
||||
|
||||
SeerEditorWidgetSourceArea::SeerEditorWidgetSourceArea(QWidget *parent) : QPlainTextEdit(parent) {
|
||||
@@ -27,6 +28,7 @@ SeerEditorWidgetSourceArea::SeerEditorWidgetSourceArea(QWidget *parent) : QPlain
|
||||
_enableBreakPointArea = false;
|
||||
_enableMiniMapArea = false;
|
||||
_ctrlKeyPressed = false;
|
||||
_sourceHighlighter = 0;
|
||||
|
||||
//QFont font("Monospace");
|
||||
//font.setStyleHint(QFont::TypeWriter);
|
||||
@@ -34,7 +36,6 @@ SeerEditorWidgetSourceArea::SeerEditorWidgetSourceArea(QWidget *parent) : QPlain
|
||||
font.setStyleHint(QFont::Monospace);
|
||||
setFont(font);
|
||||
|
||||
_sourceHighlighter = new SeerCppSourceHighlighter(document());
|
||||
|
||||
setReadOnly(true);
|
||||
setTextInteractionFlags(textInteractionFlags() | Qt::TextSelectableByKeyboard);
|
||||
@@ -586,26 +587,36 @@ void SeerEditorWidgetSourceArea::open (const QString& fullname, const QString& f
|
||||
QTextStream stream(&inputFile);
|
||||
|
||||
QString line = stream.readLine();
|
||||
QString document;
|
||||
QString text;
|
||||
|
||||
while (!line.isNull()) {
|
||||
|
||||
if (document != "") {
|
||||
document += "\n";
|
||||
if (text != "") {
|
||||
text += "\n";
|
||||
}
|
||||
|
||||
document += line;
|
||||
text += line;
|
||||
|
||||
line = stream.readLine();
|
||||
};
|
||||
|
||||
// Put the contents in the editor.
|
||||
setPlainText(document);
|
||||
setPlainText(text);
|
||||
|
||||
// Set the text cursor to the first line.
|
||||
QTextCursor cursor = textCursor();
|
||||
cursor.movePosition(QTextCursor::Start, QTextCursor::MoveAnchor, 1);
|
||||
setTextCursor(cursor);
|
||||
|
||||
// Add a syntax highlighter for C++ files.
|
||||
if (_sourceHighlighter) {
|
||||
delete _sourceHighlighter;
|
||||
}
|
||||
|
||||
QRegExp cpp_re("(?:.c|.cpp|.CPP|.cxx|.CXX|.h|.H|.hpp|.hxx|.Hxx|.HXX)$");
|
||||
if (_fullname.contains(cpp_re)) {
|
||||
_sourceHighlighter = new SeerCppSourceHighlighter(document());
|
||||
}
|
||||
}
|
||||
|
||||
const QString& SeerEditorWidgetSourceArea::fullname () const {
|
||||
|
||||
Reference in New Issue
Block a user