Skip to content
Extraits de code Groupes Projets
Sélectionner une révision Git
  • 7e72f8d58181f1c676372b2b13e786506d3f1067
  • master par défaut
  • script
  • new-devel
  • devel
  • timingView-edit
  • fix-mpv
7 résultats

Line.cc

Blame
  • Line.cc 2,47 Kio
    #include "Line.hh"
    #include "AssFactory.hh"
    
    using namespace Vivy::Ass;
    
    Line::Line(AssFactory *const factory, const QString &lineString)
        : assFactory(factory)
    {
        enum LineIndex : int {
            Layer   = 0, // int
            Start   = 1, // time
            End     = 2, // time
            Style   = 3, // text
            Name    = 4, // text
            MarginL = 5, // int
            MarginR = 6, // int
            MarginV = 7, // int
            Effect  = 8, // text
            Text    = 9, // text
            PastLastCode
    
            // NOTE: time is of the form: `h:mm:ss.cc`
        };
    
        static const QString lineHeader = "Dialogue: ";
        if (!lineString.startsWith(lineHeader))
            throw std::runtime_error(("invalid event line header: " + lineString).toStdString());
    
        const QString lineContent = lineString.mid(lineString.indexOf(": ") + 2 /* strlen ": " */);
        QStringList contentList   = lineContent.split(",", Qt::KeepEmptyParts, Qt::CaseInsensitive);
    
        if (contentList.size() < LineIndex::PastLastCode)
            throw std::runtime_error(("invalid number of items " + QString::number(contentList.size()) +
                                      " instead of something superiror or equal to " +
                                      QString::number(PastLastCode) + " for line: " + lineContent)
                                         .toStdString());
    
        layer  = Utils::decodeLineToInteger(contentList[LineIndex::Layer], "Layer is not an integer");
        effect = contentList[LineIndex::Effect];
        nameOrActor = contentList[LineIndex::Name];
        styleProperties.marginL =
            Utils::decodeLineToInteger(contentList[LineIndex::MarginL], "MarginL is not an integer");
        styleProperties.marginR =
            Utils::decodeLineToInteger(contentList[LineIndex::MarginR], "MarginR is not an integer");
        styleProperties.marginV =
            Utils::decodeLineToInteger(contentList[LineIndex::MarginV], "MarginV is not an integer");
    
        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);
    
        // Pop all but the text, it may contains `,` characters
        for (int i = 0; i < LineIndex::Text; ++i)
            contentList.removeFirst();
        ___contentAsText = contentList.join("");
    }
    
    void
    Line::setStart(quint64 s) noexcept
    {
        start = s;
        if (s > end)
            end = s;
    }
    
    void
    Line::setEnd(quint64 s) noexcept
    {
        end = s;
        if (start > s)
            start = s;
    }