12 #include <QPropertyAnimation>
16 #if QT_VERSION >= QT_VERSION_CHECK(5,13,0)
17 #include <QRegularExpression>
30 mLineNumbersEnabled(true),
31 mLineHighlightEnabled(true),
32 mMinimapEnabled(false),
33 mLineWrapEnabled(false)
39 if (mLineHighlightEnabled)
74 if (wheel->
delta() > 0)
88 painter.
setFont(mLineNumberFont);
96 int bottom =
event->rect().bottom();
110 block = block.
next();
143 void CodeEditor::clearLineHighlight()
149 void CodeEditor::highlightCurrentLine()
161 int block =
cursor.blockNumber();
168 selection.format.setBackground(mCurrentLineBackground);
170 selection.cursor =
cursor;
171 extra_selections.
append(selection);
173 oldPosition =
cursor.position();
176 }
while(
cursor.blockNumber() == block &&
cursor.position() != oldPosition);
181 void CodeEditor::handleBlockCountChanged(
int new_block_count)
183 Q_UNUSED(new_block_count);
191 void CodeEditor::updateLineNumberArea(
const QRect& rect,
int dy)
196 mLineNumberArea->
update();
199 void CodeEditor::updateMinimap(
const QRect& rect,
int dy)
221 #if QT_VERSION >= QT_VERSION_CHECK(5,13,0)
226 while (
find(regExp, options))
229 extra.format.setForeground(
QBrush(color));
230 extra.format.setBackground(mBackgroundColor);
238 while (
find(
string, options))
241 extra.format.setForeground(
QBrush(color));
242 extra.format.setBackground(mBackgroundColor);
253 mLineNumbersEnabled = !mLineNumbersEnabled;
259 mMinimapEnabled = !mMinimapEnabled;
272 if (number < 0 || number >= total)
286 font.setPointSize(pt);
302 return mLineNumberFont;
307 return mLineNumberColor;
312 return mLineNumberBackground;
317 return mLineNumberHighlightColor;
322 return mLineNumberHighlightBackground;
327 return mCurrentLineBackground;
332 mLineNumberFont =
font;
337 mLineNumberColor = color;
342 mLineNumberBackground = color;
347 mLineNumberHighlightColor = color;
352 mLineNumberHighlightBackground = color;
357 mCurrentLineBackground = color;
360 void CodeEditor::updateLayout()
363 int right_margin = 0;
367 if (mLineNumbersEnabled)
371 mLineNumberArea->
show();
374 mLineNumberArea->
hide();
396 mLineHighlightEnabled =
enabled;
401 highlightCurrentLine();
406 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
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
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