FEATURE: allow to add actions with only text in the extender titlebar, they will appear as push buttons

svn path=/trunk/KDE/kdelibs/; revision=1177247
This commit is contained in:
Marco Martin 2010-09-19 21:28:39 +00:00
parent 83a9fc7f21
commit ec9a6ad1ba
2 changed files with 46 additions and 15 deletions

View File

@ -48,6 +48,7 @@
#include "view.h" #include "view.h"
#include "widgets/iconwidget.h" #include "widgets/iconwidget.h"
#include "widgets/pushbutton.h"
#include "private/applethandle_p.h" #include "private/applethandle_p.h"
#include "private/extender_p.h" #include "private/extender_p.h"
@ -808,28 +809,37 @@ void ExtenderItemPrivate::updateToolBox()
const QSizeF widgetSize = collapseIcon->sizeFromIconSize(toolbox->iconSize()); const QSizeF widgetSize = collapseIcon->sizeFromIconSize(toolbox->iconSize());
QSet<QAction*> shownActions = actionsInOrder.toSet(); QSet<QAction*> shownActions = actionsInOrder.toSet();
QHash<QAction *, IconWidget *> actionIcons;
QHash<QAction *, QGraphicsWidget *> actionWidgets;
for (int index = startingIndex; index < toolboxLayout->count(); ++index) { for (int index = startingIndex; index < toolboxLayout->count(); ++index) {
IconWidget *widget = dynamic_cast<IconWidget*>(toolboxLayout->itemAt(index)); QGraphicsWidget *widget = dynamic_cast<QGraphicsWidget*>(toolboxLayout->itemAt(index));
QAction *widgetAction = 0;
if (!widget) { if (!widget) {
continue; continue;
} else if (qobject_cast<IconWidget*>(widget)) {
widgetAction = static_cast<IconWidget*>(widget)->action();
} else if (qobject_cast<PushButton*>(widget)) {
widgetAction = static_cast<PushButton*>(widget)->action();
} else {
continue;
} }
if (closeIndex == -1 && destroyActionVisibility && if (closeIndex == -1 && destroyActionVisibility &&
closeAction && widget->action() == closeAction) { closeAction && widgetAction == closeAction) {
closeIndex = index; closeIndex = index;
continue; continue;
} }
if (returnToSourceIndex == -1 && returnToSourceVisibility && if (returnToSourceIndex == -1 && returnToSourceVisibility &&
returnToSourceAction && widget->action() == returnToSourceAction) { returnToSourceAction && widgetAction == returnToSourceAction) {
returnToSourceIndex = index; returnToSourceIndex = index;
continue; continue;
} }
if (shownActions.contains(widget->action())) { if (shownActions.contains(widgetAction)) {
actionIcons.insert(widget->action(), widget); actionWidgets.insert(widgetAction, widget);
continue; continue;
} }
@ -837,6 +847,7 @@ void ExtenderItemPrivate::updateToolBox()
widget->deleteLater(); widget->deleteLater();
} }
// ensure the collapseIcon is the correct size. // ensure the collapseIcon is the correct size.
collapseIcon->setMinimumSize(widgetSize); collapseIcon->setMinimumSize(widgetSize);
collapseIcon->setMaximumSize(widgetSize); collapseIcon->setMaximumSize(widgetSize);
@ -844,16 +855,33 @@ void ExtenderItemPrivate::updateToolBox()
//add the actions that are actually set to visible. //add the actions that are actually set to visible.
foreach (QAction *action, actionsInOrder) { foreach (QAction *action, actionsInOrder) {
if (action->isVisible() && action != closeAction) { if (action->isVisible() && action != closeAction) {
IconWidget *icon = actionIcons.value(action); IconWidget *icon = qobject_cast<IconWidget*>(actionWidgets.value(action));
if (!icon) { PushButton *button = qobject_cast<PushButton*>(actionWidgets.value(action));
icon = new IconWidget(q);
icon->setAction(action);
}
icon->setMinimumSize(widgetSize); if (action->icon().isNull() && !action->text().isNull()) {
icon->setMaximumSize(widgetSize); if (!button) {
icon->setCursor(Qt::ArrowCursor); button = new PushButton(q);
toolboxLayout->insertItem(startingIndex, icon); button->setAction(action);
}
button->setMinimumHeight(widgetSize.height());
button->setMaximumHeight(widgetSize.height());
button->setCursor(Qt::ArrowCursor);
toolboxLayout->insertItem(startingIndex, button);
} else {
if (!icon) {
icon = new IconWidget(q);
icon->setAction(action);
}
if (action->icon().isNull()) {
icon->setText(action->text());
}
icon->setMinimumSize(widgetSize);
icon->setMaximumSize(widgetSize);
icon->setCursor(Qt::ArrowCursor);
toolboxLayout->insertItem(startingIndex, icon);
}
} }
} }

View File

@ -71,6 +71,7 @@ class ExtenderPrivate
void delayItemAddedEvent(); void delayItemAddedEvent();
void loadExtenderItems(); void loadExtenderItems();
void updateBorders(); void updateBorders();
void delayItemAddedEvent();
void updateEmptyExtenderLabel(); void updateEmptyExtenderLabel();
ExtenderGroup *findGroup(const QString &name) const; ExtenderGroup *findGroup(const QString &name) const;
@ -94,6 +95,8 @@ class ExtenderPrivate
static QGraphicsGridLayout *s_popupLayout; static QGraphicsGridLayout *s_popupLayout;
bool destroying; bool destroying;
QList<QPair<ExtenderItem *, QPointF> > pendingItems;
}; };
} // namespace Plasma } // namespace Plasma