From 231cd7411a850724066e8d9d0f487cffb8d78b96 Mon Sep 17 00:00:00 2001 From: Akos Polster Date: Fri, 19 Nov 2010 00:38:50 +0100 Subject: [PATCH] BookmarksDialog is back to normal. --- bookmarksdialog.cpp | 25 ++++++++++--------------- widgets/listwindow.cpp | 12 ++++++++++++ widgets/listwindow.h | 3 +++ 3 files changed, 25 insertions(+), 15 deletions(-) diff --git a/bookmarksdialog.cpp b/bookmarksdialog.cpp index 8de9113..f125ed9 100644 --- a/bookmarksdialog.cpp +++ b/bookmarksdialog.cpp @@ -6,7 +6,7 @@ #include "trace.h" BookmarksDialog::BookmarksDialog(Book *book_, QWidget *parent): - ListWindow(tr("(No bookmarks)"), parent), book(book_) + ListWindow(tr("(No bookmarks)\n"), parent), book(book_) { setWindowTitle(tr("Bookmarks")); if (!book) { @@ -35,20 +35,18 @@ BookmarksDialog::BookmarksDialog(Book *book_, QWidget *parent): addButton(tr("Add bookmark"), this, SLOT(onAdd()), "add"); - // FIXME - // connect(list, SIGNAL(activated(const QModelIndex &)), - // this, SLOT(onItemActivated(const QModelIndex &))); + connect(this, SIGNAL(activated(const QModelIndex &)), + this, SLOT(onItemActivated(const QModelIndex &))); } void BookmarksDialog::onGo() { TRACE; - // FIXME - // QModelIndex current = list->currentIndex(); - // if (current.isValid()) { - // emit goToBookmark(current.row()); - // close(); - // } + QModelIndex current = currentItem(); + if (current.isValid()) { + emit goToBookmark(current.row()); + close(); + } } void BookmarksDialog::onItemActivated(const QModelIndex &index) @@ -78,9 +76,7 @@ void BookmarksDialog::onAdd() void BookmarksDialog::onDelete(bool really) { -#if 0 - // FIXME - QModelIndex current = list->currentIndex(); + QModelIndex current = currentItem(); if (!current.isValid()) { return; } @@ -92,7 +88,6 @@ void BookmarksDialog::onDelete(bool really) } } int row = current.row(); - list->model()->removeRow(row); + model()->removeRow(row); book->deleteBookmark(row); -#endif } diff --git a/widgets/listwindow.cpp b/widgets/listwindow.cpp index 748be7b..59e88c9 100644 --- a/widgets/listwindow.cpp +++ b/widgets/listwindow.cpp @@ -144,6 +144,18 @@ void ListWindow::setCurrentItem(const QModelIndex &item) list->setCurrentItem(list->item(index + buttons.count())); } +QModelIndex ListWindow::currentItem() const +{ + TRACE; + QListWidgetItem *currentItem = list->currentItem(); + if (currentItem) { + int row = list->row(currentItem) - buttons.count(); + qDebug() << "Current row is" << row; + return mModel->index(row, 0); + } + return QModelIndex(); +} + #ifdef Q_WS_MAEMO_5 void ListWindow::closeEvent(QCloseEvent *event) diff --git a/widgets/listwindow.h b/widgets/listwindow.h index 71cef8b..3b3c235 100644 --- a/widgets/listwindow.h +++ b/widgets/listwindow.h @@ -39,6 +39,9 @@ public: QAction *addMenuAction(const QString &title, QObject *receiver, const char *slot); + /** Get current (selected) item. */ + QModelIndex currentItem() const; + signals: /** Emitted when a list item is activated. */ void activated(const QModelIndex &index); -- 1.7.9.5