コード例 #1
0
ファイル: ActionListWidget.cpp プロジェクト: KDE/ktutorial
void ActionListWidget::actionEvent(QActionEvent* event) {
    if (event->type() == QEvent::ActionAdded) {
        addToolButtonForAction(event->action(),
                               toolButtonForAction(event->before()));
        return;
    }

    if (event->type() == QEvent::ActionRemoved) {
        QToolButton* button = toolButtonForAction(event->action());
        layout()->removeWidget(button);
        button->deleteLater();
        return;
    }
}
コード例 #2
0
ファイル: actionrepository.cpp プロジェクト: Fale/qtmoko
QPixmap  ActionRepositoryMimeData::actionDragPixmap(const QAction *action)
{

    // Try to find a suitable pixmap. Grab either widget or icon.
    const QIcon icon = action->icon();
    if (!icon.isNull())
        return icon.pixmap(QSize(22, 22));

    foreach (QWidget *w, action->associatedWidgets())
        if (QToolButton *tb = qobject_cast<QToolButton *>(w))
            return QPixmap::grabWidget(tb);

    // Create a QToolButton
    QToolButton *tb = new QToolButton;
    tb->setText(action->text());
    tb->setToolButtonStyle(Qt::ToolButtonTextOnly);
#ifdef Q_WS_WIN // Force alien off to make adjustSize() take the system minimumsize into account.
    tb->createWinId();
#endif
    tb->adjustSize();
    const QPixmap rc = QPixmap::grabWidget(tb);
    tb->deleteLater();
    return rc;
}
コード例 #3
0
gNodeComponentWidget::gNodeComponentWidget(sJarvisNodeComponent* comp,QWidget *parent) :
    QGroupBox(parent), m_component(comp),
    ui(new Ui::gNodeComponentWidget)
{
    ui->setupUi(this);

    this->setTitle(m_component->getId());

    QList<jarvisActions> actions = m_component->getActions();
    for(int i = 0 ; i < actions.count() ; i++)
    {
        jarvisActions action = actions[i];
        //qDebug() << QString::number(int(action));
        QToolButton* b = new QToolButton(ui->actionsBox);
        QGridLayout* l = (QGridLayout*)ui->actionsBox->layout();

        if      (action == A_DIMM){
            b->deleteLater();
            QSlider* w = new QSlider(this);
            w->setMaximum(100);
            w->setValue(50);
            l->addWidget(w,l->count()/2,l->count()%2);
            connect(w,SIGNAL(valueChanged(int)),m_component,SLOT(dimm(int)));

        }else if(action == A_SET_COLOR){
            connect(b,SIGNAL(clicked()),this,SLOT(selectComponentColor()));
            b->setText(m_component->actionName((m_component->getActions()[i])));
            l->addWidget(b,l->count()/2,l->count()%2);

        }else if(action == A_SET_LEDS){
            connect(b,SIGNAL(clicked()),this,SLOT(sendImage()));
            b->setText(m_component->actionName((m_component->getActions()[i])));
            l->addWidget(b,l->count()/2,l->count()%2);

        }else if(action == A_DISPLAY){
            connect(b,SIGNAL(clicked()),this,SLOT(sendImage()));
            b->setText(m_component->actionName((m_component->getActions()[i])));
            l->addWidget(b,l->count()/2,l->count()%2);
        }else if(action == A_PLAYRTTTL){
            connect(b,SIGNAL(clicked()),this,SLOT(openRtttlPlayer()));
            b->setText(m_component->actionName((m_component->getActions()[i])));
            l->addWidget(b,l->count()/2,l->count()%2);
        }else{
            QString slotName = m_component->slotName(m_component->getActions()[i]);
            b->setText(m_component->actionName((m_component->getActions()[i])));
            l->addWidget(b,l->count()/2,l->count()%2);
            connect(b,SIGNAL(clicked()),m_component,slotName.toStdString().c_str());
        }
    }

    QList<jarvisEvents> events = m_component->getCapableEvents();
    for(int i = 0 ; i < events.count() ; i++)
    {
        gBlinkWidget* w = new gBlinkWidget(ui->eventsBox);
        QLabel* label = new QLabel(ui->eventsBox);
        QGridLayout* l = (QGridLayout*)ui->eventsBox->layout();
        l->addWidget(label,i,0);
        l->addWidget(w,i,1);
        w->setMaximumHeight(50);
        if(events[i] == E_RAW_READ)
        {
            connect(m_component,SIGNAL(rawRead()),w,SLOT(blink()));
            connect(m_component,SIGNAL(rawRead(QStringList)),w,SLOT(displayRead(QStringList)));
            label->setText(m_component->eventName((m_component->getCapableEvents()[i])));

        }else if(events[i] == E_DATA_READ)
        {
            connect(m_component,SIGNAL(dataRead()),w,SLOT(blink()));
            connect(m_component,SIGNAL(dataRead(QStringList)),w,SLOT(displayRead(QStringList)));
            label->setText(m_component->eventName((m_component->getCapableEvents()[i])));

        }else
        {
            QString signalName = m_component->signalName(m_component->getCapableEvents()[i]);
            label->setText(m_component->eventName((m_component->getCapableEvents()[i])));
            connect(m_component,signalName.toStdString().c_str(),w,SLOT(blink()));
        }
        //w->setMinimumSize(32,32);
        //w->setMaximumSize(32,32);
    }
}