#850 Summary : Added Snapshot to file command feature

This commit is contained in:
Magne Sjaastad 2016-10-27 08:09:49 +02:00
parent 8970c1cb56
commit 656d4c6c99
3 changed files with 106 additions and 3 deletions

View File

@ -20,12 +20,17 @@
#include "RiaApplication.h"
#include "RimProject.h"
#include "RimViewWindow.h"
#include <QAction>
#include <QClipboard>
#include <QDebug>
#include <QFileDialog>
#include <QFileInfo>
#include <QMdiSubWindow>
CAF_CMD_SOURCE_INIT(RicSnapshotViewToClipboardFeature, "RicSnapshotViewToClipboardFeature");
//--------------------------------------------------------------------------------------------------
@ -66,3 +71,82 @@ void RicSnapshotViewToClipboardFeature::setupActionLook(QAction* actionToSetup)
actionToSetup->setIcon(QIcon(":/SnapShot.png"));
}
CAF_CMD_SOURCE_INIT(RicSnapshotViewToFileFeature, "RicSnapshotViewToFileFeature");
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicSnapshotViewToFileFeature::saveSnapshotAs(const QString& fileName)
{
RimViewWindow* viewWindow = RiaApplication::activeViewWindow();
if (viewWindow)
{
QImage image = viewWindow->snapshotWindowContent();
if (!image.isNull())
{
if (image.save(fileName))
{
qDebug() << "Saved snapshot image to " << fileName;
}
else
{
qDebug() << "Error when trying to save snapshot image to " << fileName;
}
}
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RicSnapshotViewToFileFeature::isCommandEnabled()
{
return true;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicSnapshotViewToFileFeature::onActionTriggered(bool isChecked)
{
RiaApplication* app = RiaApplication::instance();
RimProject* proj = app->project();
QString startPath;
if (!proj->fileName().isEmpty())
{
QFileInfo fi(proj->fileName());
startPath = fi.absolutePath();
}
else
{
startPath = app->lastUsedDialogDirectory("IMAGE_SNAPSHOT");
}
startPath += "/image.png";
QString fileName = QFileDialog::getSaveFileName(NULL, tr("Save File"), startPath, tr("Image files (*.bmp *.png * *.jpg)"));
if (fileName.isEmpty())
{
return;
}
// Remember the directory to next time
app->setLastUsedDialogDirectory("IMAGE_SNAPSHOT", QFileInfo(fileName).absolutePath());
RicSnapshotViewToFileFeature::saveSnapshotAs(fileName);
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicSnapshotViewToFileFeature::setupActionLook(QAction* actionToSetup)
{
actionToSetup->setText("Snapshot To File");
actionToSetup->setIcon(QIcon(":/SnapShotSave.png"));
}

View File

@ -30,10 +30,28 @@ class RicSnapshotViewToClipboardFeature : public caf::CmdFeature
protected:
// Overrides
virtual bool isCommandEnabled();
virtual void onActionTriggered( bool isChecked );
virtual void setupActionLook( QAction* actionToSetup );
virtual bool isCommandEnabled() override;
virtual void onActionTriggered( bool isChecked ) override;
virtual void setupActionLook( QAction* actionToSetup ) override;
};
//==================================================================================================
///
//==================================================================================================
class RicSnapshotViewToFileFeature : public caf::CmdFeature
{
CAF_CMD_HEADER_INIT;
public:
static void saveSnapshotAs(const QString& fileName);
protected:
// Overrides
virtual bool isCommandEnabled() override;
virtual void onActionTriggered(bool isChecked) override;
virtual void setupActionLook(QAction* actionToSetup) override;
};

View File

@ -239,6 +239,7 @@ void RiuMainPlotWindow::createToolBars()
QToolBar* toolbar = addToolBar(tr("View Snapshots"));
toolbar->setObjectName(toolbar->windowTitle());
toolbar->addAction(cmdFeatureMgr->action("RicSnapshotViewToClipboardFeature"));
toolbar->addAction(cmdFeatureMgr->action("RicSnapshotViewToFileFeature"));
}
{