File indexing completed on 2024-12-22 04:40:13
0001 /* 0002 SPDX-FileCopyrightText: 2020-2022 Mladen Milinkovic <max@smoothware.net> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 #include "debug.h" 0007 0008 #include "helpers/common.h" 0009 0010 #include <QMetaEnum> 0011 #include <QStringBuilder> 0012 0013 using namespace SubtitleComposer; 0014 0015 0016 QString 0017 SubtitleComposer::propertyName(QTextFormat::Property key) 0018 { 0019 if(key >= QTextFormat::UserProperty) 0020 return $("UserProperty+") % QString::number(key - QTextFormat::UserProperty); 0021 const char *keyName = QMetaEnum::fromType<QTextFormat::Property>().valueToKey(static_cast<int>(key)); 0022 return keyName ? keyName : QString::number(key); 0023 } 0024 0025 QString 0026 SubtitleComposer::textFormatString(const QTextFormat &format) 0027 { 0028 QString res; 0029 const QMap<int, QVariant> &props = format.properties(); 0030 for(auto it = props.cbegin(); it != props.cend(); ++it) 0031 res.append(propertyName(QTextFormat::Property(it.key())) % QChar(':') % it.value().toString() % $("; ")); 0032 return res; 0033 } 0034 0035 QString 0036 SubtitleComposer::dumpFormatRanges(const QString &text, const QVector<QTextLayout::FormatRange> &ranges) 0037 { 0038 QString res; 0039 for(const QTextLayout::FormatRange &r: ranges) { 0040 res.append(QChar::LineFeed % QChar('"') % QString(text).mid(r.start, r.length) % QChar('"') % QChar::Space % textFormatString(r.format)); 0041 } 0042 return res; 0043 }