BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
gui2::ImportTextView Class Reference

Text view to show imported data. More...

Inheritance diagram for gui2::ImportTextView:
[legend]
Collaboration diagram for gui2::ImportTextView:
[legend]

Public Member Functions

 ImportTextView (QWidget *parent=nullptr)
 
void lineNumberAreaPaintEvent (QPaintEvent *event)
 
int lineNumberAreaWidth ()
 

Protected Member Functions

void resizeEvent (QResizeEvent *event) override
 

Private Slots

void highlightCurrentLine ()
 
void updateLineNumberArea (const QRect &rect, int dy)
 
void updateLineNumberAreaWidth (int newBlockCount)
 

Private Attributes

QWidget * lineNumberArea
 

Detailed Description

Text view to show imported data.

Definition at line 36 of file importtextview.h.

Constructor & Destructor Documentation

◆ ImportTextView()

gui2::ImportTextView::ImportTextView ( QWidget *  parent = nullptr)

Definition at line 30 of file importtextview.cpp.

30  : QPlainTextEdit(parent)
31 {
32  lineNumberArea = new LineNumberArea(this);
33 
34  connect(this, &ImportTextView::blockCountChanged, this,
36  connect(this, &ImportTextView::updateRequest, this, &ImportTextView::updateLineNumberArea);
37  connect(this, &ImportTextView::cursorPositionChanged, this,
39 
41  // highlightCurrentLine();
42 
43  setReadOnly(true);
44  setWordWrapMode(QTextOption::NoWrap);
45 
46  setFont(QFont("Monospace", ModelView::Utils::SystemPointSize() * 0.8, QFont::Light));
47 }
void updateLineNumberArea(const QRect &rect, int dy)
void updateLineNumberAreaWidth(int newBlockCount)
MVVM_VIEW_EXPORT int SystemPointSize()
Returns size in points of default system font.

References highlightCurrentLine(), lineNumberArea, ModelView::Utils::SystemPointSize(), updateLineNumberArea(), and updateLineNumberAreaWidth().

Here is the call graph for this function:

Member Function Documentation

◆ highlightCurrentLine

void gui2::ImportTextView::highlightCurrentLine ( )
privateslot

Definition at line 87 of file importtextview.cpp.

88 {
89  QList<QTextEdit::ExtraSelection> extraSelections;
90 
91  if (!isReadOnly()) {
92  QTextEdit::ExtraSelection selection;
93 
94  QColor lineColor = QColor(Qt::yellow).lighter(160);
95 
96  selection.format.setBackground(lineColor);
97  selection.format.setProperty(QTextFormat::FullWidthSelection, true);
98  selection.cursor = textCursor();
99  selection.cursor.clearSelection();
100  extraSelections.append(selection);
101  }
102 
103  setExtraSelections(extraSelections);
104 }

Referenced by ImportTextView().

◆ lineNumberAreaPaintEvent()

void gui2::ImportTextView::lineNumberAreaPaintEvent ( QPaintEvent *  event)

Definition at line 106 of file importtextview.cpp.

107 {
108  QPainter painter(lineNumberArea);
109  painter.fillRect(event->rect(), Qt::lightGray);
110 
111  QTextBlock block = firstVisibleBlock();
112  int blockNumber = block.blockNumber();
113  int top = qRound(blockBoundingGeometry(block).translated(contentOffset()).top());
114  int bottom = top + qRound(blockBoundingRect(block).height());
115 
116  while (block.isValid() && top <= event->rect().bottom()) {
117  if (block.isVisible() && bottom >= event->rect().top()) {
118  QString number = QString::number(blockNumber + 1);
119  painter.setPen(Qt::black);
120  painter.drawText(0, top, lineNumberArea->width() - line_number_gap,
121  fontMetrics().height(), Qt::AlignRight, number);
122  }
123 
124  block = block.next();
125  top = bottom;
126  bottom = top + qRound(blockBoundingRect(block).height());
127  ++blockNumber;
128  }
129 }

References lineNumberArea.

◆ lineNumberAreaWidth()

int gui2::ImportTextView::lineNumberAreaWidth ( )

Definition at line 49 of file importtextview.cpp.

50 {
51  int digits = 1;
52  int max = qMax(1, blockCount());
53  while (max >= 10) {
54  max /= 10;
55  ++digits;
56  }
57 
58  int space = line_number_gap * 2 + fontMetrics().horizontalAdvance(QLatin1Char('9')) * digits;
59 
60  return space;
61 }

Referenced by resizeEvent(), and updateLineNumberAreaWidth().

◆ resizeEvent()

void gui2::ImportTextView::resizeEvent ( QResizeEvent *  event)
overrideprotected

Definition at line 79 of file importtextview.cpp.

80 {
81  QPlainTextEdit::resizeEvent(e);
82 
83  QRect cr = contentsRect();
84  lineNumberArea->setGeometry(QRect(cr.left(), cr.top(), lineNumberAreaWidth(), cr.height()));
85 }

References lineNumberArea, and lineNumberAreaWidth().

Here is the call graph for this function:

◆ updateLineNumberArea

void gui2::ImportTextView::updateLineNumberArea ( const QRect &  rect,
int  dy 
)
privateslot

Definition at line 68 of file importtextview.cpp.

69 {
70  if (dy)
71  lineNumberArea->scroll(0, dy);
72  else
73  lineNumberArea->update(0, rect.y(), lineNumberArea->width(), rect.height());
74 
75  if (rect.contains(viewport()->rect()))
77 }

References lineNumberArea, and updateLineNumberAreaWidth().

Referenced by ImportTextView().

Here is the call graph for this function:

◆ updateLineNumberAreaWidth

void gui2::ImportTextView::updateLineNumberAreaWidth ( int  newBlockCount)
privateslot

Definition at line 63 of file importtextview.cpp.

64 {
65  setViewportMargins(lineNumberAreaWidth(), 0, 0, 0);
66 }

References lineNumberAreaWidth().

Referenced by ImportTextView(), and updateLineNumberArea().

Here is the call graph for this function:

Member Data Documentation

◆ lineNumberArea

QWidget* gui2::ImportTextView::lineNumberArea
private

The documentation for this class was generated from the following files: