void NodeList_sV::setSpeed(qreal segmentTime, qreal speed) { int left, right; findBySegment(segmentTime, left, right); if (left >= 0 && right >= 0) { Node_sV *leftN = &m_list[left]; Node_sV *rightN = &m_list[right]; qreal y = leftN->y() + speed*(rightN->x()-leftN->x()); if (y > m_maxY || y < 0) { if (y > m_maxY) { qDebug() << speed << "x speed would shoot over maximum time. Correcting."; y = m_maxY; } else { qDebug() << speed << "x speed goes below 0. Correcting."; y = 0; } qreal xNew = leftN->x() + (y - leftN->y())/speed; rightN->setY(y); if (xNew - leftN->x() >= m_minDist) { add(Node_sV(xNew, y)); } else { qDebug() << "New node would be too close, not adding it."; } } else { rightN->setY(y); } } else { qDebug() << "Outside segment."; } validate(); }
bool NodeList_sV::add(Node_sV node) { bool add = true; #ifdef DEBUG_NL qDebug() << "Before adding: \n" << *this; #endif node.setX(qMax(.0, node.x())); node.setY(qMax(.0, qMin(m_maxY, node.y()))); int pos = find(node.x()); if (pos >= 0 && m_list.size() > pos) { add = fabs(node.x()-m_list.at(pos).x()) > m_minDist; #ifdef DEBUG_NL qDebug() << "Left distance is " << fabs(node.x()-m_list.at(pos).x()); #endif if (add && m_list.size() > pos+1) { add = fabs(node.x()-m_list.at(pos+1).x()) > m_minDist; #ifdef DEBUG_NL qDebug() << "Right distance is " << fabs(node.x()-m_list.at(pos+1).x()); #endif } } #ifdef DEBUG_NL qDebug() << "Adding? " << add; #endif if (add) { m_list.append(node); qSort(m_list); if (m_list.size() > 1) { m_segments.grow(); } // Reset curve type of neighbours if this is a linear node int index = m_list.indexOf(node); if (index > 0 && node.leftCurveType() == CurveType_Linear) { m_list[index-1].setRightCurveType(CurveType_Linear); } if (index < m_list.size()-1 && node.rightCurveType() == CurveType_Linear) { m_list[index+1].setLeftCurveType(CurveType_Linear); } fixHandles(index-1); fixHandles(index); } #ifdef DEBUG_NL qDebug() << "After adding: \n" << *this; #endif validate(); return add; }
void MainWindow::slotNewProject() { NewProjectDialog npd(this); if (npd.exec() == QDialog::Accepted) { try { Project_sV *project = npd.buildProject(); // Save project XmlProjectRW_sV writer; //qDebug() << "Saving project as " << npd.filename; // check if directory exist ... QFileInfo projfile(npd.projectFilename()); QDir dir(projfile.absoluteDir()); if (!dir.exists()) { dir.mkpath("."); } try { writer.saveProject(project, npd.projectFilename()); statusBar()->showMessage(QString(tr("Saved project as: %1")).arg(npd.projectFilename())); setWindowModified(false); } catch (Error_sV &err) { QMessageBox(QMessageBox::Warning, tr("Error writing project file"), err.message()).exec(); } m_projectPath = npd.projectFilename(); project->preferences()->viewport_secRes() = QPointF(400, 400)/project->frameSource()->framesCount()*project->frameSource()->fps()->fps(); /* add a first (default) node */ Node_sV snode; snode.setX(0.0); snode.setY(0.0); project->nodes()->add(snode); loadProject(project); m_wCanvas->showHelp(true); setWindowModified(true); } catch (FrameSourceError &err) { QMessageBox(QMessageBox::Warning, "Frame source error", err.message()).exec(); } } }