From kde-commits Sun Nov 23 20:14:29 2003 From: Unai Garro Date: Sun, 23 Nov 2003 20:14:29 +0000 To: kde-commits Subject: kdenonbeta/krecipes/src/widgets X-MARC-Message: https://marc.info/?l=kde-commits&m=106961854713358 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 -#include +#include #include @@ -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.:"<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 widgetList; // Stores the indexes for the widgets + QMap positionList; // Stores the indexes for the widgets + QMap widgetList; // Stores the widgets for each position (just the inverse mapping) KreMenuButton* activeButton; // Indicates which button is highlighted