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

void CAScoreViewPort::paintEvent ( QPaintEvent *  e  )  [private, slot]

General Qt's paint event. All the music elements get actually rendered in this method.

Definition at line 844 of file scoreviewport.cpp.

References CAMusElement::color(), CAMusElement::context(), CADrawableAccidental::draw(), CAKDTree< T >::findInRange(), CANote::generateNoteName(), CAMusElement::isPlayable(), CAMusElement::isVisible(), CAMusElement::musElementType(), CAKDTree< T >::size(), CAVoice::staff(), and zoom().

                                               {
      if (_holdRepaint)
            return;

      // draw the border
      QPainter p(this);
      if (_drawBorder) {
            p.setPen(_borderPen);
            p.drawRect(0,0,width()-1,height()-1);
      }

      p.setClipping(true);
      if (_repaintArea) {
            p.setClipRect(QRect(qRound((_repaintArea->x() - _worldX)*_zoom),
                                qRound((_repaintArea->y() - _worldY)*_zoom),
                                qRound(_repaintArea->width()*_zoom),
                                qRound(_repaintArea->height()*_zoom)),
                          Qt::UniteClip);
      } else {
            p.setClipRect(QRect(_canvas->x(),
                                _canvas->y(),
                                _canvas->width(),
                                _canvas->height()),
                          Qt::UniteClip);
      }


      // draw the background
      if (_repaintArea)
            p.fillRect(qRound((_repaintArea->x() - _worldX)*_zoom), qRound((_repaintArea->y() - _worldY)*_zoom), qRound(_repaintArea->width()*_zoom), qRound(_repaintArea->height()*_zoom), _backgroundColor);
      else
            p.fillRect(_canvas->x(), _canvas->y(), _canvas->width(), _canvas->height(), _backgroundColor);

      // draw contexts
      QList<CADrawableContext*> cList;
      int j = _drawableCList.size();
      if (_repaintArea)
            cList = _drawableCList.findInRange(_repaintArea->x(), _repaintArea->y(), _repaintArea->width(),_repaintArea->height());
      else
            cList = _drawableCList.findInRange(_worldX, _worldY, _worldW, _worldH);

      for (int i=0; i<cList.size(); i++) {
            CADrawSettings s = {
                       _zoom,
                         qRound((cList[i]->xPos() - _worldX) * _zoom),
                           qRound((cList[i]->yPos() - _worldY) * _zoom),
                           drawableWidth(), drawableHeight(),
                           ((_currentContext == cList[i])?selectedContextColor():foregroundColor()),
                           _worldX,
                           _worldY
            };
            cList[i]->draw(&p, s);
      }

      // draw music elements
      QList<CADrawableMusElement*> mList;
      if (_repaintArea)
            mList = _drawableMList.findInRange(_repaintArea->x(), _repaintArea->y(), _repaintArea->width(),_repaintArea->height());
      else
            mList = _drawableMList.findInRange(_worldX, _worldY, _worldW, _worldH);

      p.setRenderHint( QPainter::Antialiasing, CACanorus::settings()->antiAliasing() );

      for (int i=0; i<mList.size(); i++) {
            QColor color;
            CAMusElement *elt = mList[i]->musElement();

            if ( _selection.contains(mList[i])) {
                  color = selectionColor();
            } else
            if ( selectedVoice() &&
                 (elt &&
                  (elt->isPlayable() && static_cast<CAPlayable*>(elt)->voice()==selectedVoice() ||
                   (!elt->isPlayable() && elt->context()==selectedVoice()->staff()) ||
                   elt->context()!=selectedVoice()->staff()) ||
                  !elt && mList[i]->drawableContext()->context()==selectedVoice()->staff()
                 ) ||
                 (!selectedVoice())
               ) {
                  if ( elt && elt->musElementType()==CAMusElement::Rest &&
                       static_cast<CAPlayable*>(elt)->voice()==selectedVoice() &&
                       static_cast<CARest*>(elt)->restType()==CARest::Hidden
                     ) {
                        color = hiddenElementsColor();
                  } else if ( elt && elt->musElementType()==CAMusElement::Rest &&
                              static_cast<CARest*>(elt)->restType()==CARest::Hidden ||
                              elt && !elt->isVisible()
                            ) {
                        color = QColor(0,0,0,0); // transparent color
                  } else if ( elt && elt->color()!=QColor(0,0,0,0) ) {
                        color = elt->color(); // set elements color, if defined
                  } else {
                        color = foregroundColor(); // set default color for foreground elements
                  }
            } else {
                  if ( elt && elt->musElementType()==CAMusElement::Rest &&
                       static_cast<CARest*>(elt)->restType()==CARest::Hidden
                     ) {
                        color = QColor(0,0,0,0); // transparent color
                  } else {
                        color = disabledElementsColor();
                  }
            }

            CADrawSettings s = {
                           _zoom,
                           qRound((mList[i]->xPos() - _worldX) * _zoom),
                           qRound((mList[i]->yPos() - _worldY) * _zoom),
                           drawableWidth(), drawableHeight(),
                           color,
                           _worldX,
                           _worldY
                           };
            mList[i]->draw(&p, s);
            if ( _selection.contains(mList[i]) && mList[i]->isHScalable() ) {
                  s.color = foregroundColor();
                  mList[i]->drawHScaleHandles(&p, s);
            }
            if ( _selection.contains(mList[i]) && mList[i]->isVScalable() ) {
                  s.color = foregroundColor();
                  mList[i]->drawVScaleHandles(&p, s);
            }
      }

      // draw selection regions
      for (int i=0; i<selectionRegionList().size(); i++) {
            CADrawSettings c = {
                  _zoom,
                  qRound( (selectionRegionList().at(i).x() - _worldX) * _zoom),
                  qRound( (selectionRegionList().at(i).y() - _worldY) * _zoom),
                  qRound( selectionRegionList().at(i).width() * _zoom),
                  qRound( selectionRegionList().at(i).height() * _zoom),
                  selectionAreaColor(),
            _worldX,
            _worldY
            };
            drawSelectionRegion( &p, c );
      }

      // draw shadow note
      if (_shadowNoteVisible) {
            for (int i=0; i<_shadowDrawableNote.size(); i++) {
                  if ( CACanorus::settings()->shadowNotesInOtherStaffs() || _shadowDrawableNote[i]->drawableContext() == currentContext() ) {
                        CADrawSettings s = {
                              _zoom,
                              qRound((_shadowDrawableNote[i]->xPos() - _worldX - _shadowDrawableNote[i]->width()/2) * _zoom),
                              qRound((_shadowDrawableNote[i]->yPos() - _worldY) * _zoom),
                              drawableWidth(), drawableHeight(),
                              disabledElementsColor(),
                     _worldX,
                     _worldY
                        };

                        _shadowDrawableNote[i]->draw(&p, s);

                        if (_drawShadowNoteAccs) {
                              CADrawableAccidental acc(_shadowNoteAccs, 0, 0, 0, _shadowDrawableNote[i]->yCenter());
                              s.x -= qRound((acc.width()+2)*_zoom);
                              s.y = qRound((acc.yPos() - _worldY)*_zoom);
                              acc.draw(&p, s);
                        }
                  }
            }

            // draw note name
            if (_shadowNote.size()) {
                  QFont font("FreeSans");
                  font.setPixelSize( 20 );
                  p.setFont(font);
                  p.setPen(disabledElementsColor());
                  p.drawText( qRound((_xCursor-_worldX+10) * _zoom), qRound((_yCursor-_worldY-10) * _zoom), CANote::generateNoteName(_shadowNote[0]->diatonicPitch().noteName(), _shadowNoteAccs) );
            }
      }

      // flush the oldWorld coordinates as they're needed for the first repaint only
      _oldWorldX = _worldX; _oldWorldY = _worldY;
      _oldWorldW = _worldW; _oldWorldH = _worldH;

      if (_repaintArea) {
            delete _repaintArea;
            _repaintArea = 0;
            p.setClipping(false);
      }
}


Generated by  Doxygen 1.6.0   Back to index