Added background for ListItemContextButtonBar
[situare] / src / ui / listitemcontextbuttonbar.cpp
index 96c0b75..4a8edb5 100644 (file)
@@ -20,6 +20,7 @@
 */
 
 #include <QDebug>
+#include <QPainter>
 #include <QPropertyAnimation>
 #include <QStateMachine>
 
@@ -36,6 +37,15 @@ ListItemContextButtonBar::ListItemContextButtonBar(QWidget *parent) :
 {
     qDebug() << __PRETTY_FUNCTION__;
 
+    // --- BAR LOOK ---
+    const int BAR_HEIGHT = 78;
+    setFixedHeight(BAR_HEIGHT);
+
+    m_backgroundLeft = new QPixmap(":/res/images/list_item_context_button_bar_left.png");
+    m_backgroundMiddle = new QPixmap(":/res/images/list_item_context_button_bar_tile.png");
+    m_backgroundRight = new QPixmap(":/res/images/list_item_context_button_bar_right.png");
+
+    // --- ANIMATION ---
     const int ANIMATION_DURATION_MS = 150;
 
     m_animation = new QPropertyAnimation(this, "pos", this);
@@ -45,9 +55,23 @@ ListItemContextButtonBar::ListItemContextButtonBar(QWidget *parent) :
             this, SLOT(onAnimationFinished()));
 }
 
+ListItemContextButtonBar::~ListItemContextButtonBar()
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    if (m_backgroundLeft)
+        delete m_backgroundLeft;
+
+    if (m_backgroundMiddle)
+        delete m_backgroundMiddle;
+
+    if (m_backgroundRight)
+        delete m_backgroundRight;
+}
+
 void ListItemContextButtonBar::changeButtons()
 {
-    qWarning() << __PRETTY_FUNCTION__;
+    qDebug() << __PRETTY_FUNCTION__;
 
     Q_ASSERT(m_animation->state() == QAbstractAnimation::Stopped);
 
@@ -74,7 +98,7 @@ void ListItemContextButtonBar::changeButtons()
 
 void ListItemContextButtonBar::hideContextButtonBar()
 {
-    qWarning() << __PRETTY_FUNCTION__;
+    qDebug() << __PRETTY_FUNCTION__;
 
     m_state = StateClosing;
     m_animation->setDirection(QAbstractAnimation::Backward);
@@ -83,7 +107,7 @@ void ListItemContextButtonBar::hideContextButtonBar()
 
 void ListItemContextButtonBar::onAnimationFinished()
 {
-    qWarning() << __PRETTY_FUNCTION__;
+    qDebug() << __PRETTY_FUNCTION__;
 
     if (m_animation->direction() == QAbstractAnimation::Backward) {
         m_state = StateHidden;
@@ -101,21 +125,37 @@ void ListItemContextButtonBar::onAnimationFinished()
 
 void ListItemContextButtonBar::onListItemSelectionChanged(bool itemIsSelected)
 {
-    qWarning() << __PRETTY_FUNCTION__;
+    qDebug() << __PRETTY_FUNCTION__;
 
-    /// @todo m_waitForOpen is not cleared if item selection is removed while waiting
+    if (itemIsSelected) {
+        if (m_newContextButtons)
+            m_waitForOpen = true;
+        else if (m_state != StateVisible)
+            showContextButtonBar();
+    } else {
+        if (m_newContextButtons)
+            m_waitForOpen = false;
+        else if (m_state != StateHidden)
+            hideContextButtonBar();
+    }
+}
 
-    if (m_newContextButtons)
-        m_waitForOpen = true;
-    else if (itemIsSelected && (m_state != StateVisible))
-        showContextButtonBar();
-    else if (!itemIsSelected && (m_state != StateHidden))
-        hideContextButtonBar();
+void ListItemContextButtonBar::paintEvent(QPaintEvent *event)
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    Q_UNUSED(event);
+
+    QPainter painter(this);
+
+    painter.drawPixmap(0, 0, *m_backgroundLeft);
+    painter.drawTiledPixmap(24, 0, width() - 2 * 24, 78, *m_backgroundMiddle);
+    painter.drawPixmap(width() - 24, 0, *m_backgroundRight);
 }
 
 void ListItemContextButtonBar::setContextButtons(QWidget *contextButtons)
 {
-    qWarning() << __PRETTY_FUNCTION__;
+    qDebug() << __PRETTY_FUNCTION__;
 
     m_newContextButtons = contextButtons;
     m_waitForOpen = false;
@@ -128,7 +168,7 @@ void ListItemContextButtonBar::setContextButtons(QWidget *contextButtons)
 
 void ListItemContextButtonBar::showContextButtonBar()
 {
-    qWarning() << __PRETTY_FUNCTION__;
+    qDebug() << __PRETTY_FUNCTION__;
 
     m_state = StateOpening;
     m_animation->setDirection(QAbstractAnimation::Forward);