Add chapter navigation. Move some toolbar items to the menu on Maemo.
authorAkos Polster <polster@marzipan.pipacs.com>
Tue, 27 Jul 2010 21:03:23 +0000 (23:03 +0200)
committerAkos Polster <polster@marzipan.pipacs.com>
Tue, 27 Jul 2010 21:03:23 +0000 (23:03 +0200)
chaptersdialog.cpp [new file with mode: 0644]
chaptersdialog.h [new file with mode: 0644]
dorian.pro
dorian.qrc
icons/mac/chapters.png [new file with mode: 0755]
mainwindow.cpp
mainwindow.h
pkg/changelog

diff --git a/chaptersdialog.cpp b/chaptersdialog.cpp
new file mode 100644 (file)
index 0000000..a769421
--- /dev/null
@@ -0,0 +1,46 @@
+#include <QtGui>
+
+#include "chaptersdialog.h"
+#include "book.h"
+
+ChaptersDialog::ChaptersDialog(Book *b, QWidget *parent):
+    QMainWindow(parent), book(b)
+{
+#ifdef Q_WS_MAEMO_5
+    setAttribute(Qt::WA_Maemo5StackedWindow, true);
+#endif
+    setWindowTitle(tr("Bookmarks"));
+
+    QFrame *frame = new QFrame(this);
+    setCentralWidget(frame);
+    QHBoxLayout *horizontalLayout = new QHBoxLayout(this);
+    frame->setLayout(horizontalLayout);
+
+    list = new QListWidget(this);
+    list->setSelectionMode(QAbstractItemView::SingleSelection);
+    foreach (QString id, book->toc) {
+        QString contentTitle = book->content[id].name;
+        (void)new QListWidgetItem(contentTitle, list);
+    }
+    horizontalLayout->addWidget(list);
+    connect(list, SIGNAL(itemActivated(QListWidgetItem*)),
+            this, SLOT(onItemActivated(QListWidgetItem*)));
+
+#ifndef Q_WS_MAEMO_5
+    QDialogButtonBox *buttonBox = new QDialogButtonBox(Qt::Vertical);
+    QPushButton *closeButton = buttonBox->addButton(QDialogButtonBox::Close);
+    connect(closeButton, SIGNAL(clicked()), this, SLOT(onClose()));
+    horizontalLayout->addWidget(buttonBox);
+#endif // Q_WS_MAEMO_5
+}
+
+void ChaptersDialog::onItemActivated(QListWidgetItem *item)
+{
+    emit goToChapter(list->row(item));
+    close();
+}
+
+void ChaptersDialog::onClose()
+{
+    close();
+}
diff --git a/chaptersdialog.h b/chaptersdialog.h
new file mode 100644 (file)
index 0000000..018470f
--- /dev/null
@@ -0,0 +1,31 @@
+#ifndef CHAPTERSDIALOG_H
+#define CHAPTERSDIALOG_H
+
+#include <QMainWindow>
+
+class QWidget;
+class QListWidget;
+class QListWidgetItem;
+class Book;
+
+/** Display book chapters. */
+class ChaptersDialog: public QMainWindow
+{
+    Q_OBJECT
+
+public:
+    explicit ChaptersDialog(Book *book, QWidget *parent = 0);
+
+signals:
+    void goToChapter(int index);
+
+public slots:
+    void onItemActivated(QListWidgetItem *);
+    void onClose();
+
+protected:
+    Book *book;
+    QListWidget *list;
+};
+
+#endif // CHAPTERSDIALOG_H
index 18cd168..9bce40e 100644 (file)
@@ -18,7 +18,8 @@ SOURCES += \
     bookmarksdialog.cpp \
     sortedlibrary.cpp \
     bookmarkinfodialog.cpp \
-    dialog.cpp
+    dialog.cpp \
+    chaptersdialog.cpp
 
 HEADERS += \
     mainwindow.h \
@@ -42,7 +43,8 @@ HEADERS += \
     sortedlibrary.h \
     ncxhandler.h \
     bookmarkinfodialog.h \
-    dialog.h
+    dialog.h \
+    chaptersdialog.h
 
 RESOURCES += \
     dorian.qrc
index c716cf1..7a73617 100644 (file)
@@ -35,5 +35,7 @@
         <file>icons/settings-landscape.png</file>
         <file>icons/next-disabled.png</file>
         <file>icons/previous-disabled.png</file>
+        <file>icons/chapters.png</file>
+        <file>icons/mac/chapters.png</file>
     </qresource>
 </RCC>
diff --git a/icons/mac/chapters.png b/icons/mac/chapters.png
new file mode 100755 (executable)
index 0000000..d6c9669
Binary files /dev/null and b/icons/mac/chapters.png differ
index 4dc9466..aa956dd 100755 (executable)
@@ -18,6 +18,7 @@
 #include "settingswindow.h"
 #include "bookmarksdialog.h"
 #include "settings.h"
+#include "chaptersdialog.h"
 
 #ifdef DORIAN_TEST_MODEL
 #include "modeltest.h"
@@ -55,27 +56,34 @@ MainWindow::MainWindow(QWidget *parent):
 #if defined(Q_WS_X11) && !defined(Q_WS_MAEMO_5)
     toolBar->setIconSize(QSize(42, 42));
 #endif
+
     previousAction = addToolBarAction(view, SLOT(goPrevious()), "previous");
     nextAction = addToolBarAction(view, SLOT(goNext()), "next");
-    bookmarksAction = addToolBarAction(this, SLOT(showBookmarks()),
-                                       "bookmarks");
+    chaptersAction = addToolBarAction(this, SLOT(showChapters()), "chapters");
+    bookmarksAction = addToolBarAction(this, SLOT(showBookmarks()), "bookmarks");
+
 #ifdef Q_WS_MAEMO_5
-    infoAction = new QAction(this);
+    infoAction = menuBar()->addAction(tr("Book details"));
+    connect(infoAction, SIGNAL(triggered()), this, SLOT(showInfo()));
+    libraryAction = menuBar()->addAction(tr("Library"));
+    connect(libraryAction, SIGNAL(triggered()), this, SLOT(showLibrary()));
+    settingsAction = menuBar()->addAction(tr("Settings"));
+    connect(settingsAction, SIGNAL(triggered()), this, SLOT(showSettings()));
+    devToolsAction = menuBar()->addAction(tr("Developer"));
+    connect(devToolsAction, SIGNAL(triggered()), this, SLOT(showDevTools()));
 #else
     infoAction = addToolBarAction(this, SLOT(showInfo()), "document-properties");
-#endif
     libraryAction = addToolBarAction(this, SLOT(showLibrary()),
                                      "system-file-manager");
     settingsAction = addToolBarAction(this, SLOT(showSettings()),
                                       "preferences-system");
-#ifdef Q_WS_MAEMO_5
-    devToolsAction = new QAction(this);
-#else
     devToolsAction = addToolBarAction(this, SLOT(showDevTools()), "developer");
+#endif // Q_WS_MAEMO_5
+
     QFrame *frame = new QFrame(toolBar);
     frame->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
     toolBar->addWidget(frame);
-#endif
+
     fullScreenAction = addToolBarAction(this, SLOT(showFullScreen()),
                                         "view-fullscreen");
 
@@ -299,3 +307,21 @@ void MainWindow::onGoToBookmark(int index)
     Book *book = Library::instance()->book(mCurrent);
     view->goToBookmark(book->bookmarks()[index]);
 }
+
+void MainWindow::showChapters()
+{
+    Book *book = Library::instance()->book(mCurrent);
+    if (book) {
+        ChaptersDialog *chapters = new ChaptersDialog(book, this);
+        chapters->setWindowModality(Qt::WindowModal);
+        connect(chapters, SIGNAL(goToChapter(int)),
+                this, SLOT(onGoToChapter(int)));
+        chapters->show();
+    }
+}
+
+void MainWindow::onGoToChapter(int index)
+{
+    view->goToBookmark(Book::Bookmark(index, 0));
+}
+
index 3671cb2..8de1543 100755 (executable)
@@ -32,6 +32,8 @@ public slots:
     void onChapterLoadEnd(int index);
     void onAddBookmark();
     void onGoToBookmark(int index);
+    void showChapters();
+    void onGoToChapter(int index);
 
 protected:
 #ifdef Q_WS_MAEMO5
@@ -59,6 +61,7 @@ private:
     QAction *backwardAction;
     QAction *previousAction;
     QAction *nextAction;
+    QAction *chaptersAction;
     QToolBar *toolBar;
     QDialog *settings;
     DevTools *devTools;
index 4bcbc3f..3a7e927 100644 (file)
@@ -2,8 +2,10 @@ dorian (0.0.11-1) unstable; urgency=low
 
   * Facelift bookmark manager
   * Make Maemo friendly dialog box class
+  * Add chapter navigation
+  * Move some toobar items to menu items on Maemo
 
- -- Akos Polster <akos@pipacs.com>  Sun, 25 Jul 2010 20:00:00 +0200
+ -- Akos Polster <akos@pipacs.com>  Tue, 27 Jul 2010 20:00:00 +0200
 
 dorian (0.0.10-1) unstable; urgency=low