29 #include <osgDB/WriteFile>
31 #include <QtCore/QDir>
32 #include <QtCore/QEvent>
33 #include <QApplication>
36 #include "core/common/WLogger.h"
37 #include "events/WEventTypes.h"
38 #include "WMainWindow.h"
39 #include "WQtGLWidget.h"
40 #include "WQtGLDockWidget.h"
42 #include "WQtGLScreenCapture.h"
46 m_glDockWidget( parent ),
47 m_viewer( m_glDockWidget->getGLWidget()->getViewer() )
50 setObjectName(
"Recorder Dock - " + parent->
getDockTitle() );
51 setWindowTitle(
"Recorder - " + parent->
getDockTitle() );
55 QHBoxLayout* layout =
new QHBoxLayout(
this );
65 QVBoxLayout* configLayout =
new QVBoxLayout();
69 QGroupBox* frameCounterGroup =
new QGroupBox(
"Frame" );
70 QVBoxLayout* frameCounterGroupLayout =
new QVBoxLayout();
71 frameCounterGroup->setLayout( frameCounterGroupLayout );
79 QGroupBox* resolutionGroup =
new QGroupBox(
"Resolution" );
80 QGridLayout* resolutionGroupLayout =
new QGridLayout();
81 resolutionGroup->setLayout( resolutionGroupLayout );
97 QPushButton* resolutionButton =
new QPushButton(
"Set" );
98 resolutionButton->setCheckable(
true );
100 resolutionGroupLayout->addWidget( resolutionButton, 0, 2 );
101 resolutionGroupLayout->addWidget(
new QLabel(
"Custom Resolution" ), 1, 0, 1, 3 );
105 connect( resolutionButton, SIGNAL( toggled(
bool ) ),
this, SLOT(
resolutionChange(
bool ) ) );
108 QGroupBox* fileGroup =
new QGroupBox(
"Output Files" );
109 QVBoxLayout* fileGroupLayout =
new QVBoxLayout();
110 fileGroup->setLayout( fileGroupLayout );
112 QLabel* configFileHint =
new QLabel();
113 configFileHint->setWordWrap(
true );
114 configFileHint->setText(
115 "The filename used for all captured frames. This filename can contain some special tags which get replaced:"
117 "<li> %f - the frame number"
122 std::string defaultFilename = ( QDir::homePath() + QDir::separator() +
123 "OpenWalnut - " + parent->
getDockTitle() +
" - Frame %f.png" ).toStdString();
126 fileGroupLayout->addWidget( configFileHint );
130 configLayout->addWidget( resolutionGroup );
131 configLayout->addWidget( frameCounterGroup );
132 configLayout->addWidget( fileGroup );
139 QVBoxLayout* screenshotLayout =
new QVBoxLayout();
151 QLabel* screenshotLabel =
new QLabel();
152 screenshotLabel->setWordWrap(
true );
153 screenshotLabel->setText(
"Take a screenshot of the current scene with the current camera. You need to specify "
154 "a filename in the toolbox item \"Configuration\"." );
155 screenshotLayout->addWidget( screenshotLabel );
163 QVBoxLayout* movieLayout =
new QVBoxLayout();
166 QLabel* movieLabel =
new QLabel();
167 movieLabel->setWordWrap(
true );
168 movieLabel->setText(
"Take a screenshot for every frame with the current camera. You need to specify a filename "
169 "in the toolbox item \"Configuration\". "
170 "You should always add %f to your filename to differentiate between each frame. "
171 "This kind of recording can be very slow and produce a high IO load on your machine. Consider recording movies with "
172 "the animation tool which plays back a previously recorded scene and snapshot it frame-wise. "
173 "To create a movie with these images, you can use free encoders like ffmpeg, transcode or mencoder."
175 movieLabel->setTextInteractionFlags( Qt::TextSelectableByKeyboard | Qt::TextSelectableByMouse );
187 movieLayout->addWidget( movieLabel );
197 QCoreApplication::postEvent(
this,
new QEvent(
static_cast< QEvent::Type
>( WQT_SCREENCAPTURE_EVENT ) ) );
208 boost::placeholders::_1,
209 boost::placeholders::_2,
210 boost::placeholders::_3 ) );
244 std::ostringstream ss;
247 ss.setf( std::ios::right, std::ios::adjustfield );
248 ss.setf( std::ios::fixed, std::ios::floatfield );
255 while( ( pos = filename.find(
"%f" ) ) != std::string::npos )
257 filename.replace( pos, 2, ss.str() );
260 wlog::info(
"WQtGLScreenCapture" ) <<
"Writing frame " << totalFrames <<
" to " << filename;
261 osgDB::writeImageFile( *image, filename );
267 if(
event->type() == WQT_SCREENCAPTURE_EVENT )
271 size_t frame = r->get().m_frames;
272 size_t framesLeft = r->get().m_framesLeft;
276 std::ostringstream time;
278 time <<
"Recorded Movie-Time: " <<
static_cast< float >( frame ) / 24.0f;
281 std::ostringstream frames;
282 frames <<
"Recorded Frames: " << frame;
286 if( framesLeft == 0 )
302 return QWidget::event(
event );
307 m_viewer->getScreenCapture()->screenshot();
312 wlog::info(
"WQtGLScreenCapture" ) <<
"Started recording.";
313 m_viewer->getScreenCapture()->recordStart();
318 wlog::info(
"WQtGLScreenCapture" ) <<
"Stopped recording.";
319 m_viewer->getScreenCapture()->recordStop();
324 wlog::debug(
"WQtGLScreenCapture" ) <<
"Resetting frame-counter.";
325 m_viewer->getScreenCapture()->resetFrameCounter();
330 QCoreApplication::postEvent(
this,
new QEvent(
static_cast< QEvent::Type
>( WQT_SCREENCAPTURE_EVENT ) ) );
342 wlog::debug(
"WQtGLScreenCapture" ) <<
"Forcing resolution";
371 wlog::debug(
"WQtGLScreenCapture" ) <<
"Restoring resolution";
QLineEdit * m_customHeight
Widget for entering a custom resolution height.
void resetFrames()
Slot triggered by m_configFrameResetButton.
void screenShot()
Initiates taking a screenshot.
virtual ~WQtGLScreenCapture()
Destructor.
boost::signals2::connection m_recordConnection
Recording - callback connection.
QPushButton * m_screenshotButton
The trigger which triggers the screenshot.
QWidget * m_screenshotWidget
Widget containing all the widgets to control movie recording.
QLabel * m_configFrameLabel
Shows recorded frames.
QWidget * m_configWidget
The configuration widget.
QPushButton * m_movieRecButton
record button
boost::signals2::connection m_imageConnection
New image incoming - callback connection to handleImage.
void handleImage(size_t framesLeft, size_t totalFrames, osg::ref_ptr< osg::Image > image) const
The function handles new images.
QPushButton * m_configFrameResetButton
Triggers frame counter reset.
WGEViewer::SPtr m_viewer
The actual screen capture instance.
QToolBox * m_toolbox
The toolbox containing all the stuff.
void toolBoxChanged(int index)
Someone changed the open tab in the toolbox.
virtual void saveSettings()
Save settings.
virtual void restoreSettings()
Restore settings.
QAction * m_screenshotAction
This action triggers a screenshot.
void resolutionChange(bool force)
Changes resolution of gl widget.
void stopRec()
Slot triggered by m_moveStopButton.
void startRec()
Slot triggered by m_moveRecButton.
QPushButton * m_movieStopButton
stop button
QWidget * m_movieWidget
Widget containing all the widgets to control movie recording.
QAction * getScreenshotTrigger() const
Returns the trigger used for screenshotting.
QLabel * m_movieTimeLabel
Shows recorded time in movie-time.
QComboBox * m_resolutionCombo
Stores the resolution the user wants to have.
void recCallback()
Called by the screencapture callback to notify this widget about recording.
WQtGLScreenCapture(WQtGLDockWidget *parent)
Creates screen capture gui for the specified capture callback of a certain view.
QLineEdit * m_customWidth
Widget for entering a custom resolution width.
QLineEdit * m_configFileEdit
The filename for the screenshot.
WQtGLDockWidget * m_glDockWidget
My parent.
virtual bool event(QEvent *event)
Custom event dispatcher.
static QSettings & getSettings()
Returns the settings object.
static WIconManager * getIconManager()
Get the icon manager of this gui instance.
std::shared_ptr< WSharedObjectTicketRead< RecordingInformation > > ReadTicket
Type for read tickets.
WStreamedLogger debug(const std::string &source)
Logging a debug message.
WStreamedLogger info(const std::string &source)
Logging an information message.