[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: koffice/kexi/plugins/reportspgz/backend
From: Adam Pigg <adam () piggz ! co ! uk>
Date: 2008-05-04 14:11:11
Message-ID: 1209910271.596777.28067.nullmailer () svn ! kde ! org
[Download RAW message or body]
SVN commit 803932 by piggz:
Scripting support for images, allowing code such as:
function detail_onrender()
{
var img = report.objectByName("Image1");
img.setResizeMode("Stretch");
img.loadFromFile(math.value("Path"));
}
M +24 -20 common/krimagedata.cpp
M +2 -11 common/krimagedata.h
M +3 -0 common/krreportdata.cpp
M +3 -1 common/krreportdata.h
M +1 -1 renderer/scripting/krscripthandler.cpp
M +34 -1 renderer/scripting/krscriptimage.cpp
M +32 -5 renderer/scripting/krscriptimage.h
M +2 -2 wrtembed/reportdesigner.cpp
--- trunk/koffice/kexi/plugins/reportspgz/backend/common/krimagedata.cpp #803931:803932
@@ -33,7 +33,7 @@
QDomNodeList nl = element.childNodes();
QString n;
QDomNode node;
- _img_inline = false;
+
for ( int i = 0; i < nl.count(); i++ )
{
node = nl.item ( i );
@@ -55,7 +55,6 @@
kDebug() << "while parsing field data, encountered unknown element: " << n << endl;
}
}
- _img_inline = false;
}
else if ( n == "name" )
{
@@ -75,7 +74,6 @@
// method
kDebug() << "Loading Image Data" << endl;
setInlineImageData ( node.firstChild().nodeValue().toLatin1() );
- _img_inline = true;
}
else if ( n == "rect" )
{
@@ -122,15 +120,8 @@
bool KRImageData::isInline()
{
- return !(inlineImageData() == "");
+ return !(inlineImageData().isEmpty());
}
-void KRImageData::setInline ( bool yes )
-{
- if ( _img_inline != yes )
- {
- _img_inline = yes;
- }
-}
QString KRImageData::inlineImageData()
{
@@ -145,16 +136,29 @@
return imageEncoded;
}
-void KRImageData::setInlineImageData ( QByteArray dat )
+void KRImageData::setInlineImageData ( QByteArray dat, const QString &fn )
{
- QByteArray binaryStream;
-
- binaryStream = KCodecs::base64Decode(dat);
- QImage img (binaryStream);
- QPixmap pix;
- pix.convertFromImage(img, QPixmap::Color);
-
- _staticImage->setValue(pix);
+
+
+ if (!fn.isEmpty())
+ {
+ QPixmap pix(fn);
+ _staticImage->setValue(pix);
+ }
+ else
+ {
+
+ QByteArray binaryStream;
+
+ binaryStream = KCodecs::base64Decode(dat);
+ QImage img(binaryStream);
+ QPixmap pix;
+ pix.convertFromImage(img, QPixmap::Color);
+
+ _staticImage->setValue(pix);
+
+ }
+
}
QString KRImageData::mode() { return _resizeMode->value().toString(); }
--- trunk/koffice/kexi/plugins/reportspgz/backend/common/krimagedata.h #803931:803932
@@ -51,8 +51,8 @@
virtual int type() const;
void setMode ( QString );
- void setInline ( bool );
- void setInlineImageData ( QByteArray );
+
+ void setInlineImageData ( QByteArray, const QString& = QString());
void setColumn( QString );
QString mode();
bool isInline();
@@ -64,20 +64,11 @@
QRect _rect();
KRPos _pos;
KRSize _size;
- //QString mode;
- //QString format; // }
- //QString inline_data; // } INLINE
- // OR
- //ORDataData data; // } FROM DB
-
KoProperty::Property * _controlSource;
KoProperty::Property* _resizeMode;
KoProperty::Property* _staticImage;
-
-
QString _format;
- bool _img_inline;
private:
static int RTTI;
--- trunk/koffice/kexi/plugins/reportspgz/backend/common/krreportdata.cpp #803931:803932
@@ -64,7 +64,10 @@
else if ( elemThis.tagName() == "datasource" )
query = elemThis.text();
else if ( elemThis.tagName() == "script" )
+ {
script = elemThis.text();
+ _interpreter = elemThis.attribute("interpreter");
+ }
else if ( elemThis.tagName() == "size" )
{
if ( elemThis.firstChild().isText() )
--- trunk/koffice/kexi/plugins/reportspgz/backend/common/krreportdata.h #803931:803932
@@ -88,11 +88,13 @@
*/
KRSectionData* section(const QString&);
+ QString interpreter(){return _interpreter;}
protected:
QString title;
QString query;
QString script;
-
+ QString _interpreter;
+
ReportPageOptions page;
KRSectionData * pghead_first;
--- trunk/koffice/kexi/plugins/reportspgz/backend/renderer/scripting/krscripthandler.cpp #803931:803932
@@ -52,7 +52,7 @@
// Create the Kross::Action instance .
_action = new Kross::Action(this, "ReportScript");
- _action->setInterpreter("javascript");
+ _action->setInterpreter(d->interpreter());
//Add math functions to the script
_functions = new KRScriptFunctions(_curs);
--- trunk/koffice/kexi/plugins/reportspgz/backend/renderer/scripting/krscriptimage.cpp #803931:803932
@@ -1,6 +1,6 @@
/*
* Kexi Report Plugin
- * Copyright (C) 2007-2008 by Adam Pigg (adam@piggz.co.uk)
+ * Copyright (C) 2007-2008 by Adam Pigg (adam@piggz.co.uk)
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -19,6 +19,9 @@
*/
#include "krscriptimage.h"
#include <krimagedata.h>
+#include <QBuffer>
+#include <kcodecs.h>
+#include <kdebug.h>
namespace Scripting
{
@@ -50,4 +53,34 @@
{
_image->_size.setPointSize ( s );
}
+
+ QString Image::resizeMode()
+ {
+ return _image->_resizeMode->value().toString();
+ }
+
+ void Image::setResizeMode ( const QString &rm )
+ {
+ if ( rm == "Stretch" )
+ {
+ _image->_resizeMode->setValue ( "Stretch" );
+ }
+ else
+ {
+ _image->_resizeMode->setValue ( "Clip" );
+ }
+ }
+
+ void Image::setInlineImage( const QByteArray &ba )
+ {
+ _image->setInlineImageData(ba);
+ }
+
+ void Image::loadFromFile( const QVariant &pth )
+ {
+ QPixmap img;
+
+ QString str = pth.toString();
+ _image->setInlineImageData(QByteArray(), str);
+ }
}
--- trunk/koffice/kexi/plugins/reportspgz/backend/renderer/scripting/krscriptimage.h #803931:803932
@@ -1,6 +1,6 @@
/*
* Kexi Report Plugin
- * Copyright (C) 2007-2008 by Adam Pigg (adam@piggz.co.uk)
+ * Copyright (C) 2007-2008 by Adam Pigg (adam@piggz.co.uk)
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -36,15 +36,15 @@
{
Q_OBJECT
public:
- Image ( KRImageData *);
+ Image ( KRImageData * );
~Image();
public slots:
/**
- * Get the position of the barcode
- * @return position in points
+ * Get the position of the barcode
+ * @return position in points
*/
QPointF position();
@@ -65,7 +65,34 @@
* Set the size of the barcode in points
* @param Size
*/
- void setSize ( const QSizeF& );
+ void setSize ( const QSizeF& );
+
+ /**
+ * Get the resize mode for the image
+ * @return resizeMode Clip or Stretch
+ */
+ QString resizeMode();
+
+ /**
+ * Sets the resize mode for the image
+ * @param ResizeMode "Stretch" or "Clip" default is to clip
+ */
+ void setResizeMode(const QString &);
+
+ /**
+ * Sets the data for the static image
+ * the data should be base64 encoded
+ * @param RawImageData
+ */
+ void setInlineImage(const QByteArray&);
+
+ /**
+ * Get the data from a file (expected to be an image)
+ * the returned data will be base64 encoded
+ * @param Path location of file
+ * @return File data enoded in base64
+ */
+ void loadFromFile(const QVariant &);
private:
KRImageData *_image;
--- trunk/koffice/kexi/plugins/reportspgz/backend/wrtembed/reportdesigner.cpp #803931:803932
@@ -734,6 +734,7 @@
QDomElement scr = doc.createElement ( "script" );
scr.appendChild ( doc.createTextNode ( _script ) );
+ scr.setAttribute("interpreter", _interpreter->value().toString());
root.appendChild ( scr );
QDomElement grd = doc.createElement ( "grid" );
@@ -1561,9 +1562,8 @@
d->editorDialog->setMainWidget ( d->editor );
d->editorDialog->setMinimumSize ( 600,500 );
- d->editor->setHighlightMode ( "javascript" );
-
}
+ d->editor->setHighlightMode ( _interpreter->value().toString() );
d->editor->setText ( orig );
if ( d->editorDialog->exec() )
{
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic