📄 compositionview.cpp
字号:
// // Draw segment labels (they must be drawn over the preview rects) // if (m_showSegmentLabels) { for (i = rects.begin(); i != end; ++i) { drawCompRectLabel(*i, p, clipRect); } } // drawAreaArtifacts(p, clipRect);}void CompositionView::drawAreaAudioPreviews(QPainter * p, const QRect& clipRect){ CompositionModel::AudioPreviewDrawData::const_iterator api = m_audioPreviewRects.begin(); CompositionModel::AudioPreviewDrawData::const_iterator apEnd = m_audioPreviewRects.end(); QRect rectToFill, // rect to fill on canvas localRect; // the rect of the tile to draw on the canvas QPoint basePoint, // origin of segment rect drawBasePoint; // origin of rect to fill on canvas QRect r; for (; api != apEnd; ++api) { rectToFill = api->rect; basePoint = api->basePoint; rectToFill.moveTopLeft(basePoint); rectToFill &= clipRect; r = rectToFill; drawBasePoint = rectToFill.topLeft(); rectToFill.moveBy( -basePoint.x(), -basePoint.y()); int firstPixmapIdx = (r.x() - basePoint.x()) / AudioPreviewPainter::tileWidth(); if (firstPixmapIdx >= api->pixmap.size()) { // RG_DEBUG << "CompositionView::drawAreaAudioPreviews : WARNING - miscomputed pixmap array : r.x = " // << r.x() << " - basePoint.x = " << basePoint.x() << " - firstPixmapIdx = " << firstPixmapIdx // << endl; continue; } int x = 0, idx = firstPixmapIdx; // RG_DEBUG << "CompositionView::drawAreaAudioPreviews : clipRect = " << clipRect // << " - firstPixmapIdx = " << firstPixmapIdx << endl; while (x < clipRect.width()) { int pixmapRectXOffset = idx * AudioPreviewPainter::tileWidth(); localRect.setRect(basePoint.x() + pixmapRectXOffset, basePoint.y(), AudioPreviewPainter::tileWidth(), api->rect.height()); // RG_DEBUG << "CompositionView::drawAreaAudioPreviews : initial localRect = " // << localRect << endl; localRect &= r; if (idx == firstPixmapIdx && api->resizeOffset != 0) { // this segment is being resized from start, clip beginning of preview localRect.moveBy(api->resizeOffset, 0); } // RG_DEBUG << "CompositionView::drawAreaAudioPreviews : localRect & clipRect = " // << localRect << endl; if (localRect.isEmpty()) { // RG_DEBUG << "CompositionView::drawAreaAudioPreviews : localRect & clipRect is empty\n"; break; } localRect.moveBy( -(basePoint.x() + pixmapRectXOffset), -basePoint.y()); // RG_DEBUG << "CompositionView::drawAreaAudioPreviews : drawing pixmap " // << idx << " at " << drawBasePoint << " - localRect = " << localRect // << " - preResizeOrigin : " << api->preResizeOrigin << endl; p->drawImage(drawBasePoint, api->pixmap[idx], localRect, Qt::ColorOnly | Qt::ThresholdDither | Qt::AvoidDither); ++idx; if (idx >= api->pixmap.size()) break; drawBasePoint.setX(drawBasePoint.x() + localRect.width()); x += localRect.width(); } }}void CompositionView::drawAreaArtifacts(QPainter * p, const QRect& clipRect){ // // Playback Pointer // drawPointer(p, clipRect); // // Tmp rect (rect displayed while drawing a new segment) // if (m_tmpRect.isValid() && m_tmpRect.intersects(clipRect)) { p->setBrush(m_tmpRectFill); p->setPen(CompositionColourCache::getInstance()->SegmentBorder); drawRect(m_tmpRect, p, clipRect); } // // Tool guides (crosshairs) // if (m_drawGuides) drawGuides(p, clipRect); // // Selection Rect // if (m_drawSelectionRect) { drawRect(m_selectionRect, p, clipRect, false, 0, false); } // // Floating Text // if (m_drawTextFloat) drawTextFloat(p, clipRect); // // Split line // if (m_splitLinePos.x() > 0 && clipRect.contains(m_splitLinePos)) { p->save(); p->setPen(m_guideColor); p->drawLine(m_splitLinePos.x(), m_splitLinePos.y(), m_splitLinePos.x(), m_splitLinePos.y() + getModel()->grid().getYSnap()); p->restore(); }}void CompositionView::drawGuides(QPainter * p, const QRect& /*clipRect*/){ // no need to check for clipping, these guides are meant to follow the mouse cursor QPoint guideOrig(m_topGuidePos, m_foreGuidePos); p->save(); p->setPen(m_guideColor); p->drawLine(guideOrig.x(), 0, guideOrig.x(), contentsHeight()); p->drawLine(0, guideOrig.y(), contentsWidth(), guideOrig.y()); p->restore();}void CompositionView::drawCompRect(const CompositionRect& r, QPainter *p, const QRect& clipRect, int intersectLvl, bool fill){ p->save(); QBrush brush = r.getBrush(); if (r.isRepeating()) { QColor brushColor = brush.color(); brush.setColor(brushColor.light(150)); } p->setBrush(brush); p->setPen(r.getPen()); drawRect(r, p, clipRect, r.isSelected(), intersectLvl, fill); if (r.isRepeating()) { CompositionRect::repeatmarks repeatMarks = r.getRepeatMarks(); // RG_DEBUG << "CompositionView::drawCompRect() : drawing repeating rect " << r // << " nb repeat marks = " << repeatMarks.size() << endl; // draw 'start' rectangle with original brush // QRect startRect = r; startRect.setWidth(repeatMarks[0] - r.x()); p->setBrush(r.getBrush()); drawRect(startRect, p, clipRect, r.isSelected(), intersectLvl, fill); // now draw the 'repeat' marks // p->setPen(CompositionColourCache::getInstance()->RepeatSegmentBorder); int penWidth = std::max(r.getPen().width(), 1u); for (unsigned int i = 0; i < repeatMarks.size(); ++i) { int pos = repeatMarks[i]; if (pos > clipRect.right()) break; if (pos >= clipRect.left()) { QPoint p1(pos, r.y() + penWidth), p2(pos, r.y() + r.height() - penWidth - 1); // RG_DEBUG << "CompositionView::drawCompRect() : drawing repeat mark at " // << p1 << "-" << p2 << endl; p->drawLine(p1, p2); } } } p->restore();}void CompositionView::drawCompRectLabel(const CompositionRect& r, QPainter *p, const QRect& clipRect){ // draw segment label //#ifdef NOT_DEFINED if (!r.getLabel().isEmpty() /* && !r.isSelected() */) { p->save(); p->setPen(GUIPalette::getColour(GUIPalette::SegmentLabel)); p->setBrush(white); QRect textRect(r); textRect.setX(textRect.x() + 3); QString label = " " + r.getLabel() + " "; QRect textBoundingRect = p->boundingRect(textRect, Qt::AlignLeft | Qt::AlignVCenter, label); p->drawRect(textBoundingRect & r); p->drawText(textRect, Qt::AlignLeft | Qt::AlignVCenter, label); p->restore(); }#else if (!r.getLabel().isEmpty()) { p->save(); QFont font; font.setPixelSize(r.height() / 2.2); font.setWeight(QFont::Bold); font.setItalic(false); p->setFont(font); QRect labelRect = QRect (r.x(), r.y() + ((r.height() - p->fontMetrics().height()) / 2) + 1, r.width(), p->fontMetrics().height()); int x = labelRect.x() + p->fontMetrics().width('x'); int y = labelRect.y(); QBrush brush = r.getBrush(); QColor surroundColour = brush.color().light(110); int h, s, v; surroundColour.hsv(&h, &s, &v); if (v < 150) surroundColour.setHsv(h, s, 225); p->setPen(surroundColour); for (int i = 0; i < 9; ++i) { if (i == 4) continue; int wx = x, wy = y; if (i < 3) --wx; if (i > 5) ++wx; if (i % 3 == 0) --wy; if (i % 3 == 2) ++wy; labelRect.setX(wx); labelRect.setY(wy); p->drawText(labelRect, Qt::AlignLeft | Qt::AlignTop, r.getLabel()); } labelRect.setX(x); labelRect.setY(y); p->setPen(GUIPalette::getColour (GUIPalette::SegmentLabel)); p->drawText(labelRect, Qt::AlignLeft | Qt::AlignVCenter, r.getLabel()); p->restore(); }#endif}void CompositionView::drawRect(const QRect& r, QPainter *p, const QRect& clipRect, bool isSelected, int intersectLvl, bool fill){ // RG_DEBUG << "CompositionView::drawRect : intersectLvl = " << intersectLvl // << " - brush col = " << p->brush().color() << endl; // RG_DEBUG << "CompositionView::drawRect " << r << " - xformed : " << p->xForm(r) // << " - contents x = " << contentsX() << ", contents y = " << contentsY() << endl; p->save(); QRect rect = r; if (fill) { if (isSelected) { QColor fillColor = p->brush().color(); fillColor = fillColor.dark(200); QBrush b = p->brush(); b.setColor(fillColor); p->setBrush(b); // RG_DEBUG << "CompositionView::drawRect : selected color : " << fillColor << endl; } if (intersectLvl > 0) { QColor fillColor = p->brush().color(); fillColor = fillColor.dark((intersectLvl) * 105); QBrush b = p->brush(); b.setColor(fillColor); p->setBrush(b); // RG_DEBUG << "CompositionView::drawRect : intersected color : " << fillColor << " isSelected : " << isSelected << endl; } } else { p->setBrush(Qt::NoBrush); } // Paint using the small coordinates... QRect intersection = rect.intersect(clipRect); if (clipRect.contains(rect)) { p->drawRect(rect); } else { // draw only what's necessary if (!intersection.isEmpty() && fill) p->fillRect(intersection, p->brush()); int rectTopY = rect.y(); if (rectTopY >= clipRect.y() && rectTopY <= (clipRect.y() + clipRect.height())) { // to prevent overflow, in case the original rect is too wide // the line would be drawn "backwards" p->drawLine(intersection.topLeft(), intersection.topRight()); } int rectBottomY = rect.y() + rect.height(); if (rectBottomY >= clipRect.y() && rectBottomY <= (clipRect.y() + clipRect.height())) // to prevent overflow, in case the original rect is too wide // the line would be drawn "backwards" p->drawLine(intersection.bottomLeft(), intersection.bottomRight()); int rectLeftX = rect.x(); if (rectLeftX >= clipRect.x() && rectLeftX <= (clipRect.x() + clipRect.width())) p->drawLine(rect.topLeft(), rect.bottomLeft()); unsigned int rectRightX = rect.x() + rect.width(); // make sure we don't overflow if (rectRightX >= unsigned(clipRect.x()) && rectRightX <= unsigned(clipRect.x() + clipRect.width())) p->drawLine(rect.topRight(), rect.bottomRight()); } p->restore();}QColor CompositionView::mixBrushes(QBrush a, QBrush b){ QColor ac = a.color(), bc = b.color(); int aR = ac.red(), aG = ac.green(), aB = ac.blue(), bR = bc.red(), bG = bc.green(), bB = ac.blue(); ac.setRgb((aR + bR) / 2, (aG + bG) / 2, (aB + bB) / 2); return ac;}void CompositionView::drawIntersections(const CompositionModel::rectcontainer& rects, QPainter * p, const QRect& clipRect){ if (! (rects.size() > 1)) return ; CompositionModel::rectcontainer intersections; CompositionModel::rectcontainer::const_iterator i = rects.begin(), j = rects.begin(); for (; j != rects.end(); ++j) { CompositionRect testRect = *j; i = j; ++i; // set i to pos after j if (i == rects.end()) break; for (; i != rects.end(); ++i) { CompositionRect ri = testRect.intersect(*i);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -