diff options
author | Bent Bisballe Nyeng <deva@aasimon.org> | 2013-05-09 12:04:49 +0200 |
---|---|---|
committer | Bent Bisballe Nyeng <deva@aasimon.org> | 2013-05-09 12:04:49 +0200 |
commit | 14041f774fc25ea1372587c344c42cdc57172155 (patch) | |
tree | c953eb1b7e0b5ef771950665de02c44c42ab8206 /dgedit/samplesorter.cc | |
parent | a4d73c0cb2321bd61bd31d2922ae469389e5825e (diff) |
Click sorted samples hilight the corresponding canvas selection.
Diffstat (limited to 'dgedit/samplesorter.cc')
-rw-r--r-- | dgedit/samplesorter.cc | 30 |
1 files changed, 28 insertions, 2 deletions
diff --git a/dgedit/samplesorter.cc b/dgedit/samplesorter.cc index 71b1654..adfdf65 100644 --- a/dgedit/samplesorter.cc +++ b/dgedit/samplesorter.cc @@ -176,10 +176,10 @@ void SampleSorter::setActiveSelection(Selection s) #define mapX(x) (((double)x)*(width()-1)) #define mapY(x) x - +#define C_RADIUS 2 static void drawCircle(QPainter &p, int x, int y) { - p.drawEllipse(x-2, y-2, 4, 4); + p.drawEllipse(x - C_RADIUS, y - C_RADIUS, 2 * C_RADIUS, 2 * C_RADIUS); } void SampleSorter::paintEvent(QPaintEvent *event) @@ -224,6 +224,26 @@ void SampleSorter::paintEvent(QPaintEvent *event) } } +Selection *SampleSorter::getSelectionByCoordinate(int px, int py) +{ + py -= C_RADIUS; + + QMap<float, Selection>::iterator i = sorted.begin(); + while(i != sorted.end()) { + float x = (i.key()/max); + x = sqrt(x); + x *= (float)width(); + if(px < (x + C_RADIUS) && px > (x - C_RADIUS) && + py < (MAP(x) + C_RADIUS) && py > (MAP(x) - C_RADIUS)) { + return &i.value(); + } + i++; + } + + return NULL; +} + + void SampleSorter::mouseMoveEvent(QMouseEvent *event) { if(cur_thr != -1 && cur_thr < threshold.size()) { @@ -250,6 +270,12 @@ void SampleSorter::mousePressEvent(QMouseEvent *event) { if(event->button() == Qt::LeftButton) { + Selection *psel = getSelectionByCoordinate(event->x(), event->y()); + if(psel) { + emit activeSelectionChanged(*psel); + return; + } + // Check if threshold is being dragged. for(size_t i = 0; i < (size_t)threshold.size(); i++) { if(abs(event->x() - mapX(threshold[i])) < 2 || |