Centering, re-factoring
authorSami Rämö <sami.ramo@ixonos.com>
Mon, 6 Sep 2010 08:43:30 +0000 (11:43 +0300)
committerSami Rämö <sami.ramo@ixonos.com>
Mon, 6 Sep 2010 08:43:30 +0000 (11:43 +0300)
 - Buttons are now horizontally centered

 - Bar position and animation target values are now set only once
   in the constructor

src/ui/listitemcontextbuttonbar.cpp
src/ui/listitemcontextbuttonbar.h

index 45fc2e0..6f82dc4 100644 (file)
@@ -51,6 +51,17 @@ ListItemContextButtonBar::ListItemContextButtonBar(QWidget *parent) :
     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");
 
+    // --- LAYOUT ---
+    m_barLayout = new QHBoxLayout();
+    setLayout(m_barLayout);
+    m_barLayout->setContentsMargins(0, 0, 0, 0);
+
+    // --- SET POSITION ---
+    // center this widget horizontally to middle of the panel contents area and set outside of
+    // the view
+    const int FROM_PANEL_CONTENTS_LEFT = PANEL_WIDTH / 2 - width() / 2;
+    move(PANEL_TAB_BAR_WIDTH + PANEL_BAR_WIDTH + FROM_PANEL_CONTENTS_LEFT, -size().height());
+
     // --- ANIMATION ---
     const int ANIMATION_DURATION_MS = 150;
 
@@ -59,6 +70,11 @@ ListItemContextButtonBar::ListItemContextButtonBar(QWidget *parent) :
 
     connect(m_animation, SIGNAL(finished()),
             this, SLOT(onAnimationFinished()));
+
+    // target values for animations
+    m_animation->setStartValue(pos());
+    const int Y = 0;
+    m_animation->setEndValue(QPoint(pos().x(), Y));
 }
 
 ListItemContextButtonBar::~ListItemContextButtonBar()
@@ -84,25 +100,16 @@ void ListItemContextButtonBar::changeButtons()
     if (!isVisible())
         show();
 
-    // Hide previous buttons (if any)
-    if (m_contextButtons)
+    // Remove old buttons (if any)
+    if (m_contextButtons) {
+        m_barLayout->removeWidget(m_contextButtons);
         m_contextButtons->setParent(0);
+    }
 
     m_contextButtons = m_newContextButtons;
     m_newContextButtons = 0;
-    m_contextButtons->setParent(this);
-    m_contextButtons->show();
-//    setFixedWidth(m_contextButtons->width());
 
-    // center this widget horizontally to middle of the panel contents area and set outside of
-    // the view
-    const int FROM_PANEL_CONTENTS_LEFT = PANEL_WIDTH / 2 - width() / 2;
-    move(PANEL_TAB_BAR_WIDTH + PANEL_BAR_WIDTH + FROM_PANEL_CONTENTS_LEFT, -size().height());
-
-    // update new target values for animations
-    m_animation->setStartValue(pos());
-    const int Y = 0;
-    m_animation->setEndValue(QPoint(pos().x(), Y));
+    m_barLayout->addWidget(m_contextButtons, 0, Qt::AlignHCenter);
 }
 
 void ListItemContextButtonBar::hideContextButtonBar()
index 71be646..fb4a10b 100644 (file)
@@ -24,6 +24,7 @@
 
 #include <QWidget>
 
+class QHBoxLayout;
 class QPropertyAnimation;
 
 /**
@@ -134,6 +135,8 @@ private:
 
     bool m_waitForOpen;                 ///< Is showing requested while chaging buttons is not ready
 
+    QHBoxLayout *m_barLayout;           ///< Main layout of this widget
+
     QPixmap *m_backgroundLeft;          ///< Background picture, left part
     QPixmap *m_backgroundMiddle;        ///< Background picture, center part
     QPixmap *m_backgroundRight;         ///< Background picture, right part