31 #include <QMessageBox> 32 #include <QImageWriter> 33 #include <QVBoxLayout> 34 #include <QHBoxLayout> 35 #include <QDialogButtonBox> 37 #include <QPushButton> 38 #include <QFileDialog> 50 , main_window_( main_window )
51 , render_window_( render_window )
52 , save_full_window_( false )
53 , delay_timer_( new QTimer( this ))
55 , default_save_dir_( default_save_dir )
61 QCheckBox* full_window_checkbox =
new QCheckBox(
"Save entire rviz window" );
63 button_box_ =
new QDialogButtonBox( QDialogButtonBox::Save |
64 QDialogButtonBox::Retry |
65 QDialogButtonBox::Cancel );
67 QVBoxLayout* main_layout =
new QVBoxLayout;
69 main_layout->addWidget(
new QLabel(
"Image will be saved at the original resolution." ));
70 main_layout->addWidget( full_window_checkbox );
73 setLayout( main_layout );
76 connect( full_window_checkbox, SIGNAL( toggled(
bool )),
this, SLOT(
setSaveFullWindow(
bool )));
85 move( center.x() - width() / 2,
86 center.y() - height() / 2 );
90 QWidget::showEvent( event );
128 if( clicked ==
button_box_->button( QDialogButtonBox::Save ))
132 else if( clicked ==
button_box_->button( QDialogButtonBox::Retry ))
136 else if( clicked ==
button_box_->button( QDialogButtonBox::Cancel ))
144 QString default_save_file =
146 "/rviz_screenshot_" +
147 QDateTime::currentDateTime().toString(
"yyyy_MM_dd-hh_mm_ss" ) +
149 QString
filename = QFileDialog::getSaveFileName(
this,
"Save image", default_save_file );
152 QString with_slashes = QDir::fromNativeSeparators( filename );
153 QString file_part = with_slashes.section(
'/', -1 );
154 default_save_dir_ = QDir::toNativeSeparators( with_slashes.section(
'/', 0, -2 ));
160 if( file_part.lastIndexOf(
"." ) <= 0 )
164 QImageWriter writer( filename );
171 QString error_message;
172 if( writer.error() == QImageWriter::UnsupportedFormatError )
174 QString suffix = filename.section(
'.', -1 );
175 QString formats_string;
176 QList<QByteArray> formats = QImageWriter::supportedImageFormats();
177 formats_string = formats[0];
178 for(
int i = 1; i < formats.size(); i++ )
180 formats_string +=
", " + formats[ i ];
184 "File type '" + suffix +
"' is not supported.\n" +
185 "Supported image formats are: " + formats_string +
"\n";
189 error_message =
"Failed to write image to file " + filename;
192 QMessageBox::critical(
this,
"Error", error_message );
ScreenshotDialog(QWidget *main_window, QWidget *render_window, const QString &default_save_dir=QString())
void savedInDirectory(const QString &directory)
Emitted when the user saves a file.
ScaledImageWidget * image_widget_
QString default_save_dir_
void onButtonClicked(QAbstractButton *clicked)
QDialogButtonBox * button_box_
virtual void showEvent(QShowEvent *event)
void setSaveFullWindow(bool save_full_window)