add support for add a highlight for the currently active input line to the line number display
This commit is contained in:
@ -28,7 +28,7 @@
|
|||||||
#include <QTextBlock>
|
#include <QTextBlock>
|
||||||
#include <QUrl>
|
#include <QUrl>
|
||||||
|
|
||||||
CodeEditor::CodeEditor(QWidget *parent) : QPlainTextEdit(parent)
|
CodeEditor::CodeEditor(QWidget *parent) : QPlainTextEdit(parent), highlight(-1)
|
||||||
{
|
{
|
||||||
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);
|
||||||
@ -83,7 +83,7 @@ int CodeEditor::lineNumberAreaWidth()
|
|||||||
++digits;
|
++digits;
|
||||||
}
|
}
|
||||||
|
|
||||||
int space = 3 + fontMetrics().horizontalAdvance(QLatin1Char('9')) * digits;
|
int space = 3 + fontMetrics().horizontalAdvance(QLatin1Char('9')) * (digits + 2);
|
||||||
|
|
||||||
return space;
|
return space;
|
||||||
}
|
}
|
||||||
@ -94,6 +94,12 @@ void CodeEditor::setFont(const QFont &newfont)
|
|||||||
document()->setDefaultFont(newfont);
|
document()->setDefaultFont(newfont);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CodeEditor::setHighlight(int block)
|
||||||
|
{
|
||||||
|
highlight = block;
|
||||||
|
repaint();
|
||||||
|
}
|
||||||
|
|
||||||
void CodeEditor::updateLineNumberAreaWidth(int /* newBlockCount */)
|
void CodeEditor::updateLineNumberAreaWidth(int /* newBlockCount */)
|
||||||
{
|
{
|
||||||
setViewportMargins(lineNumberAreaWidth(), 0, 0, 0);
|
setViewportMargins(lineNumberAreaWidth(), 0, 0, 0);
|
||||||
@ -167,15 +173,22 @@ void CodeEditor::highlightCurrentLine()
|
|||||||
void CodeEditor::lineNumberAreaPaintEvent(QPaintEvent *event)
|
void CodeEditor::lineNumberAreaPaintEvent(QPaintEvent *event)
|
||||||
{
|
{
|
||||||
QPainter painter(lineNumberArea);
|
QPainter painter(lineNumberArea);
|
||||||
painter.fillRect(event->rect(), Qt::lightGray);
|
|
||||||
QTextBlock block = firstVisibleBlock();
|
QTextBlock block = firstVisibleBlock();
|
||||||
int blockNumber = block.blockNumber();
|
int blockNumber = block.blockNumber();
|
||||||
|
|
||||||
int top = qRound(blockBoundingGeometry(block).translated(contentOffset()).top());
|
int top = qRound(blockBoundingGeometry(block).translated(contentOffset()).top());
|
||||||
int bottom = top + qRound(blockBoundingRect(block).height());
|
int bottom = top + qRound(blockBoundingRect(block).height());
|
||||||
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)) {
|
||||||
painter.setPen(Qt::black);
|
painter.setPen(Qt::black);
|
||||||
|
} else {
|
||||||
|
number = QString(">") + QString::number(blockNumber + 1) + "<";
|
||||||
|
painter.fillRect(0, top, lineNumberArea->width(), fontMetrics().height(),
|
||||||
|
Qt::darkRed);
|
||||||
|
painter.setPen(Qt::white);
|
||||||
|
}
|
||||||
painter.drawText(0, top, lineNumberArea->width(), fontMetrics().height(),
|
painter.drawText(0, top, lineNumberArea->width(), fontMetrics().height(),
|
||||||
Qt::AlignRight, number);
|
Qt::AlignRight, number);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -29,6 +29,7 @@ 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);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void resizeEvent(QResizeEvent *event) override;
|
void resizeEvent(QResizeEvent *event) override;
|
||||||
@ -48,6 +49,7 @@ private slots:
|
|||||||
private:
|
private:
|
||||||
QWidget *lineNumberArea;
|
QWidget *lineNumberArea;
|
||||||
QShortcut *help_action;
|
QShortcut *help_action;
|
||||||
|
int highlight;
|
||||||
|
|
||||||
QMap<QString, QString> cmd_map;
|
QMap<QString, QString> cmd_map;
|
||||||
QMap<QString, QString> fix_map;
|
QMap<QString, QString> fix_map;
|
||||||
|
|||||||
@ -659,6 +659,13 @@ void LammpsGui::logupdate()
|
|||||||
t_remain = lammps.get_thermo("cpuremain");
|
t_remain = lammps.get_thermo("cpuremain");
|
||||||
t_total = t_elapsed + t_remain + 1.0e-10;
|
t_total = t_elapsed + t_remain + 1.0e-10;
|
||||||
completed = t_elapsed / t_total * 1000.0;
|
completed = t_elapsed / t_total * 1000.0;
|
||||||
|
|
||||||
|
int nline = -1;
|
||||||
|
void *ptr = lammps.last_thermo("line", 0);
|
||||||
|
if (ptr) {
|
||||||
|
nline = *((int *)ptr);
|
||||||
|
ui->textEdit->setHighlight(nline);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
progress->setValue(completed);
|
progress->setValue(completed);
|
||||||
@ -747,6 +754,7 @@ void LammpsGui::run_done()
|
|||||||
delete logupdater;
|
delete logupdater;
|
||||||
logupdater = nullptr;
|
logupdater = nullptr;
|
||||||
progress->setValue(1000);
|
progress->setValue(1000);
|
||||||
|
ui->textEdit->setHighlight(-1);
|
||||||
|
|
||||||
capturer->EndCapture();
|
capturer->EndCapture();
|
||||||
auto log = capturer->GetCapture();
|
auto log = capturer->GetCapture();
|
||||||
|
|||||||
Reference in New Issue
Block a user