Commit dbd1559a authored by Dirk Wilden's avatar Dirk Wilden

snapshots


git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@5262 383ad7c9-94d9-4d36-a494-682f7c89f535
parent 96574530
......@@ -1028,6 +1028,18 @@ void Core::snapshot( unsigned int _viewerId ){
}
void Core::applicationSnapshot(){
if ( OpenFlipper::Options::gui() )
coreWidget_->applicationSnapshot();
}
void Core::applicationSnapshotName(QString _name){
if ( OpenFlipper::Options::gui() )
coreWidget_->applicationSnapshotName(_name);
}
void Core::resizeViewer(int _width, int _height ){
if ( OpenFlipper::Options::gui() ){
//+40 / +20 corresponds to the bottom and right scrollbar
......
......@@ -300,6 +300,12 @@ public slots:
*/
void snapshot(unsigned int _viewerId = 0);
/// Take a snapshot from the whole app
void applicationSnapshot();
/// Set the baseName for the application snapshot
void applicationSnapshotName(QString _name);
/// resize the examinerViewer
void resizeViewer(int _width, int _height );
......
......@@ -209,14 +209,14 @@ void CoreWidget::updatePopupMenuCoordsysNode(QMenu* _menu , const int _part) {
QAction* copyView = _menu->addAction("Copy View");
copyView->setToolTip("Copy current view to clipboard");
copyView->setIcon( QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"copyView.png") );
copyView->setIcon( QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"edit-copy.png") );
connect(copyView, SIGNAL(triggered()), this, SLOT(slotCopyView()) );
//====================================================================================================
QAction* pasteView = _menu->addAction("Paste View");
pasteView->setToolTip("Paste current view from clipboard");
pasteView->setIcon( QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"pasteView.png") );
pasteView->setIcon( QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"edit-paste.png") );
connect(pasteView, SIGNAL(triggered()), this , SLOT( slotPasteView( ) ) );
//====================================================================================================
......@@ -226,14 +226,6 @@ void CoreWidget::updatePopupMenuCoordsysNode(QMenu* _menu , const int _part) {
snapshot->setIcon( QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"snapshot.png") );
connect(snapshot, SIGNAL(triggered()), this, SLOT( slotSnapshot() ) );
//====================================================================================================
QAction* snapshotName = _menu->addAction("Set Snapshot Name");
snapshotName->setToolTip("Set a name for snapshots");
snapshotName->setIcon( QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"snapshotName.png") );
connect(snapshotName, SIGNAL(triggered()), this, SLOT(slotSnapshotName()) );
}
/** \brief Update context Menu when background has been clicked on.
......
......@@ -83,7 +83,7 @@ CoreWidget( QVector<ViewMode*>& _viewModes,
moveButton_(0),
lightButton_(0),
pickButton_(0),
questionButton_(0),
questionButton_(0),
globalDrawMenu_(0),
drawGroup_(0),
viewGroup_(0),
......@@ -94,6 +94,8 @@ CoreWidget( QVector<ViewMode*>& _viewModes,
contextSelectionMenu_(0),
drawGroupViewer_(0),
viewerDrawMenu_(0),
snapshotName_("snap.png"),
snapshotCounter_(0),
stackMenu_(0),
helpBrowserDeveloper_(0),
helpBrowserUser_(0),
......
......@@ -557,18 +557,18 @@ public:
/// Copy view from the last active examiner
void slotCopyView( );
/// Create a snapshot of the last active examiner
void slotSnapshot();
/// Set the snapShot name for all examiners
void slotSnapshotName();
/// Called when a coordsys drawMode has been changed
void slotViewerDrawMenu( QAction * _action );
/// Creates a draw Menu for the currently active Viewer
void slotUpdateViewerDrawMenu();
/// Create a snapshot of the last active examiner
void slotSnapshot();
/// Set the snapShot name for all examiners
void slotSnapshotName();
private :
/** Update the contextmenu for the given position inside an examiner widget
*
......@@ -601,6 +601,36 @@ public:
/** @} */
//===========================================================================
/** @name Snapshots
* @{ */
//===========================================================================
private:
QString snapshotName_;
int snapshotCounter_;
public slots:
/// Create a snapshot of the whole app with fileDialog
// void viewerSnapshotDialog();
/// Create a snapshot of the whole app
// void viewerSnapshot();
/// Create a snapshot of the whole app with fileDialog
void applicationSnapshotDialog();
/// Create a snapshot of the whole app
void applicationSnapshot();
/// Set the snapshot name
void applicationSnapshotName(QString _name);
/** @} */
//===========================================================================
/** @name StackWidget controls
* @{ */
......
......@@ -317,6 +317,25 @@ void CoreWidget::setupMenuBar()
connect( viewAllAction,SIGNAL( triggered() ), this, SLOT( slotGlobalViewAll() ) );
viewMenu_->addAction( viewAllAction);
// QAction* snapShotAction = new QAction( "Viewer Snapshot", viewMenu_ );
// snapShotAction->setIcon( QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"snapshot.png") );
// snapShotAction->setCheckable( false );
// snapShotAction->setToolTip("Take a snapshot from all viewers.");
// snapShotAction->setWhatsThis( "Viewer Snapshot<br><br>"
// "Take a snapshot of all viewers at once.");
// connect( snapShotAction,SIGNAL( triggered() ), this, SLOT( slotSnapshot() ) );
// viewMenu_->addAction( snapShotAction);
QAction* appSnapShotAction = new QAction( "Snapshot", viewMenu_ );
appSnapShotAction->setIcon( QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"snapshot.png") );
appSnapShotAction->setCheckable( false );
appSnapShotAction->setToolTip("Take a snapshot from OpenFlipper.");
appSnapShotAction->setWhatsThis( "Snapshot<br><br>"
"Take a snapshot from OpenFlipper.");
connect( appSnapShotAction,SIGNAL( triggered() ), this, SLOT( applicationSnapshotDialog() ) );
viewMenu_->addAction( appSnapShotAction);
perspectiveProjectionAction_ = new QAction( "Switch Viewers to Perspective Projection", viewMenu_ );;
perspectiveProjectionAction_->setIcon( QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"perspective.png") );
perspectiveProjectionAction_->setCheckable( false );
......
......@@ -224,11 +224,127 @@ void CoreWidget::slotLocalChangeTwoSidedLighting(bool _lighting) {
PluginFunctions::viewerProperties().twoSidedLighting(_lighting);
}
/// Take a snapshot of the current Viewer
void CoreWidget::slotSnapshot() {
examiner_widgets_[PluginFunctions::activeExaminer()]->snapshot();
QFileInfo fi(PluginFunctions::viewerProperties().snapshotName());
int counter = PluginFunctions::viewerProperties().snapshotCounter();
QString suggest = fi.path() + QDir::separator() +fi.baseName() + "." + QString::number(counter) + ".";
QString format="png";
if (fi.completeSuffix() == "ppm")
format="ppmraw";
suggest += format;
QString newName = QFileDialog::getSaveFileName(this, tr("Save Snapshot"), suggest, tr("Images (*.png *.ppm)"));
if (!newName.isEmpty())
{
if (newName != suggest)
PluginFunctions::viewerProperties().snapshotBaseFileName(newName);
examiner_widgets_[PluginFunctions::activeExaminer()]->snapshot();
}
}
///Take a snapshot of the whole application
void CoreWidget::applicationSnapshotDialog() {
QFileInfo fi(snapshotName_);
QString suggest = fi.path() + QDir::separator() +fi.baseName() + "." + QString::number(snapshotCounter_) + ".";
QString format="png";
if (fi.completeSuffix() == "ppm")
format="ppmraw";
suggest += format;
QString newName = QFileDialog::getSaveFileName(this, tr("Save Snapshot"), suggest, tr("Images (*.png *.ppm)"));
if (!newName.isEmpty())
{
if (newName != suggest){
snapshotName_ = newName;
snapshotCounter_ = 0;
}else
snapshotCounter_++;
QApplication::processEvents();
QPixmap pic = QPixmap::grabWindow( winId() );
pic.save(newName);
}
}
///Take a snapshot of the whole application
void CoreWidget::applicationSnapshot() {
QFileInfo fi(snapshotName_);
QString suggest = fi.path() + QDir::separator() +fi.baseName() + "." + QString::number(snapshotCounter_++) + ".";
QString format="png";
if (fi.completeSuffix() == "ppm")
format="ppmraw";
suggest += format;
QApplication::processEvents();
QPixmap pic = QPixmap::grabWindow( winId() );
pic.save(suggest);
}
///Take a snapshot of all viewers
// void CoreWidget::viewerSnapshot() {
//
// QFileInfo fi(snapshotName_);
//
// QString suggest = fi.path() + QDir::separator() +fi.baseName() + "." + QString::number(snapshotCounter_++) + ".";
//
// QString format="png";
//
// if (fi.completeSuffix() == "ppm")
// format="ppmraw";
//
// suggest += format;
//
// switch ( coreWidget_->baseLayout_->mode() ){
//
// case QtMultiViewLayout::SingleView:
//
// QImage img;
// examiner_widgets_[PluginFunctions::activeExaminer()]->snapshot(img);
//
// img.save(suggest);
//
// break;
// case QtMultiViewLayout::Grid:
// break;
// case QtMultiViewLayout::HSplit:
// break;
// default: break;
//
// }
// }
void CoreWidget::applicationSnapshotName(QString _name) {
snapshotName_ = _name;
snapshotCounter_ = 0;
}
void CoreWidget::slotPasteView( ) {
examiner_widgets_[PluginFunctions::activeExaminer()]->actionPasteView();
}
......
......@@ -1915,6 +1915,18 @@ void glViewer::slotPropertiesUpdated() {
updateGL();
}
void glViewer::snapshot(QImage& _image)
{
makeCurrent();
qApp->processEvents();
makeCurrent();
glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
paintGL();
glFinish();
copyToImage(_image, scenePos().x(), scenePos().y(), glWidth(), glHeight(), GL_BACK);
}
void glViewer::snapshot()
{
......
......@@ -672,6 +672,9 @@ private:
*/
virtual void snapshot();
/// Take a snapshot and store it in the given image
virtual void snapshot(QImage& _image);
/** @} */
//===========================================================================
......
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