mirror of
https://github.com/OPM/ResInsight.git
synced 2025-01-24 07:16:53 -06:00
#850 Summary : Added Snapshot to file command feature
This commit is contained in:
parent
8970c1cb56
commit
656d4c6c99
@ -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"));
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
};
|
||||
|
||||
|
||||
|
@ -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"));
|
||||
}
|
||||
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user