diff options
author | Tim E. Real <termtech@rogers.com> | 2011-02-27 09:12:38 +0000 |
---|---|---|
committer | Tim E. Real <termtech@rogers.com> | 2011-02-27 09:12:38 +0000 |
commit | 1a4f5609b180772326e48aaca43b0ac02ff8f268 (patch) | |
tree | dcdd60840c6fff5cb5ccf374645b66603399f079 /muse2/muse | |
parent | b12a5b74f811a565a6c8d8922cccfd281e639f2a (diff) |
Fixed piano roll controller graph text drawing (finally!)
Diffstat (limited to 'muse2/muse')
-rw-r--r-- | muse2/muse/ctrl/ctrlcanvas.cpp | 75 | ||||
-rw-r--r-- | muse2/muse/ctrl/ctrlcanvas.h | 1 | ||||
-rw-r--r-- | muse2/muse/widgets/view.cpp | 106 |
3 files changed, 107 insertions, 75 deletions
diff --git a/muse2/muse/ctrl/ctrlcanvas.cpp b/muse2/muse/ctrl/ctrlcanvas.cpp index d8281b1e..6f37d1ee 100644 --- a/muse2/muse/ctrl/ctrlcanvas.cpp +++ b/muse2/muse/ctrl/ctrlcanvas.cpp @@ -12,6 +12,7 @@ #include <QCursor> #include <QMouseEvent> +#include "app.h" #include "globals.h" #include "ctrledit.h" #include "midieditor.h" @@ -108,6 +109,7 @@ CtrlCanvas::CtrlCanvas(MidiEditor* e, QWidget* parent, int xmag, const char* name, CtrlPanel* pnl) : View(parent, xmag, 1, name) { setBg(Qt::white); + setFont(config.fonts[3]); editor = e; drag = DRAG_OFF; tool = PointerTool; @@ -133,6 +135,7 @@ CtrlCanvas::CtrlCanvas(MidiEditor* e, QWidget* parent, int xmag, setCurTrackAndPart(); } connect(song, SIGNAL(songChanged(int)), SLOT(songChanged(int))); + connect(muse, SIGNAL(configChanged()), SLOT(configChanged())); curDrumInstrument = editor->curDrumInstrument(); //printf("CtrlCanvas::CtrlCanvas curDrumInstrument:%d\n", curDrumInstrument); @@ -339,6 +342,15 @@ bool CtrlCanvas::setCurTrackAndPart() } //--------------------------------------------------------- +// configChanged +//--------------------------------------------------------- + +void CtrlCanvas::configChanged() +{ + songChanged(SC_CONFIG); +} + +//--------------------------------------------------------- // songChanged // all marked parts are added to the internal event list //--------------------------------------------------------- @@ -349,6 +361,9 @@ void CtrlCanvas::songChanged(int type) if(type == SC_MIDI_CONTROLLER) return; + if(type & SC_CONFIG) + setFont(config.fonts[3]); + bool changed = false; if(type & (SC_CONFIG | SC_PART_MODIFIED | SC_SELECTION)) changed = setCurTrackAndPart(); @@ -1240,8 +1255,11 @@ void CtrlCanvas::pdrawItems(QPainter& p, const QRect& rect, const MidiPart* part int w = rect.width() + 2; int wh = height(); + noEvents=true; + if(velo) { + noEvents=false; for(iCEvent i = items.begin(); i != items.end(); ++i) { CEvent* e = *i; @@ -1292,9 +1310,10 @@ void CtrlCanvas::pdrawItems(QPainter& p, const QRect& rect, const MidiPart* part } int x1 = rect.x(); int lval = CTRL_VAL_UNKNOWN; - noEvents=false; + ///noEvents=false; for (iCEvent i = items.begin(); i != items.end(); ++i) { + noEvents=false; CEvent* e = *i; // Draw unselected part controller events (lines) on top of selected part events (bars). //if((fg && (e->part() == part)) || (!fg && (e->part() != part))) @@ -1361,7 +1380,7 @@ void CtrlCanvas::pdrawItems(QPainter& p, const QRect& rect, const MidiPart* part { if(!fg) { p.fillRect(x1, 0, (x+w) - x1, wh, Qt::darkGray); - noEvents=true; + ///noEvents=true; } } else @@ -1463,28 +1482,6 @@ void CtrlCanvas::pdraw(QPainter& p, const QRect& rect) } } - /* - //--------------------------------------------------- - // draw marker - //--------------------------------------------------- - - int xp = mapx(pos[0]); - if (xp >= x && xp < x+w) { - p.setPen(Qt::red); - p.drawLine(xp, y, xp, y+h); - } - xp = mapx(pos[1]); - if (xp >= x && xp < x+w) { - p.setPen(Qt::blue); - p.drawLine(xp, y, xp, y+h); - } - xp = mapx(pos[2]); - if (xp >= x && xp < x+w) { - p.setPen(Qt::blue); - p.drawLine(xp, y, xp, y+h); - } - */ - //--------------------------------------------------- // draw lasso //--------------------------------------------------- @@ -1503,19 +1500,23 @@ void CtrlCanvas::pdraw(QPainter& p, const QRect& rect) void CtrlCanvas::drawOverlay(QPainter& p) { - //QString s(_controller->name()); QString s(_controller ? _controller->name() : QString("")); - p.setFont(config.fonts[3]); + + //p.setFont(config.fonts[3]); // Use widget font instead. + p.setFont(font()); + p.setPen(Qt::black); - QFontMetrics fm(config.fonts[3]); - int y = fm.lineSpacing() + 2; - //printf("CtrlCanvas::drawOverlay fm w:%d h:%d\n", fm.width(_controller ? _controller->name() : QString("")), fm.height()); + + //QFontMetrics fm(config.fonts[3]); // Use widget font metrics instead. + //int y = fm.lineSpacing() + 2; + int y = fontMetrics().lineSpacing() + 2; + p.drawText(2, y, s); if (noEvents) { //p.setFont(config.fonts[3]); //p.setPen(Qt::black); - p.drawText(width()/2-100,height()/2-10, "Use shift + pencil or line tool to draw new events"); - //p.drawText(2 , y * 2, "Use shift + pencil or line tool to draw new events"); + //p.drawText(width()/2-100,height()/2-10, "Use shift + pencil or line tool to draw new events"); + p.drawText(2 , y * 2, "Use shift + pencil or line tool to draw new events"); } } @@ -1526,18 +1527,22 @@ void CtrlCanvas::drawOverlay(QPainter& p) QRect CtrlCanvas::overlayRect() const { - QFontMetrics fm(config.fonts[3]); + //QFontMetrics fm(config.fonts[3]); // Use widget font metrics instead (and set a widget font) !!! + QFontMetrics fm(fontMetrics()); QRect r(fm.boundingRect(_controller ? _controller->name() : QString(""))); - //QRect r(0, 0, fm.width(_controller ? _controller->name() : QString("")), fm.height()); + //r.translate(2, 2); // top/left margin - r.translate(2, fm.lineSpacing() + 2); // + int y = fm.lineSpacing() + 2; + r.translate(2, y); if (noEvents) { QRect r2(fm.boundingRect(QString("Use shift + pencil or line tool to draw new events"))); - r2.translate(width()/2-100, height()/2-10); + //r2.translate(width()/2-100, height()/2-10); + r2.translate(2, y * 2); r |= r2; } + //printf("CtrlCanvas::overlayRect x:%d y:%d w:%d h:%d\n", r.x(), r.y(), r.width(), r.height()); return r; } diff --git a/muse2/muse/ctrl/ctrlcanvas.h b/muse2/muse/ctrl/ctrlcanvas.h index e76bf71c..e06874e2 100644 --- a/muse2/muse/ctrl/ctrlcanvas.h +++ b/muse2/muse/ctrl/ctrlcanvas.h @@ -141,6 +141,7 @@ class CtrlCanvas : public View { private slots: void songChanged(int type); + void configChanged(); void setCurDrumInstrument(int); public slots: diff --git a/muse2/muse/widgets/view.cpp b/muse2/muse/widgets/view.cpp index 3637e320..fb480527 100644 --- a/muse2/muse/widgets/view.cpp +++ b/muse2/muse/widgets/view.cpp @@ -141,12 +141,39 @@ void View::setXPos(int x) #else scroll(delta, 0); - QRect olr = overlayRect().translated(delta, 0); - //olr.setHeight(height()); - //olr.setWidth(olr.width() * 2); - //printf("scroll update: x:%d y:%d w:%d h:%d\n", olr.x(), olr.y(), olr.width(), olr.height()); - //repaint(overlayRect().translated(delta, 0)); - update(olr); + QRect olr = overlayRect(); + // Is there an overlay? + if(!olr.isNull()) + { + // Are we shifting right (moving left)? + if(delta >= 0) + { + // Translate not good - need to set x to delta. + //olr.translate(delta, 0); + olr.setX(delta); + olr.setWidth(olr.x() + olr.width() + delta); + } + else + // We are shifting left (moving right). + { + // Translate not good - need to limit x to 0. + //olr.translate(delta, 0); + olr.setX(olr.x() + delta); + } + + if(olr.x() < 0) + olr.setX(0); + if(olr.right() > width()) + olr.setRight(width()); + + if(olr.y() < 0) + olr.setY(0); + if(olr.bottom() > height()) + olr.setBottom(height()); + + //printf("scroll X update: x:%d y:%d w:%d h:%d\n", olr.x(), olr.y(), olr.width(), olr.height()); + update(olr); + } #endif } @@ -201,8 +228,39 @@ void View::setYPos(int y) #else scroll(0, delta); - //repaint(overlayRect().translate(0, delta)); - update(overlayRect().translated(0, delta)); + QRect olr = overlayRect(); + // Is there an overlay? + if(!olr.isNull()) + { + // Are we shifting down (moving up)? + if(delta >= 0) + { + // Translate not good - need to set y to delta. + //olr.translate(0, delta); + olr.setY(delta); + olr.setHeight(olr.y() + olr.height() + delta); + } + else + // We are shifting up (moving down). + { + // Translate not good - need to limit y to 0. + //olr.translate(0, delta); + olr.setY(olr.y() + delta); + } + + if(olr.x() < 0) + olr.setX(0); + if(olr.right() > width()) + olr.setRight(width()); + + if(olr.y() < 0) + olr.setY(0); + if(olr.bottom() > height()) + olr.setBottom(height()); + + //printf("scroll Y update: x:%d y:%d w:%d h:%d\n", olr.x(), olr.y(), olr.width(), olr.height()); + update(olr); + } #endif } @@ -247,39 +305,7 @@ void View::paintEvent(QPaintEvent* ev) p.drawPixmap(ev->rect().topLeft(), pm, ev->rect()); #else - - /* - QRect er = ev->rect(); - QRect or = overlayRect(); - // Is there an overlay to be drawn? Is it not already fully contained by the requested paint rectangle? - if(!or.isNull() && !er.contains(or)) - { - // Is at least part of the overlay contained by the paint rectangle? - if(!(er & or).isNull()) - { - // Then we only need one paint pass... - // TODO: Controller canvas ignores paint rectangle height. - // So we can get away with just uniting the rectangles. - // When controller canvas is finally optimized to respect height, - // this should be more optimized by drawing only 'subtraction' - // of intersection result from the overlay rectangle. - // Something like: paint(er); paint(or - (er & or)); - // But there's no '-' operator. Hmm how to do that... - paint(er | or); - } - else - { - // Then we need two separate paint passes... - // Paint the requested rectangle as usual. - paint(er); - // Paint the overlay rectangle portion as well. - paint(or); - } - } - */ - paint(ev->rect()); - //paint(er); #endif } |