changeset 27:38fe0ea9e46e

* Some fixes to waveform layer greyscaling * Tidying in panner class
author Chris Cannam
date Fri, 03 Feb 2006 17:30:47 +0000
parents 94381052a6c9
children 202d1dca67d2
files layer/TimeValueLayer.cpp layer/WaveformLayer.cpp widgets/Pane.cpp widgets/Panner.cpp widgets/Panner.h
diffstat 5 files changed, 69 insertions(+), 107 deletions(-) [+]
line wrap: on
line diff
--- a/layer/TimeValueLayer.cpp	Thu Feb 02 17:31:08 2006 +0000
+++ b/layer/TimeValueLayer.cpp	Fri Feb 03 17:30:47 2006 +0000
@@ -462,23 +462,22 @@
 	    SparseTimeValueModel::PointList::const_iterator j = i;
 	    ++j;
 
+	    int nx;
+
 	    if (j != points.end()) {
-		
 		const SparseTimeValueModel::Point &q(*j);
-		int nx = getXForFrame(q.frame);
+		nx = getXForFrame(q.frame);
+	    } else {
+		nx = getXForFrame(m_model->getEndFrame());
+	    }
 
-		if (nx == x) continue;
+	    if (nx <= x) continue;
 
-		if (nx < x + 5 && illuminateFrame != p.frame) {
-		    paint.setPen(Qt::NoPen);
-		}
+	    if (nx < x + 5 && illuminateFrame != p.frame) {
+		paint.setPen(Qt::NoPen);
+	    }
 
-		paint.drawRect(x, -1, nx - x, m_view->height() + 1);
-
-	    } else {
-
-		paint.drawLine(x, 0, x, m_view->height());
-	    }
+	    paint.drawRect(x, -1, nx - x, m_view->height() + 1);
 	}
 
 ///	if (p.label != "") {
--- a/layer/WaveformLayer.cpp	Thu Feb 02 17:31:08 2006 +0000
+++ b/layer/WaveformLayer.cpp	Fri Feb 03 17:30:47 2006 +0000
@@ -412,15 +412,20 @@
     
     QColor greys[3];
     if (m_colour == Qt::black) {
-	for (int i = 0; i < 3; ++i) {
+	for (int i = 0; i < 3; ++i) { // 0 lightest, 2 darkest
 	    int level = 192 - 64 * i;
 	    greys[i] = QColor(level, level, level);
 	}
     } else {
-	int factor = (m_view->hasLightBackground() ? 120 : 80);
-	greys[2] = m_colour.light(factor);
-	greys[1] = greys[2].light(factor);
-	greys[0] = greys[1].light(factor);
+	int h, s, v;
+	m_colour.getHsv(&h, &s, &v);
+	for (int i = 0; i < 3; ++i) { // 0 lightest, 2 darkest
+	    if (m_view->hasLightBackground()) {
+		greys[i] = QColor::fromHsv(h, s * (i + 1) / 4, v);
+	    } else {
+		greys[i] = QColor::fromHsv(h, s * (3 - i) / 4, v);
+	    }
+	}
     }
         
     QColor midColour = m_colour;
@@ -549,22 +554,29 @@
 		meanTop     =  AudioLevel::multiplier_to_preview(range.absmean * m_gain, m);
 	    }
 
-	    int topFill = (rangeTop < 0 ? -rangeTop : rangeTop) % greyLevels;
-	    int bottomFill = (rangeBottom < 0 ? -rangeBottom : rangeBottom) % greyLevels;
+	    rangeBottom = my * greyLevels - rangeBottom;
+	    rangeTop    = my * greyLevels - rangeTop;
+	    meanBottom  = my - meanBottom;
+	    meanTop     = my - meanTop;
+
+	    int topFill = (rangeTop % greyLevels);
+	    if (topFill > 0) topFill = greyLevels - topFill;
+
+	    int bottomFill = (rangeBottom % greyLevels);
+
 	    rangeTop = rangeTop / greyLevels;
 	    rangeBottom = rangeBottom / greyLevels;
 
 	    bool clipped = false;
-	    if (rangeTop < -m) { rangeTop = -m; clipped = true; }
-	    if (rangeTop >  m) { rangeTop =  m; clipped = true; }
-	    if (rangeBottom < -m) { rangeBottom = -m; clipped = true; }
-	    if (rangeBottom >  m) { rangeBottom =  m; clipped = true; }
+
+	    if (rangeTop < my - m) { rangeTop = my - m; }
+	    if (rangeTop > my + m) { rangeTop = my + m; }
+	    if (rangeBottom < my - m) { rangeBottom = my - m; }
+	    if (rangeBottom > my + m) { rangeBottom = my + m; }
+
+	    if (range.max * m_gain <= -1.0 ||
+		range.max * m_gain >= 1.0) clipped = true;
 	    
-	    rangeBottom = my - rangeBottom;
-	    rangeTop    = my - rangeTop;
-	    meanBottom  = my - meanBottom;
-	    meanTop     = my - meanTop;
-
 	    if (meanBottom > rangeBottom) meanBottom = rangeBottom;
 	    if (meanTop < rangeTop) meanTop = rangeTop;
 
@@ -614,12 +626,12 @@
 			if (topFill > 0 &&
 			    (!drawMean || (rangeTop < meanTop - 1))) {
 			    paint->setPen(greys[topFill - 1]);
-			    paint->drawPoint(x, rangeTop - 1);
+			    paint->drawPoint(x, rangeTop);
 			}
 			if (bottomFill > 0 && 
 			    (!drawMean || (rangeBottom > meanBottom + 1))) {
 			    paint->setPen(greys[bottomFill - 1]);
-			    paint->drawPoint(x, rangeBottom + 1);
+			    paint->drawPoint(x, rangeBottom);
 			}
 		    }
 		}
--- a/widgets/Pane.cpp	Thu Feb 02 17:31:08 2006 +0000
+++ b/widgets/Pane.cpp	Fri Feb 03 17:30:47 2006 +0000
@@ -40,12 +40,18 @@
 bool
 Pane::shouldIlluminateLocalFeatures(const Layer *layer, QPoint &pos)
 {
+/*!!!
     for (LayerList::iterator vi = m_layers.end(); vi != m_layers.begin(); ) {
 	--vi;
 	if (layer != *vi) return false;
 	pos = m_identifyPoint;
 	return m_identifyFeatures;
     }
+*/
+    if (layer == getSelectedLayer()) {
+	pos = m_identifyPoint;
+	return m_identifyFeatures;
+    }
 
     return false;
 }
@@ -162,34 +168,6 @@
 
 		paint.restore();
 	    }
-
-/*!!!
-	    QRect descRect = (*vi)->getFeatureDescriptionRect(paint,
-							      m_identifyPoint);
-	    if (descRect.width() > 0 && descRect.height() > 0 &&
-		r.left() + r.width() >= width() - descRect.width() &&
-		r.top() < descRect.height()) {
-		
-//		Profiler profiler("Pane::paintEvent - painting local feature description", true);
-		
-//		std::cerr << "Pane::paintEvent: calling paint.save() in feature description block" << std::endl;
-		paint.save();
-		
-		paint.setPen(Qt::black);
-		paint.setBrush(Qt::white);
-		
-		QRect rect(width() - descRect.width() - 1, 0,
-			   descRect.width(), descRect.height());
-		
-		paint.drawRect(rect);
-		
-		paint.setBrush(Qt::NoBrush);
-		(*vi)->paintLocalFeatureDescription(paint, rect, m_identifyPoint);
-		
-		paint.restore();
-	    }
-
-*/
 	}
 
 	break;
--- a/widgets/Panner.cpp	Thu Feb 02 17:31:08 2006 +0000
+++ b/widgets/Panner.cpp	Fri Feb 03 17:30:47 2006 +0000
@@ -43,7 +43,7 @@
 void
 Panner::registerView(View *widget)
 {
-    m_widgets[widget] = WidgetRec(0, -1);
+    m_widgets.insert(widget);
     update(); 
 }
 
@@ -62,7 +62,6 @@
 
     if (p == this) return;
     if (m_widgets.find(p) != m_widgets.end()) {
-	m_widgets[p].first = f;
 	update();
     }
 }
@@ -72,7 +71,6 @@
 {
     if (p == this) return;
     if (m_widgets.find(p) != m_widgets.end()) {
-	m_widgets[p].second = z;
 	update();
     }
 }
@@ -82,27 +80,15 @@
 {
     bool changed = false;
 
-    if (m_playPointerFrame / m_zoomLevel != f / m_zoomLevel) changed = true;
+    if (getXForFrame(m_playPointerFrame) != getXForFrame(f)) changed = true;
     m_playPointerFrame = f;
 
-    for (WidgetMap::iterator i = m_widgets.begin(); i != m_widgets.end(); ++i) {
-	unsigned long of = i->second.first;
-	i->second.first = f;
-	if (of / m_zoomLevel != f / m_zoomLevel) changed = true;
-    }
-
     if (changed) update();
 }
 
 void
 Panner::paintEvent(QPaintEvent *e)
 {
-/*!!!
-    // Force View to recalculate zoom in case the size of the
-    // widget has changed.  (We need a better name/mechanism for this)
-    m_newModel = true;
-*/
-
     // Recalculate zoom in case the size of the widget has changed.
 
     size_t startFrame = getModelsStartFrame();
@@ -139,30 +125,28 @@
     paint.setPen(Qt::black);
 
     int y = 0;
-    long prevCentre = 0;
-    long prevZoom = -1;
 
-    for (WidgetMap::iterator i = m_widgets.begin(); i != m_widgets.end(); ++i) {
-	if (!i->first) continue;
+    int prevx0 = -10;
+    int prevx1 = -10;
 
-	View *w = (View *)i->first;
-	if (i->second.second < 0) i->second.second = w->getZoomLevel();
-	if (i->second.second < 0) continue;
+    for (WidgetSet::iterator i = m_widgets.begin(); i != m_widgets.end(); ++i) {
+	if (!*i) continue;
 
-	long c = (long)i->second.first;
-	long z = (long)i->second.second;
+	View *w = (View *)*i;
 
-	long f0 = c - (w->width() / 2) * z;
-	long f1 = c + (w->width() / 2) * z;
+	long f0 = w->getFrameForX(0);
+	long f1 = w->getFrameForX(w->width());
 
-	int x0 = (f0 - long(getCentreFrame())) / getZoomLevel() + width()/2;
-	int x1 = (f1 - long(getCentreFrame())) / getZoomLevel() + width()/2 - 1;
+	int x0 = getXForFrame(f0);
+	int x1 = getXForFrame(f1);
 
-	if (c != prevCentre || z != prevZoom) {
+	if (x0 != prevx0 || x1 != prevx1) {
 	    y += height() / 10 + 1;
-	    prevCentre = c;
-	    prevZoom = z;
+	    prevx0 = x0;
+	    prevx1 = x1;
 	}
+
+	if (x1 <= x0) x1 = x0 + 1;
 	
 	paint.drawRect(x0, y, x1 - x0, height() - 2 * y);
     }
@@ -174,10 +158,11 @@
 Panner::mousePressEvent(QMouseEvent *e)
 {
     m_clickPos = e->pos();
-    for (WidgetMap::iterator i = m_widgets.begin(); i != m_widgets.end(); ++i) {
-	if (i->first && i->second.second >= 0) {
+    for (WidgetSet::iterator i = m_widgets.begin(); i != m_widgets.end(); ++i) {
+	if (*i) {
 	    m_clickedInRange = true;
-	    m_dragCentreFrame = i->second.first;
+	    m_dragCentreFrame = ((View *)*i)->getCentreFrame();
+	    break;
 	}
     }
 }
@@ -196,17 +181,6 @@
 {
     if (!m_clickedInRange) return;
 
-/*!!!
-    long newFrame = getStartFrame() + e->x() * m_zoomLevel;
-
-    if (newFrame < 0) newFrame = 0;
-    if (newFrame >= getModelsEndFrame()) {
-	newFrame = getModelsEndFrame();
-	if (newFrame > 0) --newFrame;
-    }
-    emit centreFrameChanged(this, newFrame, true);
-*/
-
     long xoff = int(e->x()) - int(m_clickPos.x());
     long frameOff = xoff * m_zoomLevel;
     
--- a/widgets/Panner.h	Thu Feb 02 17:31:08 2006 +0000
+++ b/widgets/Panner.h	Fri Feb 03 17:30:47 2006 +0000
@@ -53,9 +53,8 @@
     bool m_clickedInRange;
     size_t m_dragCentreFrame;
     
-    typedef std::pair<size_t, int> WidgetRec; // centre, zoom (-1 = invalid)
-    typedef std::map<void *, WidgetRec> WidgetMap;
-    WidgetMap m_widgets;
+    typedef std::set<void *> WidgetSet;
+    WidgetSet m_widgets;
 };
 
 #endif