Added method for setting the context buttons
authorPekka Nissinen <pekka.nissinen@ixonos.com>
Thu, 19 Aug 2010 11:15:21 +0000 (14:15 +0300)
committerPekka Nissinen <pekka.nissinen@ixonos.com>
Thu, 19 Aug 2010 11:15:21 +0000 (14:15 +0300)
src/ui/panelcontextbuttonbar.cpp
src/ui/panelcontextbuttonbar.h

index 0a6ce46..11c4bbd 100644 (file)
 #include <QDebug>
 #include <QPainter>
 
+#include "imagebutton.h"
+
 #include "panelcontextbuttonbar.h"
 
-const int CONTEXT_BUTTON_BAR_RECT_X = 0;
 const int CONTEXT_BUTTON_BAR_WIDTH = 78;
-const int CONTEXT_BUTTON_BAR_HEIGHT = 16;
-const int CONTEXT_BUTTON_BAR_TOP_HEIGHT = 32;
 
 PanelContextButtonBar::PanelContextButtonBar(QWidget *parent)
     : QWidget(parent)
@@ -37,10 +36,7 @@ PanelContextButtonBar::PanelContextButtonBar(QWidget *parent)
     m_barTile.load(":/res/images/panel_context_button_bar_tile.png");
     m_barTop.load(":/res/images/panel_context_button_bar_top.png");
 
-    m_barRect.setRect(CONTEXT_BUTTON_BAR_RECT_X, CONTEXT_BUTTON_BAR_TOP_HEIGHT,
-                      CONTEXT_BUTTON_BAR_WIDTH, CONTEXT_BUTTON_BAR_HEIGHT);
-
-    resize(CONTEXT_BUTTON_BAR_WIDTH, CONTEXT_BUTTON_BAR_HEIGHT + CONTEXT_BUTTON_BAR_TOP_HEIGHT);
+    setFixedWidth(CONTEXT_BUTTON_BAR_WIDTH);
 }
 
 void PanelContextButtonBar::paintEvent(QPaintEvent *event)
@@ -49,12 +45,45 @@ void PanelContextButtonBar::paintEvent(QPaintEvent *event)
 
     Q_UNUSED(event);
 
+    const int CONTEXT_BUTTON_BAR_RECT_X = 0;
+
+    const int CONTEXT_BUTTON_BAR_TOP_HEIGHT = 32;
     const int CONTEXT_BUTTON_BAR_TOP_X = 0;
     const int CONTEXT_BUTTON_BAR_TOP_Y = 0;
 
     QPainter painter(this);
 
+    m_barRect.setRect(CONTEXT_BUTTON_BAR_RECT_X, CONTEXT_BUTTON_BAR_TOP_HEIGHT,
+                      CONTEXT_BUTTON_BAR_WIDTH, height() - CONTEXT_BUTTON_BAR_TOP_HEIGHT);
+
     painter.drawPixmap(CONTEXT_BUTTON_BAR_TOP_X, CONTEXT_BUTTON_BAR_TOP_Y, m_barTop);
     painter.drawTiledPixmap(m_barRect, m_barTile);
 
 }
+
+void PanelContextButtonBar::setContextButtons(const QList<ImageButton *> &contextButtonList)
+{
+    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);
+    }
+
+    m_contextButtonList = contextButtonList;
+
+    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));
+    }
+
+    setFixedHeight(CONTEXT_BUTTON_MARGIN_TOP + (CONTEXT_BUTTON_HEIGHT * contextButtonList.size()));
+
+    emit positionChangeRequested();
+}
index 4e39c0a..d2528ae 100644 (file)
@@ -24,6 +24,8 @@
 
 #include <QWidget>
 
+class ImageButton;
+
 class PanelContextButtonBar : public QWidget
 {
     Q_OBJECT
@@ -48,9 +50,31 @@ protected:
     void paintEvent(QPaintEvent *event);
 
 /*******************************************************************************
+ * MEMBER FUNCTIONS AND SLOTS
+ ******************************************************************************/
+public:
+    /**
+     * @brief Sets the context buttons to the context button bar
+     *
+     * @param contextButtonList List of context buttons
+     */
+    void setContextButtons(const QList<ImageButton *> &contextButtonList);
+
+/*******************************************************************************
+ * SIGNALS
+ ******************************************************************************/
+signals:
+    /**
+     * @brief This signal is called when context button bar needs to be repositioned
+     */
+    void positionChangeRequested();
+
+/*******************************************************************************
  * DATA MEMBERS
  ******************************************************************************/
 private:
+    QList<ImageButton *> m_contextButtonList;
+
     QPixmap m_barTile;  ///< Pixmap for button bar
     QPixmap m_barTop;   ///< Pixmap for button bar top