pathfinder.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #include <QMessageBox>
00028 #include <QPixmap>
00029 #include "pageitem_polygon.h"
00030 #include "pathfinder.h"
00031 #include "pathfinderdialog.h"
00032 #include "scribuscore.h"
00033 #include "util_math.h"
00034 #include "util_icon.h"
00035
00036 int pathfinder_getPluginAPIVersion()
00037 {
00038 return PLUGIN_API_VERSION;
00039 }
00040
00041 ScPlugin* pathfinder_getPlugin()
00042 {
00043 PathFinderPlugin* plug = new PathFinderPlugin();
00044 Q_CHECK_PTR(plug);
00045 return plug;
00046 }
00047
00048 void pathfinder_freePlugin(ScPlugin* plugin)
00049 {
00050 PathFinderPlugin* plug = dynamic_cast<PathFinderPlugin*>(plugin);
00051 Q_ASSERT(plug);
00052 delete plug;
00053 }
00054
00055 PathFinderPlugin::PathFinderPlugin() : ScActionPlugin()
00056 {
00057
00058
00059 languageChange();
00060 }
00061
00062 PathFinderPlugin::~PathFinderPlugin() {};
00063
00064 void PathFinderPlugin::languageChange()
00065 {
00066
00067
00068
00069 m_actionInfo.name = "PathFinder";
00070
00071 m_actionInfo.text = tr("Path Operations...");
00072
00073 m_actionInfo.menu = "ItemPathOps";
00074 m_actionInfo.parentMenu = "Item";
00075 m_actionInfo.subMenuName = tr("Path Tools");
00076
00077
00078
00079
00080 m_actionInfo.enabledOnStartup = true;
00081 m_actionInfo.notSuitableFor.append(PageItem::Line);
00082 m_actionInfo.notSuitableFor.append(PageItem::TextFrame);
00083 m_actionInfo.notSuitableFor.append(PageItem::ImageFrame);
00084 m_actionInfo.notSuitableFor.append(PageItem::PolyLine);
00085 m_actionInfo.notSuitableFor.append(PageItem::PathText);
00086 m_actionInfo.notSuitableFor.append(PageItem::LatexFrame);
00087 m_actionInfo.needsNumObjects = 2;
00088 }
00089
00090 const QString PathFinderPlugin::fullTrName() const
00091 {
00092 return QObject::tr("PathFinder");
00093 }
00094
00095 const ScActionPlugin::AboutData* PathFinderPlugin::getAboutData() const
00096 {
00097 AboutData* about = new AboutData;
00098 Q_CHECK_PTR(about);
00099 about->authors = QString::fromUtf8("Franz Schmid <Franz.Schmid@altmuehlnet.de>");
00100 about->shortDescription = tr("Path Operations");
00101 about->description = tr("Apply fancy boolean operations to paths.");
00102
00103
00104
00105 about->license = "GPL";
00106 return about;
00107 }
00108
00109 void PathFinderPlugin::deleteAboutData(const AboutData* about) const
00110 {
00111 Q_ASSERT(about);
00112 delete about;
00113 }
00114
00115 bool PathFinderPlugin::run(ScribusDoc* doc, QString)
00116 {
00117 QString vers = QString(qVersion()).left(5);
00118 if (vers < "4.3.3")
00119 {
00120 QMessageBox::information(doc->scMW(), tr("Qt Version too old"), tr("This plugin requires at least version 4.3.3 of the Qt library"));
00121 return true;
00122 }
00123 ScribusDoc* currDoc = doc;
00124 if (currDoc == 0)
00125 currDoc = ScCore->primaryMainWindow()->doc;
00126 if (currDoc->m_Selection->count() > 1)
00127 {
00128 PageItem *Item1 = currDoc->m_Selection->itemAt(0);
00129 PageItem *Item2 = currDoc->m_Selection->itemAt(1);
00130 PathFinderDialog *dia = new PathFinderDialog(currDoc->scMW(), Item1, Item2);
00131 if (dia->exec())
00132 {
00133 if (dia->keepItem1)
00134 {
00135 if (dia->swapped)
00136 currDoc->Items->insert(Item2->ItemNr, new PageItem_Polygon(*Item2));
00137 else
00138 currDoc->Items->insert(Item1->ItemNr, new PageItem_Polygon(*Item1));
00139 }
00140 if (dia->keepItem2)
00141 {
00142 if (dia->swapped)
00143 currDoc->Items->insert(Item1->ItemNr, new PageItem_Polygon(*Item1));
00144 else
00145 currDoc->Items->insert(Item2->ItemNr, new PageItem_Polygon(*Item2));
00146 }
00147 if (dia->keepItem1 || dia->keepItem2)
00148 currDoc->renumberItemsInListOrder();
00149 if (dia->opMode != 4)
00150 {
00151 PageItem *currItem;
00152 QPainterPath path;
00153 FPointArray points;
00154 if (dia->targetColorIsSource1)
00155 {
00156 currItem = Item1;
00157 if (dia->swapped)
00158 {
00159 currItem = Item2;
00160 currItem->setXYPos(Item1->xPos(), Item1->yPos());
00161 currItem->setRotation(0.0);
00162 }
00163 }
00164 else
00165 {
00166 if (dia->swapped)
00167 currItem = Item1;
00168 else
00169 {
00170 currItem = Item2;
00171 currItem->setXYPos(Item1->xPos(), Item1->yPos());
00172 currItem->setRotation(0.0);
00173 }
00174 }
00175 path = dia->result;
00176 points.fromQPainterPath(path);
00177 currItem->PoLine = points;
00178 currItem->Frame = false;
00179 currItem->ClipEdited = true;
00180 currItem->FrameType = 3;
00181 currDoc->AdjustItemSize(currItem);
00182 currItem->OldB2 = currItem->width();
00183 currItem->OldH2 = currItem->height();
00184 currItem->updateClip();
00185 currItem->ContourLine = currItem->PoLine.copy();
00186 currDoc->m_Selection->removeItem(currItem);
00187 currDoc->itemSelection_DeleteItem();
00188 }
00189 else
00190 {
00191 QPainterPath path;
00192 FPointArray points;
00193 PageItem *newItem;
00194 path = dia->result;
00195 if (!path.isEmpty())
00196 {
00197 points.fromQPainterPath(path);
00198 Item1->PoLine = points;
00199 Item1->Frame = false;
00200 Item1->ClipEdited = true;
00201 Item1->FrameType = 3;
00202 currDoc->AdjustItemSize(Item1);
00203 Item1->OldB2 = Item1->width();
00204 Item1->OldH2 = Item1->height();
00205 Item1->updateClip();
00206 Item1->ContourLine = Item1->PoLine.copy();
00207 }
00208
00209 path = QPainterPath();
00210 path = dia->result1;
00211 if (!path.isEmpty())
00212 {
00213 points.fromQPainterPath(path);
00214 Item2->setXYPos(Item1->xPos(), Item1->yPos());
00215 Item2->setRotation(0.0);
00216 Item2->PoLine = points;
00217 Item2->Frame = false;
00218 Item2->ClipEdited = true;
00219 Item2->FrameType = 3;
00220 currDoc->AdjustItemSize(Item2);
00221 Item2->OldB2 = Item2->width();
00222 Item2->OldH2 = Item2->height();
00223 Item2->updateClip();
00224 Item2->ContourLine = Item2->PoLine.copy();
00225 }
00226
00227 path = QPainterPath();
00228 path = dia->result2;
00229 if (!path.isEmpty())
00230 {
00231 if (dia->targetColorIsSource1)
00232 newItem = new PageItem_Polygon(*Item1);
00233 else
00234 {
00235 newItem = new PageItem_Polygon(*Item2);
00236 newItem->setXYPos(Item1->xPos(), Item1->yPos());
00237 newItem->setRotation(0.0);
00238 }
00239 currDoc->Items->append(newItem);
00240 newItem->ItemNr = currDoc->Items->count()-1;
00241 points.fromQPainterPath(path);
00242 newItem->PoLine = points;
00243 newItem->Frame = false;
00244 newItem->ClipEdited = true;
00245 newItem->FrameType = 3;
00246 currDoc->AdjustItemSize(newItem);
00247 newItem->OldB2 = newItem->width();
00248 newItem->OldH2 = newItem->height();
00249 newItem->updateClip();
00250 newItem->ContourLine = newItem->PoLine.copy();
00251 }
00252 currDoc->m_Selection->clear();
00253 }
00254 currDoc->changed();
00255 }
00256 delete dia;
00257 }
00258 return true;
00259 }