Added CopyViewToClipboard feature

This commit is contained in:
Magne Sjaastad 2016-06-27 21:01:17 +02:00
parent 2e0553d99c
commit 0680e830b4
11 changed files with 202 additions and 3 deletions

View File

@ -47,6 +47,7 @@ ${CEE_CURRENT_LIST_DIR}RicShowPlotWindowFeature.h
${CEE_CURRENT_LIST_DIR}RicLaunchUnitTestsFeature.h
${CEE_CURRENT_LIST_DIR}RicExportToLasFileFeature.h
${CEE_CURRENT_LIST_DIR}RicImportInputEclipseCaseOpmFeature.h
${CEE_CURRENT_LIST_DIR}RicSnapshotViewToClipboardFeature.h
# General delete of any object in a child array field
${CEE_CURRENT_LIST_DIR}RicDeleteItemExec.h
@ -96,6 +97,7 @@ ${CEE_CURRENT_LIST_DIR}RicShowPlotWindowFeature.cpp
${CEE_CURRENT_LIST_DIR}RicLaunchUnitTestsFeature.cpp
${CEE_CURRENT_LIST_DIR}RicExportToLasFileFeature.cpp
${CEE_CURRENT_LIST_DIR}RicImportInputEclipseCaseOpmFeature.cpp
${CEE_CURRENT_LIST_DIR}RicSnapshotViewToClipboardFeature.cpp
# General delete of any object in a child array field

View File

@ -0,0 +1,83 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2016 Statoil ASA
//
// ResInsight is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// ResInsight 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 General Public License at <http://www.gnu.org/licenses/gpl.html>
// for more details.
//
/////////////////////////////////////////////////////////////////////////////////
#include "RicSnapshotViewToClipboardFeature.h"
#include "RiaApplication.h"
#include "RimView.h"
#include "RimViewWindow.h"
#include "RimWellLogPlot.h"
#include "RiuMainPlotWindow.h"
#include "RiuMainWindow.h"
#include <QClipboard>
#include <QAction>
CAF_CMD_SOURCE_INIT(RicSnapshotViewToClipboardFeature, "RicSnapshotViewToClipboardFeature");
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RicSnapshotViewToClipboardFeature::isCommandEnabled()
{
return true;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicSnapshotViewToClipboardFeature::onActionTriggered(bool isChecked)
{
RimViewWindow* viewWindow = NULL;
QWidget* topLevelWidget = RiaApplication::activeWindow();
if (dynamic_cast<RiuMainWindow*>(topLevelWidget))
{
viewWindow = RiaApplication::instance()->activeReservoirView();
}
if (dynamic_cast<RiuMainPlotWindow*>(topLevelWidget))
{
viewWindow = RiaApplication::instance()->activeWellLogPlot();
}
if (viewWindow)
{
QClipboard* clipboard = QApplication::clipboard();
if (clipboard)
{
QImage image = viewWindow->snapshotWindowContent();
if (!image.isNull())
{
clipboard->setImage(image);
}
}
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicSnapshotViewToClipboardFeature::setupActionLook(QAction* actionToSetup)
{
actionToSetup->setText("Close");
}

View File

@ -0,0 +1,39 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2016 Statoil ASA
//
// ResInsight is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// ResInsight 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 General Public License at <http://www.gnu.org/licenses/gpl.html>
// for more details.
//
/////////////////////////////////////////////////////////////////////////////////
#pragma once
#include "cafCmdFeature.h"
//==================================================================================================
///
//==================================================================================================
class RicSnapshotViewToClipboardFeature : public caf::CmdFeature
{
CAF_CMD_HEADER_INIT;
protected:
// Overrides
virtual bool isCommandEnabled();
virtual void onActionTriggered( bool isChecked );
virtual void setupActionLook( QAction* actionToSetup );
};

View File

@ -32,6 +32,7 @@
#include "cvfColor3.h"
#include <QDateTime>
#include "qwt_plot_renderer.h"
CAF_PDM_SOURCE_INIT(RimSummaryPlot, "SummaryPlot");
@ -197,6 +198,29 @@ void RimSummaryPlot::setupBeforeSave()
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QImage RimSummaryPlot::snapshotWindowContent()
{
QImage image;
if (m_qwtPlot)
{
image = QImage(m_qwtPlot->size(), QImage::Format_ARGB32);
image.fill(QColor(Qt::white).rgb());
QPainter painter(&image);
QRectF rect(0, 0, m_qwtPlot->size().width(), m_qwtPlot->size().height());
QwtPlotRenderer plotRenderer;
plotRenderer.render(m_qwtPlot, &painter, rect);
}
return image;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------

View File

@ -54,6 +54,7 @@ public:
void loadDataAndUpdate();
void handleViewerDeletion();
void updateYAxisUnit();
protected:
// Overridden PDM methods
virtual caf::PdmFieldHandle* objectToggleField() { return &m_showWindow; }
@ -61,6 +62,8 @@ protected:
virtual void fieldChangedByUi(const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue) override;
virtual void setupBeforeSave() override;
virtual QImage snapshotWindowContent() override;
private:
void updateViewerWidget();
void detachAllCurves();

View File

@ -242,6 +242,28 @@ void RimView::updateViewerWidget()
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QImage RimView::snapshotWindowContent()
{
QImage image;
if (m_viewer)
{
m_viewer->repaint();
GLint currentReadBuffer;
glGetIntegerv(GL_READ_BUFFER, &currentReadBuffer);
glReadBuffer(GL_FRONT);
image = m_viewer->grabFrameBuffer();
glReadBuffer(currentReadBuffer);
}
return image;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------

View File

@ -192,6 +192,9 @@ protected:
virtual void resetLegendsInViewer() = 0;
virtual void calculateCurrentTotalCellVisibility(cvf::UByteArray* totalVisibility) = 0;
virtual QImage snapshotWindowContent() override;
QPointer<RiuViewer> m_viewer;
caf::PdmField<int> m_currentTimeStep;

View File

@ -44,12 +44,13 @@ public:
void setMdiWindowGeometry(const RimMdiWindowGeometry& windowGeometry);
RimMdiWindowGeometry mdiWindowGeometry();
virtual QImage snapshotWindowContent() = 0;
protected:
void setViewWidget(QWidget* viewWidget);
// Possible abilities of this class
//virtual QImage snapshotWindowContent() = 0;
//caf::PdmField<QString> name;
//caf::PdmField<bool> showWindow;

View File

@ -181,6 +181,22 @@ caf::PdmFieldHandle* RimWellLogPlot::objectToggleField()
return &m_showWindow;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QImage RimWellLogPlot::snapshotWindowContent()
{
QImage image;
if (m_viewer)
{
QPixmap pix = QPixmap::grabWidget(m_viewer);
image = pix.toImage();
}
return image;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------

View File

@ -93,6 +93,9 @@ protected:
virtual caf::PdmFieldHandle* objectToggleField();
virtual caf::PdmFieldHandle* userDescriptionField() { return &m_userName; }
virtual QImage snapshotWindowContent() override;
private:
void updateViewerWidget();
void updateViewerWidgetWindowTitle();

View File

@ -160,6 +160,9 @@ void RiuMainPlotWindow::createMenus()
//--------------------------------------------------------------------------------------------------
void RiuMainPlotWindow::createToolBars()
{
caf::CmdFeatureManager* cmdFeatureMgr = caf::CmdFeatureManager::instance();
CVF_ASSERT(cmdFeatureMgr);
{
// Snapshots
QToolBar* toolbar = addToolBar(tr("View Snapshots"));
@ -167,10 +170,10 @@ void RiuMainPlotWindow::createToolBars()
toolbar->addAction(m_snapshotToClipboard);
toolbar->addAction(m_snapshotToFile);
toolbar->addAction(m_snapshotAllViewsToFile);
toolbar->addAction(cmdFeatureMgr->action("RicSnapshotViewToClipboardFeature"));
}
caf::CmdFeatureManager* cmdFeatureMgr = caf::CmdFeatureManager::instance();
CVF_ASSERT(cmdFeatureMgr);
{
QToolBar* toolbar = addToolBar(tr("Window Management"));