示例#1
0
void TimeLineCells::mouseDoubleClickEvent( QMouseEvent* event )
{
    int frameNumber = getFrameNumber( event->pos().x() );
    int layerNumber = getLayerNumber( event->pos().y() );

    // -- short scrub --
    if ( event->pos().y() < 20 )
    {
        mPrefs->set(SETTING::SHORT_SCRUB, !shortScrub);
    }

    // -- layer --
    Layer* layer = mEditor->object()->getLayer( layerNumber );
    if ( layer )
    {
        if ( m_eType == TIMELINE_CELL_TYPE::Tracks && ( layerNumber != -1 ) && ( frameNumber > 0 ) && layerNumber < mEditor->object()->getLayerCount() )
        {
            mEditor->object()->getLayer( layerNumber )->mouseDoubleClick( event, frameNumber );
        }
        else if ( m_eType == TIMELINE_CELL_TYPE::Layers )
        {
            layer->editProperties();
            update();
        }
    }
}
BOOST_FIXTURE_TEST_CASE(mappingFirst, myFixture)
{
  auto bank = fparamManagerInstance.getParamBank();
  auto mapping = JPetGeomMapping(bank);
  BOOST_REQUIRE_EQUAL(mapping.getLayersCount(), 3u);
  BOOST_REQUIRE_EQUAL(mapping.getLayersCount(),
                      3u); // is checking same thing 2 times was intended?
  JPetLayer layerOK(1, true, "Layer01", 42.5);
  JPetLayer layerWrong(2, true, "Layer02", 50);

  BOOST_REQUIRE_EQUAL(mapping.getLayerNumber(layerOK), 1u);
  BOOST_REQUIRE_EQUAL(mapping.getLayerNumber(layerWrong),
                      JPetGeomMapping::kBadLayerNumber);

  BOOST_REQUIRE_EQUAL(mapping.getSlotsCount(0),
                      JPetGeomMapping::kBadSlotNumber);
  BOOST_REQUIRE_EQUAL(mapping.getSlotsCount(1), 2u);
  BOOST_REQUIRE_EQUAL(mapping.getSlotsCount(2), 1u);

  auto sizes = mapping.getLayersSizes();
  BOOST_REQUIRE(!sizes.empty());
  BOOST_REQUIRE_EQUAL(sizes.size(), 3u);
}
示例#3
0
void TimeLineCells::mouseReleaseEvent( QMouseEvent* event )
{
    qDebug( "TimeLineCell: mouse release event." );
    if ( event->button() != primaryButton ) return;

    primaryButton = Qt::NoButton;
    endY = startY;
    emit mouseMovedY( 0 );
    timeLine->scrubbing = false;
    int frameNumber = getFrameNumber( event->pos().x() );
    if ( frameNumber < 1 ) frameNumber = -1;
    int layerNumber = getLayerNumber( event->pos().y() );
    if ( m_eType == TIMELINE_CELL_TYPE::Tracks && primaryButton != Qt::MidButton && layerNumber != -1 && layerNumber < mEditor->object()->getLayerCount() )
    {
        Layer *currentLayer = mEditor->object()->getLayer(layerNumber);

        if (!timeLine->scrubbing && !movingFrames && !clickSelecting && !boxSelecting ) {

            // Deselecting if we didn't move, scrub nor select anything
            //
            if ( event->modifiers() == Qt::ControlModifier ) {
                // Add/remove from already selected
                currentLayer->toggleFrameSelected(frameNumber, true);
            }
            else {
                currentLayer->toggleFrameSelected(frameNumber, false);
            }
        }

        currentLayer->mouseRelease( event, frameNumber );
    }
    if ( m_eType == TIMELINE_CELL_TYPE::Layers && layerNumber != startLayerNumber && startLayerNumber != -1 && layerNumber != -1 )
    {
        mEditor->moveLayer( startLayerNumber, layerNumber );
    }
    timeLine->updateContent();
}
示例#4
0
void TimeLineCells::mousePressEvent( QMouseEvent* event )
{
    if ( primaryButton != Qt::NoButton ) return;
    int frameNumber = getFrameNumber( event->pos().x() );
    int layerNumber = getLayerNumber( event->pos().y() );

    startY = event->pos().y();
    startLayerNumber = layerNumber;
    endY = event->pos().y();

    startFrameNumber = frameNumber;
    lastFrameNumber = startFrameNumber;

    canMoveFrame    = false;
    movingFrames    = false;

    canBoxSelect    = false;
    boxSelecting    = false;

    clickSelecting  = false;

    primaryButton = event->button();

    mEditor->tools()->currentTool()->switchingLayers();
    switch ( m_eType )
    {
    case TIMELINE_CELL_TYPE::Layers:
        if ( layerNumber != -1 && layerNumber < mEditor->object()->getLayerCount() )
        {
            if ( event->pos().x() < 15 )
            {
                mEditor->switchVisibilityOfLayer( layerNumber );
            }
            else
            {
                mEditor->layers()->setCurrentLayer( layerNumber );
            }
        }
        if ( layerNumber == -1 )
        {
            if ( event->pos().x() < 15 )
            {
                mEditor->toggleShowAllLayers();
            }
        }
        break;
    case TIMELINE_CELL_TYPE::Tracks:
        if ( event->button() == Qt::MidButton )
        {
            lastFrameNumber = getFrameNumber( event->pos().x() );
        }
        else
        {
            if ( frameNumber == mEditor->currentFrame() && ( !shortScrub || ( shortScrub && startY < 20 ) ) )
            {
                if (mEditor->playback()->isPlaying())
                {
                    mEditor->playback()->stop();
                }
                timeLine->scrubbing = true;
            }
            else
            {
                if ( ( layerNumber != -1 ) && layerNumber < mEditor->object()->getLayerCount() )
                {
                    int previousLayerNumber = mEditor->layers()->currentLayerIndex();

                    if (previousLayerNumber != layerNumber) {
                        Layer *previousLayer = mEditor->object()->getLayer(previousLayerNumber);
                        previousLayer->deselectAll();

                        mEditor->setCurrentLayer( layerNumber );
                    }

                    Layer *currentLayer = mEditor->object()->getLayer(layerNumber);


                    // Check if we are using the alt key
                    //
                    if (event->modifiers() == Qt::AltModifier) {

                        // If it is the case, we select everything that is after the selected frame
                        //
                        clickSelecting = true;
                        canMoveFrame = true;

                        currentLayer->selectAllFramesAfter(frameNumber);

                    }
                    // Check if we are clicking on a non selected frame
                    //
                    else if (!currentLayer->isFrameSelected(frameNumber)) {

                        // If it is the case, we select it
                        //
                        canBoxSelect = true;
                        clickSelecting = true;

                        if ( event->modifiers() == Qt::ControlModifier ) {
                            // Add/remove from already selected
                            currentLayer->toggleFrameSelected(frameNumber, true);
                        }
                        else if ( event->modifiers() == Qt::ShiftModifier ) {
                            // Select a range from the last selected
                            currentLayer->extendSelectionTo(frameNumber);
                        }
                        else {
                            currentLayer->toggleFrameSelected(frameNumber, false);
                        }
                    }
                    else {

                        // We clicked on a selected frame, we can move it
                        //
                        canMoveFrame = true;
                    }

                    currentLayer->mousePress( event, frameNumber );
                    timeLine->updateContent();
                }
                else
                {
                    if ( frameNumber > 0 )
                    {
                        if (mEditor->playback()->isPlaying())
                        {
                            mEditor->playback()->stop();
                        }

                        mEditor->scrubTo( frameNumber );

                        timeLine->scrubbing = true;
                        qDebug( "Scrub to %d frame", frameNumber );
                    }
                }
            }
        }
        break;
    }
}
示例#5
0
void TimeLineCells::drawContent()
{
    if ( m_pCache == NULL )
    {
        m_pCache = new QPixmap( size() );
        if ( m_pCache->isNull() )
        {
            // fail to create cache
            return;
        }
    }

    QPainter painter( m_pCache );

    Object* object = mEditor->object();

    Q_ASSERT_X( object != nullptr, "", "" );

    Layer* layer = object->getLayer( mEditor->layers()->currentLayerIndex() );
    if ( layer == NULL ) return;

    // grey background of the view
    painter.setPen( Qt::NoPen );
    painter.setBrush( Qt::lightGray );
    painter.drawRect( QRect( 0, 0, width(), height() ) );

    // --- draw layers of the current object
    for ( int i = 0; i < object->getLayerCount(); i++ )
    {
        if ( i != mEditor->layers()->currentLayerIndex() )
        {
            Layer* layeri = object->getLayer( i );
            if ( layeri != NULL )
            {
                switch ( m_eType )
                {
                case TIMELINE_CELL_TYPE::Tracks:
                    layeri->paintTrack( painter, this, m_offsetX,
                                        getLayerY( i ), width() - m_offsetX,
                                        getLayerHeight(), false, frameSize );
                    break;

                case TIMELINE_CELL_TYPE::Layers:
                    layeri->paintLabel( painter, this, 0,
                                        getLayerY( i ), width() - 1,
                                        getLayerHeight(), false, mEditor->allLayers() );
                    break;
                }
            }
        }
    }
    if ( abs( getMouseMoveY() ) > 5 )
    {
        if ( m_eType == TIMELINE_CELL_TYPE::Tracks )
        {
            layer->paintTrack( painter, this, m_offsetX, getLayerY( mEditor->layers()->currentLayerIndex() ) + getMouseMoveY(), width() - m_offsetX, getLayerHeight(), true, frameSize );
        }
        if ( m_eType == TIMELINE_CELL_TYPE::Layers )
        {
            layer->paintLabel( painter, this, 0, getLayerY( mEditor->layers()->currentLayerIndex() ) + getMouseMoveY(), width() - 1, getLayerHeight(), true, mEditor->allLayers() );
        }
        painter.setPen( Qt::black );
        painter.drawRect( 0, getLayerY( getLayerNumber( endY ) ) - 1, width(), 2 );
    }
    else
    {
        if ( m_eType == TIMELINE_CELL_TYPE::Tracks )
        {
            layer->paintTrack( painter,
                               this,
                               m_offsetX,
                               getLayerY( mEditor->layers()->currentLayerIndex() ),
                               width() - m_offsetX,
                               getLayerHeight(),
                               true,
                               frameSize );
        }
        if ( m_eType == TIMELINE_CELL_TYPE::Layers )
        {
            layer->paintLabel( painter,
                               this, 
                               0, 
                               getLayerY( mEditor->layers()->currentLayerIndex() ),
                               width() - 1,
                               getLayerHeight(),
                               true,
                               mEditor->allLayers() );
        }
    }

    // --- draw top
    painter.setPen( Qt::NoPen );
    painter.setBrush( QColor( 220, 220, 220 ) );
    painter.drawRect( QRect( 0, 0, width() - 1, m_offsetY - 1 ) );
    painter.setPen( Qt::gray );
    painter.drawLine( 0, 0, width() - 1, 0 );
    painter.drawLine( 0, m_offsetY - 2, width() - 1, m_offsetY - 2 );
    painter.setPen( Qt::lightGray );
    painter.drawLine( 0, m_offsetY - 3, width() - 1, m_offsetY - 3 );
    painter.drawLine( 0, 0, 0, m_offsetY - 3 );

    if ( m_eType == TIMELINE_CELL_TYPE::Layers )
    {
        // --- draw circle
        painter.setPen( Qt::black );
        if ( mEditor->allLayers() == 0 ) { painter.setBrush( Qt::NoBrush ); }
        if ( mEditor->allLayers() == 1 ) { painter.setBrush( Qt::darkGray ); }
        if ( mEditor->allLayers() == 2 ) { painter.setBrush( Qt::black ); }
        painter.setRenderHint( QPainter::Antialiasing, true );
        painter.drawEllipse( 6, 4, 9, 9 );
        painter.setRenderHint( QPainter::Antialiasing, false );
    }
    else if ( m_eType == TIMELINE_CELL_TYPE::Tracks )
    {
        // --- draw ticks
        painter.setPen( QColor( 70, 70, 70, 255 ) );
        painter.setBrush( Qt::darkGray );
        painter.setFont( QFont( "helvetica", 10 ) );
        int incr = 0;
        int fps = mEditor->playback()->fps();
        for ( int i = frameOffset; i < frameOffset + ( width() - m_offsetX ) / frameSize; i++ )
        {
            incr = ( i < 9 ) ? 4 : 0;

            if(i + 1 >= timeLine->getRangeLower() && i < timeLine->getRangeUpper())
            {
                painter.setPen( Qt::NoPen );
                painter.setBrush( Qt::yellow );

                painter.drawRect( getFrameX( i ), 1, frameSize + 1, 2 );

                painter.setPen( QColor( 70, 70, 70, 255 ) );
                painter.setBrush( Qt::darkGray );
            }

            if ( i%fps == 0 )
            {
                painter.drawLine( getFrameX( i ), 1, getFrameX( i ), 5 );
            }
            else if ( i%fps == fps / 2 )
            {
                painter.drawLine( getFrameX( i ), 1, getFrameX( i ), 5 );
            }
            else
            {
                painter.drawLine( getFrameX( i ), 1, getFrameX( i ), 3 );
            }
            if ( i == 0 || i%fps == fps - 1 )
            {
                painter.drawText( QPoint( getFrameX( i ) + incr, 15 ), QString::number( i + 1 ) );
            }
        }

        // --- draw left border line
        painter.setPen( Qt::darkGray );
        painter.drawLine( 0, 0, 0, height() );
    }
}