All pastes #1326546 Raw Edit

Stuff

public text v1 · immutable
#1326546 ·published 2009-02-03 20:36 UTC
rendered paste body
Index: libs/libmythui/mythuibuttonlist.h
===================================================================
--- libs/libmythui/mythuibuttonlist.h	(revision 19923)
+++ libs/libmythui/mythuibuttonlist.h	(working copy)
@@ -178,11 +178,14 @@
     void Const();
     virtual void Init();
 
+    virtual void CalculateButtonPositions();
+
     void InsertItem(MythUIButtonListItem *item);
 
     void SetPositionArrowStates(void);
 
     /* methods for subclasses to override */
+    virtual void newCalculateVisibleItems(void);
     virtual void CalculateVisibleItems(void);
     virtual QPoint GetButtonPosition(int column, int row) const;
 
@@ -203,6 +206,8 @@
 
     int m_itemWidth;
     int m_itemHeight;
+    int m_itemSelectedWidth;
+    int m_itemSelectedHeight;
     int m_itemHorizSpacing;
     int m_itemVertSpacing;
     uint m_itemsVisible;
Index: libs/libmythui/mythuibuttonlist.cpp
===================================================================
--- libs/libmythui/mythuibuttonlist.cpp	(revision 19923)
+++ libs/libmythui/mythuibuttonlist.cpp	(working copy)
@@ -217,6 +217,7 @@
         for (int i = 0; i < button; i++)
              m_ButtonList[i]->SetVisible(false);
 
+
         bool seenSelected = false;
 
         MythUIStateType *realButton = NULL;
@@ -245,6 +246,8 @@
             buttonItem->SetToRealButton(realButton, selected);
             realButton->SetVisible(true);
 
+
+
             if (m_wrapStyle == WrapItems && it == (m_itemList.end()-1) &&
                 m_itemCount >= (int)m_itemsVisible)
             {
@@ -258,6 +261,9 @@
             }
 
             button++;
+            VERBOSE(VB_IMPORTANT, QString("m_selPosition %1 button %2").arg(m_selPosition).arg(button));
+            
+            
         }
 
         for (; button < (int)m_itemsVisible; button++)
@@ -744,6 +750,8 @@
             m_itemHeight = itemArea.height();
         if (m_itemWidth < itemArea.width())
             m_itemWidth = itemArea.width();
+        m_itemSelectedHeight = itemArea.height();
+        m_itemSelectedWidth = itemArea.width();
     }
     // End Hack
 
@@ -886,6 +894,88 @@
     return QPoint(x,y);
 }
 
+void MythUIButtonList::newCalculateVisibleItems(void)
+{
+    int y = 0;
+    int x = 0;
+    m_itemsVisible = 0;
+    m_rows = 0;
+    m_columns = 0;
+
+    if ((m_layout == LayoutHorizontal) || (m_layout == LayoutGrid))
+    {
+        if (x <= m_contentsRect.width() - m_itemSelectedWidth)
+        {
+            y += m_itemSelectedWidth + m_itemHorizSpacing;
+            m_columns++;
+        }
+
+        while (x <= m_contentsRect.width() - m_itemWidth)
+        {
+            x += m_itemWidth + m_itemHorizSpacing;
+            m_columns++;
+        }
+    }
+
+    if ((m_layout == LayoutVertical) || (m_layout == LayoutGrid))
+    {
+
+        if (y <= m_contentsRect.height() - m_itemSelectedHeight)
+        {
+            y += m_itemSelectedHeight + m_itemVertSpacing;
+            m_rows++;
+        }
+
+        while (y <= m_contentsRect.height() - m_itemHeight)
+        {
+            y += m_itemHeight + m_itemVertSpacing;
+            m_rows++;
+        }
+    }
+
+    if (m_rows <= 0)
+        m_rows = 1;
+
+    if (m_columns <= 0)
+        m_columns = 1;
+
+    m_itemsVisible = m_columns * m_rows;
+}
+
+void MythUIButtonList::CalculateButtonPositions(void)
+{
+	
+	int col = 1;
+    int row = 1;
+
+    int x = 0;
+    int y = 1;
+    int lastx = m_contentsRect.x();
+    int lasty = m_contentsRect.y();
+    
+    for (int i = 0; i < (int)m_itemsVisible; i++)
+    {
+        QString name = QString("buttonlist button %1").arg(i);
+        MythUIStateType *button = new MythUIStateType(this, name);
+        button->CopyFrom(buttontemplate);
+
+        if (col > m_columns)
+        {
+            col = 1;
+            y = lasty + (m_itemHeight + m_itemVertSpacing);
+            row++;
+            lasty = y;
+        }
+
+        button->SetPosition(x,y);
+        x = lastx + (m_itemWidth + m_itemHorizSpacing);
+        col++;
+        lastx = x;
+       // m_ButtonList.push_back(button);
+    }
+	
+}
+
 void MythUIButtonList::CalculateVisibleItems(void)
 {
     int y = 0;