Example #1
1
MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
// -----------------------------------------------------------------------
    ui->setupUi(this);
    QGraphicsScene *scene = new QGraphicsScene(this);
    ui->graphicsView->setScene(scene);
// -----------------------------------------------------------------------
    // kolor pedzla
    QBrush brush = QBrush(Qt::red);
    brush.setStyle(Qt::DiagCrossPattern);
    // tworzymy obiekts
    QGraphicsRectItem *rect = new QGraphicsRectItem(10, 10, 90, 90);
    rect->setBrush(brush);
// -----------------------------------------------------------------------
// -----------------------------------------------------------------------
    // definiujemy czas trwania animacji
    QTimeLine *timeLine = new QTimeLine(1000);
    timeLine->setFrameRange(0, 100);

    // definiujemy animacje
    QGraphicsItemAnimation *animation = new QGraphicsItemAnimation();
    animation->setItem(rect);
    animation->setTimeLine(timeLine);

    // animacja
    int odcinek = 100;
    for (int i = 0; i < 100; ++i)
        animation->setPosAt(i / 100.0, QPointF(i, i));

    // uruchamiamy scenę i animację
    scene->addItem(rect);
    timeLine->start();
}
Example #2
0
MessageBubble::MessageBubble(QGraphicsWidget* parent)
: GraphicsHudWidget(parent)
, d(new MessageBubblePrivate)
{
    d->mWidget = new QGraphicsWidget;
    d->mCountDownWidget = new CountDownWidget;
    d->mCountDownWidget->setValue(1);
    d->mLabel = new GraphicsHudLabel;

    QTimeLine* timeLine = new QTimeLine(TIMEOUT, this);
    connect(timeLine, SIGNAL(valueChanged(qreal)),
            SLOT(slotTimeLineChanged(qreal)));
    connect(timeLine, SIGNAL(finished()),
            SLOT(fadeOut()));
    connect(this, SIGNAL(fadedOut()),
            SLOT(deleteLater()));
    timeLine->start();

    d->mLayout = new QGraphicsLinearLayout(d->mWidget);
    d->mLayout->setContentsMargins(0, 0, 0, 0);
    d->mLayout->addItem(d->mCountDownWidget);
    d->mLayout->addItem(d->mLabel);

    init(d->mWidget, GraphicsHudWidget::OptionCloseButton);
}
Example #3
0
int main(int argv, char *args[])
{
    QApplication app(argv, args);

//! [0]
    QGraphicsItem *ball = new QGraphicsEllipseItem(0, 0, 20, 20);
    
    QTimeLine *timer = new QTimeLine(5000);
    timer->setFrameRange(0, 100);
    
    QGraphicsItemAnimation *animation = new QGraphicsItemAnimation;
    animation->setItem(ball);
    animation->setTimeLine(timer);

    for (int i = 0; i < 200; ++i) 
	animation->setPosAt(i / 200.0, QPointF(i, i));
    
    QGraphicsScene *scene = new QGraphicsScene();
    scene->setSceneRect(0, 0, 250, 250);
    scene->addItem(ball);

    QGraphicsView *view = new QGraphicsView(scene);
    view->show();

    timer->start();
//! [0]

    return app.exec();
}
void smallPictureView::movItemPos(int i){

    allPixItem.at(i)->show();
    QTimeLine *timeLine = new QTimeLine(300);
    timeLine->setFrameRange(0, 300);
    midPixItemFlag->hide();
    scene.setSceneRect(0,widheight-81,widwidth,48);
    //scene.setSceneRect(-widwidth/2, -24,widwidth,48);
    allAnimation.at(i)->setTimeLine(timeLine);
    allAnimation.at(i)->clear();
    allAnimation.at(i)->setItem(allPixItem.at(i));
    if(i<selectedNum){//left
        //将该项目的位置设置为给定的步长值到指定的点。
        allAnimation.at(i)->setPosAt(1, QPointF((36+1)*(i-selectedNum-1)+width()/2.0,widheight-81));
    }else if(i>selectedNum){//right
        //将该项目的位置设置为给定的步长值到指定的点。
        allAnimation.at(i)->setPosAt(1, QPointF(3+(36+1)*(i-selectedNum)+width()/2.0,widheight-81));
    }else{//selected
        if(selectedNum!=oldSelectNum){

            midPixItemFlag->hide();
            oldSelectNum = selectedNum;
        }
        //将该项目的位置设置为给定的步长值到指定的点。
        allAnimation.at(i)->setPosAt(1, QPointF(3-18+(36+1)*(i-selectedNum)+width()/2.0,widheight-81));
        connect(timeLine,SIGNAL(finished()),this,SLOT(timelineFinished()));
    }
    timeLine->start();
}
Example #5
0
File: pong.cpp Project: andpei/pong
Pong::Pong() {
    // players
    player1 = new QGraphicsRectItem(0, 0, PADDLE, PADDLE * 3);
    player1->setPos(PADDLE, (HEIGHT - PADDLE * 3) / 2);
    player1->setBrush(QBrush(Qt::gray));
    addItem(player1);
    player2 = new QGraphicsRectItem(0, 0, PADDLE, PADDLE * 3);
    player2->setPos(WIDTH - PADDLE * 2, (HEIGHT - PADDLE * 3) / 2);
    player2->setBrush(QBrush(Qt::gray));
    addItem(player2);

    // ball
    ball = new QGraphicsEllipseItem(0, 0, PADDLE, PADDLE);
    ball->setPos((WIDTH - PADDLE) / 2, (HEIGHT - PADDLE) / 2);
    ball->setBrush(QBrush(Qt::gray));
    addItem(ball);

    // score
    tscore1 = new QGraphicsSimpleTextItem();
    tscore1->setText("0");
    tscore1->setFont(QFont("Times", 36, QFont::Bold));
    tscore1->setPos(WIDTH / 2 - PADDLE - 24, PADDLE);
    tscore1->setBrush(QBrush(Qt::gray));
    addItem(tscore1);
    tscore2 = new QGraphicsSimpleTextItem();
    tscore2->setText("0");
    tscore2->setFont(QFont("Times", 36, QFont::Bold));
    tscore2->setPos(WIDTH / 2 + PADDLE, PADDLE);
    tscore2->setBrush(QBrush(Qt::gray));
    addItem(tscore2);

    // line
    int h = 0;
    int pointSize = PADDLE / 4;
    while (h < HEIGHT) {
        QGraphicsRectItem *linePoint = new QGraphicsRectItem(0, 0, pointSize, pointSize);
        linePoint->setBrush(QBrush(Qt::gray));
        linePoint->setPos((WIDTH - pointSize) / 2, h);
        addItem(linePoint);
        h += pointSize * 2;
    }

    score1 = 0;
    score2 = 0;
    dx = -1;
    dy = -1;
    speedUpCounter = 0;
    ballSpeed = 0.2;
    setSceneRect(0, 0, WIDTH, HEIGHT);
    setBackgroundBrush(QBrush(Qt::black));

    QTimeLine *timer = new QTimeLine();
    timer->setFrameRange(0, 100);
    timer->setLoopCount(10000);
    timer->start();

    connect(timer, SIGNAL(frameChanged(int)), this, SLOT(value_changed(int)));
}
void OnOffButton::animate(int xStart, int xEnd)
{
    QTimeLine *timeLine = new QTimeLine(300, this);
    timeLine->setFrameRange(xStart, xEnd);
    connect(timeLine, SIGNAL(frameChanged(int)), this, SLOT(updateAnimation(int)));
    timeLine->start();


}
Example #7
0
void LinkDialogGraphicsScene::wheelAction(float offset) {
    currentScrollSteps_ = offset;

    QTimeLine* anim = new QTimeLine(750, this);
    anim->setUpdateInterval(20);
    connect(anim, SIGNAL(valueChanged(qreal)), SLOT(executeTimeLine(qreal)));
    connect(anim, SIGNAL(finished()), SLOT(terminateTimeLine()));
    anim->start();
}
void LinkDialogProcessorGraphicsItem::animationStart() {
    animateExpansion_ = 0.1f;

    QTimeLine* anim = new QTimeLine(50, this);
    anim->setUpdateInterval(20);
    connect(anim, SIGNAL(valueChanged(qreal)), SLOT(animate(qreal)));
    connect(anim, SIGNAL(finished()), SLOT(animationEnd()));
    anim->start();
}
Example #9
0
void EditorView::startAnimation(char const *slot)
{
    QTimeLine *anim = new QTimeLine(zoomAnimationTimes * zoomAnimationInterval, this);
    anim->setUpdateInterval(zoomAnimationInterval);

    connect(anim, SIGNAL(valueChanged(qreal)), this, slot);
    connect(anim, SIGNAL(finished()), this, SLOT(animFinished()));
    anim->start();
}
Example #10
0
int main (int argc, char** argv)
{
    QApplication app(argc, argv);

    QGraphicsView view;
    QGraphicsScene *scene = new QGraphicsScene(&view);
    scene->setItemIndexMethod(QGraphicsScene::NoIndex);

    Line *left, *right, *right2;

    int of = pos_x;

    for(int i = 0; i < c; i++)
    {
        Line* ball = new Line(QPoint(of, -2));
        scene->addItem(ball);
        of += size;
        if(i==0)
            left = ball;
        else if(i == c - 1)
            right = ball;
        else if(i == c - 2)
            right2 = ball;
    }

    QTimeLine *LeftTimerTo      = newAnim(left,0,45,QEasingCurve::OutQuart);
    QTimeLine *LeftTimerReturn    = newAnim(left,45,0,QEasingCurve::InQuart);
    QTimeLine *RightTimerTo     = newAnim(right,0,-45,QEasingCurve::OutQuart);
    QTimeLine *RightTimerBack   = newAnim(right,-45,0,QEasingCurve::InQuart);
    QTimeLine *RightTimerTo2     = newAnim(right2,0,-45,QEasingCurve::OutQuart);
    QTimeLine *RightTimerBack2   = newAnim(right2,-45,0,QEasingCurve::InQuart);



    scene->setSceneRect(0, 0, 940, 460);

    view.setCacheMode(QGraphicsView::CacheBackground);
    view.setViewportUpdateMode(QGraphicsView::FullViewportUpdate);
    view.setScene(scene);
    view.resize(960, 480);
    view.show();

    QObject::connect(LeftTimerTo,   SIGNAL(finished()), LeftTimerReturn,  SLOT(start()));
    QObject::connect(LeftTimerReturn, SIGNAL(finished()), RightTimerTo,   SLOT(start()));
    QObject::connect(LeftTimerReturn, SIGNAL(finished()), RightTimerTo2,   SLOT(start()));
    QObject::connect(RightTimerTo,  SIGNAL(finished()), RightTimerBack, SLOT(start()));
    QObject::connect(RightTimerTo2,  SIGNAL(finished()), RightTimerBack2, SLOT(start()));
    QObject::connect(RightTimerBack,SIGNAL(finished()), LeftTimerTo,    SLOT(start()));

    LeftTimerReturn->start();

    return app.exec();
}
Example #11
0
void MyQGraphicsView::wheelEvent ( QWheelEvent * event )
{
    int numDegrees = event->delta() / 8;
    int numSteps = numDegrees / 15;  // see QWheelEvent documentation
    _numScheduledScalings += numSteps;
    if (_numScheduledScalings * numSteps < 0)  // if user moved the wheel in another direction, we reset previously scheduled scalings
        _numScheduledScalings = numSteps;
 
    QTimeLine *anim = new QTimeLine(350, this);
    anim->setUpdateInterval(50);
 
    connect(anim, SIGNAL(valueChanged(qreal)), SLOT(scalingTime(qreal)));
    connect(anim, SIGNAL(finished()), SLOT(animFinished()));
    anim->start();
}
Example #12
0
animate::animate()
{
     setPixmap(QPixmap(":/animate/dancer/dancer_2a1.png"));

     QTimeLine *timeline = new QTimeLine(2000);

     timeline->setFrameRange(0,16);

     connect(timeline,SIGNAL(frameChanged(int)),SLOT(setpic(int)));

     timeline->start();



}
Example #13
0
void PathologyViewer::zoom(float numSteps) {
  if (!_img) {
    return;
  }
  _numScheduledScalings += numSteps;
  if (_numScheduledScalings * numSteps < 0)  {
    _numScheduledScalings = numSteps;
  }

  QTimeLine *anim = new QTimeLine(300, this);
  anim->setUpdateInterval(5);

  connect(anim, SIGNAL(valueChanged(qreal)), SLOT(scalingTime(qreal)));
  connect(anim, SIGNAL(finished()), SLOT(zoomFinished()));
  anim->start();
}
Example #14
0
    void smoothScrollTo(const QModelIndex& index)
    {
        if (!index.isValid()) {
            return;
        }

        const QRect rect = q->visualRect(index);

        int oldValue = scrollBar()->value();
        int newValue = scrollToValue(rect);
        if (mTimeLine->state() == QTimeLine::Running) {
            mTimeLine->stop();
        }
        mTimeLine->setFrameRange(oldValue, newValue);
        mTimeLine->start();
    }
void MainWindow::slotAddAnimationItem() //在场景中加入一个动画星星
{
    StartItem *item = new StartItem;
    QGraphicsItemAnimation *anim = new QGraphicsItemAnimation;
    anim->setItem(item);
    QTimeLine *timeLine = new QTimeLine(4000);
    timeLine->setCurveShape(QTimeLine::SineCurve);
    timeLine->setLoopCount(0);

    anim->setTimeLine(timeLine);

    int y =(qrand()%400)-200;
    for(int i=0; i<400; i++)
    {
        anim->setPosAt(i/400.0,QPointF(i-200,y));
    }
    timeLine->start();
    scene->addItem(item);
}
Example #16
0
void GraphBase::UpDateStrategy(QString strategyName)
{

    //存入原来的位置
    this->mAnimationStartPosition.clear();
    for (NodeBase *node : mNodes)
    {
        node->setFlag(QGraphicsItem::ItemSendsScenePositionChanges, false);
        mAnimationStartPosition.push_back(node->scenePos());
    }

    if (strategyName == "Circular")
    {
        vtkSmartPointer<vtkCircularLayoutStrategy> circularStrategy
            = vtkSmartPointer<vtkCircularLayoutStrategy>::New();
        mStoredLayout->SetLayoutStrategy(circularStrategy);
    }
    if (strategyName == "ForceDirected")
    {
        vtkSmartPointer<vtkForceDirectedLayoutStrategy> forceStrategy
            = vtkSmartPointer<vtkForceDirectedLayoutStrategy>::New();
        mStoredLayout->SetLayoutStrategy(forceStrategy);
    }
    if (strategyName == "Fast2D")
    {
        vtkSmartPointer<vtkFast2DLayoutStrategy> fastStrategy
            = vtkSmartPointer<vtkFast2DLayoutStrategy>::New();
        mStoredLayout->SetLayoutStrategy(fastStrategy);
    }

    mStoredLayout->Update();
    mOutPutGraph = mStoredLayout->GetOutput();


    UpdateEndPosition(strategyName);
    QTimeLine *animation = new QTimeLine();
    animation->setUpdateInterval(50);
    connect(animation, SIGNAL(valueChanged(qreal)), this, SLOT(OnAnimation(qreal)));
    connect(animation, SIGNAL(finished()), this, SLOT(OnAnimationEnd()));
    
    animation->start();
}
Example #17
0
void MainWindow::createProgressBar()
{
	QxtProgressLabel* label = new QxtProgressLabel(statusBar());

	QProgressBar* bar = new QProgressBar(statusBar());
	bar->setMaximumWidth(label->sizeHint().width() * 2);
	bar->setRange(0, 120);

	QTimeLine* timeLine = new QTimeLine(120000, this);
	timeLine->setFrameRange(0, 120);

	connect(timeLine, SIGNAL(frameChanged(int)), bar, SLOT(setValue(int)));
	connect(timeLine, SIGNAL(finished()), label, SLOT(restart()));
	connect(bar, SIGNAL(valueChanged(int)), label, SLOT(setValue(int)));
	timeLine->start();

    statusBar()->addPermanentWidget(new QLabel(tr("Dummy Progress:"), this));
	statusBar()->addPermanentWidget(bar);
	statusBar()->addPermanentWidget(label);
}
Example #18
0
Pong::Pong()
{
	this->setSceneRect(0, 0, WIDTH, HEIGHT);
	this->p1 = new QGraphicsRectItem(0, 0,
					 PADDLE,
					 PADDLE*3);
	this->p2 = new QGraphicsRectItem(0, 0,
					 PADDLE,
					 PADDLE*3);

	this->p1->setPos(PADDLE, (HEIGHT-PADDLE*3)/2);
	this->p2->setPos(WIDTH-PADDLE*2, (HEIGHT-PADDLE*3)/2);
	this->p1->setBrush(QBrush(Qt::red));
	this->p2->setBrush(QBrush(Qt::blue));

	/* ball */
	this->ball = new QGraphicsEllipseItem(0, 0, PADDLE, PADDLE);
	this->ball->setPos((WIDTH-PADDLE)/2, (HEIGHT-PADDLE)/2);
	this->ball->setBrush(QBrush(Qt::black));
	
	this->setFocusItem(p1);

	this->dx = -1;
	this->dy = -1;

	QTimeLine *timer = new QTimeLine(5000);
	timer->setFrameRange(0, 100);
	
	this->addItem(ball);
	this->addItem(p1);
	this->addItem(p2);

	timer->setLoopCount(10000);
	timer->start();
	connect(timer,
		SIGNAL(frameChanged(int)),
		this,
		SLOT(value_changed(int)));
	}
//cppcheck-suppress unusedFunction
void VMainGraphicsView::wheelEvent(QWheelEvent *event)
{
    int numSteps = event->delta() / 8 / 15;  // see QWheelEvent documentation

    _numScheduledScalings += numSteps;
    if (_numScheduledScalings * numSteps < 0)
    {  // if user moved the wheel in another direction, we reset
        _numScheduledScalings = numSteps;       // previously scheduled scalings
    }

    QTimeLine *anim = new QTimeLine(300, this);
    anim->setUpdateInterval(20);

    if (QApplication::keyboardModifiers() == Qt::ControlModifier)
    {// If you press CTRL this code will be executed
        connect(anim, &QTimeLine::valueChanged, this, &VMainGraphicsView::scalingTime);
    }
    else
    {
        connect(anim, &QTimeLine::valueChanged, this, &VMainGraphicsView::scrollingTime);
    }
    connect(anim, &QTimeLine::finished, this, &VMainGraphicsView::animFinished);
    anim->start();
}
Example #20
0
 void startTimeLine()
 {
     if (mOpacityTimeLine->state() != QTimeLine::Running) {
         mOpacityTimeLine->start();
     }
 }
Example #21
0
 void startTimeLine()
 {
     if (mTimeLine->state() != QTimeLine::Running) {
         mTimeLine->start();
     }
 }
Example #22
0
bool
GridItemDelegate::editorEvent( QEvent* event, QAbstractItemModel* model, const QStyleOptionViewItem& option, const QModelIndex& index )
{
    Q_UNUSED( model );
    Q_UNUSED( option );

    if ( event->type() != QEvent::MouseButtonRelease &&
            event->type() != QEvent::MouseMove &&
            event->type() != QEvent::MouseButtonPress &&
            event->type() != QEvent::Leave )
        return false;

    bool hoveringArtist = false;
    if ( m_artistNameRects.contains( index ) )
    {
        const QRect artistNameRect = m_artistNameRects[ index ];
        const QMouseEvent* ev = static_cast< QMouseEvent* >( event );
        hoveringArtist = artistNameRect.contains( ev->pos() );
    }

    if ( event->type() == QEvent::MouseMove )
    {
        if ( hoveringArtist )
            m_view->setCursor( Qt::PointingHandCursor );
        else
            m_view->setCursor( Qt::ArrowCursor );

        foreach ( const QModelIndex& idx, m_playButton.keys() )
        {
            if ( index != idx )
                m_playButton.take( idx )->deleteLater();
        }

        if ( !m_playButton.contains( index ) && !m_spinner.contains( index ) && !m_pauseButton.contains( index ) )
        {
            foreach ( ImageButton* button, m_playButton )
                button->deleteLater();
            m_playButton.clear();

            ImageButton* button = new ImageButton( m_view );
            button->setPixmap( RESPATH "images/play-rest.png" );
            button->setPixmap( RESPATH "images/play-pressed.png", QIcon::Off, QIcon::Active );
            button->setFixedSize( 48, 48 );
            button->move( option.rect.center() - QPoint( 23, 23 ) );
            button->setContentsMargins( 0, 0, 0, 0 );
            button->setFocusPolicy( Qt::NoFocus );
            button->installEventFilter( this );
            button->show();

            NewClosure( button, SIGNAL( clicked( bool ) ),
                        const_cast<GridItemDelegate*>(this), SLOT( onPlayClicked( QPersistentModelIndex ) ), QPersistentModelIndex( index ) );

            m_playButton[ index ] = button;
        }

        if ( m_hoveringOver != index || ( !hoveringArtist && m_hoveringOver.isValid() ) )
        {
            emit updateIndex( m_hoveringOver );

            if ( hoveringArtist )
                m_hoveringOver = index;
            else
                m_hoveringOver = QPersistentModelIndex();

            emit updateIndex( index );
        }

        if ( m_hoverIndex != index )
        {
            if ( m_hoverIndex.isValid() )
            {
                QTimeLine* fadeOut = createTimeline( QTimeLine::Forward );
                _detail::Closure* c = NewClosure( fadeOut, SIGNAL( frameChanged( int ) ), this, SLOT( fadingFrameChanged( QPersistentModelIndex ) ), QPersistentModelIndex( m_hoverIndex ) );
                c->setAutoDelete( false );
                c = NewClosure( fadeOut, SIGNAL( finished() ), this, SLOT( fadingFrameFinished( QPersistentModelIndex ) ), QPersistentModelIndex( m_hoverIndex ) );
                c->setAutoDelete( false );
                m_hoverFaders[ m_hoverIndex ] = fadeOut;
                fadeOut->start();
            }

            emit updateIndex( m_hoverIndex );
            m_hoverIndex = index;

            QTimeLine* fadeIn = createTimeline( QTimeLine::Backward );
            _detail::Closure* c = NewClosure( fadeIn, SIGNAL( frameChanged( int ) ), this, SLOT( fadingFrameChanged( QPersistentModelIndex ) ), QPersistentModelIndex( index ) );
            c->setAutoDelete( false );
            c = NewClosure( fadeIn, SIGNAL( finished() ), this, SLOT( fadingFrameFinished( QPersistentModelIndex ) ), QPersistentModelIndex( index ) );
            c->setAutoDelete( false );

            m_hoverFaders[ index ] = fadeIn;
            fadeIn->start();

            emit updateIndex( index );
        }
Example #23
0
bool
GridItemDelegate::editorEvent( QEvent* event, QAbstractItemModel* model, const QStyleOptionViewItem& option, const QModelIndex& index )
{
    Q_UNUSED( model );
    Q_UNUSED( option );

    if ( event->type() != QEvent::MouseButtonRelease &&
         event->type() != QEvent::MouseMove &&
         event->type() != QEvent::MouseButtonPress &&
         event->type() != QEvent::Leave )
        return false;

    const QMouseEvent* ev = static_cast< QMouseEvent* >( event );
    bool hoveringArtist = false;
    bool hoveringAlbum = false;
    bool hoveringBuyButton = false;
    if ( m_artistNameRects.contains( index ) )
    {
        const QRect artistNameRect = m_artistNameRects[ index ];
        hoveringArtist = artistNameRect.contains( ev->pos() );
    }
    if ( m_albumNameRects.contains( index ) )
    {
        const QRect albumNameRect = m_albumNameRects[ index ];
        hoveringAlbum = albumNameRect.contains( ev->pos() );
    }
    if ( m_buyButtonRects.contains( index ) )
    {
        const QRect buyButtonRect = m_buyButtonRects[ index ];
        hoveringBuyButton = buyButtonRect.contains( ev->pos() );
    }

    QRect coverRect = m_view->visualRect( index );
    coverRect.setHeight( coverRect.width() );
    const bool hoveringCover = coverRect.contains( ev->pos() );

    if ( event->type() == QEvent::MouseMove )
    {
        if ( hoveringArtist || hoveringAlbum || hoveringBuyButton )
            m_view->setCursor( Qt::PointingHandCursor );
        else
            m_view->setCursor( Qt::ArrowCursor );

        foreach ( const QModelIndex& idx, m_hoverControls.keys() )
        {
            if ( index != idx )
                m_hoverControls.take( idx )->deleteLater();
        }

        if ( hoveringCover && !m_hoverControls.contains( index ) && !m_spinner.contains( index ) )
        {
            foreach ( HoverControls* control, m_hoverControls )
                control->deleteLater();
            m_hoverControls.clear();

            QRect cRect = option.rect;
            cRect.setHeight( cRect.width() );

            HoverControls* controls = new HoverControls( m_view );
            controls->setFixedSize( m_margin * 2, m_margin + m_margin / 4 );
            controls->move( cRect.center() - QPoint( controls->width() / 2 -1, controls->height() / 2 -1 ) );
            controls->setContentsMargins( 0, 0, 0, 0 );
            controls->setFocusPolicy( Qt::NoFocus );
            controls->installEventFilter( this );
            controls->show();

            NewClosure( controls, SIGNAL( play() ),
                        const_cast<GridItemDelegate*>(this), SLOT( onPlayClicked( QPersistentModelIndex ) ), QPersistentModelIndex( index ) );

            m_hoverControls[ index ] = controls;
        }

        if ( m_hoveringOverArtist != index || ( !hoveringArtist && m_hoveringOverArtist.isValid() ) )
        {
            emit updateIndex( m_hoveringOverArtist );

            if ( hoveringArtist )
                m_hoveringOverArtist = index;
            else
                m_hoveringOverArtist = QPersistentModelIndex();

            emit updateIndex( index );
        }
        if ( m_hoveringOverAlbum != index || ( !hoveringAlbum && m_hoveringOverAlbum.isValid() ) )
        {
            emit updateIndex( m_hoveringOverAlbum );

            if ( hoveringAlbum )
                m_hoveringOverAlbum = index;
            else
                m_hoveringOverAlbum = QPersistentModelIndex();

            emit updateIndex( index );
        }
        if ( m_hoveringOverBuyButton != index || ( !hoveringBuyButton && m_hoveringOverBuyButton.isValid() ) )
        {
            emit updateIndex( m_hoveringOverBuyButton );

            if ( hoveringBuyButton )
                m_hoveringOverBuyButton = index;
            else
                m_hoveringOverBuyButton = QPersistentModelIndex();

            emit updateIndex( index );
        }

        if ( m_hoverIndex != index || !hoveringCover )
        {
            if ( m_hoverIndex.isValid() )
            {
                int startFrame = 100;
                if ( m_hoverFaders.contains( m_hoverIndex ) )
                {
                    QTimeLine* oldFader = m_hoverFaders.take( m_hoverIndex );
                    startFrame = oldFader->currentFrame();
                    oldFader->deleteLater();
                }

                QTimeLine* fadeOut = createTimeline( QTimeLine::Backward, startFrame );
                _detail::Closure* c = NewClosure( fadeOut, SIGNAL( frameChanged( int ) ), this, SLOT( fadingFrameChanged( QPersistentModelIndex ) ), QPersistentModelIndex( m_hoverIndex ) );
                c->setAutoDelete( false );
                c = NewClosure( fadeOut, SIGNAL( finished() ), this, SLOT( fadingFrameFinished( QPersistentModelIndex ) ), QPersistentModelIndex( m_hoverIndex ) );
                c->setAutoDelete( false );

                m_hoverFaders[ m_hoverIndex ] = fadeOut;
                fadeOut->start();
            }
            emit updateIndex( m_hoverIndex );

            foreach ( HoverControls* controls, m_hoverControls )
                controls->deleteLater();
            m_hoverControls.clear();
            m_hoverIndex = QPersistentModelIndex();
        }

        if ( hoveringCover && m_hoverIndex != index )
        {
            m_hoverIndex = index;
            int startFrame = 0;
            if ( m_hoverFaders.contains( index ) )
            {
                QTimeLine* oldFader = m_hoverFaders.take( index );
                startFrame = oldFader->currentFrame();
                oldFader->deleteLater();
            }

            QTimeLine* fadeIn = createTimeline( QTimeLine::Forward, startFrame );
            _detail::Closure* c = NewClosure( fadeIn, SIGNAL( frameChanged( int ) ), this, SLOT( fadingFrameChanged( QPersistentModelIndex ) ), QPersistentModelIndex( index ) );
            c->setAutoDelete( false );
            c = NewClosure( fadeIn, SIGNAL( finished() ), this, SLOT( fadingFrameFinished( QPersistentModelIndex ) ), QPersistentModelIndex( index ) );
            c->setAutoDelete( false );

            m_hoverFaders[ index ] = fadeIn;
            fadeIn->start();

            emit updateIndex( index );
        }
Example #24
0
void PointSetAnnotationTool::keyPressEvent(QKeyEvent *event) {
  if (event->key() == Qt::Key::Key_Escape) {
    cancelAnnotation();
  }
  else if (event->key() == Qt::Key::Key_Delete && event->modifiers() == Qt::ShiftModifier) {
    if (_generating) {
      cancelAnnotation();
    }
    else {
      QSet<QtAnnotation*> selectedAnnotations = _annotationPlugin->getSelectedAnnotations();
      for (QSet<QtAnnotation*>::iterator it = selectedAnnotations.begin(); it != selectedAnnotations.end(); ++it) {
        _annotationPlugin->deleteAnnotation(*it);
      }
    }
  }
  else if (event->key() == Qt::Key::Key_Delete) {
    if (_generating) {
      if (_annotationPlugin->getGeneratedAnnotation()->getAnnotation()->getCoordinates().size() < 2) {
        cancelAnnotation();
      }
      else {
        _annotationPlugin->getGeneratedAnnotation()->removeCoordinate(-1);
        if (!_annotationPlugin->getGeneratedAnnotation()->getAnnotation()->getCoordinates().empty()) {
          Point prev = _annotationPlugin->getGeneratedAnnotation()->getAnnotation()->getCoordinate(-1);
          _last = Point(prev.getX() * _viewer->getSceneScale(), prev.getY() * _viewer->getSceneScale());
        }
      }
    }
    else if (_annotationPlugin->getActiveAnnotation()) {
      if (_annotationPlugin->getActiveAnnotation()->getAnnotation()->getCoordinates().size() <= 1) {
        _annotationPlugin->deleteAnnotation(_annotationPlugin->getActiveAnnotation());
      }
      else if (_annotationPlugin->getActiveAnnotation()->getActiveSeedPoint() > -1) {
        int activeSeedPoint = _annotationPlugin->getActiveAnnotation()->getActiveSeedPoint();
        _annotationPlugin->getActiveAnnotation()->removeCoordinate(activeSeedPoint);
        if (activeSeedPoint - 1 >= 0) {
          _annotationPlugin->getActiveAnnotation()->setActiveSeedPoint(activeSeedPoint - 1);
        }
        else {
          _annotationPlugin->getActiveAnnotation()->setActiveSeedPoint(_annotationPlugin->getActiveAnnotation()->getAnnotation()->getCoordinates().size() - 1);
        }
      }
      else if (_annotationPlugin->getActiveAnnotation()) {
        _annotationPlugin->getActiveAnnotation()->removeCoordinate(-1);
      }
    }
  }
  else if (event->key() == Qt::Key::Key_Z) {
    if (_annotationPlugin->getActiveAnnotation()) {
      QTimeLine * anim = new QTimeLine(500);

      _start_zoom = _viewer->mapToScene(_viewer->viewport()->rect()).boundingRect();
      _end_zoom = _annotationPlugin->getActiveAnnotation()->mapToScene(_annotationPlugin->getActiveAnnotation()->boundingRect()).boundingRect();
      anim->setFrameRange(0, 100);
      anim->setUpdateInterval(5);

      connect(anim, SIGNAL(valueChanged(qreal)), SLOT(zoomToAnnotation(qreal)));
      connect(anim, SIGNAL(finished()), SLOT(zoomToAnnotationFinished()));
      anim->start();
    }
  }
}