[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: KDE/kdeedu/kalgebra
From: Aleix Pol Gonzalez <aleixpol () gmail ! com>
Date: 2010-12-14 19:08:58
Message-ID: 20101214190858.1971CAC8A7 () svn ! kde ! org
[Download RAW message or body]
SVN commit 1206519 by apol:
Let the user save 2D graphs without file extension.
BUG: 259651
M +7 -3 analitzagui/graph2d.cpp
M +3 -1 analitzagui/graph2d.h
M +14 -3 src/kalgebra.cpp
--- trunk/KDE/kdeedu/kalgebra/analitzagui/graph2d.cpp #1206518:1206519
@@ -547,11 +547,13 @@
return ret;
}
-bool Graph2D::toImage(const QString &path)
+bool Graph2D::toImage(const QString &path, Format f)
{
+ Q_ASSERT(!path.isEmpty());
bool b=false;
- if(!path.isEmpty() && path.endsWith(".svg")) {
+ switch(f) {
+ case SVG: {
QFile f(path);
QSvgGenerator gen;
gen.setOutputDevice(&f);
@@ -559,9 +561,11 @@
drawFunctions(&gen);
b=true;
forceRepaint();
- } else if(!path.isEmpty() && path.endsWith(".png")) {
+ } break;
+ case PNG:
this->repaint();
b=buffer.save(path, "PNG");
+ break;
}
return b;
--- trunk/KDE/kdeedu/kalgebra/analitzagui/graph2d.h #1206518:1206519
@@ -52,6 +52,8 @@
Selection /**< There is a rectangle delimiting a region, for zooming. */
};
+ enum Format { PNG, SVG };
+
/** Constructor. Constructs a new Graph2D. */
explicit Graph2D(FunctionsModel* fm, QWidget *parent = 0);
@@ -63,7 +65,7 @@
QSize sizeHint() const { return QSize(100, 100); }
/** Saves the graphs to a file located at @p path. */
- bool toImage(const QString& path);
+ bool toImage(const QString& path, Format f);
/** Sets whether we will see a grid or only the axes. */
void setSquares(bool newSquare) { m_squares=newSquare; forceRepaint(); }
--- trunk/KDE/kdeedu/kalgebra/src/kalgebra.cpp #1206518:1206519
@@ -56,6 +56,7 @@
#include <KProcess>
#include <KRecentFilesAction>
#include <KApplication>
+#include <kabstractfilewidget.h>
class Add2DOption : public InlineOptions
{
@@ -560,10 +561,20 @@
void KAlgebra::saveGraph()
{
- QString path = KFileDialog::getSaveFileName(KUrl(), i18n("*.png|Image \
File\n*.svg|SVG File"), this, QString(), \
KFileDialog::ConfirmOverwrite);
- if(!path.isEmpty())
- m_graph2d->toImage(path);
+ KFileDialog dialog(KUrl(), i18n("*.png|Image File\n*.svg|SVG File"), this);
+ dialog.setOperationMode(KFileDialog::Saving);
+ dialog.setConfirmOverwrite(true);
+
+ if(dialog.exec()) {
+ QString filter = dialog.fileWidget()->currentFilter();
+ QString filename = dialog.selectedFile();
+
+ Graph2D::Format f=Graph2D::PNG;
+ if(filename.endsWith(".svg") || (!filename.endsWith(".png") && filter.mid(2, \
3)=="svg")) + f=Graph2D::SVG;
+ m_graph2d->toImage(filename, f);
}
+}
void KAlgebra::tabChanged(int n)
{
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic