Logo Search packages:      
Sourcecode: canorus version File versions  Download package

void CAMainWin::sourceViewPortCommit ( QString  inputString  )  [private, slot]

Called when a user clicks "Commit" button in source viewport.

Definition at line 3640 of file mainwin.cpp.

References _viewPortList, CAVoice::addLyricsContext(), CAStaff::addVoice(), CALyricsContext::associatedVoice(), clearUI(), CALyricsContext::cloneLyricsContextProperties(), CASourceViewPort::document(), CAVoice::getSignList(), CASheet::insertContextAfter(), CASourceViewPort::lyricsContext(), CAVoice::remove(), CASheet::removeContext(), CAVoice::removeLyricsContext(), CAStaff::removeVoice(), CASourceViewPort::setLyricsContext(), CASourceViewPort::setVoice(), CAContext::sheet(), CAVoice::staff(), CAStaff::synchronizeVoices(), CAViewPort::viewPortType(), and CASourceViewPort::voice().

Referenced by initViewPort().

                                                        {
      CASourceViewPort *v = static_cast<CASourceViewPort*>(sender());

      stopPlayback();
      if (v->document()) {
            // CanorusML document source
            CACanorus::undo()->createUndoCommand( document(), tr("commit CanorusML source", "undo") );

            clearUI();  // clear GUI before clearing the data part!
            if ( document() )
                  delete document();

            CACanorus::undo()->pushUndoCommand();
            CACanorusMLImport open( inputString );
            open.importDocument();
            open.wait();

            if (open.importedDocument()) {
                  CACanorus::undo()->changeDocument( document(), open.importedDocument() );
                  setDocument( open.importedDocument() );
            }
            CACanorus::rebuildUI(document());
      } else
      if (v->voice()) {
            // LilyPond voice source
            CACanorus::undo()->createUndoCommand( document(), tr("commit LilyPond source", "undo") );

            CALilyPondImport li( inputString );

            CAVoice *oldVoice = v->voice();

            QList<CAMusElement*> signList = oldVoice->getSignList();
            for (int i=0; i<signList.size(); i++)
                  oldVoice->remove( signList[i] );  // removes signs from all voices

            li.setTemplateVoice( oldVoice );      // copy properties
            li.importVoice();
            li.wait();

            CAVoice *newVoice = li.importedVoice();
            oldVoice->staff()->removeVoice(oldVoice);

            newVoice->staff()->addVoice( newVoice );
            newVoice->staff()->synchronizeVoices();

            // FIXME any way to avoid this?
            CAScoreViewPort *scorevp;
            foreach(CAViewPort* vp, _viewPortList) {
                  if(vp->viewPortType() == CAViewPort::ScoreViewPort && (scorevp = static_cast<CAScoreViewPort*>(vp))->selectedVoice() == oldVoice)
                        scorevp->setSelectedVoice(newVoice);
            }

            v->setVoice( newVoice );
            CACanorus::undo()->pushUndoCommand();
            CACanorus::rebuildUI(document(), newVoice->staff()->sheet());
            oldVoice->staff()->addVoice(oldVoice);
            delete oldVoice; // also removes voice from the staff
      } else
      if (v->lyricsContext()) {
            // LilyPond lyrics source
            CACanorus::undo()->createUndoCommand( document(), tr("commit LilyPond source", "undo") );

            CALilyPondImport li( inputString );

            li.importLyricsContext();
            li.wait();
            CALyricsContext *newLc = li.importedLyricsContext();
            CALyricsContext *oldLc = v->lyricsContext();
            newLc->cloneLyricsContextProperties( oldLc );
            if (newLc->associatedVoice()) {
                  newLc->associatedVoice()->removeLyricsContext( oldLc );
                  newLc->associatedVoice()->addLyricsContext(newLc);
            }
            newLc->sheet()->insertContextAfter( oldLc, newLc );
            newLc->sheet()->removeContext( oldLc );
            v->setLyricsContext( newLc );
            delete oldLc;

            CACanorus::undo()->pushUndoCommand();
            CACanorus::rebuildUI(document(), v->lyricsContext()->sheet());
      }

      setCurrentViewPort( v );
}


Generated by  Doxygen 1.6.0   Back to index