📄 compositionview.cpp
字号:
wheelEvent(e);}CompositionItem CompositionView::getFirstItemAt(QPoint pos){ CompositionModel::itemcontainer items = getModel()->getItemsAt(pos); if (items.size()) { // find topmost item CompositionItem res = *(items.begin()); unsigned int maxZ = res->z(); CompositionModel::itemcontainer::iterator maxZItemPos = items.begin(); for (CompositionModel::itemcontainer::iterator i = items.begin(); i != items.end(); ++i) { CompositionItem ic = *i; if (ic->z() > maxZ) { RG_DEBUG << k_funcinfo << "found new topmost at z=" << ic->z() << endl; res = ic; maxZ = ic->z(); maxZItemPos = i; } } // get rid of the rest; items.erase(maxZItemPos); for (CompositionModel::itemcontainer::iterator i = items.begin(); i != items.end(); ++i) delete *i; return res; } else { RG_DEBUG << k_funcinfo << "no item under cursor\n"; } return CompositionItem();}void CompositionView::setSnapGrain(bool fine){ if (m_fineGrain) { grid().setSnapTime(SnapGrid::NoSnap); } else { grid().setSnapTime(fine ? SnapGrid::SnapToBeat : SnapGrid::SnapToBar); }}void CompositionView::slotUpdateSegmentsDrawBuffer(){ // RG_DEBUG << "CompositionView::slotUpdateSegmentsDrawBuffer()\n"; slotAllDrawBuffersNeedRefresh(); updateContents();}void CompositionView::slotUpdateSegmentsDrawBuffer(const QRect& rect){ // RG_DEBUG << "CompositionView::slotUpdateSegmentsDrawBuffer() rect " // << rect << " - valid : " << rect.isValid() << endl; slotAllDrawBuffersNeedRefresh(rect); if (rect.isValid()) { updateContents(rect); } else { updateContents(); }}void CompositionView::slotRefreshColourCache(){ CompositionColourCache::getInstance()->init(); clearSegmentRectsCache(); slotUpdateSegmentsDrawBuffer();}void CompositionView::slotNewMIDIRecordingSegment(Segment* s){ getModel()->addRecordingItem(CompositionItemHelper::makeCompositionItem(s));}void CompositionView::slotNewAudioRecordingSegment(Segment* s){ getModel()->addRecordingItem(CompositionItemHelper::makeCompositionItem(s));}void CompositionView::slotStoppedRecording(){ getModel()->clearRecordingItems();}void CompositionView::resizeEvent(QResizeEvent* e){ QScrollView::resizeEvent(e); slotUpdateSize(); int w = std::max(m_segmentsDrawBuffer.width(), visibleWidth()); int h = std::max(m_segmentsDrawBuffer.height(), visibleHeight()); m_segmentsDrawBuffer.resize(w, h); m_artifactsDrawBuffer.resize(w, h); slotAllDrawBuffersNeedRefresh(); // RG_DEBUG << "CompositionView::resizeEvent() : drawBuffer size = " << m_segmentsDrawBuffer.size() << endl;}void CompositionView::viewportPaintEvent(QPaintEvent* e){ QMemArray<QRect> rects = e->region().rects(); for (unsigned int i = 0; i < rects.size(); ++i) { viewportPaintRect(rects[i]); }}void CompositionView::viewportPaintRect(QRect r){ QRect updateRect = r; r &= viewport()->rect(); r.moveBy(contentsX(), contentsY()); // RG_DEBUG << "CompositionView::viewportPaintRect() r = " << r // << " - moveBy " << contentsX() << "," << contentsY() << " - updateRect = " << updateRect // << " - refresh " << m_segmentsDrawBufferRefresh << " artrefresh " << m_artifactsDrawBufferRefresh << endl; bool scroll = false; bool changed = checkScrollAndRefreshDrawBuffer(r, scroll); if (changed || m_artifactsDrawBufferRefresh.isValid()) { // r was modified by checkScrollAndRefreshDrawBuffer QRect copyRect(r | m_artifactsDrawBufferRefresh); copyRect.moveBy( -contentsX(), -contentsY()); // RG_DEBUG << "copying from segment to artifacts buffer: " << copyRect << endl; bitBlt(&m_artifactsDrawBuffer, copyRect.x(), copyRect.y(), &m_segmentsDrawBuffer, copyRect.x(), copyRect.y(), copyRect.width(), copyRect.height()); m_artifactsDrawBufferRefresh |= r; } if (m_artifactsDrawBufferRefresh.isValid()) { refreshArtifactsDrawBuffer(m_artifactsDrawBufferRefresh); m_artifactsDrawBufferRefresh = QRect(); } if (scroll) { bitBlt(viewport(), 0, 0, &m_artifactsDrawBuffer, 0, 0, m_artifactsDrawBuffer.width(), m_artifactsDrawBuffer.height()); } else { bitBlt(viewport(), updateRect.x(), updateRect.y(), &m_artifactsDrawBuffer, updateRect.x(), updateRect.y(), updateRect.width(), updateRect.height()); } // DEBUG // QPainter pdebug(viewport()); // static QPen framePen(Qt::red, 1); // pdebug.setPen(framePen); // pdebug.drawRect(updateRect);}bool CompositionView::checkScrollAndRefreshDrawBuffer(QRect &rect, bool& scroll){ bool all = false; QRect refreshRect = m_segmentsDrawBufferRefresh; int w = visibleWidth(), h = visibleHeight(); int cx = contentsX(), cy = contentsY(); scroll = (cx != m_lastBufferRefreshX || cy != m_lastBufferRefreshY); if (scroll) { // RG_DEBUG << "checkScrollAndRefreshDrawBuffer: scrolling by (" // << cx - m_lastBufferRefreshX << "," << cy - m_lastBufferRefreshY << ")" << endl; if (refreshRect.isValid()) { // If we've scrolled and there was an existing refresh // rect, we can't be sure whether the refresh rect // predated or postdated the internal update of scroll // location. Cut our losses and refresh everything. refreshRect.setRect(cx, cy, w, h); } else { // No existing refresh rect: we only need to handle the // scroll if (cx != m_lastBufferRefreshX) { int dx = m_lastBufferRefreshX - cx; if (dx > -w && dx < w) { QPainter cp(&m_segmentsDrawBuffer); cp.drawPixmap(dx, 0, m_segmentsDrawBuffer); if (dx < 0) { refreshRect |= QRect(cx + w + dx, cy, -dx, h); } else { refreshRect |= QRect(cx, cy, dx, h); } } else { refreshRect.setRect(cx, cy, w, h); all = true; } } if (cy != m_lastBufferRefreshY && !all) { int dy = m_lastBufferRefreshY - cy; if (dy > -h && dy < h) { QPainter cp(&m_segmentsDrawBuffer); cp.drawPixmap(0, dy, m_segmentsDrawBuffer); if (dy < 0) { refreshRect |= QRect(cx, cy + h + dy, w, -dy); } else { refreshRect |= QRect(cx, cy, w, dy); } } else { refreshRect.setRect(cx, cy, w, h); all = true; } } } } bool needRefresh = false; if (refreshRect.isValid()) { needRefresh = true; } if (needRefresh) refreshSegmentsDrawBuffer(refreshRect); m_segmentsDrawBufferRefresh = QRect(); m_lastBufferRefreshX = cx; m_lastBufferRefreshY = cy; rect |= refreshRect; if (scroll) rect.setRect(cx, cy, w, h); return needRefresh;}void CompositionView::refreshSegmentsDrawBuffer(const QRect& rect){ // Profiler profiler("CompositionView::refreshDrawBuffer", true); // RG_DEBUG << "CompositionView::refreshSegmentsDrawBuffer() r = " // << rect << endl; QPainter p(&m_segmentsDrawBuffer, viewport()); p.translate( -contentsX(), -contentsY()); if (!m_backgroundPixmap.isNull()) { QPoint pp(rect.x() % m_backgroundPixmap.height(), rect.y() % m_backgroundPixmap.width()); p.drawTiledPixmap(rect, m_backgroundPixmap, pp); } else { p.eraseRect(rect); } drawArea(&p, rect); // DEBUG - show what's updated // QPen framePen(Qt::red, 1); // p.setPen(framePen); // p.drawRect(rect); // m_segmentsDrawBufferNeedsRefresh = false;}void CompositionView::refreshArtifactsDrawBuffer(const QRect& rect){ // RG_DEBUG << "CompositionView::refreshArtifactsDrawBuffer() r = " // << rect << endl; QPainter p; p.begin(&m_artifactsDrawBuffer, viewport()); p.translate( -contentsX(), -contentsY()); // QRect r(contentsX(), contentsY(), m_artifactsDrawBuffer.width(), m_artifactsDrawBuffer.height()); drawAreaArtifacts(&p, rect); p.end(); // m_artifactsDrawBufferNeedsRefresh = false;}void CompositionView::drawArea(QPainter *p, const QRect& clipRect){ // Profiler profiler("CompositionView::drawArea", true); // RG_DEBUG << "CompositionView::drawArea() clipRect = " << clipRect << endl; CompositionModel::AudioPreviewDrawData* audioPreviewData = 0; CompositionModel::RectRanges* notationPreviewData = 0; // // Fetch previews // if (m_showPreviews) { notationPreviewData = &m_notationPreviewRects; m_notationPreviewRects.clear(); audioPreviewData = &m_audioPreviewRects; m_audioPreviewRects.clear(); } // // Fetch segment rectangles to draw // const CompositionModel::rectcontainer& rects = getModel()->getRectanglesIn(clipRect, notationPreviewData, audioPreviewData); CompositionModel::rectcontainer::const_iterator i = rects.begin(); CompositionModel::rectcontainer::const_iterator end = rects.end(); // // Draw Segment Rectangles // p->save(); for (; i != end; ++i) { p->setBrush(i->getBrush()); p->setPen(i->getPen()); // RG_DEBUG << "CompositionView::drawArea : draw comp rect " << *i << endl; drawCompRect(*i, p, clipRect); } p->restore(); if (rects.size() > 1) { // RG_DEBUG << "CompositionView::drawArea : drawing intersections\n"; drawIntersections(rects, p, clipRect); } // // Previews // if (m_showPreviews) { p->save(); // draw audio previews // drawAreaAudioPreviews(p, clipRect); // draw notation previews // CompositionModel::RectRanges::const_iterator npi = m_notationPreviewRects.begin(); CompositionModel::RectRanges::const_iterator npEnd = m_notationPreviewRects.end(); for (; npi != npEnd; ++npi) { CompositionModel::RectRange interval = *npi; p->save(); p->translate(interval.basePoint.x(), interval.basePoint.y()); // RG_DEBUG << "CompositionView::drawArea : translating to x = " << interval.basePoint.x() << endl; for (; interval.range.first != interval.range.second; ++interval.range.first) { const PreviewRect& pr = *(interval.range.first); QColor defaultCol = CompositionColourCache::getInstance()->SegmentInternalPreview; QColor col = interval.color.isValid() ? interval.color : defaultCol; p->setBrush(col); p->setPen(col); // RG_DEBUG << "CompositionView::drawArea : drawing preview rect at x = " << pr.x() << endl; p->drawRect(pr); } p->restore(); } p->restore(); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -