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

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

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

See also:
CAScoreViewPort::mouseMoveEvent(), scoreViewPortMousePress(), scoreViewPortWheel(), scoreViewPortKeyPress()

Definition at line 1697 of file mainwin.cpp.

References CAScoreViewPort::addSelectionRegion(), CAScoreViewPort::clearSelectionRegionList(), CAScoreViewPort::coordsToTime(), CAScoreViewPort::currentContext(), CAScoreViewPort::findContextsInRegion(), CAScoreViewPort::lastMousePressCoords(), CAMusElementFactory::noteExtraAccs(), CAScoreViewPort::resizeDirection(), CAScoreViewPort::selection(), CAMusElementFactory::setNoteAccs(), CAScoreViewPort::setShadowNoteAccs(), CAScoreViewPort::setShadowNoteVisible(), CAScoreViewPort::timeToCoords(), and CAScoreViewPort::updateHelpers().

Referenced by initViewPort().

                                                                    {
      CAScoreViewPort *c = static_cast<CAScoreViewPort*>(sender());
      if ( mode() == SelectMode && c->resizeDirection()!=CADrawable::Undefined ) {
            int time = c->coordsToTime(coords.x());
            time -= (time % CAPlayableLength::musicLengthToTimeLength(CAPlayableLength::Sixteenth)); // round timelength to eighth notes length
            if ( c->resizeDirection()==CADrawable::Right && (time > c->selection().at(0)->musElement()->timeStart()) ) {
                  c->selection().at(0)->musElement()->setTimeLength( time - c->selection().at(0)->musElement()->timeStart() );
                  c->selection().at(0)->setWidth( c->timeToCoords(time) - c->selection().at(0)->xPos() );
                  c->repaint();
            } else
            if ( c->resizeDirection()==CADrawable::Left && (time < c->selection().at(0)->musElement()->timeEnd()) ) {
                  c->selection().at(0)->musElement()->setTimeLength( c->selection().at(0)->musElement()->timeEnd() - time );
                  c->selection().at(0)->musElement()->setTimeStart( time );
                  c->selection().at(0)->setXPos( c->timeToCoords(time) );
                  c->selection().at(0)->setWidth( c->timeToCoords(c->selection().at(0)->musElement()->timeEnd()) - c->timeToCoords(time) );
                  c->repaint();
            }
      } else
      if ( (mode() == InsertMode && musElementFactory()->musElementType() == CAMusElement::Note) ) {
            CADrawableStaff *s;
            if (c->currentContext()?(c->currentContext()->drawableContextType() == CADrawableContext::DrawableStaff):0)
                  s = (CADrawableStaff*)c->currentContext();
            else
                  return;

            if ( musElementFactory()->musElementType() == CAMusElement::Note ||
             musElementFactory()->musElementType() == CAMusElement::Rest) {
                  c->setShadowNoteVisible(true);
        }

            // calculate the musical pitch out of absolute world coordinates and the current clef
            int pitch = s->calculatePitch(coords.x(), coords.y());

            // write into the main window's status bar the note pitch name
            int iNoteAccs = s->getAccs(coords.x(), pitch) + musElementFactory()->noteExtraAccs();
            musElementFactory()->setNoteAccs( iNoteAccs );
            c->setShadowNoteAccs(iNoteAccs);
            c->updateHelpers();
            c->repaint();
      } else
      if ( mode()!=InsertMode  && e->buttons()==Qt::LeftButton ) { // multiple selection
            c->clearSelectionRegionList();
            int x=c->lastMousePressCoords().x(), y=c->lastMousePressCoords().y(),
                w=coords.x()-c->lastMousePressCoords().x(), h=coords.y()-c->lastMousePressCoords().y();
            if (w<0) { x+=w; w*=(-1); } // user selected from right to left
            if (h<0) { y+=h; h*=(-1); } // user selected from bottom to top
            QRect selectionRect( x, y, w, h );

            QList<CADrawableContext*> dcList = c->findContextsInRegion( selectionRect );
            for (int i=0; i<dcList.size(); i++) {
                  QList<CADrawableMusElement*> musEltList = dcList[i]->findInRange( selectionRect.x(), selectionRect.x() + selectionRect.width() );
                  for (int j=0; j<musEltList.size(); j++)
                        if (musEltList[j]->drawableMusElementType()==CADrawableMusElement::DrawableSlur)
                              musEltList.removeAt(j--);

                  if (musEltList.size()) {
                        c->addSelectionRegion( QRect(musEltList.front()->xPos(), dcList[i]->yPos(),
                                                     musEltList.back()->xPos()+musEltList.back()->width()-musEltList.front()->xPos(), dcList[i]->height()) );
                  }
            }
            c->repaint();
      }
}


Generated by  Doxygen 1.6.0   Back to index