cleanup image save dialog aesthetics
authorDiane Trout <diane@caltech.edu>
Thu, 12 Oct 2006 23:52:19 +0000 (23:52 +0000)
committerDiane Trout <diane@caltech.edu>
Thu, 12 Oct 2006 23:52:19 +0000 (23:52 +0000)
ticket:96
one of the problems is that when people try saving an image they
couldn't find where the image was saved too. This is probably because
they didn't set a file name and no errors were thrown.

this patch ties the "save as" prompt to the save button, so once someone
gets the pixel size right they have to chose a filename.

I also fixed the problem where it wasn't loading the "lock aspect ratio"
icon out of the resource file, and made a few other aesthetics updates.

qui/ImageSaveDialog.cpp
qui/ImageSaveDialog.hpp
qui/ImageScaler.cpp
qui/ImageScaler.hpp

index 3c5b0095f071b558884e6dd3c3cb5dda913897ea..0357af402dc97c7585c1a2995b4d8053d045c8c1 100644 (file)
@@ -1,10 +1,10 @@
 #include <QDialog>
 #include <QFileDialog>
-#include <QGridLayout>
+#include <QVBoxLayout>
+#include <QHBoxLayout>
 #include <QLabel>
 #include <QPixmap>
 #include <QPushButton>
-//#include <QVBoxLayout>
 #include <QGLWidget>
 
 #include "ImageSaveDialog.hpp"
@@ -15,7 +15,7 @@
 ImageSaveDialog::ImageSaveDialog(QGLWidget *newglwidget, QWidget *parent)
   : QDialog(parent)
 {
-  setWindowTitle(tr("Save Mussa Image"));
+  setWindowTitle(tr("Mussa Save Image"));
 
   // Init
   glwidget = newglwidget;
@@ -30,16 +30,6 @@ ImageSaveDialog::ImageSaveDialog(QGLWidget *newglwidget, QWidget *parent)
     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);
@@ -52,26 +42,35 @@ ImageSaveDialog::ImageSaveDialog(QGLWidget *newglwidget, QWidget *parent)
          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);
+  QHBoxLayout *button_layout = new QHBoxLayout;
+  button_layout->addStretch(1);
+  button_layout->addWidget(saveButton);
+  button_layout->addWidget(cancelButton);
+  
+  QHBoxLayout *image_centerer = new QHBoxLayout;
+  image_centerer->addStretch(1);
+  image_centerer->addWidget(imageScaler);
+  image_centerer->addStretch(1);
+  QVBoxLayout *layout = new QVBoxLayout;
+  
+  layout->addStretch(1);
+  layout->addLayout(image_centerer);
+  layout->addStretch(1);
+  layout->addLayout(button_layout);
   setLayout(layout);
 }
 
-
 void ImageSaveDialog::accept()
 {
-  std::cout << "Accepted!\n";
-  savePixmap();
-  done(1);
+  bool endDialog = true;
+  savePixmap(endDialog);
+  if (endDialog) {
+    done(1);
+  }
 }
 
 void ImageSaveDialog::reject()
 {
-  std::cout << "Rejected!\n";
   done(0);
 }
 
@@ -81,32 +80,6 @@ void ImageSaveDialog::setSize(int width, int height)
   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();
@@ -135,25 +108,33 @@ QPixmap ImageSaveDialog::renderOpenGlPixmap()
   return QPixmap();
 }
 
-void ImageSaveDialog::savePixmap()
+void ImageSaveDialog::savePixmap(bool &endDialog)
 {
   QString filePath;
-  filePath = filePathLabel->text();
-  
-  if (filePath.isEmpty())
-    //FIXME: Include prompt telling user of failure
-    return;
-
-  QPixmap pixmap;
-  pixmap = renderOpenGlPixmap();
+  filePath = QFileDialog::getSaveFileName(this,
+            "Choose a filename to save image",
+            ".",
+            "Images (*.png *.jpg)");  
+
+  if (filePath.isNull()) {
+    // user canceled
+    endDialog = false;;
+  } else if (filePath.isEmpty()) {
+    // somethings wrong
+    endDialog = false;
+  } else {
+    QPixmap pixmap;
+    pixmap = renderOpenGlPixmap();
   
-  //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;
+    endDialog = true;
+    //Save pixelmap to file!
+    if (filePath.endsWith(".png"))
+      pixmap.save(filePath, "PNG");
+    else if (filePath.endsWith(".jpg"))
+      pixmap.save(filePath, "JPG");
+    else {
+      filePath.append(".png");
+      pixmap.save(filePath, "PNG");
+    }
+  }
 }
index beda6ee95e2107e8c64e3e89447880b00f888a28..411bfe97d5951176539d6f4a4df505f0f134d7bf 100644 (file)
@@ -19,25 +19,22 @@ public:
 public slots:
   void accept();
   void reject();
-  //  int exec();
-  void promptFileDialog();
   void setSize(int width, int height);
 
-signals:
-
 private:
-  void savePixmap();
+  //! prompt user for file name and save image, if (endDialog) close dialog
+  /** if endDialog is true, we should close the dialog box,
+   *  otherwise, keep the dialog box. (In case the user canceled out
+   *  of save as.
+   */  
+  void savePixmap(bool &endDialog);
   QSize getOpenGlPixmapSize();
   QPixmap renderOpenGlPixmap();
 
   ImageScaler *imageScaler;
-  //QPixmap *pixmap;
-  QLabel *filePathLabel;
-  QPushButton *browseButton;
   QPushButton *saveButton;
   QPushButton *cancelButton;
-  QGLWidget *glwidget;
-  
+  QGLWidget *glwidget;  
 };
 
 #endif 
index dbf9d58b63c7a5f1ef96015b2918ea5429191d5c..9593d7bec463f990704b1d615635fdd1db92a38b 100644 (file)
@@ -10,7 +10,7 @@
 #include "ImageScaler.hpp"
 
 ImageScaler::ImageScaler(QWidget *parent)
-  : QWidget(parent)
+  : QFrame(parent)
 {
   lockAspectRatio = false;
   aspectRatio = 1.0;
@@ -19,11 +19,10 @@ ImageScaler::ImageScaler(QWidget *parent)
   curWidth = 1;
   curHeight = 1;
   
-  //lockAspectAction = new QAction(
-  //lockAspectAction->setCheckable(true);
-
+  setFrameStyle(QFrame::StyledPanel);
+   
   lockButton = new QCheckBox();
-  lockButton->setIcon(QIcon(tr("icons/lock.png")));
+  lockButton->setIcon(QIcon(":icons/lock.png"));
   lockButton->setToolTip(tr("Lock aspect ratio"));
   lockButton->setWhatsThis(tr("Lock aspect ratio"));
   connect(lockButton, SIGNAL(stateChanged(int)), 
index 86c2696c1f7b84ebad7a55936a89bd6f317caaa7..22a7377e6161f26cdaf03b5826e57f2f81bae5ae 100644 (file)
@@ -1,14 +1,14 @@
 #ifndef _IMAGESCALER_H_
 #define _IMAGESCALER_H_
 
-#include <QWidget>
+#include <QFrame>
 
 class QSpinBox;
 class QLabel;
 class QAction;
 class QCheckBox;
 
-class ImageScaler : public QWidget
+class ImageScaler : public QFrame
 {
   Q_OBJECT