Smoothen switch between full screen/normal view on Maemo.
[dorian] / widgets / listwindow.cpp
index e12f4c2..5e6fa34 100644 (file)
@@ -11,7 +11,7 @@
 #endif
 
 ListWindow::ListWindow(const QString &noItems_, QWidget *parent):
-        QMainWindow(parent), mModel(0), noItems(noItems_)
+        MainBase(parent), mModel(0), noItems(noItems_)
 {
 #if defined(Q_WS_MAEMO_5)
     setAttribute(Qt::WA_Maemo5StackedWindow, true);
@@ -32,11 +32,15 @@ ListWindow::ListWindow(const QString &noItems_, QWidget *parent):
     QAction *closeAction = new QAction(parent? tr("Back"): tr("Exit"), this);
     closeAction->setSoftKeyRole(QAction::NegativeSoftKey);
     connect(closeAction, SIGNAL(triggered()), this, SLOT(close()));
-    QMainWindow::addAction(closeAction);
+    MainBase::addAction(closeAction);
 #endif // Q_OS_SYMBIAN
 
     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()
@@ -104,10 +108,7 @@ void ListWindow::addButton(const QString &title, QObject *receiver,
 {
     TRACE;
 
-#ifdef Q_OS_SYMBIAN
-    Q_UNUSED(iconName);
-    addMenuAction(title, receiver, slot);
-#else
+#if defined(Q_WS_MAEMO_5)
     Button b;
     b.title = title;
     b.receiver = receiver;
@@ -115,6 +116,25 @@ void ListWindow::addButton(const QString &title, QObject *receiver,
     b.iconName = iconName;
     insertButton(buttons.length(), b);
     buttons.append(b);
+#else
+    (void)addToolBarAction(receiver, slot, iconName, title, true);
+#endif
+}
+
+void ListWindow::addItemButton(const QString &title, QObject *receiver,
+                               const char *slot, const QString &iconName)
+{
+    TRACE;
+#if defined(Q_WS_MAEMO_5)
+    Q_UNUSED(title);
+    Q_UNUSED(receiver);
+    Q_UNUSED(slot);
+    Q_UNUSED(iconName);
+#else
+    QAction *toolBarAction =
+            addToolBarAction(receiver, slot, iconName, title, true);
+    toolBarAction->setEnabled(false);
+    itemActions.append(toolBarAction);
 #endif
 }
 
@@ -137,7 +157,6 @@ QAction *ListWindow::addMenuAction(const QString &title, QObject *receiver,
     Q_UNUSED(slot);
     action = new QAction(this);
 #endif
-    action->setCheckable(true);
     return action;
 }
 
@@ -154,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));
 }
 
@@ -188,14 +208,11 @@ void ListWindow::closeEvent(QCloseEvent *event)
 
 #endif // Q_WS_MAEMO_5
 
-#ifdef Q_OS_SYMBIAN
-
-void ListWindow::show()
+void ListWindow::onItemSelectionChanged()
 {
-    foreach (QWidget *w, QApplication::allWidgets()) {
-        w->setContextMenuPolicy(Qt::NoContextMenu);
+    TRACE;
+    bool enabled = currentItem().isValid();
+    foreach (QAction *action, itemActions) {
+        action->setEnabled(enabled);
     }
-    showMaximized();
 }
-
-#endif // Q_OS_SYMBIAN