* lump all actions over the max at the end

* don't use magic numbers but the enum
* don't leak icon items when the action is destroyed

svn path=/trunk/KDE/kdelibs/; revision=1035440
This commit is contained in:
Aaron J. Seigo 2009-10-15 02:39:38 +00:00
parent 5a36b63df8
commit 0d90362d1a
2 changed files with 26 additions and 21 deletions

View File

@ -356,25 +356,44 @@ void IconWidgetPrivate::init()
void IconWidget::addIconAction(QAction *action)
{
int count = d->cornerActions.count();
if (count > 3) {
if (count >= IconWidgetPrivate::LastIconPosition) {
kDebug() << "no more room for more actions!";
// just overlap it with the last item for now. ugly, but there you go.
}
IconAction *iconAction = new IconAction(this, action);
d->cornerActions.append(iconAction);
connect(action, SIGNAL(destroyed(QObject*)), this, SLOT(actionDestroyed(QObject*)));
iconAction->setRect(d->actionRect((IconWidgetPrivate::ActionPosition)count));
iconAction->setRect(d->actionRect(qMin((IconWidgetPrivate::ActionPosition)count, IconWidgetPrivate::LastIconPosition)));
}
void IconWidget::removeIconAction(QAction *action)
{
foreach (IconAction *i_action, d->cornerActions) {
if (i_action->action() == action) {
delete i_action;
d->cornerActions.removeAll(i_action);
//WARNING: do NOT access the action pointer passed in, as it may already be
//be destroyed. see IconWidgetPrivate::actionDestroyed(QObject*)
int count = 0;
bool found = false;
foreach (IconAction *iconAction, d->cornerActions) {
if (found) {
iconAction->setRect(d->actionRect((IconWidgetPrivate::ActionPosition)count));
} else if (iconAction->action() == action) {
delete iconAction;
d->cornerActions.removeAll(iconAction);
}
if (count < IconWidgetPrivate::LastIconPosition) {
++count;
}
}
// redraw since an action has been deleted.
update();
}
void IconWidgetPrivate::actionDestroyed(QObject *action)
{
q->removeIconAction(static_cast<QAction*>(action));
}
void IconWidget::setAction(QAction *action)
@ -387,20 +406,6 @@ QAction *IconWidget::action() const
return d->action;
}
void IconWidgetPrivate::actionDestroyed(QObject *action)
{
QList<IconAction*>::iterator it = cornerActions.begin();
while (it != cornerActions.end()) {
if ((*it)->action() == action) {
cornerActions.erase(it);
break;
}
}
q->update(); // redraw since an action has been deleted.
}
int IconWidget::numDisplayLines()
{
return d->numDisplayLines;

View File

@ -166,7 +166,7 @@ public:
TopRight,
BottomLeft,
BottomRight,
LastIconPosition
LastIconPosition = BottomRight
};
// Margin functions