| 269 | } |
| 270 | |
| 271 | CodeEditor::CodeEditor(QWidget *parent) : |
| 272 | QPlainTextEdit(parent), |
| 273 | mWidgetStyle(new CodeEditorStyle(defaultStyleLight)) |
| 274 | { |
| 275 | mLineNumberArea = new LineNumberArea(this); |
| 276 | mHighlighter = new Highlighter(document(), mWidgetStyle); |
| 277 | mErrorPosition = -1; |
| 278 | |
| 279 | QFont font("Monospace"); |
| 280 | font.setStyleHint(QFont::TypeWriter); |
| 281 | setFont(font); |
| 282 | mLineNumberArea->setFont(font); |
| 283 | |
| 284 | // set widget coloring by overriding widget style sheet |
| 285 | setObjectName("CodeEditor"); |
| 286 | setStyleSheet(generateStyleString()); |
| 287 | |
| 288 | auto *copyText = new QShortcut(QKeySequence(Qt::CTRL | Qt::Key_C),this); |
| 289 | auto *allText = new QShortcut(QKeySequence(Qt::CTRL | Qt::Key_A),this); |
| 290 | |
| 291 | connect(this, SIGNAL(blockCountChanged(int)), this, SLOT(updateLineNumberAreaWidth(int))); |
| 292 | connect(this, SIGNAL(updateRequest(QRect,int)), this, SLOT(updateLineNumberArea(QRect,int))); |
| 293 | connect(copyText, SIGNAL(activated()), this, SLOT(copy())); |
| 294 | connect(allText, SIGNAL(activated()), this, SLOT(selectAll())); |
| 295 | |
| 296 | updateLineNumberAreaWidth(0); |
| 297 | } |
| 298 | |
| 299 | CodeEditor::~CodeEditor() |
| 300 | { |