Kleo::ProgressDialog::ProgressDialog(Job *job, const QString &baseText, QWidget *creator, const char *name, WFlags f) : QProgressDialog(creator, name, false, f), mBaseText(baseText) { assert(job); setBar(new ProgressBar(this, "replacement progressbar in Kleo::ProgressDialog")); setMinimumDuration(2000 /*ms*/); setAutoReset(false); setAutoClose(false); setLabelText(baseText); setProgress(0, 0); // activate busy indicator connect(job, SIGNAL(progress(const QString &, int, int)), SLOT(slotProgress(const QString &, int, int))); connect(job, SIGNAL(done()), SLOT(slotDone())); connect(this, SIGNAL(canceled()), job, SLOT(slotCancel())); QTimer::singleShot(minimumDuration(), this, SLOT(forceShow())); }
bool LyricJson::loadLRC(const QString& path, const QString& musicPath) { QFile infile(path); if (!infile.open(QIODevice::ReadOnly | QIODevice::Text)) { return false; } _song.Clear(); auto settings = Settings::getInstance(); _song.general.maxline = 2; // always 2 ? while (!infile.atEnd()) { QByteArray lineByte = infile.readLine(); QString line = QString::fromStdString(lineByte.toStdString()).trimmed(); if (!line.startsWith("[")) { continue; } if (!line.contains("]")) { continue; } int indexOfClose = line.indexOf("]"); QString controlPart = line.mid(1, indexOfClose - 1).trimmed(); if (controlPart.startsWith("ti:")) { _song.info.title = controlPart.right(controlPart.length() - 3); // no trim } else if (controlPart.startsWith("au:")) { _song.info.author = controlPart.right(controlPart.length() - 3); // no trim } else if (controlPart.startsWith("ar:")) { _song.info.artist = controlPart.right(controlPart.length() - 3); // no trim } else if (controlPart.startsWith("al:")) { _song.info.album = controlPart.right(controlPart.length() - 3); // no trim } else if (controlPart.startsWith("by:")) { _song.info.by = controlPart.right(controlPart.length() - 3); // no trim } else if (controlPart.startsWith("offset:")) { _song.general.offset = controlPart.right(controlPart.length() - 7).toLongLong(); } else if (controlPart.at(0).isDigit()) { QTime beginTime = QTime::fromString(controlPart + "0", "mm:ss.zzz"); qint64 begin = beginTime.msecsSinceStartOfDay(); KJsonSentence sentence; KJsonWord word; word.begin = begin; word.end = begin + settings->maximumDuration(); //std::numeric_limits<qint64>::max(); word.text = line.right(line.length() - indexOfClose - 1); if (word.text.isEmpty()) { int thisIndex = _song.lyric.sentencelist.count(); if (thisIndex % _song.general.maxline == 0) { // skip continue; } else { // move up // skip multiple whites if (_song.lyric.sentencelist.last().wordlist.last().begin < 0) { continue; } else { word.end = word.begin + settings->minimumDuration(); } } } if (!_song.lyric.sentencelist.empty()) { KJsonWord& lastword = _song.lyric.sentencelist.last().wordlist.last(); if (lastword.end - lastword.begin> settings->minimumDuration()) { lastword.end = begin;// - lastword.begin; } } sentence.wordlist.append(word); _song.lyric.sentencelist.append(sentence); } } KJsonSong songCopy = _song; // first generate weak version treatSentecesAsControl(); QString jsonPath = Settings::getInstance()->makeJsonPath(path, false); exportToJson(jsonPath); _song = songCopy; lrcWordSeparate(); exportToASS(Settings::getInstance()->makeASSPath(path), musicPath); return loadJson(jsonPath); }
void Kleo::ProgressDialog::setMinimumDuration(int ms) { if(0 < ms && ms < minimumDuration()) QTimer::singleShot(ms, this, SLOT(forceShow())); QProgressDialog::setMinimumDuration(ms); }