summaryrefslogtreecommitdiff
path: root/dgedit/canvastoolselections.cc
diff options
context:
space:
mode:
Diffstat (limited to 'dgedit/canvastoolselections.cc')
-rw-r--r--dgedit/canvastoolselections.cc101
1 files changed, 75 insertions, 26 deletions
diff --git a/dgedit/canvastoolselections.cc b/dgedit/canvastoolselections.cc
index 30f8970..d0aa481 100644
--- a/dgedit/canvastoolselections.cc
+++ b/dgedit/canvastoolselections.cc
@@ -34,8 +34,9 @@
#define unmapX(x) canvas->unmapX(x)
#define unmapY(x) canvas->unmapY(x)
-CanvasToolSelections::CanvasToolSelections(Canvas *c, Selections &s)
- : selections(s)
+CanvasToolSelections::CanvasToolSelections(Canvas *c, Selections &s,
+ Selections &p)
+ : selections(s), selections_preview(p)
{
threshold = 0.5; // Default from CanvasToolThreshold
@@ -48,7 +49,8 @@ CanvasToolSelections::CanvasToolSelections(Canvas *c, Selections &s)
colSel = QColor(255, 0, 0, 160);
colActiveSelBg = QColor(255, 255, 0, 60);
colActiveSel = QColor(255, 255, 0, 160);
-
+ colPreviewSelBg = QColor(0, 0, 255, 60);
+ colPreviewSel = QColor(0, 0, 255, 160);
}
bool CanvasToolSelections::mouseMoveEvent(QMouseEvent *event)
@@ -162,29 +164,54 @@ void CanvasToolSelections::paintEvent(QPaintEvent *event, QPainter &painter)
int pos = unmapX(event->rect().x());
int width = unmapX(event->rect().width());
- QVector<sel_id_t> ids = selections.ids();
- QVector<sel_id_t>::iterator i = ids.begin();
- while(i != ids.end()) {
- Selection sel = selections.get(*i);
- int from = sel.from;
- int to = sel.to;
- int fadein = sel.fadein;
- int fadeout = sel.fadeout;
- if(from > pos + width || to + width < pos) { i++; continue; }
- if(selections.active() == *i) {
- painter.setBrush(colActiveSelBg);
- painter.setPen(colActiveSel);
- } else {
- painter.setBrush(colSelBg);
- painter.setPen(colSel);
+ {
+ QVector<sel_id_t> ids = selections.ids();
+ QVector<sel_id_t>::iterator i = ids.begin();
+ while(i != ids.end()) {
+ Selection sel = selections.get(*i);
+ int from = sel.from;
+ int to = sel.to;
+ int fadein = sel.fadein;
+ int fadeout = sel.fadeout;
+ if(from > pos + width || to + width < pos) { i++; continue; }
+ if(selections.active() == *i) {
+ painter.setBrush(colActiveSelBg);
+ painter.setPen(colActiveSel);
+ } else {
+ painter.setBrush(colSelBg);
+ painter.setPen(colSel);
+ }
+ painter.drawRect(mapX(from), mapY(-1.0),
+ mapX(to) - mapX(from), mapY(1.0) - mapY(-1.0));
+ painter.drawLine(mapX(from), mapY(0.0), mapX(from + fadein), mapY(-1.0));
+ painter.drawLine(mapX(from), mapY(0.0), mapX(from + fadein), mapY(1.0));
+ painter.drawLine(mapX(to - fadeout), mapY(-1.0), mapX(to), mapY(0.0));
+ painter.drawLine(mapX(to - fadeout), mapY(1.0), mapX(to), mapY(0.0));
+ i++;
+ }
+ }
+
+ if(show_preview) {
+ QVector<sel_id_t> ids = selections_preview.ids();
+ QVector<sel_id_t>::iterator i = ids.begin();
+ while(i != ids.end()) {
+ Selection sel = selections_preview.get(*i);
+ int from = sel.from;
+ int to = sel.to;
+ int fadein = sel.fadein;
+ int fadeout = sel.fadeout;
+ if(from > pos + width || to + width < pos) { i++; continue; }
+ painter.setBrush(colPreviewSelBg);
+ painter.setPen(colPreviewSel);
+
+ painter.drawRect(mapX(from), mapY(-1.0),
+ mapX(to) - mapX(from), mapY(1.0) - mapY(-1.0));
+ painter.drawLine(mapX(from), mapY(0.0), mapX(from + fadein), mapY(-1.0));
+ painter.drawLine(mapX(from), mapY(0.0), mapX(from + fadein), mapY(1.0));
+ painter.drawLine(mapX(to - fadeout), mapY(-1.0), mapX(to), mapY(0.0));
+ painter.drawLine(mapX(to - fadeout), mapY(1.0), mapX(to), mapY(0.0));
+ i++;
}
- painter.drawRect(mapX(from), mapY(-1.0),
- mapX(to) - mapX(from), mapY(1.0) - mapY(-1.0));
- painter.drawLine(mapX(from), mapY(0.0), mapX(from + fadein), mapY(-1.0));
- painter.drawLine(mapX(from), mapY(0.0), mapX(from + fadein), mapY(1.0));
- painter.drawLine(mapX(to - fadeout), mapY(-1.0), mapX(to), mapY(0.0));
- painter.drawLine(mapX(to - fadeout), mapY(1.0), mapX(to), mapY(0.0));
- i++;
}
}
@@ -214,9 +241,21 @@ void CanvasToolSelections::fadeoutChanged(int t)
void CanvasToolSelections::autoCreateSelections()
{
+ doAutoCreateSelections(false);
+}
+
+void CanvasToolSelections::autoCreateSelectionsPreview()
+{
+ doAutoCreateSelections(true);
+}
+
+void CanvasToolSelections::doAutoCreateSelections(bool preview)
+{
float *data = canvas->data;
size_t size = canvas->size;
+ if(preview) selections_preview.clear();
+
for(size_t i = 0; i < size; i++) {
if(fabs(data[i]) > fabs(threshold)) {
int from = i;
@@ -247,7 +286,11 @@ void CanvasToolSelections::autoCreateSelections()
}
Selection s(from, to, 2, ((to - from) / 3) * fadeout);
- selections.add(s);
+ if(preview) {
+ selections_preview.add(s);
+ } else {
+ selections.add(s);
+ }
i = to+1;
}
@@ -263,3 +306,9 @@ void CanvasToolSelections::clearSelections()
canvas->setCursor(Qt::ArrowCursor);
canvas->update();
}
+
+void CanvasToolSelections::setShowPreview(bool s)
+{
+ show_preview = s;
+ canvas->update();
+}