From: Pekka Nissinen Date: Thu, 19 Aug 2010 11:15:21 +0000 (+0300) Subject: Added method for setting the context buttons X-Git-Tag: v2.0b-1~51 X-Git-Url: http://git.maemo.org/git/?p=situare;a=commitdiff_plain;h=b22c177c72658752f283512b23ab1fe5bca39617 Added method for setting the context buttons --- diff --git a/src/ui/panelcontextbuttonbar.cpp b/src/ui/panelcontextbuttonbar.cpp index 0a6ce46..11c4bbd 100644 --- a/src/ui/panelcontextbuttonbar.cpp +++ b/src/ui/panelcontextbuttonbar.cpp @@ -22,12 +22,11 @@ #include #include +#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 &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(); +} diff --git a/src/ui/panelcontextbuttonbar.h b/src/ui/panelcontextbuttonbar.h index 4e39c0a..d2528ae 100644 --- a/src/ui/panelcontextbuttonbar.h +++ b/src/ui/panelcontextbuttonbar.h @@ -24,6 +24,8 @@ #include +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 &contextButtonList); + +/******************************************************************************* + * SIGNALS + ******************************************************************************/ +signals: + /** + * @brief This signal is called when context button bar needs to be repositioned + */ + void positionChangeRequested(); + +/******************************************************************************* * DATA MEMBERS ******************************************************************************/ private: + QList m_contextButtonList; + QPixmap m_barTile; ///< Pixmap for button bar QPixmap m_barTop; ///< Pixmap for button bar top