Plasma::IconWidget *WebBrowser::addTool(const QString &iconString, QGraphicsLinearLayout *layout) { Plasma::IconWidget *icon = new Plasma::IconWidget(this); QAction *action = new QAction(KIcon(iconString), QString(), this); icon->setAction(action); icon->setPreferredSize(icon->sizeFromIconSize(IconSize(KIconLoader::Toolbar))); layout->addItem(icon); return icon; }
Plasma::IconWidget* Context::Applet::addAction( QGraphicsItem *parent, QAction *action, const int size ) { if( !action ) return 0; Plasma::IconWidget *tool = new Plasma::IconWidget( parent ); tool->setAction( action ); tool->setText( QString() ); tool->setToolTip( action->text() ); tool->setDrawBackground( false ); tool->setOrientation( Qt::Horizontal ); const QSizeF iconSize = tool->sizeFromIconSize( size ); tool->setMinimumSize( iconSize ); tool->setMaximumSize( iconSize ); tool->resize( iconSize ); tool->setZValue( zValue() + 1 ); return tool; }
void NetToolBox::addTool(QAction *action) { Plasma::IconWidget *button = new Plasma::IconWidget(this); button->setOrientation(Qt::Horizontal); button->setTextBackgroundColor(QColor()); button->installEventFilter(m_toolContainer); button->setAction(action); qreal left, top, right, bottom; m_toolContainer->itemBackground()->getContentsMargins(&left, &top, &right, &bottom); button->setContentsMargins(left, top, right, bottom); if (m_location == Plasma::LeftEdge || m_location == Plasma::RightEdge) { button->setOrientation(Qt::Vertical); } else { button->setOrientation(Qt::Horizontal); } m_actionButtons[action] = button; if (action == m_containment->action("remove")) { m_toolContainerLayout->addItem(button); --m_newToolsPosition; } else if (action == m_containment->action("add page")) { m_toolContainerLayout->insertItem(m_newToolsPosition+1, button); --m_newToolsPosition; } else if (action == m_containment->action("add applications")) { m_toolContainerLayout->insertItem(1, button); --m_newToolsPosition; } else { m_toolContainerLayout->insertItem(m_newToolsPosition, button); } ++m_newToolsPosition; if (m_toolContainerLayout->count() == 1) { m_toolContainer->itemBackground()->setTargetItem(button); } }