From 14041f774fc25ea1372587c344c42cdc57172155 Mon Sep 17 00:00:00 2001 From: Bent Bisballe Nyeng Date: Thu, 9 May 2013 12:04:49 +0200 Subject: Click sorted samples hilight the corresponding canvas selection. --- dgedit/samplesorter.cc | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) (limited to 'dgedit/samplesorter.cc') 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::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 || -- cgit v1.2.3