void Subtitle::setSecondaryData(const Subtitle &from, bool usePrimaryData) { beginCompositeAction(i18n("Set Secondary Data")); SubtitleIterator fromIt(from, Range::full()); SubtitleIterator thisIt(*this, Range::full()); // the errors that we are going to take from 'from': const int fromErrors = usePrimaryData ? SubtitleLine::PrimaryOnlyErrors : SubtitleLine::SecondaryOnlyErrors; // the errors that we are going to keep: const int thisErrors = SubtitleLine::PrimaryOnlyErrors | SubtitleLine::SharedErrors; for(SubtitleLine *fromLine = fromIt.current(), *thisLine = thisIt.current(); fromLine && thisLine; ++fromIt, ++thisIt, fromLine = fromIt.current(), thisLine = thisIt.current()) { thisLine->setSecondaryText(usePrimaryData ? fromLine->primaryText() : fromLine->secondaryText()); thisLine->setErrorFlags((thisLine->errorFlags() & thisErrors) | (fromLine->errorFlags() & fromErrors)); } if(fromIt.current()) { // from subtitle had more lines than *this QList<SubtitleLine *> lines; for(; fromIt.current(); ++fromIt) { SubtitleLine *thisLine = new SubtitleLine(*fromIt.current()); if(usePrimaryData) thisLine->setSecondaryText(thisLine->primaryText()); thisLine->setPrimaryText(SString()); thisLine->setErrorFlags(SubtitleLine::PrimaryOnlyErrors, false); lines.append(thisLine); } processAction(new InsertLinesAction(*this, lines)); } else if(thisIt.current()) { // *this had more lines than from subtitle for(SubtitleLine *thisLine = thisIt.current(); thisLine; ++thisIt, thisLine = thisIt.current()) { thisLine->setSecondaryText(SString()); thisLine->setErrorFlags(SubtitleLine::SecondaryOnlyErrors, false); } } endCompositeAction(); }
void Subtitle::setPrimaryData(const Subtitle &from, bool usePrimaryData) { beginCompositeAction(i18n("Set Primary Data")); setFormatData(from.m_formatData); setFramesPerSecond(from.framesPerSecond()); SubtitleIterator fromIt(from, Range::full()); SubtitleIterator thisIt(*this, Range::full()); // the errors that we are going to take from 'from': const int fromErrors = (usePrimaryData ? SubtitleLine::PrimaryOnlyErrors : SubtitleLine::SecondaryOnlyErrors) | SubtitleLine::SharedErrors; // the errors that we are going to keep: const int thisErrors = SubtitleLine::SecondaryOnlyErrors; for(SubtitleLine *fromLine = fromIt.current(), *thisLine = thisIt.current(); fromLine && thisLine; ++fromIt, ++thisIt, fromLine = fromIt.current(), thisLine = thisIt.current()) { thisLine->setPrimaryText(usePrimaryData ? fromLine->primaryText() : fromLine->secondaryText()); thisLine->setTimes(fromLine->showTime(), fromLine->hideTime()); thisLine->setErrorFlags((fromLine->errorFlags() & fromErrors) | (thisLine->errorFlags() & thisErrors)); thisLine->setFormatData(fromLine->formatData()); } if(fromIt.current()) { // 'from' had more lines than '*this' QList<SubtitleLine *> lines; for(; fromIt.current(); ++fromIt) { SubtitleLine *thisLine = new SubtitleLine(*fromIt.current()); if(!usePrimaryData) thisLine->setPrimaryText(thisLine->secondaryText()); thisLine->setSecondaryText(SString()); thisLine->setErrorFlags(SubtitleLine::SecondaryOnlyErrors, false); thisLine->setFormatData(fromIt.current()->formatData()); lines.append(thisLine); } InsertLinesAction a(*this, lines); processAction(&a); } else if(thisIt.current()) { // '*this' had more lines than 'from' for(SubtitleLine *thisLine = thisIt.current(); thisLine; ++thisIt, thisLine = thisIt.current()) { thisLine->setPrimaryText(SString()); thisLine->setErrorFlags(SubtitleLine::PrimaryOnlyErrors, false); thisLine->setFormatData(0); } } endCompositeAction(); }
SubtitleLine * Subtitle::insertNewLine(int index, bool timeAfter, TextTarget target) { Q_ASSERT(index <= m_lines.count()); if(index < 0) index = m_lines.count(); SubtitleLine *newLine = new SubtitleLine(); int newLineIndex = (target == Secondary) ? m_lines.count() : index; if(timeAfter) { if(newLineIndex) { // there is a previous line SubtitleLine *prevLine = m_lines.value(newLineIndex - 1); newLine->setTimes(prevLine->hideTime() + 100, prevLine->hideTime() + 1000); } else if(newLineIndex < m_lines.count()) { // there is a next line SubtitleLine *nextLine = m_lines.value(newLineIndex); newLine->setTimes(nextLine->showTime() - 1100, nextLine->showTime() - 100); } else newLine->setHideTime(1000); } else { // ! timeAfter if(newLineIndex < m_lines.count()) { // there is a next line SubtitleLine *nextLine = m_lines.at(newLineIndex); newLine->setTimes(nextLine->showTime() - 1100, nextLine->showTime() - 100); } else if(newLineIndex) { // there is a previous line SubtitleLine *prevLine = m_lines.at(newLineIndex - 1); newLine->setTimes(prevLine->hideTime() + 100, prevLine->hideTime() + 1000); } else newLine->setHideTime(1000); } if(target == Both || index == m_lines.count()) { insertLine(newLine, newLineIndex); } else if(target == Primary) { beginCompositeAction(i18n("Insert Line")); insertLine(newLine, newLineIndex); SubtitleLine *line = newLine; SubtitleIterator it(*this, Range::full(), false); for(it.toIndex(newLineIndex + 1); it.current(); ++it) { line->setSecondaryText(it.current()->secondaryText()); line = it.current(); } line->setSecondaryText(SString()); endCompositeAction(); } else if(target == Secondary) { beginCompositeAction(i18n("Insert Line")); insertLine(newLine, newLineIndex); SubtitleIterator it(*this, Range::full(), true); SubtitleLine *line = it.current(); for(--it; it.index() >= index; --it) { line->setSecondaryText(it.current()->secondaryText()); line = it.current(); } line->setSecondaryText(SString()); newLine = line; endCompositeAction(); } return newLine; }