Bookmarks with notes, first attempt.
authorAkos Polster <polster@nolove.pipacs.com>
Sat, 23 Oct 2010 22:19:54 +0000 (00:19 +0200)
committerAkos Polster <polster@nolove.pipacs.com>
Sat, 23 Oct 2010 22:19:54 +0000 (00:19 +0200)
bookmarkinfodialog.cpp
bookmarksdialog.cpp
bookmarksdialog.h
bookview.cpp
bookview.h
mainwindow.cpp
mainwindow.h
model/book.cpp
model/book.h

index 847cd3b..7e9da91 100644 (file)
@@ -17,7 +17,10 @@ BookmarkInfoDialog::BookmarkInfoDialog(Book *b, int i, QWidget *parent):
     int chapterIndex = book->chapterFromPart(bookmark.part);
     if (chapterIndex != -1) {
         QString chapterId = book->chapters[chapterIndex];
-        label += ", in\n\"" + book->content[chapterId].name + "\"";
+        label += ", in\"" + book->content[chapterId].name + "\"";
+    }
+    if (!bookmark.note.isEmpty()) {
+        label += "\n" + bookmark.note;
     }
     QLabel *info = new QLabel(label, this);
     addWidget(info);
index fdfed5b..6e22e93 100644 (file)
@@ -28,7 +28,10 @@ BookmarksDialog::BookmarksDialog(Book *book_, QWidget *parent):
         int chapterIndex = book_->chapterFromPart(bookmark.part);
         if (chapterIndex != -1) {
             QString chapterId = book_->chapters[chapterIndex];
-            label += "\nIn \"" + book_->content[chapterId].name + "\"";
+            label += ", in \"" + book_->content[chapterId].name + "\"";
+        }
+        if (!bookmark.note.isEmpty()) {
+            label += "\n" + bookmark.note;
         }
         data.append(label);
     }
@@ -69,8 +72,14 @@ void BookmarksDialog::onItemActivated(const QModelIndex &index)
 
 void BookmarksDialog::onAdd()
 {
-    emit addBookmark();
-    close();
+    bool ok;
+    QString text = QInputDialog::getText(this, tr("Add bookmark"),
+                                         tr("Note:"), QLineEdit::Normal,
+                                         QString(), &ok);
+    if (ok) {
+        emit addBookmark(text);
+        close();
+    }
 }
 
 void BookmarksDialog::onDelete(bool really)
index e623d32..581d764 100644 (file)
@@ -19,7 +19,7 @@ public:
 
 signals:
     void goToBookmark(int index);
-    void addBookmark();
+    void addBookmark(const QString &note);
 
 public slots:
     void onGo();
index 2eda697..cd6ba22 100644 (file)
@@ -287,7 +287,7 @@ void BookView::wheelEvent(QWheelEvent *e)
     showProgress();
 }
 
-void BookView::addBookmark()
+void BookView::addBookmark(const QString &note)
 {
     Trace t("BookView::addBookmark");
     if (!mBook) {
@@ -296,7 +296,7 @@ void BookView::addBookmark()
     int y = page()->mainFrame()->scrollPosition().y();
     int height = page()->mainFrame()->contentsSize().height();
     qDebug() << ((qreal)y / (qreal)height);
-    mBook->addBookmark(contentIndex, (qreal)y / (qreal)height);
+    mBook->addBookmark(contentIndex, (qreal)y / (qreal)height, note);
     update();
 }
 
index f96d599..5c0e1cd 100644 (file)
@@ -25,7 +25,7 @@ public:
     void setBook(Book *book);
     Book *book();
     void goToBookmark(const Book::Bookmark &bookmark);
-    void addBookmark();
+    void addBookmark(const QString &note);
     void setLastBookmark();
     void restoreLastBookmark();
 
index 9d6bc53..675bdd4 100755 (executable)
@@ -290,7 +290,8 @@ void MainWindow::showBookmarks()
     if (book) {
         BookmarksDialog *bookmarks = new BookmarksDialog(book, this);
         bookmarks->setWindowModality(Qt::WindowModal);
-        connect(bookmarks, SIGNAL(addBookmark()), this, SLOT(onAddBookmark()));
+        connect(bookmarks, SIGNAL(addBookmark(const QString &)),
+                this, SLOT(onAddBookmark(const QString &)));
         connect(bookmarks, SIGNAL(goToBookmark(int)),
                 this, SLOT(onGoToBookmark(int)));
         bookmarks->show();
@@ -362,10 +363,10 @@ void MainWindow::onPartLoadEnd(int index)
 #endif // Q_WS_MAEMO_5
 }
 
-void MainWindow::onAddBookmark()
+void MainWindow::onAddBookmark(const QString &note)
 {
     Trace t("MainWindow:onAddBookmark");
-    view->addBookmark();
+    view->addBookmark(note);
 }
 
 void MainWindow::onGoToBookmark(int index)
index 416865f..3a40286 100755 (executable)
@@ -34,7 +34,7 @@ public slots:
     void onSettingsChanged(const QString &key);
     void onPartLoadStart();
     void onPartLoadEnd(int index);
-    void onAddBookmark();
+    void onAddBookmark(const QString &note);
     void onGoToBookmark(int index);
     void showChapters();
     void onGoToChapter(int index);
index 3b21603..f403769 100644 (file)
@@ -300,7 +300,8 @@ void Book::load()
     for (int i = 0; i < size; i++) {
         int part = data[QString("bookmark%1part").arg(i)].toInt();
         qreal pos = data[QString("bookmark%1pos").arg(i)].toReal();
-        mBookmarks.append(Bookmark(part, pos));
+        QString note = data[QString("bookmark%1note").arg(i)].toString();
+        mBookmarks.append(Bookmark(part, pos, note));
     }
 }
 
@@ -324,6 +325,7 @@ void Book::save()
     for (int i = 0; i < mBookmarks.size(); i++) {
         data[QString("bookmark%1part").arg(i)] = mBookmarks[i].part;
         data[QString("bookmark%1pos").arg(i)] = mBookmarks[i].pos;
+        data[QString("bookmark%1note").arg(i)] = mBookmarks[i].note;
     }
     BookDb::instance()->save(path(), data);
 }
@@ -342,9 +344,9 @@ Book::Bookmark Book::lastBookmark() const
     return Book::Bookmark(mLastBookmark);
 }
 
-void Book::addBookmark(int part, qreal position)
+void Book::addBookmark(int part, qreal position, const QString &note)
 {
-    mBookmarks.append(Bookmark(part, position));
+    mBookmarks.append(Bookmark(part, position, note));
     qSort(mBookmarks.begin(), mBookmarks.end());
     save();
 }
index 8639b07..49de447 100644 (file)
@@ -27,11 +27,13 @@ public:
     /** Bookmark: a volume index and a relative position in volume. */
     struct Bookmark
     {
-        Bookmark(int part_, qreal pos_): part(part_), pos(pos_) {}
+        Bookmark(int part_, qreal pos_, const QString &note_ = QString()):
+                part(part_), pos(pos_), note(note_) {}
         Bookmark(): part(0), pos(0.0) {}
         int part;
         qreal pos;
-        bool operator<(const Bookmark&other) const {
+        QString note;
+        bool operator<(const Bookmark &other) const {
             return (part == other.part)? (pos < other.pos): (part < other.part);
         }
     };
@@ -85,7 +87,7 @@ public:
     Bookmark lastBookmark() const;
 
     /** Add bookmark. */
-    void addBookmark(int part, qreal position);
+    void addBookmark(int part, qreal position, const QString &note);
 
     /** Delete bookmark. */
     void deleteBookmark(int index);