r16116 by fschmid - Made the Mesh Distortion Plugin working again.
scribus-commit
scribus-commit at lists.scribus.net
Sun Dec 19 22:18:20 CET 2010
Author: fschmid
Date: Sun Dec 19 21:18:20 2010
New Revision: 16116
URL: http://scribus.info/websvn/listing.php?repname=Scribus&sc=1&rev=16116
Log:
Made the Mesh Distortion Plugin working again.
Modified:
trunk/Scribus/scribus/plugins/tools/2geomtools/meshdistortion/meshdistortiondialog.cpp
trunk/Scribus/scribus/plugins/tools/2geomtools/meshdistortion/meshdistortiondialog.h
trunk/Scribus/scribus/plugins/tools/lenseffects/lensdialog.cpp
Modified: trunk/Scribus/scribus/plugins/tools/2geomtools/meshdistortion/meshdistortiondialog.cpp
URL: http://scribus.info/websvn/diff.php?repname=Scribus&rev=16116&path=/trunk/Scribus/scribus/plugins/tools/2geomtools/meshdistortion/meshdistortiondialog.cpp
==============================================================================
--- trunk/Scribus/scribus/plugins/tools/2geomtools/meshdistortion/meshdistortiondialog.cpp (original)
+++ trunk/Scribus/scribus/plugins/tools/2geomtools/meshdistortion/meshdistortiondialog.cpp Sun Dec 19 21:18:20 2010
@@ -124,21 +124,92 @@
buttonZoomOut->setIcon(QIcon(loadIcon("16/zoom-out.png")));
buttonZoomIn->setIcon(QIcon(loadIcon("16/zoom-in.png")));
m_doc = doc;
+ addItemsToScene(doc->m_Selection, doc, 0, 0);
+ for(unsigned dim = 0; dim < 2; dim++)
+ {
+ sb2[dim].us = 2;
+ sb2[dim].vs = 2;
+ const int depth = sb2[dim].us*sb2[dim].vs;
+ sb2[dim].resize(depth, Geom::Linear2d(0));
+ }
+ handles.resize(sb2[0].vs*sb2[0].us*4);
+ origHandles.resize(sb2[0].vs*sb2[0].us*4);
+ unsigned ii = 0;
+ for(unsigned vi = 0; vi < sb2[0].vs; vi++)
+ {
+ for(unsigned ui = 0; ui < sb2[0].us; ui++)
+ {
+ for(unsigned iv = 0; iv < 2; iv++)
+ {
+ for(unsigned iu = 0; iu < 2; iu++)
+ {
+ handles[ii++] = Geom::Point((2*(iu+ui)/(2.*ui+1)+1)*w4, (2*(iv+vi)/(2.*vi+1)+1)*w4);
+ }
+ }
+ }
+ }
+ Geom::Point dir(1,-2);
+ for(unsigned dim = 0; dim < 2; dim++)
+ {
+ Geom::Point dir(0,0);
+ dir[dim] = 1;
+ for(unsigned vi = 0; vi < sb2[dim].vs; vi++)
+ {
+ for(unsigned ui = 0; ui < sb2[dim].us; ui++)
+ {
+ for(unsigned iv = 0; iv < 2; iv++)
+ {
+ for(unsigned iu = 0; iu < 2; iu++)
+ {
+ unsigned corner = iu + 2*iv;
+ unsigned i = ui + vi*sb2[dim].us;
+ Geom::Point base((2*(iu+ui)/(2.*ui+1)+1)*w4, (2*(iv+vi)/(2.*vi+1)+1)*w4);
+ if(vi == 0 && ui == 0)
+ base = Geom::Point(w4, w4);
+ double dl = dot((handles[corner+4*i] - base), dir)/dot(dir,dir);
+ sb2[dim][i][corner] = dl/(ww/2.0)*pow(4.0f,((int)(ui+vi)));
+ }
+ }
+ }
+ }
+ }
+ QPainterPath pathG;
+ D2sb2d2QPainterPath(&pathG, sb2, 9, ww);
+ pItemG = new QGraphicsPathItem(pathG);
+ pItemG->setPen(QPen(Qt::black));
+ pItemG->setBrush(Qt::NoBrush);
+ pItemG->setZValue(8888888);
+ scene.addItem(pItemG);
+ for(unsigned i = 0; i < handles.size(); i++)
+ {
+ origHandles[i] = handles[i];
+ double x = handles[i][Geom::X];
+ double y = handles[i][Geom::Y];
+ NodeItem* pItemN = new NodeItem(QRectF(x-4.0, y-4.0, 8.0, 8.0), i, this);
+ scene.addItem(pItemN);
+ nodeItems.append(pItemN);
+ }
+ previewLabel->setRenderHint(QPainter::Antialiasing);
+ previewLabel->setScene(&scene);
+ isFirst = true;
+ connect(buttonZoomIn, SIGNAL(clicked()), this, SLOT(doZoomIn()));
+ connect(buttonZoomOut, SIGNAL(clicked()), this, SLOT(doZoomOut()));
+ connect(resetButton, SIGNAL(clicked()), this, SLOT(doReset()));
+}
+
+void MeshDistortionDialog::addItemsToScene(Selection* itemSelection, ScribusDoc *doc, QGraphicsPathItem* parentItem, PageItem* parent)
+{
PageItem *currItem;
double gx, gy, gh, gw;
- doc->m_Selection->setGroupRect();
- doc->m_Selection->getGroupRect(&gx, &gy, &gw, &gh);
- uint selectedItemCount = doc->m_Selection->count();
+ itemSelection->setGroupRect();
+ itemSelection->getGroupRect(&gx, &gy, &gw, &gh);
+ uint selectedItemCount = itemSelection->count();
w4 = qMax(gw, gh) / 2.0;
w2 = qMax(gw, gh);
ww = qMax(gw, gh) * 2.0;
- QStack<PageItem*> groupStack;
- QStack<QGraphicsPathItem*> groupStack2;
- QStack<PageItem*> groupStack3;
- groupStack2.push(0);
for (uint i = 0; i < selectedItemCount; ++i)
{
- currItem = doc->m_Selection->itemAt(i);
+ currItem = itemSelection->itemAt(i);
FPointArray path = currItem->PoLine;
deltaX = ((w2 - gw) / 2.0) + w4;
deltaY = ((w2 - gh) / 2.0) + w4;
@@ -147,8 +218,8 @@
pp = path.toQPainterPath(false);
else
pp = path.toQPainterPath(true);
- QGraphicsPathItem* pItem = new QGraphicsPathItem(pp, groupStack2.top());
- if (groupStack2.top() == 0)
+ QGraphicsPathItem* pItem = new QGraphicsPathItem(pp, parentItem);
+ if (parentItem == 0)
{
scene.addItem(pItem);
pItem->setPos(currItem->xPos() - gx + deltaX, currItem->yPos() - gy + deltaY);
@@ -156,7 +227,6 @@
}
else
{
- PageItem* parent = groupStack3.top();
QTransform mm;
mm.rotate(-parent->rotation());
mm.translate(-parent->xPos(), -parent->yPos());
@@ -175,7 +245,8 @@
origPath.append(path_a_pw);
pItem->setZValue(i);
origPathItem.append(pItem);
- if (((currItem->fillColor() == CommonStrings::None) && (currItem->GrType == 0)) || (currItem->controlsGroup()))
+ origPageItem.append(currItem);
+ if (((currItem->fillColor() == CommonStrings::None) && (currItem->GrType == 0)) || (currItem->isGroup()))
pItem->setBrush(Qt::NoBrush);
else
{
@@ -246,7 +317,7 @@
pItem->setBrush(paint);
}
}
- if (currItem->controlsGroup())
+ if (currItem->isGroup())
pItem->setPen(Qt::NoPen);
else if (currItem->NamedLStyle.isEmpty())
{
@@ -314,47 +385,85 @@
pItem->setPen(QPen(paint, currItem->lineWidth(), currItem->lineStyle(), currItem->lineEnd(), currItem->lineJoin()));
}
}
- if (currItem->controlsGroup())
- {
- groupStack.push(currItem->groupsLastItem);
- groupStack2.push(pItem);
- groupStack3.push(currItem);
+ if (currItem->isGroup())
+ {
pItem->setFlags(QGraphicsItem::ItemClipsChildrenToShape);
- }
- if (groupStack.count() != 0)
- {
- while (currItem == groupStack.top())
- {
- groupStack3.pop();
- groupStack2.pop();
- groupStack.pop();
- if (groupStack.count() == 0)
- break;
- }
- }
- }
- for(unsigned dim = 0; dim < 2; dim++)
- {
- sb2[dim].us = 2;
- sb2[dim].vs = 2;
- const int depth = sb2[dim].us*sb2[dim].vs;
- sb2[dim].resize(depth, Geom::Linear2d(0));
- }
- handles.resize(sb2[0].vs*sb2[0].us*4);
- origHandles.resize(sb2[0].vs*sb2[0].us*4);
- unsigned ii = 0;
- for(unsigned vi = 0; vi < sb2[0].vs; vi++)
- {
- for(unsigned ui = 0; ui < sb2[0].us; ui++)
- {
- for(unsigned iv = 0; iv < 2; iv++)
- {
- for(unsigned iu = 0; iu < 2; iu++)
- {
- handles[ii++] = Geom::Point((2*(iu+ui)/(2.*ui+1)+1)*w4, (2*(iv+vi)/(2.*vi+1)+1)*w4);
- }
- }
- }
+ Selection tmpSelection(this, false);
+ for (int a = 0; a < currItem->groupItemList.count(); a++)
+ {
+ tmpSelection.addItem(currItem->groupItemList.at(a));
+ }
+ addItemsToScene(&tmpSelection, doc, pItem, currItem);
+ }
+ }
+}
+
+void MeshDistortionDialog::showEvent(QShowEvent *e)
+{
+ QDialog::showEvent(e);
+ if (isFirst)
+ {
+ QRectF scR = scene.itemsBoundingRect().adjusted(-50, -50, 50, 50);
+ previewLabel->fitInView(scR, Qt::KeepAspectRatio);
+ scene.setSceneRect(scR);
+ adjustHandles();
+ }
+ isFirst = false;
+}
+
+void MeshDistortionDialog::doZoomIn()
+{
+ previewLabel->scale(2.0, 2.0);
+ adjustHandles();
+}
+
+void MeshDistortionDialog::doZoomOut()
+{
+ previewLabel->scale(0.5, 0.5);
+ adjustHandles();
+}
+
+void MeshDistortionDialog::doReset()
+{
+ bool found = false;
+ for(int n = 0; n < nodeItems.count(); n++)
+ {
+ if (nodeItems.at(n)->isSelected())
+ {
+ found = true;
+ handles[nodeItems.at(n)->handle] = origHandles[nodeItems.at(n)->handle];
+ }
+ }
+ if (!found)
+ {
+ for(unsigned i = 0; i < handles.size(); i++)
+ {
+ handles[i] = origHandles[i];
+ }
+ }
+ adjustHandles();
+ updateMesh(false);
+}
+
+void MeshDistortionDialog::adjustHandles()
+{
+ double sc = previewLabel->matrix().m11();
+ for(int n = 0; n < nodeItems.count(); n++)
+ {
+ double x = handles[n][Geom::X];
+ double y = handles[n][Geom::Y];
+ QPointF mm = nodeItems.at(n)->mapFromScene(QPointF(x - 4.0 / sc, y - 4.0 / sc));
+ nodeItems.at(n)->setRect(QRectF(mm.x(), mm.y(), 8.0 / sc, 8.0 / sc));
+ }
+}
+
+void MeshDistortionDialog::updateMesh(bool gridOnly)
+{
+ for(int n = 0; n < nodeItems.count(); n++)
+ {
+ QPointF mm = nodeItems.at(n)->mapToScene(nodeItems.at(n)->rect().center());
+ Geom::Point mouse(mm.x(), mm.y());
+ handles[n] = mouse;
}
Geom::Point dir(1,-2);
for(unsigned dim = 0; dim < 2; dim++)
@@ -381,122 +490,6 @@
}
}
}
- QPainterPath pathG;
- D2sb2d2QPainterPath(&pathG, sb2, 9, ww);
- pItemG = new QGraphicsPathItem(pathG);
- pItemG->setPen(QPen(Qt::black));
- pItemG->setBrush(Qt::NoBrush);
- pItemG->setZValue(8888888);
- scene.addItem(pItemG);
- for(unsigned i = 0; i < handles.size(); i++)
- {
- origHandles[i] = handles[i];
- double x = handles[i][Geom::X];
- double y = handles[i][Geom::Y];
- NodeItem* pItemN = new NodeItem(QRectF(x-4.0, y-4.0, 8.0, 8.0), i, this);
- scene.addItem(pItemN);
- nodeItems.append(pItemN);
- }
- previewLabel->setRenderHint(QPainter::Antialiasing);
- previewLabel->setScene(&scene);
- isFirst = true;
- connect(buttonZoomIn, SIGNAL(clicked()), this, SLOT(doZoomIn()));
- connect(buttonZoomOut, SIGNAL(clicked()), this, SLOT(doZoomOut()));
- connect(resetButton, SIGNAL(clicked()), this, SLOT(doReset()));
-}
-
-void MeshDistortionDialog::showEvent(QShowEvent *e)
-{
- QDialog::showEvent(e);
- if (isFirst)
- {
- QRectF scR = scene.itemsBoundingRect().adjusted(-50, -50, 50, 50);
- previewLabel->fitInView(scR, Qt::KeepAspectRatio);
- scene.setSceneRect(scR);
- adjustHandles();
- }
- isFirst = false;
-}
-
-void MeshDistortionDialog::doZoomIn()
-{
- previewLabel->scale(2.0, 2.0);
- adjustHandles();
-}
-
-void MeshDistortionDialog::doZoomOut()
-{
- previewLabel->scale(0.5, 0.5);
- adjustHandles();
-}
-
-void MeshDistortionDialog::doReset()
-{
- bool found = false;
- for(int n = 0; n < nodeItems.count(); n++)
- {
- if (nodeItems.at(n)->isSelected())
- {
- found = true;
- handles[nodeItems.at(n)->handle] = origHandles[nodeItems.at(n)->handle];
- }
- }
- if (!found)
- {
- for(unsigned i = 0; i < handles.size(); i++)
- {
- handles[i] = origHandles[i];
- }
- }
- adjustHandles();
- updateMesh(false);
-}
-
-void MeshDistortionDialog::adjustHandles()
-{
- double sc = previewLabel->matrix().m11();
- for(int n = 0; n < nodeItems.count(); n++)
- {
- double x = handles[n][Geom::X];
- double y = handles[n][Geom::Y];
- QPointF mm = nodeItems.at(n)->mapFromScene(QPointF(x - 4.0 / sc, y - 4.0 / sc));
- nodeItems.at(n)->setRect(QRectF(mm.x(), mm.y(), 8.0 / sc, 8.0 / sc));
- }
-}
-
-void MeshDistortionDialog::updateMesh(bool gridOnly)
-{
- for(int n = 0; n < nodeItems.count(); n++)
- {
- QPointF mm = nodeItems.at(n)->mapToScene(nodeItems.at(n)->rect().center());
- Geom::Point mouse(mm.x(), mm.y());
- handles[n] = mouse;
- }
- Geom::Point dir(1,-2);
- for(unsigned dim = 0; dim < 2; dim++)
- {
- Geom::Point dir(0,0);
- dir[dim] = 1;
- for(unsigned vi = 0; vi < sb2[dim].vs; vi++)
- {
- for(unsigned ui = 0; ui < sb2[dim].us; ui++)
- {
- for(unsigned iv = 0; iv < 2; iv++)
- {
- for(unsigned iu = 0; iu < 2; iu++)
- {
- unsigned corner = iu + 2*iv;
- unsigned i = ui + vi*sb2[dim].us;
- Geom::Point base((2*(iu+ui)/(2.*ui+1)+1)*w4, (2*(iv+vi)/(2.*vi+1)+1)*w4);
- if(vi == 0 && ui == 0)
- base = Geom::Point(w4, w4);
- double dl = dot((handles[corner+4*i] - base), dir)/dot(dir,dir);
- sb2[dim][i][corner] = dl/(ww/2.0)*pow(4.0f,((int)(ui+vi)));
- }
- }
- }
- }
- }
if ((!gridOnly) || (origPathItem.count() < 20))
{
if (origPathItem.count() > 19)
@@ -538,12 +531,12 @@
QPainterPath path = pItem->path();
FPointArray outputPath;
outputPath.fromQPainterPath(path);
- PageItem *currItem = m_doc->m_Selection->itemAt(a);
+ PageItem *currItem = origPageItem[a];
currItem->PoLine = outputPath;
currItem->Frame = false;
currItem->ClipEdited = true;
currItem->FrameType = 3;
- m_doc->AdjustItemSize(currItem);
+ m_doc->AdjustItemSize(currItem, true);
currItem->OldB2 = currItem->width();
currItem->OldH2 = currItem->height();
currItem->updateClip();
Modified: trunk/Scribus/scribus/plugins/tools/2geomtools/meshdistortion/meshdistortiondialog.h
URL: http://scribus.info/websvn/diff.php?repname=Scribus&rev=16116&path=/trunk/Scribus/scribus/plugins/tools/2geomtools/meshdistortion/meshdistortiondialog.h
==============================================================================
--- trunk/Scribus/scribus/plugins/tools/2geomtools/meshdistortion/meshdistortiondialog.h (original)
+++ trunk/Scribus/scribus/plugins/tools/2geomtools/meshdistortion/meshdistortiondialog.h Sun Dec 19 21:18:20 2010
@@ -84,6 +84,7 @@
public:
MeshDistortionDialog(QWidget* parent, ScribusDoc *doc);
~MeshDistortionDialog() {};
+ void addItemsToScene(Selection* itemSelection, ScribusDoc *doc, QGraphicsPathItem* parentItem, PageItem* parent);
void adjustHandles();
void updateMesh(bool gridOnly);
void updateAndExit();
@@ -98,6 +99,7 @@
QGraphicsScene scene;
QGraphicsPathItem* pItemG;
QList<QGraphicsPathItem*> origPathItem;
+ QList<PageItem*> origPageItem;
QList<NodeItem*> nodeItems;
QList< Geom::Piecewise<Geom::D2<Geom::SBasis> > > origPath;
std::vector<Geom::Point> handles;
Modified: trunk/Scribus/scribus/plugins/tools/lenseffects/lensdialog.cpp
URL: http://scribus.info/websvn/diff.php?repname=Scribus&rev=16116&path=/trunk/Scribus/scribus/plugins/tools/lenseffects/lensdialog.cpp
==============================================================================
--- trunk/Scribus/scribus/plugins/tools/lenseffects/lensdialog.cpp (original)
+++ trunk/Scribus/scribus/plugins/tools/lenseffects/lensdialog.cpp Sun Dec 19 21:18:20 2010
@@ -277,10 +277,6 @@
itemSelection->setGroupRect();
itemSelection->getGroupRect(&gx, &gy, &gw, &gh);
uint selectedItemCount = itemSelection->count();
-// QStack<PageItem*> groupStack;
-// QStack<QGraphicsPathItem*> groupStack2;
-// QStack<PageItem*> groupStack3;
-// groupStack2.push(0);
for (uint i = 0; i < selectedItemCount; ++i)
{
currItem = itemSelection->itemAt(i);
@@ -449,9 +445,6 @@
}
if (currItem->isGroup())
{
- // groupStack.push(currItem->groupsLastItem);
- // groupStack2.push(pItem);
- // groupStack3.push(currItem);
pItem->setFlags(QGraphicsItem::ItemClipsChildrenToShape);
Selection tmpSelection(this, false);
for (int a = 0; a < currItem->groupItemList.count(); a++)
@@ -460,17 +453,6 @@
}
addItemsToScene(&tmpSelection, doc, pItem, currItem);
}
- /* if (groupStack.count() != 0)
- {
- while (currItem == groupStack.top())
- {
- groupStack3.pop();
- groupStack2.pop();
- groupStack.pop();
- if (groupStack.count() == 0)
- break;
- }
- } */
}
}
More information about the scribus-commit
mailing list