Scribus Developer Documentation - API
logo-pen

Scribus Developer Documentation - API

subdivide.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 "subdivide.h"
00028 #include "scribuscore.h"
00029 #include "scribusstructs.h"
00030 
00031 int subdivide_getPluginAPIVersion()
00032 {
00033     return PLUGIN_API_VERSION;
00034 }
00035 
00036 ScPlugin* subdivide_getPlugin()
00037 {
00038     SubdividePlugin* plug = new SubdividePlugin();
00039     Q_CHECK_PTR(plug);
00040     return plug;
00041 }
00042 
00043 void subdivide_freePlugin(ScPlugin* plugin)
00044 {
00045     SubdividePlugin* plug = dynamic_cast<SubdividePlugin*>(plugin);
00046     Q_ASSERT(plug);
00047     delete plug;
00048 }
00049 
00050 SubdividePlugin::SubdividePlugin() : ScActionPlugin()
00051 {
00052     // Set action info in languageChange, so we only have to do
00053     // it in one place.
00054     languageChange();
00055 }
00056 
00057 SubdividePlugin::~SubdividePlugin() {};
00058 
00059 void SubdividePlugin::languageChange()
00060 {
00061     // Note that we leave the unused members unset. They'll be initialised
00062     // with their default ctors during construction.
00063     // Action name
00064     m_actionInfo.name = "Subdivide";
00065     // Action text for menu, including accel
00066     m_actionInfo.text = tr("Subdivide Path");
00067     // Menu
00068     m_actionInfo.menu = "ItemPathOps";
00069     m_actionInfo.parentMenu = "Item";
00070     m_actionInfo.subMenuName = tr("Path Tools");
00071     m_actionInfo.enabledOnStartup = true;
00072     m_actionInfo.notSuitableFor.append(PageItem::Line);
00073     m_actionInfo.forAppMode.append(modeEditClip);
00074     m_actionInfo.needsNumObjects = 1;
00075 }
00076 
00077 const QString SubdividePlugin::fullTrName() const
00078 {
00079     return QObject::tr("Subdivide");
00080 }
00081 
00082 const ScActionPlugin::AboutData* SubdividePlugin::getAboutData() const
00083 {
00084     AboutData* about = new AboutData;
00085     Q_CHECK_PTR(about);
00086     about->authors = QString::fromUtf8("Franz Schmid <Franz.Schmid@altmuehlnet.de>");
00087     about->shortDescription = tr("Subdivide");
00088     about->description = tr("Subdivide selected Path");
00089     // about->version
00090     // about->releaseDate
00091     // about->copyright
00092     about->license = "GPL";
00093     return about;
00094 }
00095 
00096 void SubdividePlugin::deleteAboutData(const AboutData* about) const
00097 {
00098     Q_ASSERT(about);
00099     delete about;
00100 }
00101 
00102 bool SubdividePlugin::run(ScribusDoc* doc, QString)
00103 {
00104     ScribusDoc* currDoc = doc;
00105     if (currDoc == 0)
00106         currDoc = ScCore->primaryMainWindow()->doc;
00107     double nearT = 0.5;
00108     uint docSelectionCount = currDoc->m_Selection->count();
00109     if (docSelectionCount != 0)
00110     {
00111         for (uint aa = 0; aa < docSelectionCount; ++aa)
00112         {
00113             FPointArray points;
00114             PageItem *currItem = currDoc->m_Selection->itemAt(aa);
00115             if (currDoc->nodeEdit.isContourLine)
00116             {
00117                 uint psize = currItem->ContourLine.size();
00118                 for (uint a = 0; a < psize-3; a += 4)
00119                 {
00120                     if (currItem->ContourLine.point(a).x() > 900000)
00121                     {
00122                         points.setMarker();
00123                         continue;
00124                     }
00125                     FPoint base = currItem->ContourLine.point(a);
00126                     FPoint c1 = currItem->ContourLine.point(a+1);
00127                     FPoint base2 =  currItem->ContourLine.point(a+2);
00128                     FPoint c2 = currItem->ContourLine.point(a+3);
00129                     FPoint cn1 = (1.0 - nearT) * base + nearT * c1;
00130                     FPoint cn2 = (1.0 - nearT) * cn1 + nearT * ((1.0 - nearT) * c1 + nearT * c2);
00131                     FPoint cn3 = (1.0 - nearT) * ((1.0 - nearT) * c1 + nearT * c2) + nearT * ((1.0 - nearT) * c2 + nearT * base2);
00132                     FPoint cn4 = (1.0 - nearT) * c2 + nearT * base2;
00133                     FPoint bp1 = (1.0 - nearT) * cn2 + nearT * cn3;
00134                     if ((base == c1) && (base2 == c2))
00135                     {
00136                         points.addPoint(base);
00137                         points.addPoint(c1);
00138                         points.addPoint(bp1);
00139                         points.addPoint(bp1);
00140                         points.addPoint(bp1);
00141                         points.addPoint(bp1);
00142                         points.addPoint(base2);
00143                         points.addPoint(c2);
00144                     }
00145                     else
00146                     {
00147                         points.addPoint(base);
00148                         points.addPoint(cn1);
00149                         points.addPoint(bp1);
00150                         points.addPoint(cn2);
00151                         points.addPoint(bp1);
00152                         points.addPoint(cn3);
00153                         points.addPoint(base2);
00154                         points.addPoint(cn4);
00155                     }
00156                 }
00157                 currItem->ContourLine = points;
00158             }
00159             else
00160             {
00161                 uint psize = currItem->PoLine.size();
00162                 for (uint a = 0; a < psize-3; a += 4)
00163                 {
00164                     if (currItem->PoLine.point(a).x() > 900000)
00165                     {
00166                         points.setMarker();
00167                         continue;
00168                     }
00169                     FPoint base = currItem->PoLine.point(a);
00170                     FPoint c1 = currItem->PoLine.point(a+1);
00171                     FPoint base2 =  currItem->PoLine.point(a+2);
00172                     FPoint c2 = currItem->PoLine.point(a+3);
00173                     FPoint cn1 = (1.0 - nearT) * base + nearT * c1;
00174                     FPoint cn2 = (1.0 - nearT) * cn1 + nearT * ((1.0 - nearT) * c1 + nearT * c2);
00175                     FPoint cn3 = (1.0 - nearT) * ((1.0 - nearT) * c1 + nearT * c2) + nearT * ((1.0 - nearT) * c2 + nearT * base2);
00176                     FPoint cn4 = (1.0 - nearT) * c2 + nearT * base2;
00177                     FPoint bp1 = (1.0 - nearT) * cn2 + nearT * cn3;
00178                     if ((base == c1) && (base2 == c2))
00179                     {
00180                         points.addPoint(base);
00181                         points.addPoint(c1);
00182                         points.addPoint(bp1);
00183                         points.addPoint(bp1);
00184                         points.addPoint(bp1);
00185                         points.addPoint(bp1);
00186                         points.addPoint(base2);
00187                         points.addPoint(c2);
00188                     }
00189                     else
00190                     {
00191                         points.addPoint(base);
00192                         points.addPoint(cn1);
00193                         points.addPoint(bp1);
00194                         points.addPoint(cn2);
00195                         points.addPoint(bp1);
00196                         points.addPoint(cn3);
00197                         points.addPoint(base2);
00198                         points.addPoint(cn4);
00199                     }
00200                 }
00201                 currItem->PoLine = points;
00202                 currItem->Frame = false;
00203                 currItem->ClipEdited = true;
00204                 currItem->FrameType = 3;
00205                 currDoc->AdjustItemSize(currItem);
00206                 currItem->OldB2 = currItem->width();
00207                 currItem->OldH2 = currItem->height();
00208                 currItem->updateClip();
00209             }
00210         }
00211         currDoc->regionsChanged()->update(QRectF());
00212         currDoc->changed();
00213     }
00214     return true;
00215 }
Created with personalized Doxygen. This is documentation for GPL software Scribus - Open Source Desktop Publishing.