--- /dev/null
+#include <QDialog>
+#include <QFileDialog>
+#include <QGridLayout>
+#include <QLabel>
+#include <QPixmap>
+#include <QPushButton>
+//#include <QVBoxLayout>
+#include <QGLWidget>
+
+#include "ImageSaveDialog.h"
+#include "ImageScaler.h"
+
+#include <iostream>
+
+ImageSaveDialog::ImageSaveDialog(QGLWidget *newglwidget, QWidget *parent)
+ : QDialog(parent)
+{
+ // Init
+ glwidget = newglwidget;
+ //pixmap = 0;
+ imageScaler = new ImageScaler();
+
+ if (glwidget)
+ {
+ QSize tmpSize;
+ tmpSize = glwidget->size();
+ imageScaler->setWidth(tmpSize.width());
+ imageScaler->setHeight(tmpSize.height());
+ }
+
+ // File Path Label
+ filePathLabel = new QLabel();
+ filePathLabel->setFrameStyle(QFrame::Panel | QFrame::Sunken);
+ filePathLabel->setMinimumWidth(30);
+
+ // Browse Button
+ browseButton = new QPushButton(tr("Browse..."));
+ connect(browseButton, SIGNAL(clicked()),
+ this, SLOT(promptFileDialog()));
+
+ // Save Button
+ saveButton = new QPushButton(tr("Save"));
+ saveButton->setDefault(true);
+ connect(saveButton, SIGNAL(clicked()),
+ this, SLOT(accept()));
+
+ // Cancel Button
+ cancelButton = new QPushButton(tr("Cancel"));
+ connect(cancelButton, SIGNAL(clicked()),
+ this, SLOT(reject()));
+
+ // Layout
+ QGridLayout *layout = new QGridLayout;
+ layout->addWidget(imageScaler, 0, 0, 1, 0, Qt::AlignCenter);
+ layout->addWidget(filePathLabel, 1, 0);
+ layout->addWidget(browseButton, 1, 1);
+ layout->addWidget(saveButton, 2, 0);
+ layout->addWidget(cancelButton, 2, 1);
+ setLayout(layout);
+}
+
+
+void ImageSaveDialog::accept()
+{
+ std::cout << "Accepted!\n";
+ savePixmap();
+ done(1);
+}
+
+void ImageSaveDialog::reject()
+{
+ std::cout << "Rejected!\n";
+ done(0);
+}
+
+void ImageSaveDialog::setSize(int width, int height)
+{
+ imageScaler->setWidth(width);
+ imageScaler->setHeight(height);
+}
+
+//int ImageSaveDialog::exec()
+//{
+// if (glwidget)
+// {
+// QSize tmpSize;
+// tmpSize = glwidget->size();
+// imageScaler->setWidth(tmpSize.width());
+// imageScaler->setHeight(tmpSize.height());
+// }
+// return QDialog::exec();
+//}
+
+
+void ImageSaveDialog::promptFileDialog()
+{
+ QString filePath;
+ filePath = QFileDialog::getSaveFileName(this,
+ "Choose a filename to save image",
+ ".",
+ "Images (*.png *.jpg)");
+ if (filePath.isEmpty())
+ return;
+
+ filePathLabel->setText(filePath);
+}
+
+QSize ImageSaveDialog::getOpenGlPixmapSize()
+{
+ int width = imageScaler->getWidth();
+ int height = imageScaler->getHeight();
+
+ if (height > 0 && width > 0)
+ {
+ return QSize(width, height);
+ }
+
+ return QSize();
+}
+
+QPixmap ImageSaveDialog::renderOpenGlPixmap()
+{
+ std::cout << "glwidget: " << glwidget << "\n";
+ if (!glwidget)
+ return QPixmap();
+
+ std::cout << "pre get size\n";
+ QSize size = getOpenGlPixmapSize();
+ std::cout << "post get size\n";
+ if (size.isValid())
+ {
+ std::cout << "pre get pixmap\n";
+ QPixmap pixmap = glwidget->renderPixmap(size.width(), size.height());
+ std::cout << "post get pixmap\n";
+ return pixmap;
+ }
+ std::cout << "return empty\n";
+ return QPixmap();
+}
+
+void ImageSaveDialog::savePixmap()
+{
+ QString filePath;
+ filePath = filePathLabel->text();
+
+ std::cout << "File Path: " << filePath.toStdString() << "\n";
+
+ if (filePath.isEmpty())
+ //FIXME: Include prompt telling user of failure
+ return;
+
+ QPixmap pixmap;
+ std::cout << "Before render pixmap!\n";
+ pixmap = renderOpenGlPixmap();
+ std::cout << "After render pixmap!\n";
+
+ //Save pixelmap to file!
+ if (filePath.endsWith(".png"))
+ pixmap.save(filePath, "PNG");
+ else if (filePath.endsWith(".jpg"))
+ pixmap.save(filePath, "JPG");
+ else
+ //FIXME: Include prompt telling user of failure
+ return;
+ return;
+}