void KCard::stopAnimation() { if ( !d->animation ) return; delete d->animation; d->animation = 0; setZValue( d->destZ ); emit animationStopped( this ); }
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { // Загружаем интерфейс пользователя из формы и устанавливаем действия в меню ui->setupUi(this); connect(ui->action_start, SIGNAL(triggered()), ui->startButton, SLOT(click())); connect(ui->action_exit, SIGNAL(triggered()), this, SLOT(close())); connect(ui->action_Qt, SIGNAL(triggered()), qApp, SLOT(aboutQt())); connect(ui->action_help, SIGNAL(triggered()), this, SLOT(showHelp())); connect(ui->action_about, SIGNAL(triggered()), this, SLOT(showAbout())); connect(ui->action_tech, SIGNAL(triggered()), this, SLOT(showTz())); // Заводим машину состояний QStateMachine *animation = new QStateMachine(this); QState *idle = new QState(); QState *animating = new QState(); animating->assignProperty(ui->startButton,"text", tr("&Стоп")); animating->assignProperty(ui->startButton,"icon", QIcon(":/icons/control-stop-square.png")); animating->assignProperty(ui->action_start,"text",tr("О&становить анимацию")); animating->assignProperty(ui->action_start,"icon", QIcon(":/icons/control-stop-square.png")); idle->assignProperty(ui->startButton,"text", tr("Пу&ск")); idle->assignProperty(ui->startButton,"icon", QIcon(":/icons/control.png")); idle->assignProperty(ui->action_start,"text",tr("Запу&стить анимацию")); idle->assignProperty(ui->action_start,"icon", QIcon(":/icons/control.png")); QSignalTransition *startTransition = new QSignalTransition(ui->startButton, SIGNAL(clicked()), idle); startTransition->setTargetState(animating); QSignalTransition *stopTransition = new QSignalTransition(ui->startButton, SIGNAL(clicked()), animating); stopTransition->setTargetState(idle); QSignalTransition *doneTransition = new QSignalTransition(ui->widget, SIGNAL(animationStopped()), animating); doneTransition->setTargetState(idle); connect(startTransition, SIGNAL(triggered()), ui->widget, SLOT(startAnimation())); connect(stopTransition, SIGNAL(triggered()), ui->widget, SLOT(stopAnimation())); idle->addTransition(startTransition); animating->addTransition(stopTransition); animating->addTransition(doneTransition); animation->addState(idle); animation->addState(animating); animation->setInitialState(idle); animation->start(); // В Linux мячик иногда сразу не отображается... ui->widget->updateGL(); }
PuzzleBoardItem::PuzzleBoardItem(QDeclarativeItem *parent) : QDeclarativeItem(parent) { #if !defined(MEEGO_EDITION_HARMATTAN) && !defined(Q_OS_SYMBIAN) && !defined(Q_OS_BLACKBERRY) && !defined(Q_OS_BLACKBERRY_TABLET) setAcceptedMouseButtons(Qt::LeftButton | Qt::RightButton); #else setAcceptedMouseButtons(Qt::NoButton); #endif setFlag(QGraphicsItem::ItemHasNoContents, false); setAcceptTouchEvents(true); _game = new PuzzleGame(this); _autoRepaintRequests = 0; _autoRepainter = new QTimer(); _autoRepainter->setInterval(20); connect(_autoRepainter, SIGNAL(timeout()), this, SLOT(updateItem())); connect(this, SIGNAL(widthChanged()), this, SLOT(updateGame())); connect(this, SIGNAL(heightChanged()), this, SLOT(updateGame())); connect(_game, SIGNAL(animationStarting()), this, SLOT(enableAutoRepaint())); connect(_game, SIGNAL(animationStopped()), this, SLOT(disableAutoRepaint())); }
void SurfaceAnimatorDialog::computeMultiGridAnimation() { QListWidget* fileList(m_dialog.fileList); m_referenceFrames = fileList->count(); if (m_referenceFrames < 2) return; int interpolationFrames(m_dialog.interpolationFrames->value()); double isovalue(m_dialog.isovalue->value()); double delta = 1.0/interpolationFrames; QListWidgetItem* item(fileList->item(0)); Layer::CubeData* cube(QVariantPointer<Layer::CubeData>::toPointer(item->data(Qt::UserRole))); Grid* A(cube->grid()); Grid* B(0); Grid::Size size(A->size()); Grid::DataType dataType(Grid::DataType::CubeData); Grid dAB(dataType, size); Grid t(dataType, size); Animator::Combo::DataList frames; Layer::Surface* surface; QString label; int totalSurfaces((m_referenceFrames-1)*interpolationFrames); QProgressDialog progressDialog("Calculating surfaces", "Cancel", 0, totalSurfaces, this); progressDialog.setWindowModality(Qt::WindowModal); int totalProgress(0); progressDialog.setValue(totalProgress); // loop over grids for (int i = 1; i < m_referenceFrames; ++i) { if (progressDialog.wasCanceled()) return; Data::Geometry const& geomA(cube->geometry()); item = fileList->item(i); cube = QVariantPointer<Layer::CubeData>::toPointer(item->data(Qt::UserRole)); Data::Geometry const& geomB(cube->geometry()); //qDebug() << "first geom"; //geomA.dump(); //qDebug() << "second geom"; //geomB.dump(); // Geometry displacements QList<Vec> displacements; for (int a = 0; a < geomA.nAtoms(); ++a) { Vec d(geomB.position(a)-geomA.position(a)); displacements.append(d); } // Grid displacements B = cube->grid(); t = (*A); dAB = (*B); dAB -= t; surface = calculateSurface(&dAB, isovalue); surface->setText("Difference Surface"); cube->appendLayer(surface); dAB *= delta; // loop over interpolation Frames for (int j = 0; j < interpolationFrames; ++j) { Data::Geometry geomT; for (int a = 0; a < geomA.nAtoms(); ++a) { double step = (double)j/(double)interpolationFrames; Vec d(geomA.position(a) + step*displacements[a]); geomT.append(geomA.atomicNumber(a), d); } surface = calculateSurface(&t, isovalue); frames.append(new Animator::Combo::Data(geomT, surface)); label = (j == 0) ? "Cube Data " + QString::number(i) : "Interpolation Frame " + QString::number(j); surface->setText(label); cube->appendLayer(surface); ++totalProgress; progressDialog.setValue(totalProgress); if (progressDialog.wasCanceled()) return; t += dAB; // increment the interpolation grid } A = B; } // Take care of the final reference frame surface = calculateSurface(B, isovalue); surface->setText("Cube Data " + QString::number(m_referenceFrames)); cube->appendLayer(surface); frames.append(new Animator::Combo::Data(cube->geometry(), surface)); m_animator = new Animator::Combo(m_molecule, frames, interpolationFrames, m_speed); connect(m_animator, SIGNAL(finished()), this, SLOT(animationStopped())); m_dialog.playbackBox->setEnabled(true); }