diff options
Diffstat (limited to 'afdnotebook.cc')
-rw-r--r-- | afdnotebook.cc | 66 |
1 files changed, 31 insertions, 35 deletions
diff --git a/afdnotebook.cc b/afdnotebook.cc index eaff949..8b90619 100644 --- a/afdnotebook.cc +++ b/afdnotebook.cc @@ -121,6 +121,8 @@ QPixmap AfdNotebook::getPageBackground(int page) const QString file = QString("userdata/lsac_data/%1.png").arg(p.gfx->basename); QImage img; + qDebug() << "Loading page background " << file; + if (!img.load(_dir.filePath(file), "PNG")) { qWarning() << "Could not load background file:" << _dir.absoluteFilePath(file); return pix; @@ -168,7 +170,7 @@ QList<int> AfdNotebook::pagesWithStrokes(const QString &penSerial) const { if (_penData.contains(penSerial)) { const PenData &data = _penData[penSerial]; - return data.strokes.uniqueKeys(); + return data.strokes.keys(); } else { return QList<int>(); } @@ -180,36 +182,16 @@ QStringList AfdNotebook::strokeFiles(const QString &penSerial, int page) const if (!_penData.contains(penSerial)) return l; const PenData &data = _penData[penSerial]; - QMultiMap<int, StrokeData>::const_iterator it = data.strokes.find(page); - while (it != data.strokes.end() && it.key() == page) { - const StrokeData &stroke = it.value(); - l.append(_dir.filePath(stroke.file)); - ++it; - } - - return l; -} - -bool AfdNotebook::readStrokes(const QString &penSerial, int page, StfReader::StrokeHandler *handler) -{ - if (!_penData.contains(penSerial)) return true; - - StfReader stf; - stf.setStrokeHandler(handler); - - const PenData &data = _penData[penSerial]; - QMultiMap<int, StrokeData>::const_iterator it = data.strokes.find(page); - while (it != data.strokes.end() && it.key() == page) { - const StrokeData &stroke = it.value(); - qDebug() << "Reading strokes from" << stroke.file; - if (!stf.parse(_dir.filePath(stroke.file))) { - qWarning() << "Could not parse stroke file" << stroke.file; - return false; + auto it = data.strokes.find(page); + if (it != data.strokes.end()) { + const QList<StrokeData>& strokes = it.value(); + l.reserve(strokes.size()); + foreach (const StrokeData &stroke, strokes) { + l.append(_dir.filePath(stroke.file)); } - ++it; } - return true; + return l; } QMap<QString, QString> AfdNotebook::parsePropertyList(QIODevice *dev) @@ -318,12 +300,12 @@ bool AfdNotebook::parseGfx(const QString &file) if (!r.atEnd()) { QXmlStreamAttributes attrs = r.attributes(); QString imageSrc = attrs.value("src").toString(); - qDebug() << "image src" << imageSrc; + qDebug() << " image src" << imageSrc; int lastSlash = imageSrc.lastIndexOf('/'); int lastDot = imageSrc.lastIndexOf('.'); if (lastSlash >= 0 && lastDot > lastSlash) { gfx.basename = imageSrc.mid(lastSlash + 1, lastDot - lastSlash - 1); - qDebug() << "Got gfx" << gfx.basename; + qDebug() << " gfx" << gfx.basename; } } @@ -353,12 +335,14 @@ bool AfdNotebook::findPenData() QDir penDir(pageDir.filePath(penName)); if (!penDir.exists()) continue; + PenData& penData = _penData[penName]; + QStringList strokeFiles = penDir.entryList(QStringList("*.stf"), QDir::Files); foreach (const QString &strokeFile, strokeFiles) { qDebug() << " stroke data" << strokeFile; if (strokeFile.length() != 25) { - qWarning() << "Invalid stroke filename format" << strokeFile << endl; + qWarning() << "Invalid stroke filename format" << strokeFile; continue; } @@ -366,17 +350,29 @@ bool AfdNotebook::findPenData() stroke.file = penDir.filePath(strokeFile); bool ok = true; - if (ok) stroke.begin = Smartpen::fromPenTime(strokeFile.mid(2, 8).toLongLong(&ok, 16) * 1000ULL); - if (ok) stroke.end = Smartpen::fromPenTime(strokeFile.mid(13, 8).toLongLong(&ok, 16) * 1000ULL); + if (ok) stroke.begin = strokeFile.mid(2, 8).toLongLong(&ok, 16) * 1000ULL; + if (ok) stroke.end = strokeFile.mid(13, 8).toLongLong(&ok, 16) * 1000ULL; if (!ok) { - qWarning() << "Invalid stroke filename format" << strokeFile << endl; + qWarning() << "Invalid stroke filename format" << strokeFile; continue; } qDebug() << " from" << stroke.begin << "to" << stroke.end; - _penData[penName].strokes.insert(pageNum, stroke); + penData.strokes[pageNum].append(stroke); + } + + // Sort all the stroke files in each page by starting time + auto it = penData.strokes.begin(); + while (it != penData.strokes.end()) { + QList<StrokeData> &strokes = *it; + if (!strokes.isEmpty()) { + std::sort(strokes.begin(), strokes.end(), StrokeData::CompareByBeginTime); + ++it; + } else { + it = penData.strokes.erase(it); + } } } } |