Scribus Developer Documentation - API
logo-pen

Scribus Developer Documentation - API

pathfinder.cpp

Go to the documentation of this file.
00001 /*
00002 For general Scribus (>=1.3.2) copyright and licensing information please refer
00003 to the COPYING file provided with the program. Following this notice may exist
00004 a copyright and/or license notice that predates the release of Scribus 1.3.2
00005 for which a new license (GPL+exception) is in place.
00006 */
00007 /***************************************************************************
00008 *   Copyright (C) 2007 by Franz Schmid                                     *
00009 *   franz.schmid@altmuehlnet.de                                            *
00010 *                                                                          *
00011 *   This program is free software; you can redistribute it and/or modify   *
00012 *   it under the terms of the GNU General Public License as published by   *
00013 *   the Free Software Foundation; either version 2 of the License, or      *
00014 *   (at your option) any later version.                                    *
00015 *                                                                          *
00016 *   This program is distributed in the hope that it will be useful,        *
00017 *   but WITHOUT ANY WARRANTY; without even the implied warranty of         *
00018 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          *
00019 *   GNU General Public License for more details.                           *
00020 *                                                                          *
00021 *   You should have received a copy of the GNU General Public License      *
00022 *   along with this program; if not, write to the                          *
00023 *   Free Software Foundation, Inc.,                                        *
00024 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.              *
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     // Set action info in languageChange, so we only have to do
00058     // it in one place.
00059     languageChange();
00060 }
00061 
00062 PathFinderPlugin::~PathFinderPlugin() {};
00063 
00064 void PathFinderPlugin::languageChange()
00065 {
00066     // Note that we leave the unused members unset. They'll be initialised
00067     // with their default ctors during construction.
00068     // Action name
00069     m_actionInfo.name = "PathFinder";
00070     // Action text for menu, including accel
00071     m_actionInfo.text = tr("Path Operations...");
00072     // Menu
00073     m_actionInfo.menu = "ItemPathOps";
00074     m_actionInfo.parentMenu = "Item";
00075     m_actionInfo.subMenuName = tr("Path Tools");
00076 //  m_actionInfo.toolbar = "Vector";
00077 //  m_actionInfo.toolBarName = tr("Vector-Tools");
00078 //  m_actionInfo.icon1 = loadIcon("pathintersection.png");
00079 //  m_actionInfo.icon2 = loadIcon("pathintersection.png");
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     // about->version
00103     // about->releaseDate
00104     // about->copyright
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 }
Created with personalized Doxygen. This is documentation for GPL software Scribus - Open Source Desktop Publishing.