Library *library = Library::instance();
QModelIndex current = library->nowReading();
- select(current);
+ setSelected(current);
QHBoxLayout *horizontalLayout = new QHBoxLayout(this);
horizontalLayout->addWidget(list);
SIGNAL(rowsInserted(const QModelIndex &, int, int)),
this,
SLOT(onBookAdded()));
-#ifndef Q_WS_MAEMO_5
- connect(list, SIGNAL(itemSelectionChanged()),
- this, SLOT(onItemSelectionChanged()));
- connect(detailsButton, SIGNAL(clicked()), this, SLOT(onDetails()));
- connect(readButton, SIGNAL(clicked()), this, SLOT(onRead()));
- connect(removeButton, SIGNAL(clicked()), this, SLOT(onRemove()));
-#endif
connect(addButton, SIGNAL(clicked()), this, SLOT(onAdd()));
#ifdef Q_WS_MAEMO_5
connect(list, SIGNAL(itemActivated(QListWidgetItem *)),
this, SLOT(onItemActivated(QListWidgetItem *)));
#else
+ connect(list, SIGNAL(itemSelectionChanged()),
+ this, SLOT(onItemSelectionChanged()));
+ connect(detailsButton, SIGNAL(clicked()), this, SLOT(onDetails()));
+ connect(readButton, SIGNAL(clicked()), this, SLOT(onRead()));
+ connect(removeButton, SIGNAL(clicked()), this, SLOT(onRemove()));
connect(list, SIGNAL(doubleClicked(const QModelIndex &)),
this, SLOT(onItemActivated(const QModelIndex &)));
-#endif
-
-#ifndef Q_WS_MAEMO_5
+ connect(list->selectionModel(),
+ SIGNAL(selectionChanged(const QItemSelection &,
+ const QItemSelection &)),
+ this, SLOT(onItemSelectionChanged()));
onItemSelectionChanged();
-#endif
+#endif // Q_WS_MAEMO_5
}
void LibraryDialog::onAdd()
(void)QMessageBox::information(this, tr("Dorian"),
tr("This book is already in the library"), QMessageBox::Ok);
#endif // Q_WS_MAEMO_5
- select(index);
+ setSelected(index);
}
else {
library->add(path);
void LibraryDialog::onBookAdded()
{
Library *library = Library::instance();
- select(library->index(library->rowCount() - 1));
+ setSelected(library->index(library->rowCount() - 1));
}
#ifndef Q_WS_MAEMO_5
qDebug() << "LibraryDialog::onItemActivated";
QModelIndex libraryIndex = sortedLibrary->mapToSource(index);
Book *book = Library::instance()->book(libraryIndex);
- InfoDialog *info = new InfoDialog(book, this);
- info->exec();
+ (new InfoDialog(book, this))->exec();
}
QString LibraryDialog::createItemText(const Book *book)
void LibraryDialog::onItemSelectionChanged()
{
-#if 0 // FIXME
- bool enable = list->selectedItems().size();
+ bool enable = selected().isValid();
qDebug() << "LibraryDialog::onItemSelectionChanged" << enable;
readButton->setEnabled(enable);
qDebug() << " readButton";
qDebug() << " detailsButton";
removeButton->setEnabled(enable);
qDebug() << " removeButton";
-#endif
}
#endif // Q_WS_MAEMO_5
close();
}
-void LibraryDialog::select(const QModelIndex &libraryIndex)
+void LibraryDialog::setSelected(const QModelIndex &libraryIndex)
{
QModelIndex sortedIndex = sortedLibrary->mapFromSource(libraryIndex);
list->selectionModel()->clearSelection();
list->setCurrentIndex(sortedIndex);
}
}
+
+QModelIndex LibraryDialog::selected() const
+{
+ QModelIndexList selectedItems = list->selectionModel()->selectedIndexes();
+ if (selectedItems.size()) {
+ return sortedLibrary->mapToSource(selectedItems[0]);
+ }
+ return QModelIndex();
+}