Exemplo n.º 1
0
void qAnimationDlg::onItemChanged(QListWidgetItem*)
{
	//update total duration
	updateTotalDuration();

	onCurrentStepChanged(stepSelectionList->currentRow());
}
Exemplo n.º 2
0
void qAnimationDlg::preview()
{
	//we'll take the rendering time into account!
	QElapsedTimer timer;
	timer.start();

	setEnabled(false);

	//reset the interpolators and count the total number of frames
	int frameCount = countFrameAndResetInterpolators();

	//show progress dialog
	QProgressDialog progressDialog(QString("Frames: %1").arg(frameCount), "Cancel", 0, frameCount, this);
	progressDialog.setWindowTitle("Preview");
	progressDialog.show();
	QApplication::processEvents();

	double fps = fpsSpinBox->value();
	
	int frameIndex = 0;
	for ( size_t i=0; i<m_videoSteps.size(); ++i )
	{
		VideoStepItem& currentVideoStep = m_videoSteps[i];

		//theoretical waiting time per frame
		qint64 delay_ms = static_cast<int>(1000 * currentVideoStep.duration_sec / fps);

		cc2DViewportObject currentParams;
		while ( currentVideoStep.interpolator.nextView( currentParams ) )
		{
			timer.restart();
			applyViewport ( &currentParams );
			qint64 dt_ms = timer.elapsed();

			progressDialog.setValue(++frameIndex);
			QApplication::processEvents();
			if (progressDialog.wasCanceled())
			{
				break;
			}

			//remaining time
			if (dt_ms < delay_ms)
			{
				int wait_ms = static_cast<int>(delay_ms - dt_ms);
#if defined(CC_WINDOWS)
				::Sleep( wait_ms );
#else
				usleep( wait_ms * 1000 );
#endif
			}
		}
	}

	//reset view
	onCurrentStepChanged( getCurrentStepIndex() );

	setEnabled(true);
}
Exemplo n.º 3
0
qAnimationDlg::qAnimationDlg( std::vector<VideoStepItem>& videoSteps, ccGLWindow* view3d, QWidget* parent)
	: QDialog(parent)
	, Ui::AnimationDialog()
	, m_videoSteps(videoSteps)
	, m_view3d(view3d)
{
	setupUi(this);

	setWindowFlags(Qt::Tool/*Qt::Dialog | Qt::WindowStaysOnTopHint*/);

	for ( size_t i=0; i<m_videoSteps.size(); ++i )
	{
		cc2DViewportObject* viewport1 = m_videoSteps[i].interpolator.view1();

		stepSelectionList->addItem( viewport1->getName() );

		//check if the (1st) viewport has a duration in meta data (from a previous run)
		double duration_sec = 2.0;
		if (viewport1->hasMetaData(s_stepDurationKey))
		{
			duration_sec = viewport1->getMetaData(s_stepDurationKey).toDouble();
		}
		m_videoSteps[i].duration_sec = duration_sec;
	}

	//read persistent settings
	{
		QSettings settings;
		settings.beginGroup("qAnimation");
		QString defaultDir;
#ifdef _MSC_VER
		defaultDir = QApplication::applicationDirPath();
#else
		defaultDir = QDir::homePath();
#endif
		QString lastFilename = settings.value("filename", defaultDir + "/animation.mpg" ).toString();
#ifndef QFFMPEG_SUPPORT
		lastFilename = QFileInfo(lastFilename).absolutePath();
#endif
		outputFileLineEdit->setText( lastFilename );
		settings.endGroup();
	}

	connect ( fpsSpinBox,				SIGNAL( valueChanged(double) ),		this, SLOT( onFPSChanged(double) ) );
	connect ( totalTimeDoubleSpinBox,	SIGNAL( valueChanged(double) ),		this, SLOT( onTotalTimeChanged(double) ) );
	connect ( stepTimeDoubleSpinBox,	SIGNAL( valueChanged(double) ),		this, SLOT( onStepTimeChanged(double) ) );
	connect ( stepSelectionList,		SIGNAL( currentRowChanged(int) ),	this, SLOT( onCurrentStepChanged(int) ) );
	connect ( browseButton,				SIGNAL( clicked() ),				this, SLOT( onBrowseButtonClicked() ) );
	connect ( previewButton,			SIGNAL( clicked() ),				this, SLOT( preview() ) );
	connect ( renderButton,				SIGNAL( clicked() ),				this, SLOT( render() ) );
	connect ( buttonBox,				SIGNAL( accepted() ),				this, SLOT( onAccept() ) );

	stepSelectionList->setCurrentRow(0); //select the first one by default

	onCurrentStepChanged(getCurrentStepIndex());
	updateTotalDuration();
}
Exemplo n.º 4
0
bool qAnimationDlg::init(const std::vector<cc2DViewportObject*>& viewports)
{
	if (viewports.size() < 2)
	{
		assert(false);
		return false;
	}
	
	try
	{
		m_videoSteps.resize(viewports.size());
	}
	catch (const std::bad_alloc&)
	{
		//not enough memory
		return false;
	}
	
	for (size_t i=0; i<viewports.size(); ++i)
	{
		cc2DViewportObject* vp = viewports[i];

		//check if the (1st) viewport has a duration in meta data (from a previous run)
		double duration_sec = 2.0;
		if (vp->hasMetaData(s_stepDurationKey))
		{
			duration_sec = vp->getMetaData(s_stepDurationKey).toDouble();
		}
		bool isChecked = true;
		if (vp->hasMetaData(s_stepEnabledKey))
		{
			isChecked = vp->getMetaData(s_stepEnabledKey).toBool();
		}

		QString itemName = QString("step %1 (%2)").arg(QString::number(i+1), vp->getName());
		QListWidgetItem* item = new QListWidgetItem(itemName, stepSelectionList);
		item->setFlags(item->flags() | Qt::ItemIsUserCheckable); // set checkable flag
		item->setCheckState(isChecked ? Qt::Checked : Qt::Unchecked); // initialize check state
		stepSelectionList->addItem(item);

		m_videoSteps[i].viewport = vp;
		m_videoSteps[i].duration_sec = duration_sec;
	}

	connect ( stepSelectionList, SIGNAL( currentRowChanged(int) ),			this, SLOT( onCurrentStepChanged(int) ) );
	connect ( stepSelectionList, SIGNAL( itemChanged(QListWidgetItem*) ),	this, SLOT( onItemChanged(QListWidgetItem*) ) );

	stepSelectionList->setCurrentRow(0); //select the first one by default
	onCurrentStepChanged(getCurrentStepIndex());
	updateTotalDuration();

	return true;
}
Exemplo n.º 5
0
void qAnimationDlg::onLoopToggled(bool)
{
	updateTotalDuration();

	onCurrentStepChanged(stepSelectionList->currentRow());
}
Exemplo n.º 6
0
void qAnimationDlg::preview()
{
	//we'll take the rendering time into account!
	QElapsedTimer timer;
	timer.start();

	setEnabled(false);

	size_t vp1 = previewFromSelectedCheckBox->isChecked() ? static_cast<size_t>(getCurrentStepIndex()) : 0;

	//count the total number of frames
	int frameCount = countFrames(loopCheckBox->isChecked() ? 0 : vp1);
	int fps = fpsSpinBox->value();

	//show progress dialog
	QProgressDialog progressDialog(QString("Frames: %1").arg(frameCount), "Cancel", 0, frameCount, this);
	progressDialog.setWindowTitle("Preview");
	progressDialog.show();
	progressDialog.setModal(true);
	progressDialog.setAutoClose(false);
	QApplication::processEvents();

	assert(stepSelectionList->count() >= m_videoSteps.size());

	int frameIndex = 0;
	size_t vp2 = 0;
	while (getNextSegment(vp1, vp2))
	{
		Step& step1 = m_videoSteps[vp1];
		Step& step2 = m_videoSteps[vp2];

		//theoretical waiting time per frame
		qint64 delay_ms = static_cast<int>(1000 * step1.duration_sec / fps);
		int frameCount = static_cast<int>( fps * step1.duration_sec );

		ViewInterpolate interpolator(step1.viewport, step2.viewport);
		interpolator.setMaxStep(frameCount);
		cc2DViewportObject currentParams;
		while ( interpolator.nextView( currentParams ) )
		{
			timer.restart();
			applyViewport ( &currentParams );
			qint64 dt_ms = timer.elapsed();

			progressDialog.setValue(++frameIndex);
			QApplication::processEvents();
			if (progressDialog.wasCanceled())
			{
				break;
			}

			//remaining time
			if (dt_ms < delay_ms)
			{
				int wait_ms = static_cast<int>(delay_ms - dt_ms);
#if defined(CC_WINDOWS)
				::Sleep( wait_ms );
#else
				usleep( wait_ms * 1000 );
#endif
			}
		}
		if (progressDialog.wasCanceled())
		{
			break;
		}

		if (vp2 == 0)
		{
			assert(loopCheckBox->isChecked());
			frameIndex = 0;
		}
		vp1 = vp2;
	}

	//reset view
	onCurrentStepChanged(getCurrentStepIndex());

	setEnabled(true);
}