Changed the way how the context buttons are implemented and how they are forwadded...
authorPekka Nissinen <pekka.nissinen@ixonos.com>
Tue, 24 Aug 2010 09:57:45 +0000 (12:57 +0300)
committerPekka Nissinen <pekka.nissinen@ixonos.com>
Tue, 24 Aug 2010 09:57:45 +0000 (12:57 +0300)
It is now using a specialised QWidget that contains the buttons in a grid layout. Also made the required changes to
the RoutingPanel and UserInfoPanel classes.

src/ui/mainwindow.cpp
src/ui/panelbase.cpp
src/ui/panelbase.h
src/ui/panelcontextbuttonbar.cpp
src/ui/panelcontextbuttonbar.h
src/ui/routingpanel.cpp
src/ui/userinfopanel.cpp

index 18c5f85..039ba38 100644 (file)
@@ -350,10 +350,8 @@ void MainWindow::buildRoutingPanel()
     connect(this, SIGNAL(locationDataParsed(const QList<Location>&)),
             m_routingPanel, SLOT(populateLocationListView(const QList<Location>&)));
 
-    connect(m_routingPanel,
-            SIGNAL(locationItemClicked(const GeoCoordinate&, const GeoCoordinate&)),
-            this,
-            SIGNAL(locationItemClicked(const GeoCoordinate&, const GeoCoordinate&)));
+    connect(m_routingPanel, SIGNAL(locationItemClicked(const GeoCoordinate&, const GeoCoordinate&)),
+            this, SIGNAL(locationItemClicked(const GeoCoordinate&, const GeoCoordinate&)));
 
     connect(m_routingPanel, SIGNAL(routeToLocation(const GeoCoordinate&)),
             this, SIGNAL(routeTo(const GeoCoordinate&)));
index 1eb2175..59e6ab7 100644 (file)
@@ -27,11 +27,28 @@ PanelBase::PanelBase(QWidget *parent)
     : QWidget(parent)
 {
     qDebug() << __PRETTY_FUNCTION__;
+
+    const int CONTEXT_BUTTON_MARGIN_LEFT = 2;
+    const int CONTEXT_BUTTON_MARGIN_TOP = 10;
+    const int CONTEXT_BUTTON_MARGIN_RIGHT = 0;
+    const int CONTEXT_BUTTON_MARGIN_BOTTOM = 0;
+    const int CONTEXT_BUTTON_SPACING = 0;
+
+    m_contextButtons = new QWidget;
+
+    m_contextButtonLayout = new QGridLayout;
+    m_contextButtonLayout->setContentsMargins(CONTEXT_BUTTON_MARGIN_LEFT,
+                                              CONTEXT_BUTTON_MARGIN_TOP,
+                                              CONTEXT_BUTTON_MARGIN_RIGHT,
+                                              CONTEXT_BUTTON_MARGIN_BOTTOM);
+    m_contextButtonLayout->setSpacing(CONTEXT_BUTTON_SPACING);
+
+    m_contextButtons->setLayout(m_contextButtonLayout);
 }
 
-const QList<ImageButton *>& PanelBase::contextButtons() const
+QWidget* PanelBase::contextButtons() const
 {
     qDebug() << __PRETTY_FUNCTION__;
 
-    return m_contextButtonList;
+    return m_contextButtons;
 }
index 528dc29..272b8df 100644 (file)
@@ -22,6 +22,7 @@
 #ifndef PANELBASE_H
 #define PANELBASE_H
 
+#include <QGridLayout>
 #include <QWidget>
 
 class ImageButton;
@@ -48,11 +49,11 @@ public:
  ******************************************************************************/
 public:
     /**
-     * @brief Get list of context buttons
+     * @brief Getter for the context buttons
      *
-     * @returns Reference to list of context buttons
+     * @returns Pointer to context buttons widget
      */
-    const QList<ImageButton *>& contextButtons() const;
+    QWidget* contextButtons() const;
 
 /*******************************************************************************
  * SIGNALS
@@ -69,6 +70,9 @@ signals:
  * DATA MEMBERS
  ******************************************************************************/
 protected:
-    QList<ImageButton *> m_contextButtonList; ///< List of context buttons
+    QGridLayout *m_contextButtonLayout; ///< Layout for context buttons
+
+private:
+    QWidget *m_contextButtons;          ///< Widget for context buttons
 };
 #endif // PANELBASE_H
index 11c4bbd..03dfd1e 100644 (file)
 #include <QDebug>
 #include <QPainter>
 
-#include "imagebutton.h"
-
 #include "panelcontextbuttonbar.h"
 
 const int CONTEXT_BUTTON_BAR_WIDTH = 78;
 
 PanelContextButtonBar::PanelContextButtonBar(QWidget *parent)
-    : QWidget(parent)
+    : QWidget(parent),
+      m_contextButtons(0)
 {
     qDebug() << __PRETTY_FUNCTION__;
 
@@ -61,29 +60,20 @@ void PanelContextButtonBar::paintEvent(QPaintEvent *event)
 
 }
 
-void PanelContextButtonBar::setContextButtons(const QList<ImageButton *> &contextButtonList)
+void PanelContextButtonBar::setContextButtons(QWidget *contextButtons)
 {
     qDebug() << __PRETTY_FUNCTION__;
 
-    const int CONTEXT_BUTTON_HEIGHT = 74;
-    const int CONTEXT_BUTTON_MARGIN_LEFT = 2;
-    const int CONTEXT_BUTTON_MARGIN_TOP = 10;
-
     // Hide previous buttons (if any)
-    for (int i = 0; i < m_contextButtonList.size(); i ++) {
-        m_contextButtonList.at(i)->setParent(0);
-    }
+    if (m_contextButtons)
+        m_contextButtons->setParent(0);
 
-    m_contextButtonList = contextButtonList;
+    m_contextButtons = contextButtons;
 
-    for (int i = 0; i < m_contextButtonList.size(); i ++) {
-        m_contextButtonList.at(i)->setParent(this);
-        m_contextButtonList.at(i)->setVisible(true);
-        m_contextButtonList.at(i)->move(CONTEXT_BUTTON_MARGIN_LEFT,
-                                        CONTEXT_BUTTON_MARGIN_TOP + (CONTEXT_BUTTON_HEIGHT * i));
-    }
+    m_contextButtons->setParent(this);
+    m_contextButtons->setVisible(true);
 
-    setFixedHeight(CONTEXT_BUTTON_MARGIN_TOP + (CONTEXT_BUTTON_HEIGHT * contextButtonList.size()));
+    setFixedHeight(m_contextButtons->height());
 
     emit positionChangeRequested();
 }
index d2528ae..7b4a4ba 100644 (file)
@@ -24,8 +24,6 @@
 
 #include <QWidget>
 
-class ImageButton;
-
 class PanelContextButtonBar : public QWidget
 {
     Q_OBJECT
@@ -56,9 +54,9 @@ public:
     /**
      * @brief Sets the context buttons to the context button bar
      *
-     * @param contextButtonList List of context buttons
+     * @param contextButtons Pointer to context buttons
      */
-    void setContextButtons(const QList<ImageButton *> &contextButtonList);
+    void setContextButtons(QWidget *contextButtons);
 
 /*******************************************************************************
  * SIGNALS
@@ -73,12 +71,12 @@ signals:
  * DATA MEMBERS
  ******************************************************************************/
 private:
-    QList<ImageButton *> m_contextButtonList;
+    QPixmap m_barTile;          ///< Pixmap for button bar
+    QPixmap m_barTop;           ///< Pixmap for button bar top
 
-    QPixmap m_barTile;  ///< Pixmap for button bar
-    QPixmap m_barTop;   ///< Pixmap for button bar top
+    QRect m_barRect;            ///< Rect for the button bar
 
-    QRect m_barRect;    ///< Rect for the button bar
+    QWidget *m_contextButtons;  ///< Widget for context buttons
 };
 
 #endif // PANELCONTEXTBUTTONBAR_H
index 20ef5f7..af4b47d 100644 (file)
@@ -33,7 +33,7 @@ RoutingPanel::RoutingPanel(QWidget *parent)
                                                         ":/res/images/search_s.png",
                                                         "", this);
 
-    m_contextButtonList.append(searchLocationButton);
+    m_contextButtonLayout->addWidget(searchLocationButton, 0, 0);
 
     m_routeButton = new QPushButton(tr("Route to location"));
     m_routeButton->setDisabled(true);
index c1ed2b1..a8ffab5 100644 (file)
@@ -86,8 +86,8 @@ UserInfoPanel::UserInfoPanel(QWidget *parent)
                                                              ":/res/images/send_position_s.png",
                                                              "", this);
 
-    m_contextButtonList.append(updateFriendsButton);
-    m_contextButtonList.append(updateStatusMessageButton);
+    m_contextButtonLayout->addWidget(updateFriendsButton, 0, 0);
+    m_contextButtonLayout->addWidget(updateStatusMessageButton, 1, 0);
 
     connect(updateFriendsButton, SIGNAL(clicked()),
             this, SIGNAL(refreshUserData()));