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