void Ruler::setPos(const Pos& pos) { if (_cursor != pos) { int x1 = pos2pix(_cursor); int x2 = pos2pix(pos); if (x1 > x2) { int tmp = x2; x2 = x1; x1 = tmp; } update(QRect(x1-1, 0, x2-x1+2, height())); _cursor = pos; } }
void PianoView::moveLocator(int i) { if (_locator[i].valid()) { locatorLines[i]->setVisible(true); qreal x = qreal(pos2pix(_locator[i])); locatorLines[i]->setPos(QPointF(x, 0.0)); } else locatorLines[i]->setVisible(false); }
void WaveView::paintEvent(QPaintEvent* event) { QPainter p(this); int xoffset = pianoWidth + MAP_OFFSET; QRect rt(0, 0, xoffset, height()); QRect r(event->rect()); p.fillRect(r, Qt::gray); if (rt.intersects(r.translated(_xpos, 0))) p.fillRect(rt.translated(-_xpos, 0), Qt::lightGray); int x1 = r.x(); int x2 = x1 + r.width(); if (x1 < pianoWidth) x1 = pianoWidth; Pos p1 = pix2pos(x1); p.setPen(QPen(Qt::blue, 1)); for (int i = x1+1; i < x2; ++i) { Pos p2 = pix2pos(i); int val = height() * pegel(p1.frame(), p2.frame()) / 255; p1 = p2; int y1 = height() - val; int y2 = height(); p.drawLine(i, y1, i, y2); } p.setPen(QPen(Qt::lightGray, 2)); int y = height() / 2; int x = xoffset - _xpos; int w = width() - x; if (w > 0) p.drawLine(0, y, width(), y); static const QColor lcColors[3] = { Qt::red, Qt::blue, Qt::blue }; for (int i = 0; i < 3; ++i) { if (!_locator[i].valid()) continue; QPen pen(lcColors[i], 3); p.setPen(pen); int xp = pos2pix(_locator[i]); p.drawLine(xp, 0, xp, height()); } }
void Ruler::paintEvent(QPaintEvent* e) { QPainter p(this); const QRect& r = e->rect(); static const int mag[7] = { 1, 1, 2, 5, 10, 20, 50 }; int x = r.x(); int w = r.width(); int y = rulerHeight - 16; int h = 16; // 14; int y1 = r.y(); int rh = r.height(); if (y1 < rulerHeight) { rh -= rulerHeight - y1; y1 = rulerHeight; } int y2 = y1 + rh; if (x < (-_xpos)) x = -_xpos; if (!_score) return; Pos pos1 = pix2pos(x); Pos pos2 = pix2pos(x+w); //--------------------------------------------------- // draw raster //--------------------------------------------------- int bar1, bar2, beat, tick; pos1.mbt(&bar1, &beat, &tick); pos2.mbt(&bar2, &beat, &tick); int n = mag[magStep]; bar1 = (bar1 / n) * n; // round down if (bar1 && n >= 2) bar1 -= 1; bar2 = ((bar2 + n - 1) / n) * n; // round up for (int bar = bar1; bar <= bar2;) { Pos stick(_score->tempomap(), _score->sigmap(), bar, 0, 0); if (magStep) { p.setFont(_font2); int x = pos2pix(stick); QString s; s.setNum(bar + 1); p.setPen(Qt::black); p.drawLine(x, y, x, y + h); QRect r = QRect(x+2, y, 1000, h); p.drawText(r, Qt::AlignLeft | Qt::AlignVCenter, s); p.setPen(Qt::lightGray); if (x > 0) p.drawLine(x, y1, x, y2); } else { SigEvent sig = stick.timesig(); int z = sig.timesig().numerator(); for (int beat = 0; beat < z; beat++) { Pos xx(_score->tempomap(), _score->sigmap(), bar, beat, 0); int xp = pos2pix(xx); if (xp < 0) continue; QString s; QRect r(xp+2, y + 1, 1000, h); int y3; int num; if (beat == 0) { num = bar + 1; y3 = y + 2; p.setFont(_font2); } else { num = beat + 1; y3 = y + 8; p.setFont(_font1); r.moveTop(r.top() + 1); } s.setNum(num); p.setPen(Qt::black); p.drawLine(xp, y3, xp, y+h); p.drawText(r, Qt::AlignLeft | Qt::AlignVCenter, s); p.setPen(beat == 0 ? Qt::lightGray : Qt::gray); if (xp > 0) p.drawLine(xp, y1, xp, y2); } } if (bar == 0 && n >= 2) bar += (n-1); else bar += n; } // // draw mouse cursor marker // p.setPen(Qt::black); if (_cursor.valid()) { int xp = pos2pix(_cursor); if (xp >= x && xp < x+w) p.drawLine(xp, 0, xp, rulerHeight); } static const QColor lcColors[3] = { Qt::red, Qt::blue, Qt::blue }; for (int i = 0; i < 3; ++i) { if (!_locator[i].valid()) continue; p.setPen(lcColors[i]); int xp = pos2pix(_locator[i]); QPixmap* pm = markIcon[i]; // int pw = (pm->width() + 1) / 2; int pw = pm->width() / 2; int x1 = x - pw; int x2 = x + w + pw; if (xp >= x1 && xp < x2) p.drawPixmap(xp - pw, y-2, *pm); } }
void PianoView::drawBackground(QPainter* p, const QRectF& r) { if (staff == 0) return; Score* _score = staff->score(); setFrameShape(QFrame::NoFrame); QRectF r1; r1.setCoords(-1000000.0, 0.0, 480.0, 1000000.0); QRectF r2; r2.setCoords(ticks + MAP_OFFSET, 0.0, 1000000.0, 1000000.0); QColor bg(0x71, 0x8d, 0xbe); p->fillRect(r, bg); if (r.intersects(r1)) p->fillRect(r.intersected(r1), bg.darker(150)); if (r.intersects(r2)) p->fillRect(r.intersected(r2), bg.darker(150)); // // draw horizontal grid lines // qreal y1 = r.y(); qreal y2 = y1 + r.height(); qreal kh = 13.0; qreal x1 = r.x(); qreal x2 = x1 + r.width(); // int key = floor(y1 / 75); int key = floor(y1 / kh); qreal y = key * kh; for (; key < 75; ++key, y += kh) { if (y < y1) continue; if (y > y2) break; p->setPen(QPen((key % 7) == 5 ? Qt::lightGray : Qt::gray)); p->drawLine(QLineF(x1, y, x2, y)); } // // draw vertical grid lines // static const int mag[7] = { 1, 1, 2, 5, 10, 20, 50 }; Pos pos1 = pix2pos(x1); Pos pos2 = pix2pos(x2); //--------------------------------------------------- // draw raster //--------------------------------------------------- int bar1, bar2, beat, tick; pos1.mbt(&bar1, &beat, &tick); pos2.mbt(&bar2, &beat, &tick); int n = mag[magStep < 0 ? 0 : magStep]; bar1 = (bar1 / n) * n; // round down if (bar1 && n >= 2) bar1 -= 1; bar2 = ((bar2 + n - 1) / n) * n; // round up for (int bar = bar1; bar <= bar2;) { Pos stick(_score->tempomap(), _score->sigmap(), bar, 0, 0); if (magStep > 0) { double x = double(pos2pix(stick)); if (x > 0) { p->setPen(QPen(Qt::lightGray, 0.0)); p->drawLine(x, y1, x, y2); } else { p->setPen(QPen(Qt::black, 0.0)); p->drawLine(x, y1, x, y1); } } else { int z = stick.timesig().timesig().numerator(); for (int beat = 0; beat < z; beat++) { if (magStep == 0) { Pos xx(_score->tempomap(), _score->sigmap(), bar, beat, 0); int xp = pos2pix(xx); if (xp < 0) continue; if (xp > 0) { p->setPen(QPen(beat == 0 ? Qt::lightGray : Qt::gray, 0.0)); p->drawLine(xp, y1, xp, y2); } else { p->setPen(QPen(Qt::black, 0.0)); p->drawLine(xp, y1, xp, y2); } } else { int k; if (magStep == -1) k = 2; else if (magStep == -2) k = 4; else if (magStep == -3) k = 8; else if (magStep == -4) k = 16; else k = 32; int n = (MScore::division * 4) / stick.timesig().timesig().denominator(); for (int i = 0; i < k; ++i) { Pos xx(_score->tempomap(), _score->sigmap(), bar, beat, (n * i)/ k); int xp = pos2pix(xx); if (xp < 0) continue; if (xp > 0) { p->setPen(QPen(i == 0 && beat == 0 ? Qt::lightGray : Qt::gray, 0.0)); p->drawLine(xp, y1, xp, y2); } else { p->setPen(QPen(Qt::black, 0.0)); p->drawLine(xp, y1, xp, y2); } } } } } if (bar == 0 && n >= 2) bar += (n-1); else bar += n; } }