static Plasma::IconWidget *createButton(QGraphicsWidget *parent)
{
    Plasma::IconWidget *button = new Plasma::IconWidget(parent);
    button->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
    button->setOrientation(Qt::Horizontal);
    button->setDrawBackground(true);
    button->setTextBackgroundColor(QColor(Qt::transparent));
    return button;
}
Beispiel #2
0
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);
    }
}
Beispiel #3
0
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;
}