long lines wrap

This commit is contained in:
Zira project 2020-03-06 19:39:54 +05:00
parent daa34c906a
commit 88058141ea
5 changed files with 56 additions and 5 deletions

View file

@ -375,6 +375,7 @@ private:
int highlightProgressPercent;
int spellProgressPercent;
bool drawLongLineMarker;
bool wrapLines;
signals:
void ready(int index);
void statusBarText(int index, QString text);

View file

@ -78,11 +78,21 @@ Editor::Editor(SpellCheckerInterface * spellChecker, Settings * settings, Highli
setMinimumSize(0, 0);
setMaximumSize(16777215, 16777215);
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
setLineWrapMode(LineWrapMode::NoWrap);
setWordWrapMode(QTextOption::WrapMode::NoWrap);
setAcceptRichText(false);
setAcceptDrops(false);
wrapLines = false;
std::string wrapLinesStr = settings->get("editor_wrap_long_lines");
if (wrapLinesStr == "yes") wrapLines = true;
if (wrapLines) {
setLineWrapMode(LineWrapMode::FixedColumnWidth);
setLineWrapColumnOrWidth(LONG_LINE_CHARS_COUNT);
setWordWrapMode(QTextOption::WrapMode::WordWrap);
} else {
setLineWrapMode(LineWrapMode::NoWrap);
setWordWrapMode(QTextOption::WrapMode::NoWrap);
}
QString theme = QString::fromStdString(settings->get("theme"));
//QFont generalFont = QFontDatabase::systemFont(QFontDatabase::GeneralFont);
@ -819,17 +829,27 @@ void Editor::updateLineAnnotationView()
int y = top;
if (breadcrumbs->isVisible()) y += breadcrumbs->geometry().height();
int x = static_cast<int>(document()->documentLayout()->blockBoundingRect(block).width());
int h = bottom - top;
if (wrapLines && block.layout() != nullptr) {
QFontMetrics fm(font());
x = static_cast<int>(block.layout()->lineAt(block.layout()->lineCount()-1).naturalTextWidth());
if (block.layout()->lineCount() > 1) {
y += h;
h = static_cast<int>(block.layout()->lineAt(block.layout()->lineCount()-1).height());
y -= h;
}
}
x += lineNumber->geometry().width() + lineMark->geometry().width();
x += ANNOTATION_LEFT_MARGIN;
QFontMetrics fm(font());
int tw = fm.width(static_cast<Annotation *>(lineAnnotation)->getText());
tw += bottom - top; // icon
tw += h; // icon
int bw = geometry().width() - lineMap->geometry().width();
bw -= ANNOTATION_RIGHT_MARGIN;
if (x + tw < bw) x += bw - x - tw;
if (horizontalScrollBar()->isVisible()) x -= horizontalScrollBar()->value();
lineAnnotation->move(x, y);
static_cast<Annotation *>(lineAnnotation)->setSize(tw, bottom - top);
static_cast<Annotation *>(lineAnnotation)->setSize(tw, h);
if (!lineAnnotation->isVisible()) static_cast<Annotation *>(lineAnnotation)->fadeIn();
return;
}
@ -1311,6 +1331,7 @@ void Editor::resizeEvent(QResizeEvent * e)
QTextEdit::resizeEvent(e);
hidePopups();
updateWidgetsGeometry();
updateLineAnnotationView();
if (static_cast<Search *>(search)->isVisible()) {
static_cast<Search *>(search)->updateScrollBar();
}
@ -5523,6 +5544,10 @@ void Editor::highlightCurrentLine(QList<QTextEdit::ExtraSelection> * extraSelect
selectedLineSelection.format.setProperty(QTextFormat::FullWidthSelection, true);
selectedLineSelection.cursor = textCursor();
selectedLineSelection.cursor.clearSelection();
if (selectedLineSelection.cursor.block().layout() != nullptr && selectedLineSelection.cursor.block().layout()->lineCount() > 1) {
selectedLineSelection.cursor.movePosition(QTextCursor::StartOfBlock);
selectedLineSelection.cursor.movePosition(QTextCursor::EndOfLine, QTextCursor::KeepAnchor);
}
extraSelections->append(selectedLineSelection);
}

View file

@ -52,6 +52,7 @@ Settings::Settings(QObject * parent) : QObject(parent)
{"editor_show_annotations", "yes"},
{"editor_parse_interval", "5000"},
{"editor_long_line_marker_enabled", "yes"},
{"editor_wrap_long_lines", "no"},
{"highlight_spaces", "no"},
{"highlight_tabs", "no"},
{"highlight_php_extensions", "php, phtml, tpl, html"},

View file

@ -77,6 +77,7 @@ SettingsDialog::SettingsDialog(Settings * settings, QWidget * parent):
else if (newLineMode == NEW_LINE_CR) ui->filesNewLineCRRadio->setChecked(true);
else if (newLineMode == NEW_LINE_CRLF) ui->filesNewLineCRLFRadio->setChecked(true);
if (settings->get("editor_clean_before_save") == CHECKED_YES) ui->filesCleanForSaveCheckbox->setChecked(true);
if (settings->get("editor_wrap_long_lines") == CHECKED_YES) ui->filesLongLineWrapCheckBox->setChecked(true);
if (settings->get("editor_breadcrumbs_enabled") == CHECKED_YES) ui->breadcrumbsCheckbox->setChecked(true);
if (settings->get("highlight_spaces") == CHECKED_YES) ui->highlightSpacesCheckbox->setChecked(true);
if (settings->get("editor_show_annotations") == CHECKED_YES) ui->editorAnnotationsCheckBox->setChecked(true);
@ -246,6 +247,9 @@ std::unordered_map<std::string, std::string> SettingsDialog::getData()
if (ui->editorLongLineMarkerCheckBox->isChecked()) dataMap["editor_long_line_marker_enabled"] = CHECKED_YES;
else dataMap["editor_long_line_marker_enabled"] = CHECKED_NO;
if (ui->filesLongLineWrapCheckBox->isChecked()) dataMap["editor_wrap_long_lines"] = CHECKED_YES;
else dataMap["editor_wrap_long_lines"] = CHECKED_NO;
QString projectTypes = "";
QString phpTypes = "";
QStringList phpTypesList = ui->phpTypesEdit->toPlainText().split("\n");

View file

@ -558,7 +558,7 @@
</widget>
<widget class="QWidget" name="filesSettingsTab">
<attribute name="title">
<string>Files</string>
<string>Document</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
@ -670,6 +670,26 @@
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="filesLongLineWrapLayout">
<property name="leftMargin">
<number>156</number>
</property>
<property name="topMargin">
<number>10</number>
</property>
<property name="bottomMargin">
<number>10</number>
</property>
<item>
<widget class="QCheckBox" name="filesLongLineWrapCheckBox">
<property name="text">
<string>Wrap long lines</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="filesCleanForSaveLayout">
<property name="leftMargin">