aboutsummaryrefslogtreecommitdiff
path: root/afdnotebook.cc
diff options
context:
space:
mode:
Diffstat (limited to 'afdnotebook.cc')
-rw-r--r--afdnotebook.cc100
1 files changed, 31 insertions, 69 deletions
diff --git a/afdnotebook.cc b/afdnotebook.cc
index e3b024a..a1f8423 100644
--- a/afdnotebook.cc
+++ b/afdnotebook.cc
@@ -36,7 +36,7 @@ bool AfdNotebook::open(const QString &path)
void AfdNotebook::close()
{
_title.clear();
- _lastPage = _firstPage = PageAddress(0, 0, 0, 0, 0);
+ _lastPage = _firstPage = AfdPageAddress();
_pagesPerBook = 0;
_gfx.clear();
_pages.clear();
@@ -59,6 +59,33 @@ int AfdNotebook::numPages() const
return _pages.size();
}
+AfdPageAddress AfdNotebook::getPageAddress(int pageNum) const
+{
+ if (pageNum < 0 || pageNum >= _pages.size()) {
+ qWarning() << "Invalid page number:" << pageNum << "for notebook" << _title;
+ }
+ uint new_page = _firstPage.page() + pageNum;
+ return AfdPageAddress(_firstPage.section(), _firstPage.segment(), _firstPage.shelf(),
+ _firstPage.book() + new_page / _pagesPerBook,
+ new_page % _pagesPerBook);
+}
+
+int AfdNotebook::getPageNumber(const AfdPageAddress &addr) const
+{
+ if (addr.section() == _firstPage.section()
+ && addr.segment() == _firstPage.segment()
+ && addr.shelf() == _firstPage.shelf()) {
+ long firstPage = (_firstPage.book() * _pagesPerBook) + _firstPage.page();
+ long page = (addr.book() * _pagesPerBook) + addr.page() - firstPage;
+ if (page >= 0 && page < _pages.size()) {
+ return page;
+ }
+ }
+
+ qWarning() << "Invalid address for notebook" << _title;
+ return -1;
+}
+
QString AfdNotebook::getPageBackgroundName(int page) const
{
const Page& p = _pages.at(page);
@@ -167,43 +194,6 @@ bool AfdNotebook::readStrokes(const QString &penSerial, int page, StfReader::Str
return true;
}
-AfdNotebook::PageAddress::PageAddress(const QString &str)
-{
- QStringList parts = str.split('.');
- if (parts.count() == 5) {
- series = parts[0].toUInt();
- shelf = parts[1].toUInt();
- segment = parts[2].toUInt();
- book = parts[3].toUInt();
- page = parts[4].toUInt();
- } else if (parts.count() == 4) {
- series = 0;
- shelf = parts[0].toUInt();
- segment = parts[1].toUInt();
- book = parts[2].toUInt();
- page = parts[3].toUInt();
- } else {
- qWarning() << "Unknown page address syntax:" << str;
- }
-}
-
-QString AfdNotebook::PageAddress::toString() const
-{
- QStringList l;
- l.reserve(5);
-
- if (series) {
- l.append(QString::number(series));
- }
-
- l.append(QString::number(shelf));
- l.append(QString::number(segment));
- l.append(QString::number(book));
- l.append(QString::number(page));
-
- return l.join(".");
-}
-
QMap<QString, QString> AfdNotebook::parsePropertyList(QIODevice *dev)
{
QMap<QString, QString> result;
@@ -238,8 +228,8 @@ bool AfdNotebook::parseMainInfo()
_title = info["title"];
_guid = info["guid"].mid(3).toULongLong(0, 16);
- _firstPage = PageAddress(info["pagestart"]);
- _lastPage = PageAddress(info["pagestop"]);
+ _firstPage = AfdPageAddress(info["pagestart"]);
+ _lastPage = AfdPageAddress(info["pagestop"]);
_pagesPerBook = info.value("segment-pages-per-book", "108").toUInt();
return true;
@@ -333,7 +323,7 @@ bool AfdNotebook::findPenData()
foreach (QString pageName, pageDirs) {
pageName.remove('/');
qDebug() << " page data" << pageName;
- int pageNum = getPageNumber(PageAddress(pageName));
+ int pageNum = getPageNumber(AfdPageAddress(pageName));
if (pageNum < 0) continue;
QDir pageDir(dir.filePath(pageName));
@@ -358,9 +348,6 @@ bool AfdNotebook::findPenData()
stroke.file = penDir.filePath(strokeFile);
bool ok = true;
- qDebug() << " " << strokeFile.mid(2, 8) << strokeFile.mid(13, 8);
- qDebug() << " " << strokeFile.mid(2, 8).toUInt(0, 16) << strokeFile.mid(13, 8).toUInt(0, 16);
-
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);
@@ -378,28 +365,3 @@ bool AfdNotebook::findPenData()
return true;
}
-
-AfdNotebook::PageAddress AfdNotebook::getPageAddress(int page) const
-{
- PageAddress addr = _firstPage;
- Q_ASSERT(page >= 0);
- uint new_page = addr.page + page;
- addr.book += new_page / _pagesPerBook;
- addr.page = new_page % _pagesPerBook;
- return addr;
-}
-
-int AfdNotebook::getPageNumber(const PageAddress &addr)
-{
- // series(0), shelf(0), segment(0), book(0), page(0)
- if (addr.series == _firstPage.series && addr.shelf == _firstPage.shelf && addr.segment == _firstPage.segment) {
- int firstPage = (_firstPage.book * _pagesPerBook) + _firstPage.page;
- int page = (addr.book * _pagesPerBook) + addr.page - firstPage;
- if (page >= 0 && page < _pages.size()) {
- return page;
- }
- }
-
- qWarning() << "Invalid address for notebook" << _title;
- return -1;
-}