Esempio n. 1
0
void TimeLineComboBox::mouseRelease(QMouseEvent* event, bool comboBoxEvent/* = false*/)
{
	if(m_dragging)
	{
		// Save geometry changes from dragging
		m_start = (int)((x() - 1.5f) / (float)(parentWidget()->width()-2) * m_maxTime);
		m_xmlNode.setAttribute("start", m_start);
		m_end = (int)(( (width()-0.5f) / (float)(parentWidget()->width()-2)* m_maxTime ) + m_start);
		m_xmlNode.setAttribute("end", m_end);
		
		emit xmlNodeChanged();
		m_dragging = false;
	}
	if(m_sizingLeft)
	{
		// Save geometry changes from sizing
		m_start = (int)((x() - 1.5f) / (float)(parentWidget()->width()-2) * m_maxTime);
		m_xmlNode.setAttribute("start", m_start);

		emit xmlNodeChanged();
		m_sizingLeft = false;
	}
	if(m_sizingRight)
	{
		// Save geometry changes from sizing
		m_end = (int)(( (width()-0.5f) / (float)(parentWidget()->width()-2)* m_maxTime ) + m_start);
		m_xmlNode.setAttribute("end", m_end);

		emit xmlNodeChanged();
		m_sizingRight = false;
	}
}
Esempio n. 2
0
void TimeLineComboBox::setValue(const QString& value)
{
	int index = findText(value);
	if( index != -1)
	{
		m_xmlNode.setAttribute("value", value);
		m_value = QString(value);
		setCurrentIndex(index);
		emit xmlNodeChanged();
	}
}
Esempio n. 3
0
void PhonemeEditorWidget::parseXmlFile()
{
    // Clear old text boxes
    QList<TimeLineTextEdit *> oldText= m_text->findChildren<TimeLineTextEdit *>();
    while(!oldText.isEmpty())
        delete oldText.takeFirst();

    // Clear old phoneme comboboxes
    QList<TimeLineComboBox *> oldPhoneme = m_phonemes->findChildren<TimeLineComboBox *>();
    while(!oldPhoneme.isEmpty())
        delete oldPhoneme.takeFirst();

    // Get new items from phoneme xml
    QDomElement timings = m_phonemeXml.firstChildElement("PhonemeTimings");

    // Get length of phoneme timings
    QDomElement last = timings.lastChildElement("word");
    int sentenceLength = 0;
    if(!last.isNull()) sentenceLength = last.attribute("end", "0").toInt();
    last = timings.lastChildElement("phn");
    if( !last.isNull() ) sentenceLength = max(sentenceLength, last.attribute("end", "0").toInt() );

    // Get minimal phoneme width
    QDomNodeList phnlist = timings.elementsByTagName("phn");
    int minPhnWidth = 999999;
    for(unsigned int i=0; i<phnlist.length(); i++)
    {
        QDomElement phn = phnlist.item(i).toElement();
        // Skip silence
        if( phn.attribute("value").compare("x") == 0 ) continue;
        int start = phn.attribute("start", "0").toInt();
        int end = phn.attribute("end", "999999").toInt();
        if( end-start < minPhnWidth ) minPhnWidth = end-start;
    }
    int minWidth =  (int)( 39.5f / minPhnWidth * sentenceLength );

    // Get length of panels and enlarge them if too small
    if( m_text->width()-2 < minWidth)
    {
        m_text->setFixedWidth(minWidth+2);
        m_phonemes->setFixedWidth(minWidth+2);
        m_phonemeScrollArea->setFixedWidth(m_text->x()+minWidth+2);
    }

    // Add wordBoxes in reverse direction, because first nodes have higher priority
    // and should be printed above of the others
    QDomNode wordNode = timings.lastChild();
    while(!wordNode.isNull())
    {
        // Get words
        if( wordNode.nodeName().compare("word") == 0)
        {
            QDomElement word = wordNode.toElement();
            TimeLineTextEdit* wordBox = new TimeLineTextEdit(word, sentenceLength, m_text);
            connect(wordBox, SIGNAL(xmlNodeChanged()), this, SLOT(enableSaveButton()) );
            wordBox->setVisible(true);

            // Get phonemes of a word
            QDomNodeList phonemeList = word.elementsByTagName("phn");
            // also reverse direction
            for(int i = phonemeList.size()-1; i >=0; i--)
            {
                QDomElement phoneme = phonemeList.item(i).toElement();
                // Skip silence
                if( phoneme.attribute("value").compare("x") == 0 ) continue;
                TimeLineComboBox* phonemeBox = new TimeLineComboBox(phoneme, sentenceLength, m_phonemeList, m_phonemes);
                connect(phonemeBox, SIGNAL(xmlNodeChanged()), this, SLOT(enableSaveButton()) );
                connect(phonemeBox, SIGNAL(xmlNodeChanged()), wordBox, SLOT(updateFromXml()));
                phonemeBox->setVisible(true);
            }
        }
        // Get phonemes which don't belong to words
        else if( wordNode.nodeName().compare("phn") == 0 )
        {
            QDomElement phoneme = wordNode.toElement();
            // Skip silence
            if( phoneme.attribute("value").compare("x") != 0 )
            {
                TimeLineComboBox* phonemeBox = new TimeLineComboBox(phoneme, sentenceLength, m_phonemeList, m_phonemes);
                connect(phonemeBox, SIGNAL(xmlNodeChanged()), this, SLOT(enableSaveButton()) );
                phonemeBox->setVisible(true);
            }
        }

        wordNode = wordNode.previousSibling();
    }
}
Esempio n. 4
0
void TimeLineComboBox::indexChanged(int index)
{
	m_xmlNode.setAttribute("value", itemText(index));
	m_value = QString(itemText(index));
	emit xmlNodeChanged();
}