From 3c911546d4367fa1da0a21c70872159a1044a170 Mon Sep 17 00:00:00 2001 From: Akos Polster Date: Sat, 25 Dec 2010 21:57:28 +0100 Subject: [PATCH] Activate tool buttons if a list item is selected. --- bookview.cpp | 22 ++++++++++++---------- widgets/listwindow.cpp | 16 +++++++++++++++- widgets/listwindow.h | 4 ++++ 3 files changed, 31 insertions(+), 11 deletions(-) diff --git a/bookview.cpp b/bookview.cpp index d240070..fda10b9 100644 --- a/bookview.cpp +++ b/bookview.cpp @@ -314,16 +314,18 @@ void BookView::paintEvent(QPaintEvent *e) int bookmarkPos = (int)((qreal)height * (qreal)b.pos); painter.drawPixmap(2, bookmarkPos - scrollPos.y(), bookmarkPixmap); } - QPen pen(Qt::gray); - pen.setStyle(Qt::DotLine); - pen.setWidth(3); - painter.setPen(pen); - if (contentIndex > 0) { - painter.drawLine(0, -scrollPos.y(), width(), -scrollPos.y()); - } - if (contentIndex < (mBook->parts.size() - 1)) { - int h = contentsHeight - scrollPos.y() - 1; - painter.drawLine(0, h, width(), h); + if (mBook) { + QPen pen(Qt::gray); + pen.setStyle(Qt::DotLine); + pen.setWidth(3); + painter.setPen(pen); + if (contentIndex > 0) { + painter.drawLine(0, -scrollPos.y(), width(), -scrollPos.y()); + } + if (contentIndex < (mBook->parts.size() - 1)) { + int h = contentsHeight - scrollPos.y() - 1; + painter.drawLine(0, h, width(), h); + } } } diff --git a/widgets/listwindow.cpp b/widgets/listwindow.cpp index e44a781..76a7819 100644 --- a/widgets/listwindow.cpp +++ b/widgets/listwindow.cpp @@ -37,6 +37,10 @@ ListWindow::ListWindow(const QString &noItems_, QWidget *parent): connect(list, SIGNAL(activated(const QModelIndex &)), this, SLOT(onItemActivated(const QModelIndex &))); + connect(list, SIGNAL(itemSelectionChanged()), + this, SLOT(onItemSelectionChanged())); + connect(list, SIGNAL(itemSelectionChanged()), + this, SIGNAL(itemSelectionChanged())); } void ListWindow::populateList() @@ -169,7 +173,8 @@ void ListWindow::onItemActivated(const QModelIndex &index) } int row = index.row() - buttons.count(); - qDebug() << "Activated" << index.row() << ", emit activated(" << row << ")"; + qDebug() << "Activated" << index.row() << ", emit activated(" << row + << ")"; emit activated(mModel->index(row, 0)); } @@ -202,3 +207,12 @@ void ListWindow::closeEvent(QCloseEvent *event) } #endif // Q_WS_MAEMO_5 + +void ListWindow::onItemSelectionChanged() +{ + TRACE; + bool enabled = currentItem().isValid(); + foreach (QAction *action, itemActions) { + action->setEnabled(enabled); + } +} diff --git a/widgets/listwindow.h b/widgets/listwindow.h index f8d8ab4..74590ef 100644 --- a/widgets/listwindow.h +++ b/widgets/listwindow.h @@ -58,6 +58,9 @@ signals: /** Emitted when a list item is activated. */ void activated(const QModelIndex &index); + /** Emitted when selection has changed. */ + void itemSelectionChanged(); + public slots: /** Set the current (selected) item. */ void setCurrentItem(const QModelIndex &item); @@ -65,6 +68,7 @@ public slots: protected slots: void onItemActivated(const QModelIndex &); void populateList(); + void onItemSelectionChanged(); protected: struct Button { -- 1.7.9.5