Skip to content

Commit

Permalink
Correctly manage tabulations in Kdenlive's titler
Browse files Browse the repository at this point in the history
  • Loading branch information
j-b-m committed Aug 25, 2024
1 parent 241081d commit 615f121
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 4 deletions.
33 changes: 30 additions & 3 deletions src/modules/qt/kdenlivetitle_wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,8 @@ class PlainTextItem : public QGraphicsItem
QColor outlineColor,
double outline,
int align,
int lineSpacing)
int lineSpacing,
int tabWidth)
: m_metrics(QFontMetrics(font))
{
m_boundingRect = QRectF(0, 0, width, height);
Expand All @@ -157,6 +158,7 @@ class PlainTextItem : public QGraphicsItem
m_lineSpacing = lineSpacing + m_metrics.lineSpacing();
m_align = align;
m_width = width;
m_tabWidth = tabWidth;
updateText(text);
}

Expand All @@ -172,7 +174,26 @@ class PlainTextItem : public QGraphicsItem
double linePos = m_metrics.ascent();
foreach (const QString &line, lines) {
QPainterPath linePath;
linePath.addText(0, linePos, m_font, line);
const QStringList tabLines = line.split(QLatin1Char('\t'));
if (m_tabWidth > 0 && tabLines.count() > 1) {
qreal pos = 0;
qreal currentPos = 0;
for (const QString &tline : tabLines) {
QPainterPath tabPath;
if (!tline.isEmpty()) {
tabPath.addText(pos, linePos, m_font, tline);
linePath.addPath(tabPath);
currentPos = pos + tabPath.boundingRect().width();
} else {
// Several chained tabs
currentPos = pos + m_tabWidth / 2;
}
int tabsCount = ceil(currentPos / m_tabWidth);
pos = tabsCount * m_tabWidth;
}
} else {
linePath.addText(0, linePos, m_font, line);
}
linePos += m_lineSpacing;
if (m_align == Qt::AlignHCenter) {
#if (QT_VERSION > QT_VERSION_CHECK(5, 11, 0))
Expand Down Expand Up @@ -259,6 +280,7 @@ class PlainTextItem : public QGraphicsItem
int m_lineSpacing;
int m_align;
double m_width;
int m_tabWidth;
QFontMetrics m_metrics;
double m_outline;
QStringList m_params;
Expand Down Expand Up @@ -405,6 +427,10 @@ void loadFromXml(producer_ktitle self,
if (txtProperties.namedItem("alignment").isNull() == false) {
align = txtProperties.namedItem("alignment").nodeValue().toInt();
}
int tabWidth = 0;
if (txtProperties.namedItem("tab-width").isNull() == false) {
tabWidth = txtProperties.namedItem("tab-width").nodeValue().toInt();
}

double boxWidth = 0;
double boxHeight = 0;
Expand Down Expand Up @@ -462,7 +488,8 @@ void loadFromXml(producer_ktitle self,
outlineColor,
txtProperties.namedItem("font-outline").nodeValue().toDouble(),
align,
txtProperties.namedItem("line-spacing").nodeValue().toInt());
txtProperties.namedItem("line-spacing").nodeValue().toInt(),
tabWidth);
if (txtProperties.namedItem("shadow").isNull() == false) {
QStringList values = txtProperties.namedItem("shadow").nodeValue().split(
";");
Expand Down
2 changes: 1 addition & 1 deletion src/modules/qt/producer_kdenlivetitle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ schema_version: 0.1
type: producer
identifier: kdenlivetitle
title: Kdenlive Titler
version: 3
version: 4
copyright: Marco Gittler, Jean-Baptiste Mardelle
creator: Marco Gittler, Jean-Baptiste Mardelle
license: LGPLv2.1
Expand Down

0 comments on commit 615f121

Please sign in to comment.