Commit 485237f7 authored by Mike Kremer's avatar Mike Kremer

Made snapshot function scriptable. Added function signature that allows the...

Made snapshot function scriptable. Added function signature that allows the specification of user-defined snapshoit dimensions.

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@9909 383ad7c9-94d9-4d36-a494-682f7c89f535
parent 5cf3fd50
......@@ -1207,7 +1207,7 @@ void Core::snapshotBaseFileName(const QString& _fname, unsigned int _viewerId ){
}
void Core::snapshot( unsigned int _viewerId ){
void Core::snapshot( unsigned int _viewerId, int _width, int _height ){
if ( OpenFlipper::Options::gui() ) {
......@@ -1215,7 +1215,7 @@ void Core::snapshot( unsigned int _viewerId ){
emit log(LOGERR,tr("Unable to create snapshot for viewer ") + QString::number(_viewerId) );
return;
}
coreWidget_->examiner_widgets_[_viewerId]->snapshot();
coreWidget_->examiner_widgets_[_viewerId]->snapshot(_width, _height);
}
}
......@@ -1334,8 +1334,22 @@ void Core::setDescriptions(){
, QStringList(), QStringList());
emit setSlotDescription("snapshot()", tr("Make a snapshot of the viewer. If no filename"
" was set using snapshotBaseFileName() the snapshot is stored"
" in snap.png in the current directory. The captured image will have "
" the same dimensions as the current viewport. "
"For every snapshot a counter is added to the filename."), QStringList(), QStringList());
emit setSlotDescription("snapshot(uint)", tr("Make a snapshot of the viewer with id viewerId. If no filename"
" was set using snapshotBaseFileName() the snapshot is stored"
" in snap.png in the current directory. For every snapshot"
" a counter is added to the filename."), QStringList("viewerId"), QStringList("Id of viewer to be captured (default is 0)"));
emit setSlotDescription("snapshot(uint,int,int)", tr("Make a snapshot of the viewer with id viewerId."
" Pass 0 as viewerId parameter to capture the current viewer. "
" The captured image will have the specified dimensions. "
" If 0 is passed as either width or height parameter, the value will "
" automatically be set to hold the right aspect ratio, respectively. "
" If no filename was set using snapshotBaseFileName() the snapshot is stored"
" in snap.png in the current directory. For every snapshot"
" a counter is added to the filename."), QStringList(), QStringList());
" a counter is added to the filename."), QStringList(QString("viewerId;width;height").split(";")),
QStringList(QString("Id of viewer (default is 0);Width of image;Height of image").split(";")));
emit setSlotDescription("resizeViewer(int,int)", tr("Resize the viewer"),
QString(tr("width,height")).split(","),
QString(tr("new width for the viewer,new height for the viewer")).split(","));
......
......@@ -466,8 +466,9 @@ public slots:
/** Trigger a snapshot and increase the snapshot counter.
Save snapshot to file determined by snapshotBaseFileName() and
the current snapshot counter. The \a back buffer will be saved.
The id of the current viewer is 0 (default).
*/
void snapshot(unsigned int _viewerId = 0);
void snapshot(unsigned int _viewerId = 0, int _width = 0, int _height = 0);
/// Take a snapshot from the whole app
void applicationSnapshot();
......
......@@ -2035,11 +2035,20 @@ void glViewer::snapshot(QImage& _image, int _width, int _height) {
int w = 0, h = 0, bak_w = 0, bak_h = 0;
// Test if size is given:
if(_width ==0 || _height == 0) {
if(_width ==0 && _height == 0) {
// Get standard viewport size
w = glstate_->viewport_width();
h = glstate_->viewport_height();
} else {
// Adapt dimensions if aspect ratio is demanded
if(_width == 0) {
double aspect = glstate_->viewport_width()/glstate_->viewport_height();
_width = (int)(_height * aspect);
}
if(_height == 0) {
double aspect = glstate_->viewport_width()/glstate_->viewport_height();
_height = (int)(_width / aspect);
}
w = _width;
h = _height;
bak_w = glstate_->viewport_width();
......@@ -2068,19 +2077,13 @@ void glViewer::snapshot(QImage& _image, int _width, int _height) {
}
}
void glViewer::snapshot()
void glViewer::snapshot( int _width, int _height )
{
makeCurrent();
qApp->processEvents();
makeCurrent();
glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
paintGL();
glFinish();
QImage snapshot;
copyToImage(snapshot, scenePos().x(), scenePos().y(), glWidth(), glHeight(), GL_BACK);
QImage image;
// Capture image
snapshot(image, _width, _height);
QFileInfo fi(properties_.snapshotName());
QString fname = fi.path() + QDir::separator() +fi.baseName() + "." + QString::number(properties_.snapshotCounter()) + ".";
......@@ -2092,8 +2095,7 @@ void glViewer::snapshot()
fname += format;
bool rval=snapshot.save(fname,format.toUpper().toLatin1());
bool rval=image.save(fname,format.toUpper().toLatin1());
if (rval)
{
......
......@@ -765,7 +765,7 @@ private:
Save snapshot to file determined by snapshotBaseFileName() and
the current snapshot counter. The \a back buffer will be saved.
*/
virtual void snapshot();
virtual void snapshot(int _width = 0, int _height = 0);
/// Take a snapshot and store it in the given image
virtual void snapshot(QImage& _image, int _width = 0, int _height = 0);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment