10 #include <QPropertyAnimation>
14 #if QT_VERSION >= QT_VERSION_CHECK(5,13,0)
15 #include <QRegularExpression>
28 mLineNumbersEnabled(true),
29 mLineHighlightEnabled(true),
30 mMinimapEnabled(false),
31 mLineWrapEnabled(false)
37 if (mLineHighlightEnabled)
72 if (wheel->
delta() > 0)
86 painter.
setFont(mLineNumberFont);
94 int bottom =
event->rect().bottom();
97 while (block.
isValid() && top <= bottom)
108 block = block.
next();
141 void CodeEditor::clearLineHighlight()
147 void CodeEditor::highlightCurrentLine()
159 int block =
cursor.blockNumber();
166 selection.format.setBackground(mCurrentLineBackground);
168 selection.cursor =
cursor;
169 extra_selections.
append(selection);
171 oldPosition =
cursor.position();
174 }
while(
cursor.blockNumber() == block &&
cursor.position() != oldPosition);
179 void CodeEditor::handleBlockCountChanged(
int new_block_count)
181 Q_UNUSED(new_block_count);
189 void CodeEditor::updateLineNumberArea(
const QRect& rect,
int dy)
194 mLineNumberArea->
update();
197 void CodeEditor::updateMinimap(
const QRect& rect,
int dy)
207 if (
string.isEmpty())
224 #if QT_VERSION >= QT_VERSION_CHECK(5,13,0)
229 while (
find(regExp, options))
240 extra.format.setForeground(
QBrush(color));
241 extra.format.setBackground(mBackgroundColor);
249 while (
find(
string, options))
252 extra.format.setForeground(
QBrush(color));
253 extra.format.setBackground(mBackgroundColor);
264 mLineNumbersEnabled = !mLineNumbersEnabled;
270 mMinimapEnabled = !mMinimapEnabled;
283 if (number < 0 || number >= total)
297 font.setPointSize(pt);
313 return mLineNumberFont;
318 return mLineNumberColor;
323 return mLineNumberBackground;
328 return mLineNumberHighlightColor;
333 return mLineNumberHighlightBackground;
338 return mCurrentLineBackground;
343 mLineNumberFont =
font;
348 mLineNumberColor = color;
353 mLineNumberBackground = color;
358 mLineNumberHighlightColor = color;
363 mLineNumberHighlightBackground = color;
368 mCurrentLineBackground = color;
371 void CodeEditor::updateLayout()
374 int right_margin = 0;
378 if (mLineNumbersEnabled)
382 mLineNumberArea->
show();
385 mLineNumberArea->
hide();
407 mLineHighlightEnabled =
enabled;
412 highlightCurrentLine();
417 clearLineHighlight();
virtual void resizeEvent(QResizeEvent *event) override
void setHighlightCurrentLineEnabled(bool enabled)
int lineNumberAreaWidth()
void setLineNumberColor(QColor &color)
QColor lineNumberHighlightColor
void setLineWrapEnabled(bool enabled)
CodeEditor(QWidget *parent=nullptr)
virtual bool eventFilter(QObject *object, QEvent *event) override
void centerOnLine(const int number)
int first_visible_block()
void setLineNumberBackground(QColor &color)
QColor lineNumberHighlightBackground
void setMinimapEnabled(bool enabled)
void lineNumberAreaPaintEvent(QPaintEvent *event)
void handleWheelEvent(QWheelEvent *event)
void setLineNumberHighlightColor(QColor &color)
QColor lineNumberBackground
void setLineNumberFont(const QFont &font)
CodeEditorMinimap * minimap()
void setLineNumberHighlightBackground(QColor &color)
void search(const QString &string, SearchOptions searchOpts=8)
void minimapPaintEvent(QPaintEvent *event)
QColor currentLineBackground
void setLineNumberEnabled(bool enabled)
void setCurrentLineBackground(QColor &color)
A minimap that supports an easier navigation in larger files.
void adjustSliderHeight(int viewport_height)
MinimapScrollbar * scrollbar()
Shows line numbers next to a CodeEditor.
bool isExactMatch() const
bool isCaseSensitive() const
bool isRegularExpression() const
void start(QAbstractAnimation::DeletionPolicy policy)
int width(const QString &text, int len) const const
void setFrameStyle(int style)
void append(const T &value)
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
bool disconnect(const QObject *sender, const char *signal, const QObject *receiver, const char *method)
void installEventFilter(QObject *filterObj)
void drawText(const QPointF &position, const QString &text)
void setFont(const QFont &font)
void setPen(const QColor &color)
void setColor(const QColor &color)
QRectF blockBoundingGeometry(const QTextBlock &block) const const
void blockCountChanged(int newBlockCount)
QPointF contentOffset() const const
void cursorPositionChanged()
QTextDocument * document() const const
bool find(const QString &exp, QTextDocument::FindFlags options)
QTextBlock firstVisibleBlock() const const
void setLineWrapMode(QPlainTextEdit::LineWrapMode mode)
void moveCursor(QTextCursor::MoveOperation operation, QTextCursor::MoveMode mode)
virtual void resizeEvent(QResizeEvent *e) override
void setTextCursor(const QTextCursor &cursor)
QTextCursor textCursor() const const
void updateRequest(const QRect &rect, int dy)
virtual void wheelEvent(QWheelEvent *e) override
qreal height() const const
QRectF translated(qreal dx, qreal dy) const const
QString number(int n, int base)
int blockNumber() const const
bool isValid() const const
bool isVisible() const const
QTextBlock next() const const
bool movePosition(QTextCursor::MoveOperation operation, QTextCursor::MoveMode mode, int n)
int position() const const
void setDocumentMargin(qreal margin)
int lineCount() const const
void setDuration(int msecs)
void setEndValue(const QVariant &value)
void setStartValue(const QVariant &value)
QRect contentsRect() const const