[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    kdenonbeta/krecipes/src/widgets
From:       Unai Garro <Unai.Garro () ee ! ed ! ac ! uk>
Date:       2003-11-23 20:14:29
[Download RAW message or body]

CVS commit by uga: 

Fix positioning after removal of a button (right now it only supports removal of the last button)


  M +24 -3     kremenu.cpp   1.14
  M +2 -1      kremenu.h   1.7


--- kdenonbeta/krecipes/src/widgets/kremenu.cpp  #1.13:1.14
@@ -19,5 +19,5 @@
 #include <qpixmap.h>
 
-#include <iostream.h>
+#include <iostream>
 
 #include <kcursor.h>
@@ -185,8 +185,29 @@ void KreMenu::childEvent (QChildEvent *e
                 button->move(0,childPos);
                 childPos+=button->height();
-                widgetList[button]=widgetNumber; widgetNumber++; // Store index for this widget, and increment number
+                positionList[button]=widgetNumber; // Store index for this widget, and increment number
+                widgetList[widgetNumber]=button; // Store the button in the list (the inverse mapping of the previous one)
+                 widgetNumber++;
+
                 connect (button,SIGNAL(clicked(KreMenuButton*)),this,SLOT(collectClicks(KreMenuButton*)));
                 }
         }
+        else if (e->type()==QEvent::ChildRemoved)
+        {
+        QObject *child=e->child();
+        KreMenuButton *button=(KreMenuButton*) child;
+        if (positionList.find(button)!=positionList.end()) // Ensure that what was removed was a button
+                {
+                // Remove the button from the list first
+                int pos=positionList[button];
+                widgetList.remove(pos);
+                positionList.remove(button);
+
+                // Now recalculate the position of the next button
+                widgetNumber--;
+                std::cerr<<"Will be inserted after widget id.:"<<widgetNumber-1<<"\n";
+                KreMenuButton *lastButton=widgetList[widgetNumber-1];
+                if (lastButton) childPos=lastButton->y()+lastButton->height();
+                }
+        }
 
 }
@@ -201,5 +222,5 @@ activeButton->update();
 //Activate the new button
 
-int widgetn=widgetList[w];
+int widgetn=positionList[w];
 w->setActive(true); w->update();
 activeButton=w;

--- kdenonbeta/krecipes/src/widgets/kremenu.h  #1.6:1.7
@@ -53,5 +53,6 @@ private:
         int childPos;
         int widgetNumber;
-        QMap <KreMenuButton*,int> widgetList; // Stores the indexes for the widgets
+        QMap <KreMenuButton*,int> positionList; // Stores the indexes for the widgets
+        QMap <int,KreMenuButton*> widgetList; // Stores the widgets for each position (just the inverse mapping)
         KreMenuButton* activeButton; // Indicates which button is highlighted
 


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic