Example #1
0
void PhaseItem::mousePressEvent(QGraphicsSceneMouseEvent* e)
{
    if(mControlsVisible && checkRect().contains(e->pos()))
    {
        //qDebug() << "-> Check clicked";
        
        // Do not select phase when clicking on the box
        e->accept();
        
        if(mState == Qt::PartiallyChecked) mState = Qt::Checked;
        else if(mState == Qt::Checked) mState = Qt::Unchecked;
        else if(mState == Qt::Unchecked) mState = Qt::Checked;
        
        MainWindow::getInstance()->getProject()->updatePhaseEvents(mData[STATE_ID].toInt(), mState);
        
        //update();
        //if(scene())
          //  scene()->update();
    }
    else if(mControlsVisible && eyeRect().contains(e->pos()))
    {
        //qDebug() << "-> Eye clicked";
        
        // Do not select phase when clicking on the box
        e->accept();
        
        mEyeActivated = !mEyeActivated;
        ((PhasesScene*)mScene)->updateEyedPhases();
        
        update();
        if(scene())
            scene()->update();
    }
    else
    {
        AbstractItem::mousePressEvent(e);
    }
}
Example #2
0
void DataPanel::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
    QColor color=QColor(0,0,0,50);
    painter->setPen(color);
    QBrush brush=QBrush(color);
    painter->setBrush(brush);
    painter->drawRect(boundingRect());
    painter->setPen(Qt::white);
    QRectF fpsRect(5,0,boundingRect().width()/2,20);
    QString fpsStr="FPS : "+QString::number(fps);
    painter->drawText(fpsRect,fpsStr);

    fpsRect=QRectF(boundingRect().width()/2+5,0,boundingRect().width()/2,20);
    QString rStr=QObject::tr("Radius : %1").arg(displayRadius);
    painter->drawText(fpsRect,rStr);

    QRectF posRect(5,20,100,80);
    QString posStr=QObject::tr("pos: \nX: %1\nY: %2\nZ: %3").arg(mPosition.x()).arg(mPosition.y()).arg(mPosition.z());
    painter->drawText(posRect,posStr);

    QRectF eyeRect(105,20,100,80);
    QString eyeStr=QObject::tr("pos: \nX: %1\nY: %2\nZ: %3").arg(mEyePosition.x()).arg(mEyePosition.y()).arg(mEyePosition.z());
    painter->drawText(eyeRect,eyeStr);
}
Example #3
0
void PhaseItem::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget)
{
    Q_UNUSED(option);
    Q_UNUSED(widget);
    
    painter->setRenderHint(QPainter::Antialiasing);
    
    QRectF rect = boundingRect();
    int rounded = 15;
    
    QColor phaseColor = QColor(mData[STATE_COLOR_RED].toInt(),
                               mData[STATE_COLOR_GREEN].toInt(),
                               mData[STATE_COLOR_BLUE].toInt());
    QColor fontColor = getContrastedColor(phaseColor);
    
    painter->setPen(Qt::NoPen);
    painter->setBrush(phaseColor);
    painter->drawRoundedRect(rect, rounded, rounded);
    
    if(mControlsVisible)
    {
        // Checked
        QRectF cRect = checkRect();
        drawCheckBoxBox(*painter, cRect, mState, Qt::white, QColor(150, 150, 150));
        
        // Eye
        QRectF eRect = eyeRect();
        painter->setBrush(Qt::white);
        painter->setPen(Qt::black);
        painter->drawRoundedRect(eRect, 10, 10);
        if(mEyeActivated)
        {
            QPixmap eye(":eye.png");
            painter->drawPixmap(eRect, eye, eye.rect());
        }
    }
    
    // Name
    QRectF tr(rect.x() + mBorderWidth + 2*mEltsMargin + mTitleHeight,
              rect.y() + mBorderWidth + mEltsMargin,
              rect.width() - 2*mBorderWidth - 2*(mTitleHeight + 2*mEltsMargin),
              mTitleHeight);
    
    QFont font = qApp->font();
    painter->setFont(font);
    QFontMetrics metrics(font);
    QString name = mData[STATE_NAME].toString();
    name = metrics.elidedText(name, Qt::ElideRight, tr.width());
    painter->setPen(fontColor);
    painter->drawText(tr, Qt::AlignCenter, name);
    
    // Change font
    font.setPointSizeF(pointSize(11.f));
    painter->setFont(font);
    
    // Type (duration tau)
    QString tauStr = getTauString();
    if(!tauStr.isEmpty())
    {
        QRectF tpr(rect.x() + mBorderWidth + mEltsMargin,
                   rect.y() + rect.height() - mBorderWidth - mEltsMargin - mEltsHeight,
                   rect.width() - 2*mBorderWidth - 2*mEltsMargin,
                   mEltsHeight);
        
        painter->setPen(Qt::black);
        painter->setBrush(Qt::white);
        painter->drawRect(tpr);
        painter->drawText(tpr, Qt::AlignCenter, tauStr);
    }
    
    // Events
    QRectF r(rect.x() + mBorderWidth + mEltsMargin,
             rect.y() + mBorderWidth + mEltsMargin + mTitleHeight + mEltsMargin,
             rect.width() - 2 * (mEltsMargin + mBorderWidth),
             mEltsHeight);
    
    QJsonArray events = getEvents();
    double dy = mEltsMargin + mEltsHeight;
    for(int i=0; i<events.size(); ++i)
    {
        QJsonObject event = events[i].toObject();
        QColor eventColor(event[STATE_COLOR_RED].toInt(),
                          event[STATE_COLOR_GREEN].toInt(),
                          event[STATE_COLOR_BLUE].toInt());
        if(i > 0)
            r.adjust(0, dy, 0, dy);
        
        painter->fillRect(r, eventColor);
        painter->setPen(getContrastedColor(eventColor));
        painter->drawText(r, Qt::AlignCenter, event[STATE_NAME].toString());
    }
    
    // Border
    painter->setBrush(Qt::NoBrush);
    if(isSelected())
    {
        painter->setPen(QPen(Qt::white, 5.f));
        painter->drawRoundedRect(rect.adjusted(1, 1, -1, -1), rounded, rounded);
        
        painter->setPen(QPen(Qt::red, 3.f));
        painter->drawRoundedRect(rect.adjusted(1, 1, -1, -1), rounded, rounded);
    }
}