r14822 by cbradney - #8872: PATCH scaleImage/setImageScale inconsistent with other tokens, three new image manipulation tokens.
scribus-commit
scribus-commit at lists.scribus.net
Thu Feb 25 19:50:23 CET 2010
Revision: 14822
Author: cbradney
Date: 2010-02-25T18:45:50.658261Z
Commit message: #8872: PATCH scaleImage/setImageScale inconsistent with other tokens, three new image manipulation tokens.
Changeset:
M /trunk/Scribus/scribus/plugins/scriptplugin/cmdmani.cpp
M /trunk/Scribus/scribus/plugins/scriptplugin/cmdmani.h
M /trunk/Scribus/scribus/plugins/scriptplugin/scriptplugin.cpp
Diffs:
Index: scribus/plugins/scriptplugin/cmdmani.cpp
===================================================================
--- scribus/plugins/scriptplugin/cmdmani.cpp (revision 14821)
+++ scribus/plugins/scriptplugin/cmdmani.cpp (revision 14822)
@@ -11,6 +11,7 @@
#include "scribuscore.h"
#include "scribusdoc.h"
#include "undomanager.h"
+#include "sctextstream.h"
PyObject *scribus_loadimage(PyObject* /* self */, PyObject* args)
{
@@ -50,8 +51,27 @@
PyErr_SetString(ScribusException, QObject::tr("Specified item not an image frame.","python error").toLocal8Bit().constData());
return NULL;
}
+
+ // Grab the old selection - but use it only where is there any
+ Selection tempSelection(*ScCore->primaryMainWindow()->doc->m_Selection);
+ bool hadOrigSelection = (tempSelection.count() != 0);
+
+ ScCore->primaryMainWindow()->doc->m_Selection->clear();
+ // Clear the selection
+ ScCore->primaryMainWindow()->view->Deselect();
+ // Select the item, which will also select its group if
+ // there is one.
+ ScCore->primaryMainWindow()->view->SelectItemNr(item->ItemNr);
+
+ // scale
ScCore->primaryMainWindow()->doc->itemSelection_SetImageScale(x, y); //CB why when this is done above?
ScCore->primaryMainWindow()->doc->updatePic();
+
+ // Now restore the selection.
+ ScCore->primaryMainWindow()->view->Deselect();
+ if (hadOrigSelection)
+ *ScCore->primaryMainWindow()->doc->m_Selection=tempSelection;
+
// Py_INCREF(Py_None);
// return Py_None;
Py_RETURN_NONE;
@@ -73,15 +93,134 @@
PyErr_SetString(ScribusException, QObject::tr("Specified item not an image frame.","python error").toLocal8Bit().constData());
return NULL;
}
+
+ // Grab the old selection - but use it only where is there any
+ Selection tempSelection(*ScCore->primaryMainWindow()->doc->m_Selection);
+ bool hadOrigSelection = (tempSelection.count() != 0);
+
+ ScCore->primaryMainWindow()->doc->m_Selection->clear();
+ // Clear the selection
+ ScCore->primaryMainWindow()->view->Deselect();
+ // Select the item, which will also select its group if
+ // there is one.
+ ScCore->primaryMainWindow()->view->SelectItemNr(item->ItemNr);
+
+ // scale
double newScaleX = x / item->pixm.imgInfo.xres * 72.0;
double newScaleY = y / item->pixm.imgInfo.yres * 72.0;
ScCore->primaryMainWindow()->doc->itemSelection_SetImageScale(newScaleX, newScaleY); //CB why when this is done above?
ScCore->primaryMainWindow()->doc->updatePic();
+
+ // Now restore the selection.
+ ScCore->primaryMainWindow()->view->Deselect();
+ if (hadOrigSelection)
+ *ScCore->primaryMainWindow()->doc->m_Selection=tempSelection;
+
// Py_INCREF(Py_None);
// return Py_None;
Py_RETURN_NONE;
}
+PyObject *scribus_setimageoffset(PyObject* /* self */, PyObject* args)
+{
+ char *Name = const_cast<char*>("");
+ double x, y;
+ if (!PyArg_ParseTuple(args, "dd|es", &x, &y, "utf-8", &Name))
+ return NULL;
+ if(!checkHaveDocument())
+ return NULL;
+ PageItem *item = GetUniqueItem(QString::fromUtf8(Name));
+ if (item == NULL)
+ return NULL;
+ if (! item->asImageFrame())
+ {
+ PyErr_SetString(ScribusException, QObject::tr("Specified item not an image frame.","python error").toLocal8Bit().constData());
+ return NULL;
+ }
+ // Grab the old selection - but use it only where is there any
+ Selection tempSelection(*ScCore->primaryMainWindow()->doc->m_Selection);
+ bool hadOrigSelection = (tempSelection.count() != 0);
+
+ ScCore->primaryMainWindow()->doc->m_Selection->clear();
+ // Clear the selection
+ ScCore->primaryMainWindow()->view->Deselect();
+ // Select the item, which will also select its group if
+ // there is one.
+ ScCore->primaryMainWindow()->view->SelectItemNr(item->ItemNr);
+
+ // offset
+ ScCore->primaryMainWindow()->doc->itemSelection_SetImageOffset(x, y); //CB why when this is done above?
+ ScCore->primaryMainWindow()->doc->updatePic();
+
+ // Now restore the selection.
+ ScCore->primaryMainWindow()->view->Deselect();
+ if (hadOrigSelection)
+ *ScCore->primaryMainWindow()->doc->m_Selection=tempSelection;
+
+// Py_INCREF(Py_None);
+// return Py_None;
+ Py_RETURN_NONE;
+}
+
+PyObject *scribus_setimagebrightness(PyObject* /* self */, PyObject* args)
+{
+ char *Name = const_cast<char*>("");
+ double n;
+ if (!PyArg_ParseTuple(args, "d|es", &n, "utf-8", &Name))
+ return NULL;
+ if(!checkHaveDocument())
+ return NULL;
+ PageItem *item = GetUniqueItem(QString::fromUtf8(Name));
+ if (item == NULL)
+ return NULL;
+ if (! item->asImageFrame())
+ {
+ PyErr_SetString(ScribusException, QObject::tr("Specified item not an image frame.","python error").toLocal8Bit().constData());
+ return NULL;
+ }
+
+ ImageEffect ef;
+ ef.effectCode = ScImage::EF_BRIGHTNESS;
+ ScTextStream fp(&ef.effectParameters, QIODevice::WriteOnly);
+ fp << n;
+
+ item->effectsInUse.append(ef);
+ item->pixm.applyEffect(item->effectsInUse, ScCore->primaryMainWindow()->doc->PageColors, false);
+
+ ScCore->primaryMainWindow()->doc->updatePic();
+// Py_INCREF(Py_None);
+// return Py_None;
+ Py_RETURN_NONE;
+}
+
+PyObject *scribus_setimagegrayscale(PyObject* /* self */, PyObject* args)
+{
+ char *Name = const_cast<char*>("");
+ if (!PyArg_ParseTuple(args, "|es", "utf-8", &Name))
+ return NULL;
+ if(!checkHaveDocument())
+ return NULL;
+ PageItem *item = GetUniqueItem(QString::fromUtf8(Name));
+ if (item == NULL)
+ return NULL;
+ if (! item->asImageFrame())
+ {
+ PyErr_SetString(ScribusException, QObject::tr("Specified item not an image frame.","python error").toLocal8Bit().constData());
+ return NULL;
+ }
+
+ ImageEffect ef;
+ ef.effectCode = ScImage::EF_GRAYSCALE;
+
+ item->effectsInUse.append(ef);
+ item->pixm.applyEffect(item->effectsInUse, ScCore->primaryMainWindow()->doc->PageColors, false);
+
+ ScCore->primaryMainWindow()->doc->updatePic();
+// Py_INCREF(Py_None);
+// return Py_None;
+ Py_RETURN_NONE;
+}
+
PyObject *scribus_moveobjrel(PyObject* /* self */, PyObject* args)
{
char *Name = const_cast<char*>("");
@@ -110,13 +249,13 @@
ScCore->primaryMainWindow()->doc->moveGroup(ValueToPoint(x), ValueToPoint(y));
ScCore->primaryMainWindow()->view->endGroupTransaction();
}
- else
+ else {
ScCore->primaryMainWindow()->doc->MoveItem(ValueToPoint(x), ValueToPoint(y), item);
+ }
// Now restore the selection.
ScCore->primaryMainWindow()->view->Deselect();
if (hadOrigSelection)
*ScCore->primaryMainWindow()->doc->m_Selection=tempSelection;
-
Py_RETURN_NONE;
}
@@ -443,5 +582,5 @@
<< scribus_ungroupobj__doc__ << scribus_scalegroup__doc__
<< scribus_loadimage__doc__ << scribus_scaleimage__doc__
<< scribus_setimagescale__doc__ << scribus_lockobject__doc__
- << scribus_islocked__doc__ << scribus_setscaleimagetoframe__doc__;
+ << scribus_islocked__doc__ << scribus_setscaleimagetoframe__doc__ << scribus_setimagebrightness__doc__ << scribus_setimagegrayscale__doc__ << scribus_setimageoffset__doc__;
}
Index: scribus/plugins/scriptplugin/cmdmani.h
===================================================================
--- scribus/plugins/scriptplugin/cmdmani.h (revision 14821)
+++ scribus/plugins/scriptplugin/cmdmani.h (revision 14822)
@@ -169,6 +169,18 @@
PyObject *scribus_scaleimage(PyObject * /*self*/, PyObject* args);
/*! docstring */
+PyDoc_STRVAR(scribus_setimageoffset__doc__,
+QT_TR_NOOP("setImageOffset(x, y [, \"name\"])\n\
+\n\
+Sets the internal offset of the picture in the image frame \"name\".\n\
+If \"name\" is not given the currently selected item is used.\n\
+\n\
+May raise WrongFrameTypeError if the target frame is not an image frame\n\
+"));
+/*! Scale Image. */
+PyObject *scribus_setimageoffset(PyObject * /*self*/, PyObject* args);
+
+/*! docstring */
PyDoc_STRVAR(scribus_setimagescale__doc__,
QT_TR_NOOP("setImageScale(x, y [, \"name\"])\n\
\n\
@@ -182,6 +194,31 @@
PyObject *scribus_setimagescale(PyObject * /*self*/, PyObject* args);
/*! docstring */
+PyDoc_STRVAR(scribus_setimagebrightness__doc__,
+QT_TR_NOOP("setImageBrightness(n [, \"name\"])\n\
+\n\
+Set image brightness effect of the picture in the image frame \"name\".\n\
+If \"name\" is not given the currently selected item is used. A number of 1\n\
+means 100 %. Brightness factor is equal to the value shown on properties palette.\n\
+\n\
+May raise WrongFrameTypeError if the target frame is not an image frame\n\
+"));
+/*! Set Image Brightness. */
+PyObject *scribus_setimagebrightness(PyObject * /*self*/, PyObject* args);
+
+/*! docstring */
+PyDoc_STRVAR(scribus_setimagegrayscale__doc__,
+QT_TR_NOOP("setImageGrayscale([\"name\"])\n\
+\n\
+Set image grayscale effect of the picture in the image frame \"name\".\n\
+If \"name\" is not given the currently selected item is used.\n\
+\n\
+May raise WrongFrameTypeError if the target frame is not an image frame\n\
+"));
+/*! Set Image Brightness. */
+PyObject *scribus_setimagegrayscale(PyObject * /*self*/, PyObject* args);
+
+/*! docstring */
PyDoc_STRVAR(scribus_lockobject__doc__,
QT_TR_NOOP("lockObject([\"name\"]) -> bool\n\
\n\
Index: scribus/plugins/scriptplugin/scriptplugin.cpp
===================================================================
--- scribus/plugins/scriptplugin/scriptplugin.cpp (revision 14821)
+++ scribus/plugins/scriptplugin/scriptplugin.cpp (revision 14822)
@@ -430,7 +430,10 @@
{const_cast<char*>("savePageAsEPS"), scribus_savepageeps, METH_VARARGS, tr(scribus_savepageeps__doc__)},
{const_cast<char*>("scaleGroup"), scribus_scalegroup, METH_VARARGS, tr(scribus_scalegroup__doc__)},
{const_cast<char*>("scaleImage"), scribus_scaleimage, METH_VARARGS, tr(scribus_scaleimage__doc__)},
+ {const_cast<char*>("setImageBrightness"), scribus_setimagebrightness, METH_VARARGS, tr(scribus_setimagebrightness__doc__)},
+ {const_cast<char*>("setImageGrayscale"), scribus_setimagegrayscale, METH_VARARGS, tr(scribus_setimagegrayscale__doc__)},
{const_cast<char*>("setImageScale"), scribus_setimagescale, METH_VARARGS, tr(scribus_setimagescale__doc__)},
+ {const_cast<char*>("setImageOffset"), scribus_setimageoffset, METH_VARARGS, tr(scribus_setimageoffset__doc__)},
{const_cast<char*>("selectionCount"), (PyCFunction)scribus_selcount, METH_NOARGS, tr(scribus_selcount__doc__)},
{const_cast<char*>("selectObject"), scribus_selectobj, METH_VARARGS, tr(scribus_selectobj__doc__)},
{const_cast<char*>("selectText"), scribus_selecttext, METH_VARARGS, tr(scribus_selecttext__doc__)},
More information about the scribus-commit
mailing list