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(); }
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(); }
PhotoKitView::PhotoKitView(QWidget *parent) : QGraphicsView(parent),mPressed(false),mMachine(0),mCanTransform(true),mZoomOnMove(false) { //setDragMode(QGraphicsView::NoDrag); //setAlignment(Qt::AlignBottom); //setTransformationAnchor(QGraphicsView::AnchorUnderMouse); setTransformationAnchor(QGraphicsView::AnchorViewCenter); setResizeAnchor(QGraphicsView::AnchorUnderMouse); setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); //TODO: always on when debug. setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); //setBackgroundBrush(QBrush(Qt::gray)); mScene = new PhotoKitScene(this); setRenderingSystem(); mScene->setSceneRect(qApp->desktop()->rect()); setScene(mScene); mMachine = new TransformMachine;//QGraphicsItemAnimation; connect(mMachine, SIGNAL(transformChanged(QTransform)), SLOT(doTransform(QTransform))); QTimeLine *timer = new QTimeLine(kAniDuration); timer->setEasingCurve(QEasingCurve::OutQuad); timer->setFrameRange(0, 100); mMachine->setTimeLine(timer); }
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(); }
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(); }
void SCFadeCrossStrategy::setup(const SCPageEffect::Data &data, QTimeLine &timeLine) { timeLine.setFrameRange(0, 1000); // TODO might not be needed data.m_oldPageItem->setZValue(1); data.m_newPageItem->setZValue(2); data.m_newPageItem->setOpacity(0); data.m_oldPageItem->show(); data.m_newPageItem->show(); }
void KPrFadeOverColorStrategy::setup(const KPrPageEffect::Data &data, QTimeLine &timeLine) { timeLine.setFrameRange(0, 1000); // TODO might not be needed data.m_graphicsView->setBackgroundBrush(m_fadeColor); data.m_oldPageItem->setZValue(1); data.m_newPageItem->setZValue(2); data.m_newPageItem->setOpacity(0); data.m_oldPageItem->show(); data.m_newPageItem->show(); }
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(); }
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(); }
ItemAnimation::ItemAnimation(QGraphicsItem *item, QObject *parent) : QObject(parent),mHide(false),mFade(None) { mMachine = new TransformMachine;//QGraphicsItemAnimation; QTimeLine *timer = new QTimeLine(1000); timer->setEasingCurve(QEasingCurve::OutQuad); timer->setFrameRange(0, 100); mMachine->setTimeLine(timer); connect(mMachine, SIGNAL(transformChanged(QTransform)), this, SLOT(setTransform(QTransform))); connect(mMachine, SIGNAL(zValueChanged(qreal)), this, SLOT(setZValue(qreal))); connect(mMachine, SIGNAL(posChanged(QPointF)), this, SLOT(setItemPos(QPointF))); connect(mMachine->timeLine(), SIGNAL(finished()), this, SLOT(tryHide())); connect(mMachine->timeLine(), SIGNAL(finished()), this, SIGNAL(finished())); setItem(item); }
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); }
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))); }
void ZigZagWipeStrategy::setup(const SCPageEffect::Data &data, QTimeLine &timeLine) { Q_UNUSED(data); timeLine.setFrameRange(0, StepCount); }
void PinDialog::init( PinFlags flags, const QString &title, TokenData::TokenFlags token ) { setMinimumWidth( 350 ); setWindowModality( Qt::ApplicationModal ); QLabel *label = new QLabel( this ); QVBoxLayout *l = new QVBoxLayout( this ); l->addWidget( label ); QString _title = title; QString text; if( token & TokenData::PinFinalTry ) text += "<font color='red'><b>" + tr("PIN will be locked next failed attempt") + "</b></font><br />"; else if( token & TokenData::PinCountLow ) text += "<font color='red'><b>" + tr("PIN has been entered incorrectly one time") + "</b></font><br />"; text += QString( "<b>%1</b><br />" ).arg( title ); if( flags & Pin2Type ) { _title = tr("Signing") + " - " + title; text += tr("Selected action requires sign certificate.") + "<br />" + (flags & PinpadFlag ? tr("For using sign certificate enter PIN2 with pinpad") : tr("For using sign certificate enter PIN2") ); regexp.setPattern( "\\d{5,12}" ); } else { _title = tr("Authendicating") + " - " + title; text += tr("Selected action requires auth certificate.") + "<br />" + (flags & PinpadFlag ? tr("For using auth certificate enter PIN1 with pinpad") : tr("For using auth certificate enter PIN1") ); regexp.setPattern( "\\d{4,12}" ); } setWindowTitle( _title ); label->setText( text ); if( flags & PinpadFlag ) { setWindowFlags( (windowFlags() | Qt::CustomizeWindowHint) & ~Qt::WindowCloseButtonHint ); QProgressBar *progress = new QProgressBar( this ); progress->setRange( 0, 30 ); progress->setValue( progress->maximum() ); progress->setTextVisible( false ); l->addWidget( progress ); QTimeLine *statusTimer = new QTimeLine( progress->maximum() * 1000, this ); statusTimer->setCurveShape( QTimeLine::LinearCurve ); statusTimer->setFrameRange( progress->maximum(), progress->minimum() ); connect( statusTimer, SIGNAL(frameChanged(int)), progress, SLOT(setValue(int)) ); connect( this, SIGNAL(startTimer()), statusTimer, SLOT(start()) ); } else { m_text = new QLineEdit( this ); m_text->setEchoMode( QLineEdit::Password ); m_text->setFocus(); m_text->setValidator( new QRegExpValidator( regexp, m_text ) ); connect( m_text, SIGNAL(textEdited(QString)), SLOT(textEdited(QString)) ); l->addWidget( m_text ); QDialogButtonBox *buttons = new QDialogButtonBox( QDialogButtonBox::Ok|QDialogButtonBox::Cancel, Qt::Horizontal, this ); ok = buttons->button( QDialogButtonBox::Ok ); ok->setAutoDefault( true ); connect( buttons, SIGNAL(accepted()), SLOT(accept()) ); connect( buttons, SIGNAL(rejected()), SLOT(reject()) ); l->addWidget( buttons ); textEdited( QString() ); } }
void KPrSwapEffectHorizontalStrategy::setup(const KPrPageEffect::Data &data, QTimeLine &timeLine) { timeLine.setFrameRange(0, 500); data.m_oldPageItem->show(); data.m_newPageItem->show(); }
void SCBarWipeFromBottomStrategy::setup(const SCPageEffect::Data &data, QTimeLine &timeLine) { timeLine.setFrameRange(0, data.m_widget->height()); }
void KPrSpaceRotationFromTopStrategy::setup(const KPrPageEffect::Data &data, QTimeLine &timeLine) { timeLine.setFrameRange(0, 180); data.m_oldPageItem->show(); }
void DiagonalWipeStrategy::setup( const KPrPageEffect::Data &data, QTimeLine &timeLine ) { Q_UNUSED( data ); timeLine.setFrameRange( 0, StepCount ); }
void KPrClockWipeStrategy::setup( const KPrPageEffect::Data &data, QTimeLine &timeLine ) { Q_UNUSED(data); timeLine.setFrameRange( 0, 360 ); }
void KPrIrisWipeEffectStrategyBase::setup( const KPrPageEffect::Data &data, QTimeLine &timeLine ) { timeLine.setFrameRange( 0, findMaxScaling( data ) ); }
void KPrSlideWipeFromRightStrategy::setup( const KPrPageEffect::Data &data, QTimeLine &timeLine ) { timeLine.setFrameRange( 0, data.m_widget->width() ); }
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(); } } }
void KPrMatrixWipeStrategy::setup( const KPrPageEffect::Data &data, QTimeLine &timeLine ) { timeLine.setFrameRange( 0, (m_smooth ? framesPerSquare : 1) * maxIndex(m_squaresPerRow, m_squaresPerCol) ); }
void SCSlideWipeToLeftStrategy::setup(const SCPageEffect::Data &data, QTimeLine &timeLine) { timeLine.setFrameRange(0, data.m_widget->width()); }