/*! \reimp */
void QToolBar::actionEvent(QActionEvent *event)
{
    Q_D(QToolBar);
    QAction *action = event->action();
    QWidgetAction *widgetAction = qobject_cast<QWidgetAction *>(action);

    switch (event->type()) {
    case QEvent::ActionAdded: {
        Q_ASSERT_X(widgetAction == 0 || d->layout->indexOf(widgetAction) == -1,
                   "QToolBar", "widgets cannot be inserted multiple times");

        // reparent the action to this toolbar if it has been created
        // using the addAction(text) etc. convenience functions, to
        // preserve Qt 4.1.x behavior. The widget is already
        // reparented to us due to the createWidget call inside
        // createItem()
        if (widgetAction != 0 && widgetAction->d_func()->autoCreated)
            widgetAction->setParent(this);

        int index = d->layout->count();
        if (event->before()) {
            index = d->layout->indexOf(event->before());
            Q_ASSERT_X(index != -1, "QToolBar::insertAction", "internal error");
        }
        d->layout->insertAction(index, action);
        break;
    }

    case QEvent::ActionChanged:
        d->layout->invalidate();
        break;

    case QEvent::ActionRemoved: {
        int index = d->layout->indexOf(action);
        if (index != -1) {
            delete d->layout->takeAt(index);
        }
        break;
    }

    default:
        Q_ASSERT_X(false, "QToolBar::actionEvent", "internal error");
    }
}