summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleix Pol <[email protected]>2017-06-23 02:04:31 +0200
committerAleix Pol <[email protected]>2017-06-23 02:04:31 +0200
commit57e3b68f5cfd2beff3a31b7352bca5fd8be546c2 (patch)
treeea968c9b86fe34e59b7125567b2002ec2bc5a832
parentc461b44eb17bd6dd5253eac309bbde6f9c5d61f1 (diff)
Make it possible to export 3D plots from kalgebramobile
-rw-r--r--mobile/plugins/Plot2D.qml13
-rw-r--r--mobile/plugins/Plot3D.qml22
-rw-r--r--src/kalgebra.cpp20
3 files changed, 37 insertions, 18 deletions
diff --git a/mobile/plugins/Plot2D.qml b/mobile/plugins/Plot2D.qml
index e3ab9c8..2220a7a 100644
--- a/mobile/plugins/Plot2D.qml
+++ b/mobile/plugins/Plot2D.qml
@@ -10,6 +10,19 @@ KAlgebraPage
contextualActions: [
Action {
+ text: i18n("Save...")
+ onTriggered: {
+ fileDialog.title = text
+ fileDialog.proceed = function() {
+ var ret = view.save(fileDialog.fileUrl)
+ console.log("saved 2D", fileDialog.fileUrl, ret)
+ }
+ fileDialog.nameFilters = view.filters
+ fileDialog.selectExisting = false
+ fileDialog.open()
+ }
+ },
+ Action {
text: i18n("View Grid")
checkable: true
checked: view.showGrid
diff --git a/mobile/plugins/Plot3D.qml b/mobile/plugins/Plot3D.qml
index cb2e2b9..4c5597a 100644
--- a/mobile/plugins/Plot3D.qml
+++ b/mobile/plugins/Plot3D.qml
@@ -18,6 +18,7 @@
import QtQuick 2.0
import QtQuick.Layouts 1.1
+import QtQuick.Dialogs 1.0
import org.kde.analitza 1.1
import widgets 1.0
@@ -25,8 +26,29 @@ KAlgebraPage
{
id: page
+ FileDialog {
+ id: fileDialog
+ folder: shortcuts.home
+ onAccepted: proceed()
+
+ property var proceed
+ }
+
contextualActions: [
Action {
+ text: i18n("Save...")
+ onTriggered: {
+ fileDialog.title = text
+ fileDialog.proceed = function() {
+ var ret = view.save(fileDialog.fileUrl)
+ console.log("saved 3D", fileDialog.fileUrl, ret)
+ }
+ fileDialog.nameFilters = view.filters
+ fileDialog.selectExisting = false
+ fileDialog.open()
+ }
+ },
+ Action {
text: i18n("Reset Viewport")
onTriggered: view.resetViewport()
}
diff --git a/src/kalgebra.cpp b/src/kalgebra.cpp
index 453b763..117f5d6 100644
--- a/src/kalgebra.cpp
+++ b/src/kalgebra.cpp
@@ -559,25 +559,9 @@ void KAlgebra::set_solid()
void KAlgebra::save3DGraph()
{
- QString path = QFileDialog::getSaveFileName(this, QString(), QString(), i18n("PNG File (*.png);;PDF Document(*.pdf);;X3D Document (*.x3d);;STL Document (*.stl)"));
+ QString path = QFileDialog::getSaveFileName(this, QString(), QString(), m_graph3d->filters().join(";;"));
if(!path.isEmpty()) {
- if(path.endsWith(QLatin1String(".x3d")) || path.endsWith(QLatin1String(".stl"))) {
- m_graph3d->exportSurfaces(path);
- } else if(path.endsWith(QLatin1String(".pdf"))) {
- auto px = m_graph3d->grabFramebuffer();
- QPrinter printer;
- printer.setOutputFormat(QPrinter::PdfFormat);
- printer.setOutputFileName(path);
- printer.setPaperSize(px.size(), QPrinter::DevicePixel);
- printer.setPageMargins(0,0,0,0, QPrinter::DevicePixel);
- QPainter painter;
- painter.begin(&printer);
- painter.drawImage(QPoint(0,0), px);
- painter.end();
- } else {
- auto px = m_graph3d->grabFramebuffer();
- px.save(path);
- }
+ m_graph3d->save(QUrl::fromLocalFile(path));
}
}