diff view/View.cpp @ 373:0895517bb2d1 1.2-stable

* merge from trunk (1.2 ended up being tracked from trunk, but we may want this branch for fixes later)
author Chris Cannam
date Wed, 27 Feb 2008 10:32:45 +0000
parents 4a542ba875c2
children
line wrap: on
line diff
--- a/view/View.cpp	Thu Nov 29 10:43:54 2007 +0000
+++ b/view/View.cpp	Wed Feb 27 10:32:45 2008 +0000
@@ -19,6 +19,7 @@
 #include "base/ZoomConstraint.h"
 #include "base/Profiler.h"
 #include "base/Pitch.h"
+#include "base/Preferences.h"
 
 #include "layer/TimeRulerLayer.h"
 #include "layer/SingleColourLayer.h"
@@ -31,6 +32,7 @@
 #include <QApplication>
 #include <QProgressDialog>
 #include <QTextStream>
+#include <QFont>
 
 #include <iostream>
 #include <cassert>
@@ -328,9 +330,11 @@
 
 	if (e) {
             size_t rf = alignToReference(f);
+#ifdef DEBUG_VIEW_WIDGET_PAINT
             std::cerr << "View[" << this << "]::setCentreFrame(" << f
                       << "): emitting centreFrameChanged("
                       << rf << ")" << std::endl;
+#endif
             emit centreFrameChanged(rf, m_followPan, m_followPlay);
         }
     }
@@ -349,6 +353,11 @@
 {
     long z = (long)m_zoomLevel;
     long frame = m_centreFrame - (width()/2) * z;
+
+#ifdef DEBUG_VIEW_WIDGET_PAINT
+    std::cerr << "View::getFrameForX(" << x << "): z = " << z << ", m_centreFrame = " << m_centreFrame << ", width() = " << width() << ", frame = " << frame << std::endl;
+#endif
+
     frame = (frame / z) * z; // this is start frame
     return frame + x * z;
 }
@@ -503,9 +512,6 @@
 View::LayerProgressBar::LayerProgressBar(QWidget *parent) :
     QProgressBar(parent)
 {
-    QFont f(font());
-    f.setPointSize(f.pointSize() * 8 / 10);
-    setFont(f);
 }
 
 void
@@ -523,6 +529,12 @@
     m_progressBars[layer]->setMinimum(0);
     m_progressBars[layer]->setMaximum(100);
     m_progressBars[layer]->setMinimumWidth(80);
+
+    QFont f(m_progressBars[layer]->font());
+    int fs = Preferences::getInstance()->getViewFontSize();
+    f.setPointSize(std::min(fs, int(ceil(fs * 0.85))));
+
+    m_progressBars[layer]->setFont(f);
     m_progressBars[layer]->hide();
     
     connect(layer, SIGNAL(layerParametersChanged()),
@@ -655,7 +667,10 @@
     connect(this, SIGNAL(zoomLevelChanged(unsigned long, bool)),
 	    m_manager, SLOT(viewZoomLevelChanged(unsigned long, bool)));
 
-    if (m_followPlay != PlaybackIgnore) {
+    if (m_followPlay == PlaybackScrollPage) {
+//        std::cerr << "View::setViewManager: setting centre frame to global centre frame: " << m_manager->getGlobalCentreFrame() << std::endl;
+        setCentreFrame(m_manager->getGlobalCentreFrame(), false);
+    } else if (m_followPlay == PlaybackScrollContinuous) {
 //        std::cerr << "View::setViewManager: setting centre frame to playback frame: " << m_manager->getPlaybackFrame() << std::endl;
         setCentreFrame(m_manager->getPlaybackFrame(), false);
     } else if (m_followPan) {
@@ -880,8 +895,10 @@
 {
     if (m_followPan) {
         size_t f = alignFromReference(rf);
+#ifdef DEBUG_VIEW_WIDGET_PAINT
         std::cerr << "View[" << this << "]::globalCentreFrameChanged(" << rf
                   << "): setting centre frame to " << f << std::endl;
+#endif
         setCentreFrame(f, false);
     }
 }
@@ -1108,6 +1125,7 @@
     }
 
     Model *anyModel = 0;
+    Model *alignedModel = 0;
     Model *goodModel = 0;
 
     for (LayerList::const_iterator i = m_layers.begin();
@@ -1121,8 +1139,10 @@
         Model *model = (*i)->getModel();
         if (!model) continue;
 
+        anyModel = model;
+
         if (model->getAlignmentReference()) {
-            anyModel = model;
+            alignedModel = model;
             if (layer->isLayerOpaque() ||
                 dynamic_cast<RangeSummarisableTimeValueModel *>(model)) {
                 goodModel = model;
@@ -1131,6 +1151,7 @@
     }
 
     if (goodModel) return goodModel;
+    else if (alignedModel) return alignedModel;
     else return anyModel;
 }
 
@@ -1399,6 +1420,14 @@
 }
 
 void
+View::setPaintFont(QPainter &paint)
+{
+    QFont font(paint.font());
+    font.setPointSize(Preferences::getInstance()->getViewFontSize());
+    paint.setFont(font);
+}
+
+void
 View::paintEvent(QPaintEvent *e)
 {
 //    Profiler prof("View::paintEvent", false);
@@ -1583,7 +1612,7 @@
 
 	if (repaintCache) paint.begin(m_cache);
 	else paint.begin(this);
-
+        setPaintFont(paint);
 	paint.setClipRect(cacheRect);
 
         paint.setPen(getBackground());
@@ -1624,7 +1653,7 @@
 
     paint.begin(this);
     paint.setClipRect(nonCacheRect);
-
+    setPaintFont(paint);
     if (scrollables.empty()) {
         paint.setPen(getBackground());
         paint.setBrush(getBackground());
@@ -1642,6 +1671,7 @@
     paint.end();
 
     paint.begin(this);
+    setPaintFont(paint);
     if (e) paint.setClipRect(e->rect());
     if (!m_selectionCached) {
 	drawSelections(paint);
@@ -1885,6 +1915,8 @@
     
     int labelCount = 0;
 
+    // top-left point, x-coord
+
     if ((b0 = topLayer->getXScaleValue(this, r.x(), v0, u0))) {
         axs = QString("%1 %2").arg(v0).arg(u0);
         if (u0 == "Hz" && Pitch::isFrequencyInMidiRange(v0)) {
@@ -1894,6 +1926,8 @@
         aw = paint.fontMetrics().width(axs);
         ++labelCount;
     }
+
+    // bottom-right point, x-coord
         
     if (r.width() > 0) {
         if ((b1 = topLayer->getXScaleValue(this, r.x() + r.width(), v1, u1))) {
@@ -1905,15 +1939,19 @@
             bw = paint.fontMetrics().width(bxs);
         }
     }
+
+    // dimension, width
         
     if (b0 && b1 && v1 != v0 && u0 == u1) {
-        dxs = QString("(%1 %2)").arg(fabs(v1 - v0)).arg(u1);
+        dxs = QString("[%1 %2]").arg(fabs(v1 - v0)).arg(u1);
         dw = paint.fontMetrics().width(dxs);
     }
     
     b0 = false;
     b1 = false;
 
+    // top-left point, y-coord
+
     if ((b0 = topLayer->getYScaleValue(this, r.y(), v0, u0))) {
         ays = QString("%1 %2").arg(v0).arg(u0);
         if (u0 == "Hz" && Pitch::isFrequencyInMidiRange(v0)) {
@@ -1924,6 +1962,8 @@
         ++labelCount;
     }
 
+    // bottom-right point, y-coord
+
     if (r.height() > 0) {
         if ((b1 = topLayer->getYScaleValue(this, r.y() + r.height(), v1, u1))) {
             bys = QString("%1 %2").arg(v1).arg(u1);
@@ -1939,13 +1979,24 @@
     float dy = 0.f;
     QString du;
 
+    // dimension, height
+        
     if ((bd = topLayer->getYScaleDifference(this, r.y(), r.y() + r.height(),
                                             dy, du)) &&
         dy != 0) {
         if (du != "") {
-            dys = QString("(%1 %2)").arg(dy).arg(du);
+            if (du == "Hz") {
+                int semis;
+                float cents;
+                semis = Pitch::getPitchForFrequencyDifference(v0, v1, &cents);
+                dys = QString("[%1 %2 (%3)]")
+                    .arg(dy).arg(du)
+                    .arg(Pitch::getLabelForPitchRange(semis, cents));
+            } else {
+                dys = QString("[%1 %2]").arg(dy).arg(du);
+            }
         } else {
-            dys = QString("(%1)").arg(dy);
+            dys = QString("[%1]").arg(dy);
         }
         dw = std::max(dw, paint.fontMetrics().width(dys));
     }