#include "trace.h"
BookmarksDialog::BookmarksDialog(Book *book_, QWidget *parent):
- ListWindow(parent), book(book_)
+ ListWindow(tr("(No bookmarks)"), parent), book(book_)
{
setWindowTitle(tr("Bookmarks"));
if (!book) {
return;
}
- addButton(tr("Add bookmark"), this, SLOT(onAdd()), "add");
-
// Build and set bookmark model
// FIXME: Localize me
foreach (Book::Bookmark bookmark, book_->bookmarks()) {
QStringListModel *model = new QStringListModel(data, this);
setModel(model);
+ addButton(tr("Add bookmark"), this, SLOT(onAdd()), "add");
+
// FIXME
// connect(list, SIGNAL(activated(const QModelIndex &)),
// this, SLOT(onItemActivated(const QModelIndex &)));
void BookmarksDialog::onDelete(bool really)
{
+#if 0
+ // FIXME
QModelIndex current = list->currentIndex();
if (!current.isValid()) {
return;
int row = current.row();
list->model()->removeRow(row);
book->deleteBookmark(row);
+#endif
}
#include "chaptersdialog.h"
#include "book.h"
-#include "listview.h"
-ChaptersDialog::ChaptersDialog(Book *book, QWidget *parent): ListWindow(parent)
+ChaptersDialog::ChaptersDialog(Book *book, QWidget *parent):
+ ListWindow(tr("(No chapters)"), parent)
{
setWindowTitle(tr("Chapters"));
if (book) {
class QWidget;
class QModelIndex;
-class ListView;
class Book;
/** Display book chapters. */
void onItemActivated(const QModelIndex &index);
protected:
- ListView *list;
QStringList data;
};
#include "infodialog.h"
#include "settings.h"
#include "listwindow.h"
-#include "listview.h"
#include "trace.h"
#include "bookfinder.h"
#include "searchdialog.h"
#include "progressdialog.h"
#include "settings.h"
-LibraryDialog::LibraryDialog(QWidget *parent): ListWindow(parent)
+LibraryDialog::LibraryDialog(QWidget *parent): ListWindow(tr("(No books)"), parent)
{
TRACE;
setWindowTitle(tr("Library"));
// Set selected item
Library *library = Library::instance();
QModelIndex current = library->nowReading();
- // FIXME: setSelected(sortedLibrary->mapFromSource(current));
+ setCurrentItem(sortedLibrary->mapFromSource(current));
+ // Search dialog box
+ searchDialog = new SearchDialog(this);
+ connect(Search::instance(), SIGNAL(endSearch()),
+ this, SLOT(showSearchResults()));
+
+ // Progress bar
progress = new ProgressDialog(tr("Adding books"), this);
- connect(Library::instance(),
- SIGNAL(rowsInserted(const QModelIndex &, int, int)),
- this,
- SLOT(onBookAdded()));
+ connect(library, SIGNAL(rowsInserted(const QModelIndex &, int, int)),
+ this, SLOT(onBookAdded()));
connect(this, SIGNAL(activated(const QModelIndex &)),
this, SLOT(onItemActivated(const QModelIndex &)));
- // Create search dialog
- searchDialog = new SearchDialog(this);
- connect(Search::instance(), SIGNAL(endSearch()),
- this, SLOT(showSearchResults()));
-
// Retrieve default sort criteria
switch (Settings::instance()->value("lib/sortby").toInt()) {
case SortedLibrary::SortByAuthor:
void LibraryDialog::onItemActivated(const QModelIndex &index)
{
TRACE;
+
QModelIndex libraryIndex = sortedLibrary->mapToSource(index);
Book *book = Library::instance()->book(libraryIndex);
int ret = (new InfoDialog(book, this))->exec();
switch (ret) {
case InfoDialog::Read:
- {
- QModelIndex current = sortedLibrary->mapToSource(list->currentIndex());
- Q_ASSERT(current.isValid());
- Library::instance()->setNowReading(current);
- close();
- }
+ Library::instance()->setNowReading(libraryIndex);
+ close();
break;
case InfoDialog::Delete:
- {
- QModelIndex current = sortedLibrary->mapToSource(list->currentIndex());
- Library::instance()->remove(current);
- }
+ Library::instance()->remove(libraryIndex);
break;
default:
;
void LibraryDialog::setSelected(const QModelIndex &libraryIndex)
{
QModelIndex sortedIndex = sortedLibrary->mapFromSource(libraryIndex);
- list->selectionModel()->clearSelection();
if (sortedIndex.isValid()) {
- list->selectionModel()->select(sortedIndex,
- QItemSelectionModel::Select);
- list->setCurrentIndex(sortedIndex);
- }
-}
-
-QModelIndex LibraryDialog::selected() const
-{
- QModelIndexList selectedItems = list->selectionModel()->selectedIndexes();
- if (selectedItems.size()) {
- return sortedLibrary->mapToSource(selectedItems[0]);
+ setCurrentItem(sortedIndex);
}
- return QModelIndex();
}
void LibraryDialog::onAddFolder()
void LibraryDialog::onSearch()
{
+ TRACE;
int ret = searchDialog->exec();
+ qDebug() << "Search dialog returned" << ret;
if (ret != QDialog::Accepted) {
return;
}
#include "listwindow.h"
-class ListView;
class QPushButton;
class QModelIndex;
class QCloseEvent;
class Book;
class InfoWindow;
class SortedLibrary;
-class SearchDialog;
class QAction;
+class SearchDialog;
/** Manage library. */
class LibraryDialog: public ListWindow
private:
QString createItemText(Book *book);
void setSelected(const QModelIndex &index);
- QModelIndex selected() const;
- ListView *list;
SortedLibrary *sortedLibrary;
ProgressDialog *progress;
- SearchDialog *searchDialog;
QAction *sortByAuthor;
QAction *sortByTitle;
+ SearchDialog *searchDialog;
};
#endif // LIBRARYDIALOG_H
Book *book = Library::instance()->book(mCurrent);
if (book) {
BookmarksDialog *bookmarks = new BookmarksDialog(book, this);
- bookmarks->setWindowModality(Qt::WindowModal);
connect(bookmarks, SIGNAL(addBookmark(const QString &)),
this, SLOT(onAddBookmark(const QString &)));
connect(bookmarks, SIGNAL(goToBookmark(int)),
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();
QVariant Library::data(const QModelIndex &index, int role) const
{
- TRACE;
-
QVariant ret;
if (!index.isValid()) {
return ret;
switch (role) {
case Qt::DisplayRole:
- qDebug() << mBooks[index.row()]->name();
ret = mBooks[index.row()]->name();
break;
case Qt::DecorationRole:
- qDebug() << "(cover)";
ret.setValue(mBooks[index.row()]->cover);
break;
default:
* Don't close library dialog when deleting current book
* Really delete current book [#6614]
* Remove inactive items from Options menu on Symbian [#6606]
+ * Fix Library window content scrolling [#6622]
-- Akos Polster <akos@pipacs.com> Wed, 17 Nov 2010 02:00:00 +0100
SearchDialog::SearchDialog(QWidget *parent): Dyalog(parent)
{
+ TRACE;
setWindowTitle(tr("Search the Web"));
+ setAttribute(Qt::WA_DeleteOnClose, false);
QLabel *titleLabel = new QLabel(tr("Title:"), this);
title = new QLineEdit(this);
#include <QDir>
#include <QFile>
-#include "listview.h"
#include "searchresultsdialog.h"
#include "searchresultinfodialog.h"
#include "trace.h"
#include "platform.h"
SearchResultsDialog::SearchResultsDialog(const QList<Search::Result> results_,
- QWidget *parent): ListWindow(parent), results(results_)
+ QWidget *parent): ListWindow(tr("(No results)"), parent), results(results_)
{
setWindowTitle(tr("Search results"));
QStringListModel *model = new QStringListModel(data, this);
setModel(model);
- // FIXME
- // connect(list, SIGNAL(activated(const QModelIndex &)),
- // this, SLOT(onItemActivated(const QModelIndex &)));
+ connect(this, SIGNAL(activated(const QModelIndex &)),
+ this, SLOT(onItemActivated(const QModelIndex &)));
Search *search = Search::instance();
connect(search, SIGNAL(beginDownload(int)), this, SLOT(onBeginDownload(int)));
connect(search,
Library::instance()->add(fileName);
int row = results.indexOf(result);
if (-1 != row) {
- list->model()->removeRow(row);
+ model()->removeRow(row);
}
Platform::instance()->information(tr("Downloaded \"%1\"\nand added to the "
"library").arg(result.title), this);
#include "listwindow.h"
#include "search.h"
-class ListView;
class QModelIndex;
class ProgressDialog;
private:
const QList<Search::Result> results;
- ListView *list;
QStringList data;
ProgressDialog *progress;
};
#include "flickcharm.h"
#endif
-ListWindow::ListWindow(QWidget *parent): QMainWindow(parent), model(0)
+ListWindow::ListWindow(const QString &noItems_, QWidget *parent):
+ QMainWindow(parent), mModel(0), noItems(noItems_)
{
#if defined(Q_WS_MAEMO_5)
setAttribute(Qt::WA_Maemo5StackedWindow, true);
#endif
+ setAttribute(Qt::WA_DeleteOnClose);
list = new QListWidget(this);
+ list->setSelectionMode(QAbstractItemView::SingleSelection);
populateList();
setCentralWidget(list);
QMainWindow::addAction(closeAction);
#endif // Q_OS_SYMBIAN
-#ifdef Q_WS_MAC
- // FIXME
- // addAction(tr("Close"), this, SLOT(close()), QString(),
- // QDialogButtonBox::RejectRole);
-#endif // Q_WS_MAC
-
connect(list, SIGNAL(activated(const QModelIndex &)),
- this, SLOT(onItemActicvated(const QModelIndex &)));
+ this, SLOT(onItemActivated(const QModelIndex &)));
}
void ListWindow::populateList()
list->clear();
list->setIconSize(QSize(48, 48)); // FIXME
list->setUniformItemSizes(true);
- if (model) {
- for (int i = 0; i < model->rowCount(); i++) {
- QModelIndex index = model->index(i, 0);
- QString text = model->data(index, Qt::DisplayRole).toString();
- QVariant imageData = model->data(index, Qt::DecorationRole);
+ if (mModel && mModel->rowCount()) {
+ for (int i = 0; i < mModel->rowCount(); i++) {
+ QModelIndex index = mModel->index(i, 0);
+ QString text = mModel->data(index, Qt::DisplayRole).toString();
+ QVariant imageData = mModel->data(index, Qt::DecorationRole);
QIcon icon(QPixmap::fromImage(imageData.value<QImage>()));
(void)new QListWidgetItem(icon, text, list);
}
+ } else {
+ QListWidgetItem *item = new QListWidgetItem(noItems);
+ item->setFlags(Qt::NoItemFlags);
+ list->addItem(item);
}
for (int i = 0; i < buttons.count(); i++) {
- QListWidgetItem *item = new QListWidgetItem();
- item->setFlags(Qt::NoItemFlags);
- list->insertItem(i, item);
- list->setItemWidget(item, buttons[i]);
+ insertButton(i, buttons[i]);
}
}
-void ListWindow::setModel(QAbstractItemModel *model_)
+void ListWindow::insertButton(int row, const Button &b)
{
- model = model_;
+ QPushButton *pushButton = new QPushButton(
+ QIcon(Platform::instance()->icon(b.iconName)), b.title, this);
+ connect(pushButton, SIGNAL(clicked()), b.receiver, b.slot);
+ QListWidgetItem *item = new QListWidgetItem();
+ item->setFlags(Qt::NoItemFlags);
+ list->insertItem(row, item);
+ list->setItemWidget(item, pushButton);
+}
+
+void ListWindow::setModel(QAbstractItemModel *aModel)
+{
+ TRACE;
+ mModel = aModel;
populateList();
- if (model) {
- connect(model,
- SIGNAL(dataChanged(const QModelIndex &, const QModelIndex &)),
+ if (mModel) {
+ connect(mModel, SIGNAL(dataChanged(QModelIndex, QModelIndex)),
+ this, SLOT(populateList()));
+ connect(mModel, SIGNAL(rowsRemoved(QModelIndex, int, int)),
+ this, SLOT(populateList()));
+ connect(mModel, SIGNAL(rowsInserted(QModelIndex, int, int)),
this, SLOT(populateList()));
}
}
+QAbstractItemModel *ListWindow::model() const
+{
+ return mModel;
+}
+
void ListWindow::addButton(const QString &title, QObject *receiver,
const char *slot, const QString &iconName)
{
TRACE;
- QPushButton *button = new QPushButton(QIcon(Platform::instance()->
- icon(iconName)), title, this);
- connect(button, SIGNAL(clicked()), receiver, slot);
- buttons.append(button);
+ Button b;
+ b.title = title;
+ b.receiver = receiver;
+ b.slot = slot;
+ b.iconName = iconName;
- int pos = buttons.length() - 1;
- QListWidgetItem *item = new QListWidgetItem();
- list->insertItem(pos, item);
- list->setItemWidget(item, button);
+ insertButton(buttons.length(), b);
+ buttons.append(b);
}
QAction *ListWindow::addMenuAction(const QString &title, QObject *receiver,
return action;
}
-void ListWindow::onItemActivated(const QModelIndex &)
+void ListWindow::onItemActivated(const QModelIndex &index)
{
TRACE;
- // FIXME
+ int row = index.row() - buttons.count();
+ qDebug() << "Activated" << index.row() << ", emit activated(" << row << ")";
+ emit activated(mModel->index(row, 0));
+}
+
+void ListWindow::setCurrentItem(const QModelIndex &item)
+{
+ int index = item.row();
+ list->setCurrentItem(list->item(index + buttons.count()));
}
#ifdef Q_WS_MAEMO_5
public:
/**
* Constructor.
- * @param model Model for the list widget contents.
+ * @param noItems Text to display when the list has no items.
* @param parent Parent widget.
*/
- explicit ListWindow(QWidget *parent = 0);
+ explicit ListWindow(const QString &noItems, QWidget *parent = 0);
- /**
- * Set the model for the list.
- */
+ /** Set the model for the list. */
void setModel(QAbstractItemModel *model);
- /**
- * Add an action button to the beginning of the list.
- */
+ /** Get model. */
+ QAbstractItemModel *model() const;
+
+ /** Add an action button to the beginning of the list. */
void addButton(const QString &title, QObject *receiver, const char *slot,
const QString &iconPath = QString());
- /**
- * Add an action to the menu.
- */
+ /** Add an action to the menu. */
QAction *addMenuAction(const QString &title, QObject *receiver,
const char *slot);
+signals:
+ /** Emitted when a list item is activated. */
+ void activated(const QModelIndex &index);
+
public slots:
+ /** Set the current (selected) item. */
+ void setCurrentItem(const QModelIndex &item);
+
#ifdef Q_OS_SYMBIAN
void show();
#endif
void populateList();
protected:
+ struct Button {
+ QString title;
+ QObject *receiver;
+ const char *slot;
+ QString iconName;
+ };
+ void insertButton(int row, const Button &button);
#ifdef Q_WS_MAEMO_5
void closeEvent(QCloseEvent *event);
#endif
+
+private:
QListWidget *list;
- QAbstractItemModel *model;
- QList<QPushButton *> buttons;
+ QAbstractItemModel *mModel;
+ QList<Button> buttons;
+ QString noItems;
#ifdef Q_OS_SYMBIAN
FlickCharm *charm;
#endif