Save to image fix (ticket:96)
[mussa.git] / qui / ImageSaveDialog.cpp
index 3a0a63f36fa3cb0f297a86d1813e3c0ae3a0b0d0..3248e3a9bdeaf870f6315ace5e786154d5c7a071 100644 (file)
@@ -7,6 +7,12 @@
 #include <QPushButton>
 #include <QGLWidget>
 
+// Win32 debug includes
+//#include <QMessageBox>
+//#include <sstream>
+//#include <string>
+//#include <QString>
+
 #include "ImageSaveDialog.hpp"
 #include "ImageScaler.hpp"
 
 namespace fs = boost::filesystem;
 
 ImageSaveDialog::ImageSaveDialog(boost::shared_ptr<QDir> default_dir_,
-                                 QGLWidget *newglwidget
-                                 QWidget *parent)
+                                ScrollableSequenceBrowser *scrollSeqBrowser
+                                QWidget *parent)
   : QDialog(parent),
+    glwidget(scrollSeqBrowser->browser(), parent),
     default_dir(default_dir_)
 {
   setWindowTitle(tr("Mussa Save Image"));
 
   // Init
-  glwidget = newglwidget;
+
   //pixmap = 0;
   imageScaler = new ImageScaler();
 
-  if (glwidget)
-  {
-    QSize tmpSize;
-    tmpSize = glwidget->size();
-    imageScaler->setWidth(tmpSize.width());
-    imageScaler->setHeight(tmpSize.height());
-  }
+  imageScaler->setWidth(static_cast<int>(glwidget.width()));
+  imageScaler->setHeight(static_cast<int>(glwidget.height()));
   
   // Save Button
   saveButton = new QPushButton(tr("Save"));
@@ -64,6 +66,7 @@ ImageSaveDialog::ImageSaveDialog(boost::shared_ptr<QDir> default_dir_,
   layout->addStretch(1);
   layout->addLayout(button_layout);
   setLayout(layout);
+
 }
 
 QDir ImageSaveDialog::defaultDir() const
@@ -106,14 +109,32 @@ QSize ImageSaveDialog::getOpenGlPixmapSize()
 
 QPixmap ImageSaveDialog::renderOpenGlPixmap()
 {
-  if (!glwidget)
-    return QPixmap();
-
-  
   QSize size = getOpenGlPixmapSize();
   if (size.isValid()) 
   {
-    QPixmap pixmap = glwidget->renderPixmap(size.width(), size.height());
+    double cur_bp_per_pixel = glwidget.zoom();
+    float cur_width = glwidget.width();
+    float cur_height = glwidget.height();
+    
+    // Useful debug code (in windows)... hopefully never to be used again. =o)
+    //QString msg = "Zoom:   " + QString().setNum(cur_bp_per_pixel) + "\n" + 
+    //  "Width:  " + QString().setNum(cur_width) + "\n" +
+    //  "Height: " + QString().setNum(cur_height) + "\n";
+    //
+    //QMessageBox::information(this, "Debug2", 
+    //                      msg );
+    //
+
+    // When the width requested by the user is doubled, the 
+    // bp per pixel is halved in order to scale the image properly.
+    double new_bp_per_pixel = ( cur_width / size.width() ) * cur_bp_per_pixel;
+
+    // bp per pixel needs to be scaled based when the width changes
+    glwidget.setZoom(new_bp_per_pixel);
+
+    // draw pixmp
+    QPixmap pixmap = glwidget.renderPixmap(size.width(), size.height());
+
     return pixmap;    
   }
   return QPixmap();