Example #1
0
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;
}
Example #2
0
void NodeList_sV::moveHandle(const NodeHandle_sV *handle, Node_sV relPos)
{
    Node_sV otherNode;
    Node_sV *currentNode = const_cast<Node_sV*>(handle->parentNode());

    int nodeIndex = indexOf(handle->parentNode());
    Q_ASSERT(nodeIndex >= 0);
    Q_ASSERT(nodeIndex < m_list.size());

    if (handle == &currentNode->leftNodeHandle()) {
        //  o------[]
        if (nodeIndex > 0) {
            // Ensure that it does not overlap with the left node's handle (injectivity)
            otherNode = m_list.at(nodeIndex-1);
            qDebug() << "Left node: " << otherNode;
            qDebug() << "Right node: " << currentNode;
            qDebug() << "Before overlapping check: " << relPos;
            relPos.setX(qMax(relPos.x(), -(currentNode->x() - otherNode.x() - otherNode.rightNodeHandle().x())));
            qDebug() << "After overlapping check: " << relPos;
            qDebug() << "Space left: " << currentNode->x() + relPos.x() - (otherNode.x() + otherNode.rightNodeHandle().x());
        }
        // Additionally the handle has to stay on the left of its node
        relPos.setX(qMin(relPos.x(), .0));

        currentNode->setLeftNodeHandle(relPos.x(), relPos.y());

    } else {
        // []-------o
        if (nodeIndex+1 < m_list.size()) {
            otherNode = m_list.at(nodeIndex+1);
            relPos.setX(qMin(relPos.x(), otherNode.x() - currentNode->x() + otherNode.leftNodeHandle().x()));
        }
        relPos.setX(qMax(relPos.x(), .0));

        currentNode->setRightNodeHandle(relPos.x(), relPos.y());
    }
    validate();
}
Example #3
0
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();
        }
    }
}