31 #include <QMessageBox> 
   32 #include <QImageWriter> 
   33 #include <QVBoxLayout> 
   34 #include <QHBoxLayout> 
   35 #include <QDialogButtonBox> 
   37 #include <QPushButton>  
   38 #include <QFileDialog> 
   50                                    QWidget* render_window,
 
   51                                    const QString& default_save_dir)
 
   53   , main_window_(main_window)
 
   54   , render_window_(render_window)
 
   55   , save_full_window_(false)
 
   56   , delay_timer_(new QTimer(this))
 
   58   , default_save_dir_(default_save_dir)
 
   64   QCheckBox* full_window_checkbox = 
new QCheckBox(
"Save entire rviz window");
 
   67       new QDialogButtonBox(QDialogButtonBox::Save | QDialogButtonBox::Retry | QDialogButtonBox::Cancel);
 
   69   QVBoxLayout* main_layout = 
new QVBoxLayout;
 
   71   main_layout->addWidget(
new QLabel(
"Image will be saved at the original resolution."));
 
   72   main_layout->addWidget(full_window_checkbox);
 
   75   setLayout(main_layout);
 
   87     move(center.x() - width() / 2, center.y() - height() / 2);
 
   91   QWidget::showEvent(event);
 
  117   screenshot_ = w->windowHandle()->screen()->grabWindow(w->winId());
 
  123   if (clicked == 
button_box_->button(QDialogButtonBox::Save))
 
  127   else if (clicked == 
button_box_->button(QDialogButtonBox::Retry))
 
  131   else if (clicked == 
button_box_->button(QDialogButtonBox::Cancel))
 
  140                               QDateTime::currentDateTime().toString(
"yyyy_MM_dd-hh_mm_ss") + 
".png";
 
  141   QString filename = QFileDialog::getSaveFileName(
this, 
"Save image", default_save_file);
 
  144     QString with_slashes = QDir::fromNativeSeparators(filename);
 
  145     QString file_part = with_slashes.section(
'/', -1);
 
  152     if (file_part.lastIndexOf(
".") <= 0)
 
  156     QImageWriter writer(filename);
 
  163       QString error_message;
 
  164       if (writer.error() == QImageWriter::UnsupportedFormatError)
 
  166         QString suffix = filename.section(
'.', -1);
 
  167         QString formats_string;
 
  168         QList<QByteArray> formats = QImageWriter::supportedImageFormats();
 
  169         formats_string = formats[0];
 
  170         for (
int i = 1; i < formats.size(); i++)
 
  172           formats_string += 
", " + formats[i];
 
  175         error_message = 
"File type '" + suffix + 
"' is not supported.\n" +
 
  176                         "Supported image formats are: " + formats_string + 
"\n";
 
  180         error_message = 
"Failed to write image to file " + filename;
 
  183       QMessageBox::critical(
this, 
"Error", error_message);