Commit 5bf9a34f authored by Jan Möbius's avatar Jan Möbius

Moved snapshot handling to viewerproperties

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@4512 383ad7c9-94d9-4d36-a494-682f7c89f535
parent f7c37d43
......@@ -971,8 +971,7 @@ void Core::snapshotBaseFileName(const QString& _fname, unsigned int _viewerId ){
return;
}
coreWidget_->examiner_widgets_[_viewerId]->snapshotBaseFileName( _fname );
PluginFunctions::viewerProperties(_viewerId).snapshotBaseFileName( _fname );
}
}
......
......@@ -46,7 +46,9 @@ namespace Viewer {
ViewerProperties::ViewerProperties():
actionMode_(Viewer::PickingMode),
lastActionMode_(Viewer::PickingMode)
lastActionMode_(Viewer::PickingMode),
snapshotName_("snap.png"),
snapshotCounter_(0)
{
}
......@@ -56,7 +58,6 @@ namespace Viewer {
}
void ViewerProperties::actionMode(Viewer::ActionMode _am) {
std::cerr << "ActionModeChanged" << std::endl;
if (_am != actionMode_) {
lastActionMode_ = actionMode_;
actionMode_ = _am;
......@@ -65,6 +66,11 @@ namespace Viewer {
}
void ViewerProperties::snapshotBaseFileName(const QString& _fname) {
snapshotName_ = _fname;
snapshotCounter_ = 0;
}
}
\ No newline at end of file
......@@ -105,11 +105,33 @@ namespace Viewer {
//===========================================================================
/** @name Action Mode States
/** @name Snapshot settings
* @{ */
//===========================================================================
public slots:
/** Set the base file name and reset the counter for snapshots.
The image file format is determined from the file name extension,
the \a QImageIO formats are supported (e.g. ".ppm" [raw], ".png").
The current snapshot counter will be added in front of the last "."
in the filename.
\a Note: Calling snapshotBaseFileName() will always reset the snapshot
counter to 0.
*/
void snapshotBaseFileName(const QString& _fname);
/** Get the name for the current snapshot */
QString snapshotName() { return snapshotName_; };
/** Get the counter for the current snapshot and increases the counter */
int snapshotCounter() { return snapshotCounter_++; };
private:
QString snapshotName_;
int snapshotCounter_;
/** @} */
......
......@@ -299,7 +299,20 @@ void CoreWidget::updatePopupMenu(const QPoint& _point, unsigned int _examinerId)
void CoreWidget::slotSnapshotName() {
std::cerr << "Todo : slotSnapShotName only sets name for current viewer" << std::endl;
examiner_widgets_[PluginFunctions::activeExaminer()]->actionSnapshotName();
QString fname = PluginFunctions::viewerProperties().snapshotName();
fname.replace('%', '$');
fname = QFileDialog::getSaveFileName ( 0, "Save snapshot name" );
if (!fname.isEmpty())
{
fname.replace('$', '%');
PluginFunctions::viewerProperties().snapshotBaseFileName(fname);
QString msg="next snapshot: ";
statusBar()->showMessage(msg);
}
}
void CoreWidget::changeBackgroundColor(){
......@@ -330,7 +343,7 @@ void CoreWidget::changeBackgroundColor(){
}
void CoreWidget::slotSnapshot() {
examiner_widgets_[PluginFunctions::activeExaminer()]->actionSnapshot();
examiner_widgets_[PluginFunctions::activeExaminer()]->snapshot();
}
void CoreWidget::slotPasteView( ) {
......
......@@ -121,9 +121,6 @@ glViewer::glViewer( QWidget* _parent,
updateLocked_(false),
projectionUpdateLocked_(false),
blending_(true),
snapshotName_("snap.png"),
snapshotCounter_(0),
snapshot_(0),
pick_mode_name_(""),
pick_mode_idx_(-1),
renderPicking_(false),
......@@ -169,9 +166,6 @@ glViewer::glViewer( QWidget* _parent,
light_matrix_.identity();
snapshot_=new QImage;
trackMouse_ = false;
// stereo
......@@ -217,7 +211,6 @@ glViewer::glViewer( QWidget* _parent,
glViewer::~glViewer()
{
delete snapshot_;
delete glstate_;
}
......@@ -2169,5 +2162,45 @@ void glViewer::slotPropertiesUpdated() {
std::cerr << "glViewer : Properties updated" << std::endl;
}
void glViewer::snapshot()
{
makeCurrent();
glView_->raise();
qApp->processEvents();
makeCurrent();
paintGL();
glFinish();
QImage snapshot;
copyToImage(snapshot, 0, 0, glWidth(), glHeight(), GL_BACK);
QFileInfo fi(properties_.snapshotName());
QString fname = fi.path() + QDir::separator() +fi.baseName() + "." + QString::number(properties_.snapshotCounter()) + ".";
QString format="png";
if (fi.completeSuffix() == "ppm")
format="ppmraw";
fname += format;
bool rval=snapshot.save(fname,format.toUpper().toLatin1());
assert(statusbar_!=0);
if (rval)
{
statusbar_->showMessage(QString("snapshot: ")+fname,5000);
}
else
{
statusbar_->showMessage(QString("could not save snapshot to ")+fname);
}
}
//=============================================================================
//=============================================================================
......@@ -430,8 +430,6 @@ public slots:
void actionDrawMenu( QAction * _action );
void actionPickMenu( QAction * _action );
void actionSnapshotName();
void actionSnapshot();
void actionPasteView();
void actionCopyView();
......@@ -806,18 +804,7 @@ private:
//===========================================================================
public slots:
/** Set the base file name and reset the counter for snapshots.
The image file format is determined from the file name extension,
the \a QImageIO formats are supported (e.g. ".ppm" [raw], ".png").
The current snapshot counter will be added in front of the last "."
in the filename.
\a Note: Calling snapshotBaseFileName() will always reset the snapshot
counter to 0.
*/
virtual void snapshotBaseFileName(const QString& _fname);
/** Trigger a snapshot and increase the snapshot counter.
Save snapshot to file determined by snapshotBaseFileName() and
......@@ -825,12 +812,6 @@ private:
*/
virtual void snapshot();
private:
QString snapshotName_;
int snapshotCounter_;
QImage* snapshot_;
/** @} */
//===========================================================================
......
//=============================================================================
//
// OpenFlipper
// Copyright (C) 2008 by Computer Graphics Group, RWTH Aachen
// www.openflipper.org
//
//-----------------------------------------------------------------------------
//
// License
//
// OpenFlipper is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// OpenFlipper is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with OpenFlipper. If not, see <http://www.gnu.org/licenses/>.
//
//-----------------------------------------------------------------------------
//
// $Revision: 3512 $
// $Author: wilden $
// $Date: 2008-10-22 11:37:37 +0200 (Mi, 22. Okt 2008) $
//
//=============================================================================
//=============================================================================
//
// CLASS glViewer - IMPLEMENTATION
//
//=============================================================================
//== INCLUDES =================================================================
#include "QtBaseViewer.hh"
#include "QtGLGraphicsScene.hh"
#include "QtGLGraphicsView.hh"
#include <QApplication>
#include <QStatusBar>
#include <QFile>
#include <QFileInfo>
#include <QFileDialog>
//== NAMESPACES ===============================================================
//== IMPLEMENTATION ==========================================================
void glViewer::snapshotBaseFileName(const QString& _fname)
{
snapshotName_=_fname;
snapshotCounter_=0;
}
//-----------------------------------------------------------------------------
void glViewer::snapshot()
{
makeCurrent();
glView_->raise();
qApp->processEvents();
makeCurrent();
paintGL();
glFinish();
copyToImage(*snapshot_, 0, 0, glWidth(), glHeight(), GL_BACK);
QFileInfo fi(snapshotName_);
QString fname = fi.path() + QDir::separator() +fi.baseName() + "." + QString::number(snapshotCounter_) + ".";
QString format="png";
if (fi.completeSuffix() == "ppm")
format="ppmraw";
fname += format;
bool rval=snapshot_->save(fname,format.toUpper().toLatin1());
assert(statusbar_!=0);
if (rval)
{
statusbar_->showMessage(QString("snapshot: ")+fname,5000);
// if ( action_["SnapshotSavesView"]->isChecked() )
// {
// QString view; encodeView(view);
// QFile f(fname+".view"); f.open(QIODevice::WriteOnly|QIODevice::Truncate);
// QTextStream sf(&f); sf << view; f.close();
// }
}
else
{
statusbar_->showMessage(QString("could not save snapshot to ")+fname);
}
++snapshotCounter_;
}
//-----------------------------------------------------------------------------
void glViewer::actionSnapshot()
{
snapshot();
}
//-----------------------------------------------------------------------------
void glViewer::actionSnapshotName()
{
QString fname=snapshotName_;
fname.replace('%', '$');
fname = QFileDialog::getSaveFileName ( 0, "Save snapshot name" );
if (!fname.isEmpty())
{
fname.replace('$', '%');
snapshotBaseFileName(fname);
assert(statusbar_!=0);
QString msg="next snapshot: ";
statusbar_->showMessage(msg);
}
}
//=============================================================================
//=============================================================================
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