changeset 229:387f2f6fc333 sv1-1.0pre2

* Remove tip dialog for now. I don't like it enough * Fixes to export image
author Chris Cannam
date Wed, 14 Mar 2007 14:39:39 +0000
parents 1c4c9e3e44e6
children e52ed907cc42
files view/Pane.cpp view/Pane.h view/View.cpp view/View.h widgets/ListInputDialog.cpp widgets/ListInputDialog.h widgets/TipDialog.cpp
diffstat 7 files changed, 71 insertions(+), 24 deletions(-) [+]
line wrap: on
line diff
--- a/view/Pane.cpp	Tue Mar 13 19:51:09 2007 +0000
+++ b/view/Pane.cpp	Wed Mar 14 14:39:39 2007 +0000
@@ -703,10 +703,9 @@
 }
 
 bool
-Pane::render(QPainter &paint, QRect rect)
+Pane::render(QPainter &paint, int xorigin, size_t f0, size_t f1)
 {
-    if (!View::render(paint, QRect(rect.x() + m_scaleWidth, rect.y(),
-                                   rect.width() - m_scaleWidth, rect.height()))) {
+    if (!View::render(paint, xorigin + m_scaleWidth, f0, f1)) {
         return false;
     }
 
@@ -719,11 +718,11 @@
             
             paint.setPen(Qt::black);
             paint.setBrush(Qt::white);
-            paint.drawRect(0, -1, m_scaleWidth, height()+1);
+            paint.drawRect(xorigin, -1, m_scaleWidth, height()+1);
             
             paint.setBrush(Qt::NoBrush);
             (*vi)->paintVerticalScale
-                (this, paint, QRect(0, 0, m_scaleWidth, height()));
+                (this, paint, QRect(xorigin, 0, m_scaleWidth, height()));
             
             paint.restore();
             break;
@@ -734,11 +733,8 @@
 }
 
 QImage *
-Pane::toNewImage()
+Pane::toNewImage(size_t f0, size_t f1)
 {
-    size_t f0 = getModelsStartFrame();
-    size_t f1 = getModelsEndFrame();
-
     size_t x0 = f0 / getZoomLevel();
     size_t x1 = f1 / getZoomLevel();
 
@@ -765,7 +761,7 @@
     }        
 
     QPainter *paint = new QPainter(image);
-    if (!render(*paint, image->rect())) {
+    if (!render(*paint, 0, f0, f1)) {
         delete paint;
         delete image;
         return 0;
@@ -775,6 +771,26 @@
     }
 }
 
+QSize
+Pane::getImageSize(size_t f0, size_t f1)
+{
+    QSize s = View::getImageSize(f0, f1);
+    QImage *image = new QImage(100, 100, QImage::Format_RGB32);
+    QPainter paint(image);
+
+    int sw = 0;
+    if (m_manager && m_manager->shouldShowVerticalScale()) {
+        for (LayerList::iterator vi = m_layers.end(); vi != m_layers.begin(); ) {
+            --vi;
+            QPainter paint(image);
+            sw = (*vi)->getVerticalScaleWidth(this, paint);
+            break;
+        }
+    }
+    
+    return QSize(sw + s.width(), s.height());
+}
+
 size_t
 Pane::getFirstVisibleFrame() const
 {
--- a/view/Pane.h	Tue Mar 13 19:51:09 2007 +0000
+++ b/view/Pane.h	Wed Mar 14 14:39:39 2007 +0000
@@ -50,8 +50,10 @@
 
     virtual size_t getFirstVisibleFrame() const;
 
-    virtual bool render(QPainter &paint, QRect rect);
-    virtual QImage *toNewImage();
+    virtual QImage *toNewImage(size_t f0, size_t f1);
+    virtual QImage *toNewImage() { return View::toNewImage(); }
+    virtual QSize getImageSize(size_t f0, size_t f1);
+    virtual QSize getImageSize() { return View::getImageSize(); }
 
     virtual QString toXmlString(QString indent = "",
 				QString extraAttributes = "") const;
@@ -86,6 +88,8 @@
     virtual void wheelEvent(QWheelEvent *e);
     virtual void resizeEvent(QResizeEvent *e);
 
+    virtual bool render(QPainter &paint, int x0, size_t f0, size_t f1);
+
     Selection getSelectionAt(int x, bool &closeToLeft, bool &closeToRight) const;
 
     bool editSelectionStart(QMouseEvent *e);
--- a/view/View.cpp	Tue Mar 13 19:51:09 2007 +0000
+++ b/view/View.cpp	Wed Mar 14 14:39:39 2007 +0000
@@ -1612,11 +1612,8 @@
 }
 
 bool
-View::render(QPainter &paint, QRect rect)
+View::render(QPainter &paint, int xorigin, size_t f0, size_t f1)
 {
-    size_t f0 = getModelsStartFrame();
-    size_t f1 = getModelsEndFrame();
-
     size_t x0 = f0 / m_zoomLevel;
     size_t x1 = f1 / m_zoomLevel;
 
@@ -1680,7 +1677,7 @@
             return false;
         }
 
-        m_centreFrame = (x + width()/2) * m_zoomLevel;
+        m_centreFrame = f0 + (x + width()/2) * m_zoomLevel;
         
         QRect chunk(0, 0, width(), height());
 
@@ -1692,7 +1689,7 @@
 	    paint.setBrush(Qt::black);
 	}
 
-	paint.drawRect(QRect(rect.x() + x, rect.y(), width(), height()));
+	paint.drawRect(QRect(xorigin + x, 0, width(), height()));
 
 	paint.setPen(Qt::black);
 	paint.setBrush(Qt::NoBrush);
@@ -1703,9 +1700,9 @@
 	    paint.setRenderHint(QPainter::Antialiasing, false);
 
 	    paint.save();
-            paint.translate(rect.x() + x, rect.y());
+            paint.translate(xorigin + x, 0);
 
-//            std::cerr << "Centre frame now: " << m_centreFrame << " drawing to " << chunk.x() << ", " << chunk.width() << std::endl;
+            std::cerr << "Centre frame now: " << m_centreFrame << " drawing to " << chunk.x() + x + xorigin << ", " << chunk.width() << std::endl;
 
 	    (*i)->paint(this, paint, chunk);
 
@@ -1724,13 +1721,19 @@
     size_t f0 = getModelsStartFrame();
     size_t f1 = getModelsEndFrame();
 
+    return toNewImage(f0, f1);
+}
+
+QImage *
+View::toNewImage(size_t f0, size_t f1)
+{
     size_t x0 = f0 / getZoomLevel();
     size_t x1 = f1 / getZoomLevel();
     
     QImage *image = new QImage(x1 - x0, height(), QImage::Format_RGB32);
 
     QPainter *paint = new QPainter(image);
-    if (!render(*paint, image->rect())) {
+    if (!render(*paint, 0, f0, f1)) {
         delete paint;
         delete image;
         return 0;
@@ -1740,6 +1743,24 @@
     }
 }
 
+QSize
+View::getImageSize()
+{
+    size_t f0 = getModelsStartFrame();
+    size_t f1 = getModelsEndFrame();
+
+    return getImageSize(f0, f1);
+}
+    
+QSize
+View::getImageSize(size_t f0, size_t f1)
+{
+    size_t x0 = f0 / getZoomLevel();
+    size_t x1 = f1 / getZoomLevel();
+
+    return QSize(x1 - x0, height());
+}
+
 QString
 View::toXmlString(QString indent, QString extraAttributes) const
 {
--- a/view/View.h	Tue Mar 13 19:51:09 2007 +0000
+++ b/view/View.h	Wed Mar 14 14:39:39 2007 +0000
@@ -215,9 +215,11 @@
     virtual const PropertyContainer *getPropertyContainer(size_t i) const;
     virtual PropertyContainer *getPropertyContainer(size_t i);
 
-    // Render the entire contents on a wide canvas
-    virtual bool render(QPainter &paint, QRect rect);
+    // Render the contents on a wide canvas
+    virtual QImage *toNewImage(size_t f0, size_t f1);
     virtual QImage *toNewImage();
+    virtual QSize getImageSize(size_t f0, size_t f1);
+    virtual QSize getImageSize();
 
     virtual int getTextLabelHeight(const Layer *layer, QPainter &) const;
 
@@ -276,6 +278,7 @@
     virtual void paintEvent(QPaintEvent *e);
     virtual void drawSelections(QPainter &);
     virtual bool shouldLabelSelections() const { return true; }
+    virtual bool render(QPainter &paint, int x0, size_t f0, size_t f1);
 
     typedef std::vector<Layer *> LayerList;
 
--- a/widgets/ListInputDialog.cpp	Tue Mar 13 19:51:09 2007 +0000
+++ b/widgets/ListInputDialog.cpp	Wed Mar 14 14:39:39 2007 +0000
@@ -4,6 +4,7 @@
     Sonic Visualiser
     An audio file viewer and annotation editor.
     Centre for Digital Music, Queen Mary, University of London.
+    This file copyright 2006 Chris Cannam.
     
     This program is free software; you can redistribute it and/or
     modify it under the terms of the GNU General Public License as
--- a/widgets/ListInputDialog.h	Tue Mar 13 19:51:09 2007 +0000
+++ b/widgets/ListInputDialog.h	Wed Mar 14 14:39:39 2007 +0000
@@ -4,6 +4,7 @@
     Sonic Visualiser
     An audio file viewer and annotation editor.
     Centre for Digital Music, Queen Mary, University of London.
+    This file copyright 2006 Chris Cannam.
     
     This program is free software; you can redistribute it and/or
     modify it under the terms of the GNU General Public License as
--- a/widgets/TipDialog.cpp	Tue Mar 13 19:51:09 2007 +0000
+++ b/widgets/TipDialog.cpp	Wed Mar 14 14:39:39 2007 +0000
@@ -62,9 +62,10 @@
     QHBoxLayout *hbox = new QHBoxLayout;
     grid->addLayout(hbox, 1, 0);
 
-    QCheckBox *show = new QCheckBox(tr("Show tips on startup"));
+    QCheckBox *show = new QCheckBox(tr("Show tip on startup"));
     hbox->addWidget(show);
 
+    hbox->addSpacing(20);
     hbox->addStretch(10);
     
     QPushButton *prev = new QPushButton(tr("<< Previous"));