improve highlighting settings to also show errors with different color
This commit is contained in:
@ -28,7 +28,7 @@
|
|||||||
#include <QTextBlock>
|
#include <QTextBlock>
|
||||||
#include <QUrl>
|
#include <QUrl>
|
||||||
|
|
||||||
CodeEditor::CodeEditor(QWidget *parent) : QPlainTextEdit(parent), highlight(-1)
|
CodeEditor::CodeEditor(QWidget *parent) : QPlainTextEdit(parent), highlight(NO_HIGHLIGHT)
|
||||||
{
|
{
|
||||||
help_action = new QShortcut(QKeySequence::fromString("Ctrl+?"), parent);
|
help_action = new QShortcut(QKeySequence::fromString("Ctrl+?"), parent);
|
||||||
connect(help_action, &QShortcut::activated, this, &CodeEditor::get_help);
|
connect(help_action, &QShortcut::activated, this, &CodeEditor::get_help);
|
||||||
@ -94,11 +94,9 @@ void CodeEditor::setFont(const QFont &newfont)
|
|||||||
document()->setDefaultFont(newfont);
|
document()->setDefaultFont(newfont);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CodeEditor::setHighlight(int block)
|
void CodeEditor::setCursor(int block)
|
||||||
{
|
{
|
||||||
highlight = block;
|
// move cursor to given position
|
||||||
|
|
||||||
// also move cursor to current position
|
|
||||||
auto cursor = textCursor();
|
auto cursor = textCursor();
|
||||||
int moves = block - cursor.blockNumber();
|
int moves = block - cursor.blockNumber();
|
||||||
if (moves < 0)
|
if (moves < 0)
|
||||||
@ -106,6 +104,17 @@ void CodeEditor::setHighlight(int block)
|
|||||||
else
|
else
|
||||||
cursor.movePosition(QTextCursor::Down, QTextCursor::MoveAnchor, moves);
|
cursor.movePosition(QTextCursor::Down, QTextCursor::MoveAnchor, moves);
|
||||||
setTextCursor(cursor);
|
setTextCursor(cursor);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CodeEditor::setHighlight(int block, bool error)
|
||||||
|
{
|
||||||
|
if (error)
|
||||||
|
highlight = -block;
|
||||||
|
else
|
||||||
|
highlight = block;
|
||||||
|
|
||||||
|
// also reset the cursor
|
||||||
|
setCursor(block);
|
||||||
|
|
||||||
// update graphics
|
// update graphics
|
||||||
repaint();
|
repaint();
|
||||||
@ -173,12 +182,17 @@ void CodeEditor::lineNumberAreaPaintEvent(QPaintEvent *event)
|
|||||||
while (block.isValid() && top <= event->rect().bottom()) {
|
while (block.isValid() && top <= event->rect().bottom()) {
|
||||||
if (block.isVisible() && bottom >= event->rect().top()) {
|
if (block.isVisible() && bottom >= event->rect().top()) {
|
||||||
QString number = QString::number(blockNumber + 1) + " ";
|
QString number = QString::number(blockNumber + 1) + " ";
|
||||||
if ((highlight < 0) || (blockNumber != highlight)) {
|
if ((highlight == NO_HIGHLIGHT) || (blockNumber != std::abs(highlight))) {
|
||||||
painter.setPen(Qt::black);
|
painter.setPen(Qt::black);
|
||||||
} else {
|
} else {
|
||||||
number = QString(">") + QString::number(blockNumber + 1) + "<";
|
number = QString(">") + QString::number(blockNumber + 1) + "<";
|
||||||
|
if (highlight < 0)
|
||||||
painter.fillRect(0, top, lineNumberArea->width(), fontMetrics().height(),
|
painter.fillRect(0, top, lineNumberArea->width(), fontMetrics().height(),
|
||||||
Qt::darkRed);
|
Qt::darkRed);
|
||||||
|
else
|
||||||
|
painter.fillRect(0, top, lineNumberArea->width(), fontMetrics().height(),
|
||||||
|
Qt::darkGreen);
|
||||||
|
|
||||||
painter.setPen(Qt::white);
|
painter.setPen(Qt::white);
|
||||||
}
|
}
|
||||||
painter.drawText(0, top, lineNumberArea->width(), fontMetrics().height(),
|
painter.drawText(0, top, lineNumberArea->width(), fontMetrics().height(),
|
||||||
|
|||||||
@ -29,7 +29,10 @@ public:
|
|||||||
void lineNumberAreaPaintEvent(QPaintEvent *event);
|
void lineNumberAreaPaintEvent(QPaintEvent *event);
|
||||||
int lineNumberAreaWidth();
|
int lineNumberAreaWidth();
|
||||||
void setFont(const QFont &newfont);
|
void setFont(const QFont &newfont);
|
||||||
void setHighlight(int block);
|
void setCursor(int block);
|
||||||
|
void setHighlight(int block, bool error);
|
||||||
|
|
||||||
|
static constexpr int NO_HIGHLIGHT = 1 << 30;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void resizeEvent(QResizeEvent *event) override;
|
void resizeEvent(QResizeEvent *event) override;
|
||||||
|
|||||||
@ -504,6 +504,7 @@ void LammpsGui::open_file(const QString &fileName)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
ui->textEdit->setHighlight(CodeEditor::NO_HIGHLIGHT, false);
|
||||||
|
|
||||||
QFileInfo path(fileName);
|
QFileInfo path(fileName);
|
||||||
current_file = path.fileName();
|
current_file = path.fileName();
|
||||||
@ -527,6 +528,7 @@ void LammpsGui::open_file(const QString &fileName)
|
|||||||
ui->textEdit->document()->setModified(false);
|
ui->textEdit->document()->setModified(false);
|
||||||
file.close();
|
file.close();
|
||||||
dirstatus->setText(QString(" Directory: ") + current_dir);
|
dirstatus->setText(QString(" Directory: ") + current_dir);
|
||||||
|
status->setText("Ready.");
|
||||||
|
|
||||||
update_variables();
|
update_variables();
|
||||||
}
|
}
|
||||||
@ -665,7 +667,7 @@ void LammpsGui::logupdate()
|
|||||||
void *ptr = lammps.last_thermo("line", 0);
|
void *ptr = lammps.last_thermo("line", 0);
|
||||||
if (ptr) {
|
if (ptr) {
|
||||||
nline = *((int *)ptr);
|
nline = *((int *)ptr);
|
||||||
ui->textEdit->setHighlight(nline);
|
ui->textEdit->setHighlight(nline, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -755,7 +757,7 @@ void LammpsGui::run_done()
|
|||||||
delete logupdater;
|
delete logupdater;
|
||||||
logupdater = nullptr;
|
logupdater = nullptr;
|
||||||
progress->setValue(1000);
|
progress->setValue(1000);
|
||||||
ui->textEdit->setHighlight(-1);
|
ui->textEdit->setHighlight(CodeEditor::NO_HIGHLIGHT, false);
|
||||||
|
|
||||||
capturer->EndCapture();
|
capturer->EndCapture();
|
||||||
auto log = capturer->GetCapture();
|
auto log = capturer->GetCapture();
|
||||||
@ -800,13 +802,19 @@ void LammpsGui::run_done()
|
|||||||
success = false;
|
success = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int nline = CodeEditor::NO_HIGHLIGHT;
|
||||||
|
void *ptr = lammps.last_thermo("line", 0);
|
||||||
|
if (ptr) nline = *((int *)ptr);
|
||||||
|
|
||||||
if (success) {
|
if (success) {
|
||||||
status->setText("Ready.");
|
status->setText("Ready.");
|
||||||
} else {
|
} else {
|
||||||
status->setText("Failed.");
|
status->setText("Failed.");
|
||||||
|
ui->textEdit->setHighlight(nline, true);
|
||||||
QMessageBox::critical(this, "LAMMPS-GUI Error",
|
QMessageBox::critical(this, "LAMMPS-GUI Error",
|
||||||
QString("Error running LAMMPS:\n\n") + errorbuf);
|
QString("Error running LAMMPS:\n\n") + errorbuf);
|
||||||
}
|
}
|
||||||
|
ui->textEdit->setCursor(nline);
|
||||||
progress->hide();
|
progress->hide();
|
||||||
dirstatus->show();
|
dirstatus->show();
|
||||||
}
|
}
|
||||||
|
|||||||
BIN
tools/lammps-gui/run-file.png
Normal file
BIN
tools/lammps-gui/run-file.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 2.3 KiB |
Reference in New Issue
Block a user