
- Added ProjectManager class to handle project operations including opening, closing, building, and running projects. - Introduced SyntaxHighlighter class for syntax highlighting in C and C++ files. - Developed TerminalWidget for command execution and output display. - Created TextEditor with line numbering and auto-indentation features. - Established main application entry point in main.cpp. - Designed UI layout for MainWindow using Qt Designer.
78 lines
1.7 KiB
C++
78 lines
1.7 KiB
C++
#pragma once
|
|
|
|
#include <QtWidgets/QPlainTextEdit>
|
|
#include <QtCore/QTextStream>
|
|
#include <QtGui/QTextDocument>
|
|
#include <QtGui/QTextCursor>
|
|
#include <QtGui/QKeyEvent>
|
|
#include <QtCore/QTimer>
|
|
|
|
class SyntaxHighlighter;
|
|
|
|
class TextEditor : public QPlainTextEdit
|
|
{
|
|
Q_OBJECT
|
|
friend class LineNumberArea;
|
|
|
|
public:
|
|
explicit TextEditor(QWidget *parent = nullptr);
|
|
~TextEditor();
|
|
|
|
void setFilePath(const QString &filePath);
|
|
QString filePath() const;
|
|
|
|
bool isModified() const;
|
|
void setModified(bool modified);
|
|
|
|
bool loadFile(const QString &filePath);
|
|
bool saveFile();
|
|
bool saveAsFile(const QString &filePath);
|
|
|
|
void setLineNumberAreaWidth(int width);
|
|
void updateLineNumberArea(const QRect &rect, int dy);
|
|
|
|
signals:
|
|
void fileModified(bool modified);
|
|
void cursorPositionChanged(int line, int column);
|
|
|
|
protected:
|
|
void keyPressEvent(QKeyEvent *event) override;
|
|
void paintEvent(QPaintEvent *event) override;
|
|
void resizeEvent(QResizeEvent *event) override;
|
|
|
|
private slots:
|
|
void highlightCurrentLine();
|
|
void updateCursorPosition();
|
|
void autoIndent();
|
|
|
|
private:
|
|
void setupEditor();
|
|
void updateLineNumberAreaWidth(int newBlockCount);
|
|
|
|
public:
|
|
int lineNumberAreaWidth();
|
|
|
|
QString m_filePath;
|
|
bool m_isModified;
|
|
SyntaxHighlighter *m_syntaxHighlighter;
|
|
QWidget *m_lineNumberArea;
|
|
QTimer *m_autoSaveTimer;
|
|
};
|
|
|
|
// Line number area widget
|
|
class LineNumberArea : public QWidget
|
|
{
|
|
public:
|
|
LineNumberArea(TextEditor *editor) : QWidget(editor), m_textEditor(editor) {}
|
|
|
|
QSize sizeHint() const override {
|
|
return QSize(m_textEditor->lineNumberAreaWidth(), 0);
|
|
}
|
|
|
|
protected:
|
|
void paintEvent(QPaintEvent *event) override;
|
|
|
|
private:
|
|
TextEditor *m_textEditor;
|
|
};
|