Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
.moc
Makefile
.obj
*.o
.ui
.vscode
.cache
Expand Down
8 changes: 8 additions & 0 deletions src/configdialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -1698,6 +1698,13 @@ Then you can select a new shortcut by one of the following ways:
</property>
</widget>
</item>
<item row="13" column="0" colspan="4">
<widget class="QCheckBox" name="checkBoxShowIndentGuides">
<property name="text">
<string>Show Indent Guides</string>
</property>
</widget>
</item>
<item row="7" column="3" colspan="2">
<widget class="QCheckBox" name="checkBoxReplaceIndentTabByWhitespace">
<property name="text">
Expand Down Expand Up @@ -5111,6 +5118,7 @@ Note: Changing this setting will only affect documents that are opened afterward
<tabstop>spinBoxSize</tabstop>
<tabstop>comboBoxEncoding</tabstop>
<tabstop>checkBoxFolding</tabstop>
<tabstop>checkBoxShowIndentGuides</tabstop>
<tabstop>comboBoxAutoIndent</tabstop>
<tabstop>comboBoxReplaceQuotes</tabstop>
<tabstop>checkBoxRealTimeCheck</tabstop>
Expand Down
5 changes: 3 additions & 2 deletions src/configmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -533,8 +533,9 @@ ConfigManager::ConfigManager(QObject *parent): QObject (parent),
registerOption("Editor/Indent with Spaces", &editorConfig->replaceIndentTabs, false, &pseudoDialog->checkBoxReplaceIndentTabByWhitespace);
registerOption("Editor/ReplaceTextTabs", &editorConfig->replaceTextTabs, false, &pseudoDialog->checkBoxReplaceTextTabByWhitespace);
registerOption("Editor/RemoveTrailingWsOnSave", &editorConfig->removeTrailingWsOnSave, false, &pseudoDialog->checkboxRemoveTrailingWsOnSave);
registerOption("Editor/Folding", &editorConfig->folding, true, &pseudoDialog->checkBoxFolding);
registerOption("Editor/Show Line State", &editorConfig->showlinestate, true, &pseudoDialog->checkBoxLineState);
registerOption("Editor/Folding", &editorConfig->folding, true, &pseudoDialog->checkBoxFolding);
registerOption("Editor/Show Line State", &editorConfig->showlinestate, true, &pseudoDialog->checkBoxLineState);
registerOption("Editor/Show Indent Guides", &editorConfig->showIndentGuides, false, &pseudoDialog->checkBoxShowIndentGuides);
registerOption("Editor/Show Cursor State", &editorConfig->showcursorstate, true, &pseudoDialog->checkBoxState);
registerOption("Editor/Real-Time Spellchecking", &editorConfig->realtimeChecking, true, &pseudoDialog->checkBoxRealTimeCheck); //named for compatibility reasons with older txs versions
registerOption("Editor/Check Spelling", &editorConfig->inlineSpellChecking, true, &pseudoDialog->checkBoxInlineSpellCheck);
Expand Down
1 change: 1 addition & 0 deletions src/latexeditorview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1859,6 +1859,7 @@ void LatexEditorView::updateSettings()
editor->setFlag(QEditor::VerticalOverScroll, config->verticalOverScroll);
editor->setFlag(QEditor::AutoInsertLRM, config->autoInsertLRM);
editor->setFlag(QEditor::BidiVisualColumnMode, config->visualColumnMode);
editor->setFlag(QEditor::ShowIndentGuides, config->showIndentGuides);
editor->setFlag(QEditor::OverwriteOpeningBracketFollowedByPlaceholder, config->overwriteOpeningBracketFollowedByPlaceholder);
editor->setFlag(QEditor::OverwriteClosingBracketFollowingPlaceholder, config->overwriteClosingBracketFollowingPlaceholder);
//TODO: parenmatch
Expand Down
1 change: 1 addition & 0 deletions src/latexeditorview_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class LatexEditorViewConfig
int cursorSurroundLines;
bool boldCursor;
bool centerDocumentInEditor;
bool showIndentGuides;
bool folding, showlinestate, showcursorstate, realtimeChecking;
bool inlineSpellChecking, inlineCitationChecking, inlineReferenceChecking, inlineSyntaxChecking, inlineGrammarChecking, inlinePackageChecking;
bool inlineCheckNonTeXFiles;
Expand Down
72 changes: 67 additions & 5 deletions src/qcodeedit/lib/qeditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3213,8 +3213,10 @@ void QEditor::paintEvent(QPaintEvent */*e*/)
const QRectF rect(0, 0, width, height);
p.fillRect(rect, bg);

p.save();
m_doc->draw(&p, ctx);
p.save();
// Draw indent guides first so they appear behind text
drawIndentGuides(&p, ctx);
m_doc->draw(&p, ctx);
p.restore();
//qDebug("drawn %d ms",tm.elapsed());

Expand Down Expand Up @@ -6468,9 +6470,69 @@ void QEditor::removeAllMarks(){
scrlBar->removeAllShades();
}

void QEditor::addMarkRange(int start, int end, QColor color, QString type){
MarkedScrollBar *scrlBar=qobject_cast<MarkedScrollBar*>(verticalScrollBar());
scrlBar->addShade(start,end,color,type);
void QEditor::addMarkRange(int start, int end, QColor color, QString type){
MarkedScrollBar *scrlBar=qobject_cast<MarkedScrollBar*>(verticalScrollBar());
scrlBar->addShade(start,end,color,type);
}

/*!
\brief Draw indent guides (vertical lines showing indentation levels)
*/
void QEditor::drawIndentGuides(QPainter *painter, const QDocument::PaintContext &ctx)
{
if (!flag(ShowIndentGuides) || !m_doc) {
return;
}

const QFontMetrics fm = fontMetrics();
const int tabSize = m_doc->tabStop();
const int charWidth = fm.averageCharWidth();

// Use a very subtle color for the guides
QColor guideColor = palette().color(QPalette::Text);
guideColor.setAlpha(50); // Make it very subtle

painter->save();
painter->setPen(QPen(guideColor, 1, Qt::DotLine));

const int firstLine = qMax(0, int((ctx.yoffset) / m_doc->getLineSpacing()));
const int lastLine = qMin(firstLine + int(ctx.height / m_doc->getLineSpacing()) + 2, m_doc->lines() - 1);

// Only draw guides on lines that actually have indentation
for (int line = firstLine; line <= lastLine; ++line) {
QDocumentLine docLine = m_doc->line(line);
if (!docLine.isValid()) continue;

QString text = docLine.text();
if (text.trimmed().isEmpty()) continue; // Skip empty lines

// Calculate indentation level
int indentLevel = 0;
int i = 0;
while (i < text.length() && text[i].isSpace()) {
if (text[i] == '\t') {
indentLevel += tabSize - (indentLevel % tabSize); // Round up to next tab stop
} else {
indentLevel += 1;
}
i++;
}

if (indentLevel == 0) continue; // Skip lines with no indentation

// Draw vertical guides for this line's indentation levels
const qreal lineY = line * m_doc->getLineSpacing();
const qreal lineHeight = m_doc->getLineSpacing();

for (int level = tabSize; level <= indentLevel; level += tabSize) {
qreal x = level * charWidth;
if (x < ctx.width && x > 0) {
painter->drawLine(QPointF(x, lineY), QPointF(x, lineY + lineHeight));
}
}
}

painter->restore();
}

/*! @} */
13 changes: 8 additions & 5 deletions src/qcodeedit/lib/qeditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,11 @@ class QCE_EXPORT QEditor : public QAbstractScrollArea
AutoCloseChars = 0x00200000,
AutoIndent = 0x00400000,
WeakIndent = 0x00800000,
AutoInsertLRM = 0x01000000,
BidiVisualColumnMode= 0x02000000,

AutoInsertLRM = 0x01000000,
BidiVisualColumnMode= 0x02000000,

ShowIndentGuides = 0x04000000,

ShowPlaceholders = 0x10000000,
OverwriteOpeningBracketFollowedByPlaceholder = 0x20000000,
OverwriteClosingBracketFollowingPlaceholder = 0x40000000,
Expand Down Expand Up @@ -668,8 +670,9 @@ public slots:
Conflict
};

void init(bool actions = true,QDocument *doc=0);
void updateBindingsMenu();
void init(bool actions = true,QDocument *doc=0);
void updateBindingsMenu();
void drawIndentGuides(QPainter *painter, const QDocument::PaintContext &ctx);

QMenu *pMenu;
QHash<QString, QAction*> m_actions;
Expand Down