Commit 57e3b68f authored by Aleix Pol Gonzalez's avatar Aleix Pol Gonzalez 🐧

Make it possible to export 3D plots from kalgebramobile

parent c461b44e
......@@ -9,6 +9,19 @@ KAlgebraPage
anchors.margins: 0
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
......
......@@ -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,7 +26,28 @@ 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()
......
......@@ -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));
}
}
......
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