void MusicBar::append( Symbol *symbol) { symbol->setVisible(true); Symbol *lastSym = 0; if( !m_symbols.isEmpty() ){ lastSym = m_symbols.last(); } m_symbols.append( symbol ); m_symbolLayout->addItem( symbol ); if(symbol->type() == MelodyNoteType) { MelodyNote *note = qgraphicsitem_cast<MelodyNote *>(symbol); connect(note, SIGNAL(pitchHasChanged(const Pitch *)), m_stemDrawer, SLOT(updateStems())); connect(note, SIGNAL(lengthHasChanged()), m_stemDrawer, SLOT(updateStems())); if((lastSym != 0) && (lastSym->inherits("Embellishment")) ){ Embellishment *emb = qobject_cast<Embellishment *>(lastSym); emb->setFollowPitch(note->pitch()); connect(note, SIGNAL(pitchHasChanged(const Pitch*)), emb, SLOT(setFollowPitch(const Pitch *))); } } else if (symbol->inherits("Embellishment")) { if((lastSym != 0) && (lastSym->type() == MelodyNoteType)){ MelodyNote *note = qgraphicsitem_cast<MelodyNote *>(lastSym); Embellishment *emb = qobject_cast<Embellishment *>(symbol); emb->setPreceedPitch(note->pitch()); connect(note, SIGNAL(pitchHasChanged(const Pitch*)), emb, SLOT(setPreceedPitch(const Pitch*))); } } }
void MusicBar::append( Symbol *symbol) { symbol->setVisible(true); m_symbols.append( symbol ); m_layout->addItem( symbol ); if(symbol->type() == MelodyNoteType) { MelodyNote *note = qgraphicsitem_cast<MelodyNote *>(symbol); connect(note, SIGNAL(pitchHasChanged()), m_stemDrawer, SLOT(updateStems())); connect(note, SIGNAL(lengthHasChanged()), m_stemDrawer, SLOT(updateStems())); } }
void MusicBar::insert(int idx, Symbol *symbol) { int insert_idx = idx; if(insert_idx != 0 && insert_idx > m_symbols.count()-1){ insert_idx = m_symbols.count()+1; } symbol->setVisible(true); m_symbols.insert(insert_idx, symbol); if(symbol->scene() == 0){ m_scene->addItem(symbol); } updateLayout(); Symbol *symBefore = 0; Symbol *symAfter = 0; //Symbol not first or last if(idx > 0){ symBefore = m_symbols[idx-1]; } if(idx < m_symbols.count()-1){ symAfter = m_symbols[idx+1]; } //Symbol inserted as first if(idx == 0){ symBefore = m_lastSymPrev; } //Symbol inserted as last if(idx == m_symbols.count()-1){ symAfter = m_firstSymNext; } if(symbol->type() == MelodyNoteType) { MelodyNote *note = qgraphicsitem_cast<MelodyNote *>(symbol); connect(note, SIGNAL(pitchHasChanged(const Pitch *)), m_stemDrawer, SLOT(updateStems())); connect(note, SIGNAL(lengthHasChanged()), m_stemDrawer, SLOT(updateStems())); } connectSymbols(symBefore, symbol); connectSymbols(symbol, symAfter); }