diff options
Diffstat (limited to 'src/canvastoolposition.cc')
-rw-r--r-- | src/canvastoolposition.cc | 72 |
1 files changed, 60 insertions, 12 deletions
diff --git a/src/canvastoolposition.cc b/src/canvastoolposition.cc index 7784720..a90908b 100644 --- a/src/canvastoolposition.cc +++ b/src/canvastoolposition.cc @@ -32,6 +32,8 @@ #include <iostream> +constexpr int diam{8}; + #define mapX(x) canvas.mapX(x) #define mapY(x) canvas.mapY(x) #define unmapX(x) canvas.unmapX(x) @@ -56,6 +58,43 @@ CanvasToolPosition::CanvasToolPosition(Instrument& instrument, bool CanvasToolPosition::mouseMoveEvent(QMouseEvent* event) { + sel_id_t active_range = ranges.active(); + Range act_sel = ranges.get(active_range); +// +// int x1 = mapX(range.pos1); +// int x2 = mapX(range.pos2); +// highlight1 = false; +// highlight2 = false; +// if(x1 == event->x) +// { +// highlight1 = true; +// } +// else if(x2 == event->x) +// { +// highlight2 = true; +// } +// canvas->update(); +// + + if(event->button() != Qt::LeftButton && + event->y() > (canvas.height() - diam)) + { + // Check if a range is being dragged. + QVector<sel_id_t> ids = ranges.ids(); + QVector<sel_id_t>::iterator i = ids.begin(); + while(i != ids.end()) + { + Range sel = ranges.get(*i); + if(abs(event->x() - mapX(sel.pos1)) < diam/2 + || abs(event->x() - mapX(sel.pos2)) < diam/2) + { + canvas.setCursor(Qt::SplitHCursor); + return true; + } + i++; + } + } + return false; } @@ -74,7 +113,6 @@ void drawRange(const Range& range, Canvas& canvas, QPainter& painter) { int x1 = mapX(range.pos1); int x2 = mapX(range.pos2); - if(x1 > x2) { std::swap(x1, x2); @@ -87,17 +125,27 @@ void drawRange(const Range& range, Canvas& canvas, QPainter& painter) // | | // | | constexpr auto len = 8; - painter.drawLine(x1, mapY(-1.0), x1, mapY(1.0)); // left bar - - painter.drawLine(x1, mapY( 0.0), x1 + len, mapY(0.0) + len); // left arrow - painter.drawLine(x1, mapY( 0.0), x1 + len, mapY(0.0) - len); // left arrow - - painter.drawLine(x1, mapY( 0.0), x2, mapY(0.0)); // horizontal line - - painter.drawLine(x2, mapY( 0.0), x2 - len, mapY(0.0) + len); // right arrow - painter.drawLine(x2, mapY( 0.0), x2 - len, mapY(0.0) - len); // right arrow - - painter.drawLine(x2, mapY(-1.0), x2, mapY(1.0)); // right bar + auto arrows_y = canvas.height() - canvas.height() / 8; + auto balls_y = canvas.height() - diam; + if(x1 > 0 && x1 < canvas.width()) + { + painter.drawLine(x1, 0, x1, canvas.height()); // left bar + painter.drawEllipse(x1-diam/2, balls_y, diam, diam); + } + if(((x1 > 0 && x1 < canvas.width()) || (x2 > 0 && x2 < canvas.width())) && + std::abs(x1 - x2) > len) + { + painter.drawLine(x1, arrows_y, x1 + len, arrows_y + len); // left arrow + painter.drawLine(x1, arrows_y, x1 + len, arrows_y - len); // left arrow + painter.drawLine(x1, arrows_y, x2, arrows_y); // horizontal line + painter.drawLine(x2, arrows_y, x2 - len, arrows_y + len); // right arrow + painter.drawLine(x2, arrows_y, x2 - len, arrows_y - len); // right arrow + } + if(x2 > 0 && x2 < canvas.width()) + { + painter.drawLine(x2, 0, x2, canvas.height()); // right bar + painter.drawEllipse(x2-diam/2, balls_y, diam, diam); + } } } |