summaryrefslogtreecommitdiff
path: root/dgedit/samplesorter.cc
diff options
context:
space:
mode:
author- <nemo@alice.(none)>2013-05-09 17:54:53 +0200
committer- <nemo@alice.(none)>2013-05-09 17:54:53 +0200
commit0c9cfbada411dcc1fcc90306408fadfcf7e49988 (patch)
treef28ea5850f30c8a65df7405cefec54fa1e372164 /dgedit/samplesorter.cc
parent774815a97901fe9d5ce2767a8c479c52a5ad0ce8 (diff)
parent14041f774fc25ea1372587c344c42cdc57172155 (diff)
Merge branch 'master' of http://git.drumgizmo.org/drumgizmo
Diffstat (limited to 'dgedit/samplesorter.cc')
-rw-r--r--dgedit/samplesorter.cc30
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 ||