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

void CAMainWin::scoreViewPortMousePress ( QMouseEvent *  e,
const QPoint  coords 
) [private, slot]

Processes the mouse press event e with world coordinates coords. Any action happened in any of the viewports are always linked to these main window slots.

See also:
CAScoreViewPort::mousePressEvent(), scoreViewPortMouseMove(), scoreViewPortWheel(), scoreViewPortKeyPress()

Definition at line 1497 of file mainwin.cpp.

References CAPluginManager::action(), CAScoreViewPort::addToSelection(), CAScoreViewPort::clearSelection(), CAScoreViewPort::clearSelectionRegionList(), CAMusElement::context(), CASheet::contextCount(), CAContext::contextType(), CAScoreViewPort::createTextEdit(), CAScoreViewPort::currentContext(), CAToolButton::currentId(), CASheet::insertContextAfter(), insertMusElementAt(), CAMusElement::isPlayable(), CAMusElementFactory::markType(), CAScoreViewPort::musElementsAt(), CAMusElementFactory::musElementType(), CAMusElement::musElementType(), CAScoreViewPort::nearestUpContext(), CAScoreViewPort::removeFromSelection(), CAScoreViewPort::removeTextEdit(), CAScoreViewPort::resizeDirection(), CAScoreViewPort::selectCElement(), CAScoreViewPort::selectContext(), CAScoreViewPort::selection(), CAScoreViewPort::setCurrentContext(), CAMusElementFactory::setMusElementType(), CAScoreViewPort::setShadowNoteLength(), CAScoreViewPort::sheet(), CASheet::staffCount(), CAMusElement::timeEnd(), CAMusElement::timeStart(), CAScoreViewPort::updateHelpers(), updateToolBars(), and CASheet::voiceList().

Referenced by initViewPort().

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

      CADrawableContext *prevContext = v->currentContext();
      v->selectCElement(coords.x(), coords.y());

      QList<CADrawableMusElement*> l = v->musElementsAt( coords.x(), coords.y() );
      CADrawableMusElement *newlySelectedElement=0;
      int idx=-1;

      if (l.size() > 0) { // multiple elements can share the same coordinates
            if ( (v->selection().size() > 0) && (!v->selection().contains(l.front())) ) {
                  if (e->modifiers()!=Qt::ShiftModifier)
                        v->clearSelection();
                  v->addToSelection( newlySelectedElement = l[0] );      // if the previous selection was not a single element or if the new list doesn't contain the selection set the first element in the available list to the selection
            } else {
                  if (e->modifiers()==Qt::ShiftModifier && v->selection().size()) {
                        v->removeFromSelection(l[0]); // shift used on an already selected element - toggle selection
                  } else {
                        idx = (v->selection().size()?l.indexOf(v->selection().front()):-1);
                        v->clearSelection();
                        v->addToSelection( newlySelectedElement = l[((++idx < l.size()) ? idx : 0)] ); // if there are two or more elements with the same coordinates, select the next one (behind it). This way, you can click multiple times on the same place and you'll always select the other element.
                  }
            }
      } else if (e->modifiers()==Qt::NoModifier) { // no elements at that coordinates
            v->clearSelection();
      }

      // always select the context the current element belongs to
      if ( newlySelectedElement && (mode()!=InsertMode || !uiInsertPlayable->isChecked() ) )
            v->setCurrentContext( newlySelectedElement->drawableContext() );

      if ( v->currentContext() && prevContext != v->currentContext() && mode()!=InsertMode) {   // new context was selected
            // voice number widget
            if (v->currentContext()->context()->contextType() == CAContext::Staff) {
                  uiVoiceNum->setRealValue(0);
                  uiVoiceNum->setMax(static_cast<CAStaff*>(v->currentContext()->context())->voiceCount());
            }
      } else if ( prevContext != v->currentContext() && uiInsertPlayable->isChecked() ) { // but insert playable mode is active and context should remain the same
            v->setCurrentContext( prevContext );
      }

      if ( v->resizeDirection()!=CADrawable::Undefined ) {
            CACanorus::undo()->createUndoCommand( document(), tr("resize", "undo"));
      }

      switch ( mode() ) {
            case SelectMode:
            case EditMode: {
                  v->clearSelectionRegionList();


                  if ( v->selection().size() ) {
                        CADrawableMusElement *dElt = v->selection().front();
                        CAMusElement *elt = dElt->musElement();
                        if (!elt) break;

                        if ( mode()==EditMode &&
                             (elt->musElementType()==CAMusElement::Syllable || elt->musElementType()==CAMusElement::Mark && static_cast<CAMark*>(elt)->markType()==CAMark::Text)
                           ){
                              v->createTextEdit( dElt );
                        }

                        // debug
                        std::cout << "drawableMusElement: " << dElt << ", x,y=" << dElt->xPos() << "," << dElt->yPos() << ", w,h=" << dElt->width() << "," << dElt->height() << ", dContext=" << dElt->drawableContext() << std::endl;
                        std::cout << "musElement: " << elt << ", timeStart=" << elt->timeStart() << ", timeEnd=" << elt->timeEnd() << ", context=" << elt->context();
                        if (elt->isPlayable()) {
                              std::cout << ", voice=" << ((CAPlayable*)elt)->voice() << ", voiceNr=" << ((CAPlayable*)elt)->voice()->voiceNumber() << ", idxInVoice=" << ((CAPlayable*)elt)->voice()->indexOf(elt);
                              std::cout << ", voiceStaff=" << ((CAPlayable*)elt)->voice()->staff();

                              if (static_cast<CAPlayable*>(elt)->tuplet()) {
                                    std::cout << ", tuplet=" << static_cast<CAPlayable*>(elt)->tuplet();
                              }

                              if (elt->musElementType()==CAMusElement::Note)
                                    std::cout << ", pitch=" << static_cast<CANote*>(elt)->diatonicPitch().noteName();
                        }
                        if (elt->musElementType()==CAMusElement::Slur) {
                              std::cout << "noteStart=" << static_cast<CASlur*>(elt)->noteStart() << ", noteEnd=" << static_cast<CASlur*>(elt)->noteStart();
                        }
                        std::cout << std::endl;
                  } else {
                        v->removeTextEdit();
                  }

                  break;
            }
            case InsertMode: {
                  // Insert context
                  if (uiContextType->isChecked()) {
                        // Add new Context
                        CAContext *newContext;
                        CADrawableContext *dupContext = v->nearestUpContext(coords.x(), coords.y());
                        switch(uiContextType->currentId()) {
                              case CAContext::Staff: {
                                    CACanorus::undo()->createUndoCommand( document(), tr("new staff", "undo"));
                                    v->sheet()->insertContextAfter(
                                          dupContext?dupContext->context():0,
                                          newContext = new CAStaff(
                                                tr("Staff%1").arg(v->sheet()->staffCount()+1),
                                                v->sheet()
                                          )
                                    );
                                    static_cast<CAStaff*>(newContext)->addVoice();
                                    break;
                              }
                              case CAContext::LyricsContext: {
                                    CACanorus::undo()->createUndoCommand( document(), tr("new lyrics context", "undo"));

                                    int stanza=1;
                                    if (dupContext && dupContext->context() && dupContext->context()->contextType()==CAContext::LyricsContext)
                                          stanza = static_cast<CALyricsContext*>(dupContext->context())->stanzaNumber()+1;

                                    v->sheet()->insertContextAfter(
                                          dupContext?dupContext->context():0,
                                          newContext = new CALyricsContext(
                                                tr("LyricsContext%1").arg(v->sheet()->contextCount()+1),
                                                1,
                                                (v->sheet()->voiceList().size()?v->sheet()->voiceList().at(0):0)
                                          )
                                    );

                                    break;
                              }
                              case CAContext::FunctionMarkContext: {
                                    CACanorus::undo()->createUndoCommand( document(), tr("new function mark context", "undo"));
                                    v->sheet()->insertContextAfter(
                                          dupContext?dupContext->context():0,
                                          newContext = new CAFunctionMarkContext(
                                                tr("FunctionMarkContext%1").arg(v->sheet()->contextCount()+1),
                                                v->sheet()
                                          )
                                    );
                                    break;
                              }
                        }
                        CACanorus::undo()->pushUndoCommand();
                        CACanorus::rebuildUI(document(), v->sheet());

                        v->selectContext(newContext);
                        if (newContext->contextType()==CAContext::Staff) {
                              uiVoiceNum->setMax( 1 );
                              uiVoiceNum->setRealValue( 0 );
                        }
                        uiSelectMode->toggle();
                        v->repaint();
                        break;
                  } else
                  // Insert music element
                  if (uiInsertPlayable->isChecked()) {
                        // Add Note/Rest
                        if (e->button()==Qt::RightButton && musElementFactory()->musElementType()==CAMusElement::Note)
                              // place a rest when using right mouse button and note insertion is selected
                              musElementFactory()->setMusElementType( CAMusElement::Rest );
                        // show the dotted shadow note
                        currentScoreViewPort()->setShadowNoteLength( musElementFactory()->playableLength() );
                        currentScoreViewPort()->updateHelpers();
                  }

                  insertMusElementAt( coords, v );

                  if ( musElementFactory()->musElementType()==CAMusElement::Rest )
                       musElementFactory()->setMusElementType( CAMusElement::Note );

                  // Insert Syllable or Text
                  if ( (uiInsertSyllable->isChecked() || (uiMarkType->isChecked() && (musElementFactory()->markType()==CAMark::Text || musElementFactory()->markType()==CAMark::BookMark))) && !v->selection().isEmpty() ) {
                        v->createTextEdit( v->selection().front() );
                  } else {
                        v->removeTextEdit();
                  }

                  break;
            }
      }

      CAPluginManager::action("onScoreViewPortClick", document(), 0, 0, this);

      updateToolBars();
      v->repaint();
}


Generated by  Doxygen 1.6.0   Back to index