save();
}
+void Book::deleteBookmark(int index)
+{
+ mBookmarks.removeAt(index);
+ save();
+}
+
QList<Book::Bookmark> Book::bookmarks() const
{
return mBookmarks;
/** Add bookmark. */
void addBookmark(int chapter, qreal position);
+ /** Delete bookmark. */
+ void deleteBookmark(int index);
+
/** List bookmarks. */
QList<Bookmark> bookmarks() const;
--- /dev/null
+#include <QtGui>
+
+#include "bookmarkinfodialog.h"
+#include "book.h"
+
+BookmarkInfoDialog::BookmarkInfoDialog(Book *b, int i, QWidget *parent):
+ Dialog(parent),
+ book(b),
+ index(i)
+{
+ setWindowTitle(tr("Bookmark Details"));
+
+ Book::Bookmark bookmark = book->bookmarks()[index];
+ QString contentId = book->toc[bookmark.chapter];
+ QString contentTitle = book->content[contentId].name;
+ QLabel *info = new QLabel(contentTitle + "\nAt " +
+ QString::number((int)(bookmark.pos*100)) + "%", this);
+ addWidget(info);
+ addStretch();
+
+ QPushButton *read = new QPushButton(tr("Go to"), this);
+ QPushButton *remove = new QPushButton(tr("Delete"), this);
+ connect(read, SIGNAL(clicked()), this, SLOT(onRead()));
+ connect(remove, SIGNAL(clicked()), this, SLOT(onRemove()));
+ addButton(read, QDialogButtonBox::ActionRole);
+ addButton(remove, QDialogButtonBox::ActionRole);
+}
+
+void BookmarkInfoDialog::onRead()
+{
+ done(GoTo);
+}
+
+void BookmarkInfoDialog::onRemove()
+{
+ done(Delete);
+}
--- /dev/null
+#ifndef BOOKMARKINFODIALOG_H
+#define BOOKMARKINFODIALOG_H
+
+#include "dialog.h"
+
+class Book;
+
+class BookmarkInfoDialog: public Dialog
+{
+ Q_OBJECT
+
+public:
+ enum {GoTo = 1, Delete};
+ explicit BookmarkInfoDialog(Book *b, int i, QWidget *parent);
+
+public slots:
+ void onRead();
+ void onRemove();
+
+protected:
+ Book *book;
+ int index;
+};
+
+
+#endif // BOOKMARKINFODIALOG_H
#include "bookmarksdialog.h"
#include "book.h"
+#include "bookmarkinfodialog.h"
BookmarksDialog::BookmarksDialog(Book *book_, QWidget *parent):
- QDialog(parent, Qt::Dialog | Qt::WindowTitleHint |
- Qt::CustomizeWindowHint | Qt::WindowCloseButtonHint)
+ QMainWindow(parent), book(book_)
{
- setWindowTitle(tr("Bookmarks"));
-#ifndef Q_WS_MAEMO_5
- setSizeGripEnabled(true);
+#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 (Book::Bookmark bookmark, book_->bookmarks()) {
QString contentId = book_->toc[bookmark.chapter];
QString contentTitle = book_->content[contentId].name;
- list->addItem(contentTitle + ", at " +
- QString::number((int)(bookmark.pos * 100)) + "%");
+ (void)new QListWidgetItem(QIcon(":icons/bookmark.png"), contentTitle +
+ "\nAt " + QString::number((int)(bookmark.pos*100)) + "%", list);
}
- QHBoxLayout *horizontalLayout = new QHBoxLayout(this);
horizontalLayout->addWidget(list);
- QDialogButtonBox *buttonBox = new QDialogButtonBox(Qt::Vertical);
#ifndef Q_WS_MAEMO_5
+ QDialogButtonBox *buttonBox = new QDialogButtonBox(Qt::Vertical);
+
QPushButton *goButton = new QPushButton(tr("Go"), this);
- buttonBox->addButton(goButton, QDialogButtonBox::AcceptRole);
+ buttonBox->addButton(goButton, QDialogButtonBox::ActionRole);
connect(goButton, SIGNAL(clicked()), this, SLOT(onGo()));
-#endif
+
+ QPushButton *closeButton = new QPushButton(tr("Close"), this);
+ buttonBox->addButton(closeButton, QDialogButtonBox::AcceptRole);
+ connect(closeButton, SIGNAL(clicked()), this, SLOT(onClose()));
+
QPushButton *addButton = new QPushButton(tr("Add"), this);
buttonBox->addButton(addButton, QDialogButtonBox::ActionRole);
connect(addButton, SIGNAL(clicked()), this, SLOT(onAdd()));
- horizontalLayout->addWidget(buttonBox);
+ QPushButton *deleteButton = new QPushButton(tr("Delete"), this);
+ buttonBox->addButton(deleteButton, QDialogButtonBox::DestructiveRole);
+ connect(deleteButton, SIGNAL(clicked()), this, SLOT(onDelete()));
-#ifdef Q_WS_MAEMO_5
+ horizontalLayout->addWidget(buttonBox);
+#else
+ QAction *addBookmarkAction = menuBar()->addAction(tr("Add bookmark"));
+ connect(addBookmarkAction, SIGNAL(triggered()), this, SLOT(onAdd()));
+#endif // Q_WS_MAEMO_5
connect(list, SIGNAL(itemActivated(QListWidgetItem *)),
this, SLOT(onItemActivated(QListWidgetItem *)));
-#endif
}
void BookmarksDialog::onGo()
{
- if (list->selectedItems().isEmpty()) {
- return;
+ if (!list->selectedItems().isEmpty()) {
+ QListWidgetItem *item = list->selectedItems()[0];
+ emit goToBookmark(list->row(item));
+ close();
}
- QListWidgetItem *item = list->selectedItems()[0];
- int index = list->row(item) + 1;
- done(index);
}
void BookmarksDialog::onItemActivated(QListWidgetItem *item)
{
- done(list->row(item) + 1);
+ switch ((new BookmarkInfoDialog(book, list->row(item), this))->exec()) {
+ case BookmarkInfoDialog::GoTo:
+ onGo();
+ break;
+ case BookmarkInfoDialog::Delete:
+ onDelete();
+ break;
+ default:
+ ;
+ }
}
void BookmarksDialog::onAdd()
{
- done(-1);
+ emit addBookmark();
+ close();
+}
+
+void BookmarksDialog::onClose()
+{
+ close();
+}
+
+void BookmarksDialog::onDelete()
+{
+ if (!list->selectedItems().isEmpty()) {
+ QListWidgetItem *item = list->selectedItems()[0];
+ int row = list->row(item);
+ book->deleteBookmark(row);
+ delete item;
+ }
+}
+
+void BookmarksDialog::closeEvent(QCloseEvent *event)
+{
+#ifdef Q_WS_MAEMO_5
+ menuBar()->clear();
+#endif
+ event->accept();
}
#ifndef BOOKMARKSDIALOG_H
#define BOOKMARKSDIALOG_H
-#include <QDialog>
+#include <QMainWindow>
+class QCloseEvent;
class Book;
class QListWidget;
class QListWidgetItem;
/** Dialog box managing bookmarks. */
-class BookmarksDialog: public QDialog
+class BookmarksDialog: public QMainWindow
{
Q_OBJECT
explicit BookmarksDialog(Book *book, QWidget *parent = 0);
signals:
+ void goToBookmark(int index);
+ void addBookmark();
public slots:
void onGo();
void onAdd();
void onItemActivated(QListWidgetItem *);
+ void onClose();
+ void onDelete();
protected:
+ void closeEvent(QCloseEvent *e);
Book *book;
QListWidget *list;
};
--- /dev/null
+#include <QtGui>
+
+#include "dialog.h"
+
+Dialog::Dialog(QWidget *parent) :
+ QDialog(parent, Qt::Dialog | Qt::WindowTitleHint |
+ Qt::CustomizeWindowHint | Qt::WindowCloseButtonHint)
+{
+ scroller = new QScrollArea(this);
+
+#ifdef Q_WS_MAEMO_5
+ scroller->setProperty("FingerScrollable", true);
+ scroller->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
+#else
+ scroller->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
+#endif
+ scroller->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
+ scroller->setFrameStyle(QFrame::NoFrame);
+
+ content = new QWidget(scroller);
+ contentLayout = new QVBoxLayout(content);
+ contentLayout->setMargin(0);
+ content->setLayout(contentLayout);
+
+ buttonBox = new QDialogButtonBox(Qt::Vertical, this);
+ QHBoxLayout *horizontalLayout = new QHBoxLayout(this);
+ horizontalLayout->addWidget(scroller);
+ horizontalLayout->addWidget(buttonBox);
+ setLayout(horizontalLayout);
+
+ scroller->setWidget(content);
+ content->show();
+ scroller->setWidgetResizable(true);
+}
+
+void Dialog::addWidget(QWidget *widget)
+{
+ contentLayout->addWidget(widget);
+}
+
+void Dialog::addStretch(int stretch)
+{
+ contentLayout->addStretch(stretch);
+}
+
+void Dialog::addButton(QPushButton *button, QDialogButtonBox::ButtonRole role)
+{
+ buttonBox->addButton(button, role);
+}
--- /dev/null
+#ifndef DIALOG_H
+#define DIALOG_H
+
+#include <QDialog>
+#include <QDialogButtonBox>
+
+class QWidget;
+class QPushButton;
+class QScrollArea;
+class QVBoxLayout;
+
+/** Maemo- and Mac-friendly dialog box. */
+class Dialog: public QDialog
+{
+ Q_OBJECT
+
+public:
+ explicit Dialog(QWidget *parent = 0);
+
+ /** Add widget to the scrollable content pane. */
+ void addWidget(QWidget *widget);
+
+ /** Add stretch to the scrollable content pane. */
+ void addStretch(int stretch = 0);
+
+ /** Add button to the dialog button box. */
+ void addButton(QPushButton *button,
+ QDialogButtonBox::ButtonRole role = QDialogButtonBox::AcceptRole);
+
+protected:
+ QScrollArea *scroller;
+ QWidget *content;
+ QVBoxLayout *contentLayout;
+ QDialogButtonBox *buttonBox;
+};
+
+#endif // DIALOG_H
extractzip.cpp \
library.cpp \
book.cpp \
- info.cpp \
librarydialog.cpp \
devtools.cpp \
infodialog.cpp \
settingswindow.cpp \
settings.cpp \
bookmarksdialog.cpp \
- sortedlibrary.cpp
+ sortedlibrary.cpp \
+ bookmarkinfodialog.cpp \
+ dialog.cpp
HEADERS += \
mainwindow.h \
extractzip.h \
library.h \
book.h \
- info.h \
librarydialog.h \
devtools.h \
infodialog.h \
xmlerrorhandler.h \
containerhandler.h \
sortedlibrary.h \
- ncxhandler.h
+ ncxhandler.h \
+ bookmarkinfodialog.h \
+ dialog.h
RESOURCES += \
dorian.qrc
+++ /dev/null
-#include <QtGui>
-#include <QDebug>
-
-#include "info.h"
-#include "book.h"
-
-Info::Info(Book *book, QWidget *parent): QScrollArea(parent)
-{
-#ifdef Q_WS_MAEMO_5
- setProperty("FingerScrollable", true);
- setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
-#else
- setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
-#endif
- setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
- setFrameStyle(QFrame::NoFrame);
-
- QWidget *contents = new QWidget(this);
- QVBoxLayout *layout = new QVBoxLayout(contents);
- layout->setMargin(0);
- contents->setLayout(layout);
-
- if (book) {
- QLabel *title = new QLabel(book->title, contents);
- layout->addWidget(title);
- if (book->subject != "") {
- QLabel *subject = new QLabel(book->subject, contents);
- layout->addWidget(subject);
- }
- if (book->creators.size()) {
- QLabel *creators = new QLabel(contents);
- QString c = "By " + book->creators[0];
- for (int i = 1; i < book->creators.size(); i++) {
- c += ", " + book->creators[i];
- }
- creators->setText(c);
- layout->addWidget(creators);
- }
- QLabel *path = new QLabel("File: " + book->path(), contents);
- layout->addWidget(path);
- if (book->publisher != "") {
- QLabel *publisher =
- new QLabel("Published by " + book->publisher, contents);
- layout->addWidget(publisher);
- }
- if (book->source != "") {
- QLabel *source = new QLabel("Source: " + book->source, contents);
- layout->addWidget(source);
- }
- if (book->rights != "") {
- QLabel *rights = new QLabel(book->rights, contents);
- layout->addWidget(rights);
- }
- }
-
- layout->addStretch();
- setWidget(contents);
- contents->show();
- setWidgetResizable(true);
-}
+++ /dev/null
-#ifndef INFO_H
-#define INFO_H
-
-#include <QScrollArea>
-
-class QLabel;
-class Book;
-
-class Info: public QScrollArea
-{
- Q_OBJECT
-
-public:
- explicit Info(Book *book, QWidget *parent = 0);
-
-private:
- QLabel *title;
- QLabel *path;
- QLabel *creators;
-};
-
-#endif // INFO_H
#include <QtGui>
#include "infodialog.h"
-#include "info.h"
#include "book.h"
#include "library.h"
-InfoDialog::InfoDialog(Book *book_, QWidget *parent):
- QDialog(parent, Qt::Dialog | Qt::WindowTitleHint |
- Qt::CustomizeWindowHint | Qt::WindowCloseButtonHint),
- book(book_)
+InfoDialog::InfoDialog(Book *b, QWidget *parent): Dialog(parent), book(b)
{
setWindowTitle(tr("Book Details"));
- Info *info = new Info(book);
- QDialogButtonBox *buttonBox = new QDialogButtonBox(Qt::Vertical, this);
+
+ if (book) {
+ QLabel *title = new QLabel(book->title, this);
+ addWidget(title);
+ if (book->subject != "") {
+ QLabel *subject = new QLabel(book->subject, this);
+ addWidget(subject);
+ }
+ if (book->creators.size()) {
+ QLabel *creators = new QLabel(this);
+ QString c = "By " + book->creators[0];
+ for (int i = 1; i < book->creators.size(); i++) {
+ c += ", " + book->creators[i];
+ }
+ creators->setText(c);
+ addWidget(creators);
+ }
+ QLabel *path = new QLabel("File: " + book->path(), this);
+ addWidget(path);
+ if (book->publisher != "") {
+ QLabel *publisher =
+ new QLabel("Published by " + book->publisher, this);
+ addWidget(publisher);
+ }
+ if (book->source != "") {
+ QLabel *source = new QLabel("Source: " + book->source, this);
+ addWidget(source);
+ }
+ if (book->rights != "") {
+ QLabel *rights = new QLabel(book->rights, this);
+ addWidget(rights);
+ }
+ addStretch();
+ }
+
QPushButton *read = new QPushButton(tr("Read"), this);
QPushButton *remove = new QPushButton(tr("Delete"), this);
connect(read, SIGNAL(clicked()), this, SLOT(onReadBook()));
connect(remove, SIGNAL(clicked()), this, SLOT(onRemoveBook()));
- buttonBox->addButton(read, QDialogButtonBox::ActionRole);
- buttonBox->addButton(remove, QDialogButtonBox::ActionRole);
-
- QHBoxLayout *horizontalLayout = new QHBoxLayout(this);
- horizontalLayout->addWidget(info);
- horizontalLayout->addWidget(buttonBox);
- setLayout(horizontalLayout);
+ addButton(read, QDialogButtonBox::ActionRole);
+ addButton(remove, QDialogButtonBox::ActionRole);
}
void InfoDialog::onReadBook()
#ifndef INFODIALOG_H
#define INFODIALOG_H
-#include <QDialog>
+#include "dialog.h"
+class QWidget;
class Book;
-class InfoDialog: public QDialog
+class InfoDialog: public Dialog
{
Q_OBJECT
Book *book = Library::instance()->book(mCurrent);
if (book) {
BookmarksDialog *bookmarks = new BookmarksDialog(book, this);
- int ret = bookmarks->exec();
- if (ret > 0) {
- int index = ret - 1;
- view->goToBookmark(book->bookmarks()[index]);
- }
- else if (ret < 0) {
- view->addBookmark();
- }
+ bookmarks->setWindowModality(Qt::WindowModal);
+ connect(bookmarks, SIGNAL(addBookmark()), this, SLOT(onAddBookmark()));
+ connect(bookmarks, SIGNAL(goToBookmark(int)),
+ this, SLOT(onGoToBookmark(int)));
+ bookmarks->show();
}
}
previousAction->setEnabled(enablePrevious);
nextAction->setEnabled(enableNext);
}
+
+void MainWindow::onAddBookmark()
+{
+ view->addBookmark();
+}
+
+void MainWindow::onGoToBookmark(int index)
+{
+ Book *book = Library::instance()->book(mCurrent);
+ view->goToBookmark(book->bookmarks()[index]);
+}
void onSettingsChanged(const QString &key);
void onChapterLoadStart();
void onChapterLoadEnd(int index);
+ void onAddBookmark();
+ void onGoToBookmark(int index);
protected:
#ifdef Q_WS_MAEMO5
+dorian (0.0.11-1) unstable; urgency=low
+
+ * Facelift bookmark manager
+ * Make Maemo friendly dialog box class
+
+ -- Akos Polster <akos@pipacs.com> Sun, 25 Jul 2010 20:00:00 +0200
+
dorian (0.0.10-1) unstable; urgency=low
* Turn library into proper model
* Read chapter titles from NCX directory
* Display chapter titles for bookmarks
- -- Akos Polster <akos@pipacs.com> Fri, 16 Jul 2010 20:00:00 +0200
+ -- Akos Polster <akos@pipacs.com> Sat, 24 Jul 2010 20:00:00 +0200
dorian (0.0.9-1) unstable; urgency=low