Főoldal | Osztályhierarchia | Osztálylista | Fájllista | Osztálytagok | Fájlelemek | Kapcsolódó lapok

subtitle.cc

00001 /*
00002  * SubTimer source file
00003  *  Copyright (C) 2005 Peter Salvi
00004  *   Last modification: <2005.03.23., 16:20:07>
00005  *
00006  *  This program is free software; you can redistribute it and/or modify
00007  *  it under the terms of the GNU General Public License as published by
00008  *  the Free Software Foundation; either version 2 of the License, or
00009  *  (at your option) any later version.
00010  *
00011  *  This program is distributed in the hope that it will be useful,
00012  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  *  GNU General Public License for more details.
00015  *
00016  *  You should have received a copy of the GNU General Public License
00017  *  along with this program; if not, write to the Free Software
00018  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00019  */
00020 
00021 #include "subtitle.hh"
00022 
00023 SubTitle::SubTitle()
00024 {
00025   line_count = 0;
00026 }
00027 
00028 SubTitle::SubTitle(SubTitle const *s)
00029 {
00030   line_count = s->line_count;
00031   for(std::vector<Event *>::const_iterator ei = s->events.begin();
00032       ei != s->events.end(); ++ei) {
00033     Event *e = new Event;
00034     e->start = (*ei)->start;
00035     e->end = (*ei)->end;
00036     e->name = (*ei)->name;
00037     e->dialogue = (*ei)->dialogue;
00038     events.push_back(e);
00039   }
00040 }
00041 
00042 SubTitle::~SubTitle()
00043 {
00044 }
00045 
00046 size_t SubTitle::count() const 
00047 { 
00048   return line_count; 
00049 }
00050 
00051 SubTitle::Event *SubTitle::operator[](size_t const i) const 
00052 { 
00053   return events[i]; 
00054 }
00055 
00056 void SubTitle::insertBefore(size_t const i, Event *e)
00057 {
00058   std::vector<Event *>::iterator ei = events.begin();
00059   advance(ei, i);
00060   events.insert(ei, e);
00061   ++line_count;
00062 }
00063 
00064 void SubTitle::insertAfter(size_t const i, Event *e)
00065 {
00066   std::vector<Event *>::iterator ei = events.begin();
00067   advance(ei, i+1);
00068   events.insert(ei, e);
00069   ++line_count;
00070 }
00071 
00072 void SubTitle::erase(size_t const i)
00073 {
00074   std::vector<Event *>::iterator ei = events.begin();
00075   advance(ei, i);
00076   delete *ei;
00077   events.erase(ei);
00078   --line_count;
00079 }
00080 
00081 void SubTitle::eraseAll()
00082 {
00083   for(std::vector<Event *>::iterator ei = events.begin();
00084       ei != events.end(); ++ei)
00085     delete *ei;
00086   events.clear();
00087   line_count = 0;
00088 }
00089 
00090 bool SubTitle::extractTime(QString const str, QTime &t, 
00091                            bool const srt_style) const
00092 {
00093   bool ok = true;
00094   unsigned int h, m, s, z;
00095 
00096   if(srt_style) {
00097     if(sscanf(str, "%2d:%2d:%2d,%3d", &h, &m, &s, &z) != 4) 
00098       ok = false;
00099     else
00100       t = QTime(h, m, s, z);
00101   } else {
00102     if(sscanf(str, "%2d:%2d:%2d.%2d", &h, &m, &s, &z) != 4) 
00103       ok = false;
00104     else
00105       t = QTime(h, m, s, 10 * z);
00106   }
00107   return ok;
00108 }

Projekt: SubTimer Készült: Wed Mar 23 22:06:54 2005 Készítette: doxygen 1.3.6