summaryrefslogtreecommitdiff
path: root/dgedit
diff options
context:
space:
mode:
Diffstat (limited to 'dgedit')
-rw-r--r--dgedit/canvastoolselections.cc13
-rw-r--r--dgedit/canvastoolselections.h1
-rw-r--r--dgedit/mainwindow.cc3
-rw-r--r--dgedit/samplesorter.cc30
-rw-r--r--dgedit/samplesorter.h5
5 files changed, 50 insertions, 2 deletions
diff --git a/dgedit/canvastoolselections.cc b/dgedit/canvastoolselections.cc
index 5188cb0..5868b1f 100644
--- a/dgedit/canvastoolselections.cc
+++ b/dgedit/canvastoolselections.cc
@@ -53,6 +53,19 @@ CanvasToolSelections::CanvasToolSelections(Canvas *c)
}
+void CanvasToolSelections::setActiveSelection(Selection s)
+{
+ QMap<int, Selection>::iterator i = _selections.begin();
+ while(i != _selections.end()) {
+ if(s.from == i.value().from &&
+ s.to == i.value().to) active_selection = &i.value();
+ i++;
+ }
+
+ canvas->update();
+ emit activeSelectionChanged(s);
+}
+
bool CanvasToolSelections::mouseMoveEvent(QMouseEvent *event)
{
if(selection_is_moving_left) {
diff --git a/dgedit/canvastoolselections.h b/dgedit/canvastoolselections.h
index 99114de..64c52b8 100644
--- a/dgedit/canvastoolselections.h
+++ b/dgedit/canvastoolselections.h
@@ -59,6 +59,7 @@ public slots:
void thresholdChanged(double threshold);
void noiseFloorChanged(int t);
void fadeoutChanged(int t);
+ void setActiveSelection(Selection s);
private:
bool selection_is_moving_left;
diff --git a/dgedit/mainwindow.cc b/dgedit/mainwindow.cc
index 7d060cb..30cd626 100644
--- a/dgedit/mainwindow.cc
+++ b/dgedit/mainwindow.cc
@@ -117,6 +117,9 @@ MainWindow::MainWindow()
connect(selections, SIGNAL(activeSelectionChanged(Selection)),
sorter, SLOT(setActiveSelection(Selection)));
+ connect(sorter, SIGNAL(activeSelectionChanged(Selection)),
+ selections, SLOT(setActiveSelection(Selection)));
+
lh->addWidget(canvas);
lh->addWidget(yscale);
lh->addWidget(yoffset);
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 ||
diff --git a/dgedit/samplesorter.h b/dgedit/samplesorter.h
index f277ff1..7b214e7 100644
--- a/dgedit/samplesorter.h
+++ b/dgedit/samplesorter.h
@@ -61,7 +61,12 @@ protected:
void mousePressEvent(QMouseEvent *event);
void mouseReleaseEvent(QMouseEvent *event);
+signals:
+ void activeSelectionChanged(Selection selection);
+
private:
+ Selection *getSelectionByCoordinate(int x, int y);
+
Selections _selections;
QMap<float, Selection> sorted;
float min;