Add tool bars to list windows on Symbian.
authorAkos Polster <akos@pipacs.com>
Sun, 5 Dec 2010 18:36:25 +0000 (19:36 +0100)
committerAkos Polster <akos@pipacs.com>
Sun, 5 Dec 2010 18:36:25 +0000 (19:36 +0100)
bookmarksdialog.cpp
widgets/listwindow.cpp
widgets/listwindow.h
widgets/mainbase.cpp

index f125ed9..3f4bb8c 100644 (file)
@@ -34,6 +34,7 @@ BookmarksDialog::BookmarksDialog(Book *book_, QWidget *parent):
     setModel(model);
 
     addButton(tr("Add bookmark"), this, SLOT(onAdd()), "add");
+    addItemButton(tr("Delete bookmark"), this, SLOT(onDelete()), "remove");
 
     connect(this, SIGNAL(activated(const QModelIndex &)),
             this, SLOT(onItemActivated(const QModelIndex &)));
index e12f4c2..291da6b 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,7 +32,7 @@ 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 &)),
@@ -104,10 +104,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 +112,29 @@ 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);
+    (void)addMenuAction(title, receiver, slot);
+#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(iconPath);
+#else
+    QAction *toolBarAction =
+            addToolBarAction(receiver, slot, iconName, title, true);
+    // QAction *menuAction = addMenuAction(title, receiver, slot);
+    // toolBarAction->setEnabled(false);
+    // menuAction->setEnabled(false);
+    itemActions.append(toolBarAction);
+    // itemActions.append(menuAction);
 #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;
 }
 
@@ -187,15 +206,3 @@ void ListWindow::closeEvent(QCloseEvent *event)
 }
 
 #endif // Q_WS_MAEMO_5
-
-#ifdef Q_OS_SYMBIAN
-
-void ListWindow::show()
-{
-    foreach (QWidget *w, QApplication::allWidgets()) {
-        w->setContextMenuPolicy(Qt::NoContextMenu);
-    }
-    showMaximized();
-}
-
-#endif // Q_OS_SYMBIAN
index 3b3c235..3f75f78 100644 (file)
@@ -1,7 +1,8 @@
 #ifndef LISTWINDOW_H
 #define LISTWINDOW_H
 
-#include <QMainWindow>
+#include "mainbase.h"
+
 #include <QDialogButtonBox>
 #include <QList>
 
@@ -13,7 +14,7 @@ class QListWidget;
 class QModelIndex;
 
 /** A window with a list and menu actions (Maemo) or buttons (non-Maemo). */
-class ListWindow: public QMainWindow
+class ListWindow: public MainBase
 {
     Q_OBJECT
 
@@ -31,10 +32,20 @@ public:
     /** Get model. */
     QAbstractItemModel *model() const;
 
-    /** Add an action button to the beginning of the list. */
+    /**
+     * Add an action button to the beginning of the list (Maemo) or to the
+     * tool bar (non-Maemo).
+     */
     void addButton(const QString &title, QObject *receiver, const char *slot,
                    const QString &iconPath = QString());
 
+    /**
+     * Add an action button to the tool bar, which is only active if a list
+     * item is selected.
+     */
+    void addItemButton(const QString &title, QObject *receiver,
+                       const char *slot, const QString &iconPath = QString());
+
     /** Add an action to the menu. */
     QAction *addMenuAction(const QString &title, QObject *receiver,
                            const char *slot);
@@ -50,10 +61,6 @@ public slots:
     /** Set the current (selected) item. */
     void setCurrentItem(const QModelIndex &item);
 
-#ifdef Q_OS_SYMBIAN
-    void show();
-#endif
-
 protected slots:
     void onItemActivated(const QModelIndex &);
     void populateList();
@@ -78,6 +85,7 @@ private:
 #ifdef Q_OS_SYMBIAN
     FlickCharm *charm;
 #endif
+    QList<QAction *>itemActions;
 };
 
 #endif // LISTWINDOW_H
index 1869d14..54343b6 100755 (executable)
@@ -46,21 +46,14 @@ QAction *MainBase::addToolBarAction(QObject *receiver,
     TRACE;\r
     qDebug() << "icon" << iconName << "text" << text;\r
     QAction *action;\r
-#ifndef Q_OS_SYMBIAN\r
-    Q_UNUSED(important);\r
-    action = toolBar->addAction(QIcon(Platform::instance()->icon(iconName)),\r
-                                text, receiver, member);\r
-#else\r
-    if (!toolBar && important) {\r
-        // Create tool bar if needed\r
-        toolBar = new QToolBar("", this);\r
-        // toolBar->setFixedHeight(63);\r
-        toolBar->setStyleSheet("margin:0; border:0; padding:0");\r
-        toolBar->setSizePolicy(QSizePolicy::MinimumExpanding,\r
-                               QSizePolicy::Maximum);\r
-        addToolBar(Qt::BottomToolBarArea, toolBar);\r
-    }\r
+#ifdef Q_OS_SYMBIAN\r
     if (important) {\r
+        if (!toolBar) {\r
+            // Create tool bar if needed\r
+            toolBar = new QToolBar("", this);\r
+            toolBar->setStyleSheet("margin:0; border:0; padding:0");\r
+            addToolBar(Qt::BottomToolBarArea, toolBar);\r
+        }\r
         // Add tool bar action\r
         QPushButton *button = new QPushButton(this);\r
         button->setIconSize(QSize(60, 60));\r
@@ -72,14 +65,15 @@ QAction *MainBase::addToolBarAction(QObject *receiver,
         toolBar->addWidget(button);\r
     }\r
     // Add menu action, too\r
-    action = new QAction(text, this);\r
-    menuBar()->addAction(action);\r
+    action = menuBar()->addAction(text);\r
     connect(action, SIGNAL(triggered()), receiver, member);\r
+#else\r
+    Q_UNUSED(important);\r
+    action = toolBar->addAction(QIcon(Platform::instance()->icon(iconName)),\r
+                                text, receiver, member);\r
 #endif\r
 \r
-    action->setText("");\r
     action->setToolTip("");\r
-\r
     return action;\r
 }\r
 \r