Skip to content
Extraits de code Groupes Projets
Vérifiée Valider 6e4f1d4d rédigé par Kubat's avatar Kubat
Parcourir les fichiers

ASS: Construct the line with the style and its pointer and save the default text for debug purpose

parent 14038a5e
Aucune branche associée trouvée
Aucune étiquette associée trouvée
1 requête de fusion!7Add the ASS sub document and the ASS tree
......@@ -5,17 +5,9 @@
#include "Line.hh"
#include "Syl.hh"
#include "Style.hh"
#include "AssPrivate.hh"
#include "AssFactory.hh"
#include "StyleProperties.hh"
#include <memory.h>
namespace Vivy::Ass
{
using StylePtr = AssFactory::StylePtr;
using LinePtr = AssFactory::LinePtr;
using StyleWeakPtr = AssFactory::StyleWeakPtr;
using LineWeakPtr = AssFactory::LineWeakPtr;
}
#endif // VIVY_ASS_ASS_H
#include "AssFactory.hh"
#include <algorithm>
#include <stdexcept>
using namespace Vivy::Ass;
......@@ -118,7 +119,7 @@ AssFactory::AssFactory(const QString &fileName)
}
void
AssFactory::getStyles(QVector<AssFactory::StylePtr> &ret) const noexcept
AssFactory::getStyles(QVector<StylePtr> &ret) const noexcept
{
ret.clear();
for (const auto &style : assStyles)
......@@ -126,7 +127,7 @@ AssFactory::getStyles(QVector<AssFactory::StylePtr> &ret) const noexcept
}
void
AssFactory::getLines(QVector<AssFactory::LinePtr> &ret) const noexcept
AssFactory::getLines(QVector<LinePtr> &ret) const noexcept
{
ret.clear();
for (const auto &line : assLines)
......@@ -139,6 +140,21 @@ AssFactory::getInfoSection() const noexcept
return assInfo;
}
StyleWeakPtr
AssFactory::getStyle(const QString &name) const noexcept
{
auto findByName = [&name](const StylePtr &style) noexcept -> bool {
return style->getElementName() == name;
};
auto styleIt = std::find_if(std::begin(assStyles), std::end(assStyles), findByName);
if (styleIt != std::end(assStyles))
return StyleWeakPtr(*styleIt);
// Will be unable to lock
return StyleWeakPtr(spareNullStylePtr);
}
bool
AssFactory::hasStyle(const QString &name) const noexcept
{
......
......@@ -4,6 +4,7 @@
#include "../Utils.hh"
#include "Style.hh"
#include "Line.hh"
#include "AssPrivate.hh"
#include <memory.h>
#include <QFile>
......@@ -26,10 +27,6 @@ public:
Events = 3,
};
using LinePtr = std::shared_ptr<Line>;
using StylePtr = std::shared_ptr<Style>;
using LineWeakPtr = std::weak_ptr<Line>;
using StyleWeakPtr = std::weak_ptr<Style>;
using SectionContent = QMap<QString, QVariant>;
private:
......@@ -38,6 +35,8 @@ private:
QVector<LinePtr> assLines{};
QVector<StylePtr> assStyles{};
StylePtr spareNullStylePtr{ nullptr };
static inline const QString sectionScriptInfo = "Script Info";
static inline const QString sectionStyles = "V4+ Styles";
static inline const QString sectionEvents = "Events";
......@@ -60,6 +59,7 @@ public:
~AssFactory() noexcept = default;
bool hasStyle(const QString &) const noexcept;
StyleWeakPtr getStyle(const QString &) const noexcept;
SectionContent getInfoSection() const noexcept;
void getStyles(QVector<StylePtr> &) const noexcept;
......
#pragma once
#include <memory>
namespace Vivy::Ass
{
class Style;
class Line;
using StylePtr = std::shared_ptr<Style>;
using LinePtr = std::shared_ptr<Line>;
using StyleWeakPtr = std::weak_ptr<Style>;
using LineWeakPtr = std::weak_ptr<Line>;
}
......@@ -38,6 +38,7 @@ Line::Line(AssFactory *const factory, const QString &lineString)
layer = Utils::decodeLineToInteger(contentList[LineIndex::Layer], "Layer is not an integer");
effect = contentList[LineIndex::Effect];
nameOrActor = contentList[LineIndex::Name];
___contentAsText = lineContent[LineIndex::Text];
styleProperties.marginL =
Utils::decodeLineToInteger(contentList[LineIndex::MarginL], "MarginL is not an integer");
styleProperties.marginR =
......@@ -48,6 +49,7 @@ Line::Line(AssFactory *const factory, const QString &lineString)
const QString style = contentList[LineIndex::Style];
if (!assFactory->hasStyle(style))
throw std::runtime_error(("Invalid or not declared style name: " + style).toStdString());
lineStyle = assFactory->getStyle(style);
}
void
......
......@@ -5,12 +5,13 @@
#include <QtGlobal>
#include "Syl.hh"
#include "StyleProperties.hh"
#include "Style.hh"
namespace Vivy::Ass
{
class AssFactory;
class Line {
class Line final {
private:
quint64 start{ 0 };
quint64 end{ 0 };
......@@ -20,6 +21,9 @@ private:
StyleProperties styleProperties{};
QString effect{};
QString nameOrActor{};
StyleWeakPtr lineStyle;
QString ___contentAsText;
AssFactory *const assFactory;
......
......@@ -6,6 +6,7 @@
#include <QtGlobal>
#include <QColor>
#include <QObject>
#include "AssPrivate.hh"
namespace Vivy::Ass
{
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Veuillez vous inscrire ou vous pour commenter