Activate tool buttons if a list item is selected.
authorAkos Polster <polster@marzipan.local>
Sat, 25 Dec 2010 20:57:28 +0000 (21:57 +0100)
committerAkos Polster <polster@marzipan.local>
Sat, 25 Dec 2010 20:57:28 +0000 (21:57 +0100)
bookview.cpp
widgets/listwindow.cpp
widgets/listwindow.h

index d240070..fda10b9 100644 (file)
@@ -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);
+        }
     }
 }
 
index e44a781..76a7819 100644 (file)
@@ -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);
+    }
+}
index f8d8ab4..74590ef 100644 (file)
@@ -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 {