diff --git a/plugins/dockers/shapedockers/ShapeCollectionDocker.cpp b/plugins/dockers/shapedockers/ShapeCollectionDocker.cpp index 00c9dd1775..a1f29e835c 100644 --- a/plugins/dockers/shapedockers/ShapeCollectionDocker.cpp +++ b/plugins/dockers/shapedockers/ShapeCollectionDocker.cpp @@ -1,352 +1,175 @@ /* This file is part of the KDE project * Copyright (C) 2008 Peter Simonsson * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Library General Public License for more details. * * You should have received a copy of the GNU Library General Public License * along with this library; see the file COPYING.LIB. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "ShapeCollectionDocker.h" #include "CollectionItemModel.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include //This class is needed so that the menu returns a sizehint based on the layout and not on the number (0) of menu items class CollectionMenu : public QMenu { public: CollectionMenu(QWidget *parent = 0); QSize sizeHint() const override; }; CollectionMenu::CollectionMenu(QWidget *parent) : QMenu(parent) { } QSize CollectionMenu::sizeHint() const { return layout()->sizeHint(); } // // ShapeCollectionDockerFactory // ShapeCollectionDockerFactory::ShapeCollectionDockerFactory() : KoDockFactoryBase() { } QString ShapeCollectionDockerFactory::id() const { return QString("ShapeCollectionDocker"); } QDockWidget *ShapeCollectionDockerFactory::createDockWidget() { ShapeCollectionDocker *docker = new ShapeCollectionDocker(); return docker; } -void ShapeCollectionDocker::locationChanged(Qt::DockWidgetArea area) -{ - resize(0, 0); - - switch (area) { - case Qt::TopDockWidgetArea: - case Qt::BottomDockWidgetArea: - m_spacer->changeSize(0, 0, QSizePolicy::Fixed, QSizePolicy::MinimumExpanding); - break; - case Qt::LeftDockWidgetArea: - case Qt::RightDockWidgetArea: - m_spacer->changeSize(0, 0, QSizePolicy::MinimumExpanding, QSizePolicy::Preferred); - break; - default: - break; - } - m_layout->setSizeConstraint(QLayout::SetMinAndMaxSize); - m_layout->invalidate(); -} // // ShapeCollectionDocker // - ShapeCollectionDocker::ShapeCollectionDocker(QWidget *parent) : QDockWidget(parent) { setWindowTitle(i18n("Add Shape")); - QWidget *mainWidget = new QWidget(this); - m_layout = new QGridLayout(mainWidget); - m_layout->setMargin(0); - m_layout->setHorizontalSpacing(0); - m_layout->setVerticalSpacing(0); - m_layout->setSizeConstraint(QLayout::SetMinAndMaxSize); - setWidget(mainWidget); - - m_quickView = new QListView(mainWidget); - m_layout->addWidget(m_quickView, 0, 0); + m_quickView = new QListView(this); m_quickView->setViewMode(QListView::IconMode); m_quickView->setDragDropMode(QListView::DragOnly); m_quickView->setSelectionMode(QListView::SingleSelection); m_quickView->setResizeMode(QListView::Adjust); m_quickView->setFlow(QListView::LeftToRight); m_quickView->setGridSize(QSize(40, 44)); - m_quickView->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); - m_quickView->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); - m_quickView->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); m_quickView->setTextElideMode(Qt::ElideNone); m_quickView->setWordWrap(true); - - m_spacer = new QSpacerItem(0, 0, QSizePolicy::Fixed, QSizePolicy::Fixed); - m_layout->addItem(m_spacer, 1, 2); - m_layout->setRowStretch(1, 1); - m_layout->setColumnStretch(2, 1); - - connect(this, SIGNAL(dockLocationChanged(Qt::DockWidgetArea)), this, SLOT(locationChanged(Qt::DockWidgetArea))); - - m_moreShapes = new QToolButton(mainWidget); - m_moreShapes->setText(i18n("More")); - m_moreShapes->setToolButtonStyle(Qt::ToolButtonIconOnly); - m_moreShapes->setIconSize(QSize(32, 32)); - m_moreShapes->setIcon(koIcon("shape-choose")); - m_moreShapes->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); - m_layout->addWidget(m_moreShapes, 0, 1); - - m_moreShapesContainer = new CollectionMenu(mainWidget); - m_moreShapes->setMenu(m_moreShapesContainer); - m_moreShapes->setPopupMode(QToolButton::InstantPopup); - QGridLayout *containerLayout = new QGridLayout(m_moreShapesContainer); - containerLayout->setMargin(4); - - m_collectionChooser = new QListWidget(m_moreShapesContainer); - containerLayout->addWidget(m_collectionChooser, 0, 0, 1, 2); - m_collectionChooser->setViewMode(QListView::IconMode); - m_collectionChooser->setSelectionMode(QListView::SingleSelection); - m_collectionChooser->setResizeMode(QListView::Adjust); - m_collectionChooser->setGridSize(QSize(75, 64)); - m_collectionChooser->setMovement(QListView::Static); - m_collectionChooser->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); - m_collectionChooser->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); - connect(m_collectionChooser, SIGNAL(itemClicked(QListWidgetItem*)), - this, SLOT(activateShapeCollection(QListWidgetItem*))); - - - m_collectionView = new QListView(m_moreShapesContainer); - containerLayout->addWidget(m_collectionView, 0, 2, -1, 1); - m_collectionView->setViewMode(QListView::IconMode); - m_collectionView->setDragDropMode(QListView::DragOnly); - m_collectionView->setSelectionMode(QListView::SingleSelection); - m_collectionView->setResizeMode(QListView::Adjust); - m_collectionView->setGridSize(QSize(48 + 20, 48)); - m_collectionView->setFixedSize(QSize(165, 345)); - m_collectionView->setWordWrap(true); - + setWidget(m_quickView); // Load the default shapes and add them to the combobox loadDefaultShapes(); } void ShapeCollectionDocker::setCanvas(KoCanvasBase *canvas) { setEnabled(canvas != 0); } void ShapeCollectionDocker::unsetCanvas() { setEnabled(false); } void ShapeCollectionDocker::loadDefaultShapes() { - QList defaultList; - QList arrowList; - QList funnyList; - QList geometricList; QList quicklist; - int quickCount = 0; - - QStringList quickShapes; - quickShapes << "TextShapeID" << "PictureShape" << "ChartShape" << "ArtisticText"; - KConfigGroup cfg = KSharedConfig::openConfig()->group("KoShapeCollection"); - quickShapes = cfg.readEntry("QuickShapes", quickShapes); Q_FOREACH (const QString &id, KoShapeRegistry::instance()->keys()) { KoShapeFactoryBase *factory = KoShapeRegistry::instance()->value(id); // don't show hidden factories if (factory->hidden()) { continue; } bool oneAdded = false; Q_FOREACH (const KoShapeTemplate &shapeTemplate, factory->templates()) { + + qDebug() << "Adding factory" << shapeTemplate.name; + oneAdded = true; KoCollectionItem temp; temp.id = shapeTemplate.id; temp.name = shapeTemplate.name; temp.toolTip = shapeTemplate.toolTip; temp.icon = KisIconUtils::loadIcon(shapeTemplate.iconName); temp.properties = shapeTemplate.properties; - if (shapeTemplate.family == "funny") { - funnyList.append(temp); - } else if (shapeTemplate.family == "arrow") { - arrowList.append(temp); - } else if (shapeTemplate.family == "geometric") { - geometricList.append(temp); - } else { - defaultList.append(temp); - } + quicklist.append(temp); QString id = temp.id; if (!shapeTemplate.templateId.isEmpty()) { id += '_' + shapeTemplate.templateId; } - if (quickShapes.contains(id)) { - quicklist.append(temp); - quickCount++; - } } if (!oneAdded) { KoCollectionItem temp; temp.id = factory->id(); temp.name = factory->name(); temp.toolTip = factory->toolTip(); temp.icon = KisIconUtils::loadIcon(factory->iconName()); temp.properties = 0; - if (factory->family() == "funny") { - funnyList.append(temp); - } else if (factory->family() == "arrow") { - arrowList.append(temp); - } else if (factory->family() == "geometric") { - geometricList.append(temp); - } else { - defaultList.append(temp); - } - - if (quickShapes.contains(temp.id)) { - quicklist.append(temp); - quickCount++; - } + quicklist.append(temp); } } - CollectionItemModel *model = new CollectionItemModel(this); - model->setShapeTemplateList(defaultList); - addCollection("default", i18n("Default"), model); - - model = new CollectionItemModel(this); - model->setShapeTemplateList(geometricList); - addCollection("geometric", i18n("Geometrics"), model); - - model = new CollectionItemModel(this); - model->setShapeTemplateList(arrowList); - addCollection("arrow", i18n("Arrows"), model); - - model = new CollectionItemModel(this); - model->setShapeTemplateList(funnyList); - addCollection("funny", i18n("Funny"), model); + qDebug() << "quickList:" << quicklist.size(); CollectionItemModel *quickModel = new CollectionItemModel(this); quickModel->setShapeTemplateList(quicklist); m_quickView->setModel(quickModel); - int fw = m_quickView->frameWidth(); - m_quickView->setMaximumSize(QSize(quickCount * 40 + 2 * fw + 1, 44 + 2 * fw + 1)); - m_quickView->setMinimumSize(QSize(quickCount * 40 + 2 * fw + 1, 44 + 2 * fw + 1)); - - m_collectionChooser->setMinimumSize(QSize(75 + 2 * fw, 0)); - m_collectionChooser->setMaximumSize(QSize(75 + 2 * fw, 1000)); - - m_collectionChooser->setCurrentRow(0); - activateShapeCollection(m_collectionChooser->item(0)); -} - -void ShapeCollectionDocker::activateShapeCollection(QListWidgetItem *item) -{ - QString id = item->data(Qt::UserRole).toString(); - - if (m_modelMap.contains(id)) { - m_collectionView->setModel(m_modelMap[id]); - } else { - qCritical() << "Didn't find a model with id ==" << id; - } - -} - -bool ShapeCollectionDocker::addCollection(const QString &id, const QString &title, CollectionItemModel *model) -{ - if (m_modelMap.contains(id)) { - return false; - } - - m_modelMap.insert(id, model); - QListWidgetItem *collectionChooserItem = new QListWidgetItem(koIcon("shape-choose"), title); - collectionChooserItem->setData(Qt::UserRole, id); - m_collectionChooser->addItem(collectionChooserItem); - return true; -} - - -QIcon ShapeCollectionDocker::generateShapeIcon(KoShape *shape) -{ - KoZoomHandler converter; - - qreal diffx = 30 / converter.documentToViewX(shape->size().width()); - qreal diffy = 30 / converter.documentToViewY(shape->size().height()); - converter.setZoom(qMin(diffx, diffy)); - - QPixmap pixmap(qRound(converter.documentToViewX(shape->size().width())) + 2, qRound(converter.documentToViewY(shape->size().height())) + 2); - pixmap.fill(Qt::white); - QPainter painter(&pixmap); - painter.setRenderHint(QPainter::Antialiasing, true); - painter.translate(1, 1); - KoShapePaintingContext paintContext; //FIXME - shape->paint(painter, converter, paintContext); - painter.end(); - - return QIcon(pixmap); } diff --git a/plugins/dockers/shapedockers/ShapeCollectionDocker.h b/plugins/dockers/shapedockers/ShapeCollectionDocker.h index 8c582e8cb6..2c70233d93 100644 --- a/plugins/dockers/shapedockers/ShapeCollectionDocker.h +++ b/plugins/dockers/shapedockers/ShapeCollectionDocker.h @@ -1,100 +1,77 @@ /* This file is part of the KDE project * Copyright (C) 2008 Peter Simonsson * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Library General Public License for more details. * * You should have received a copy of the GNU Library General Public License * along with this library; see the file COPYING.LIB. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KOSHAPECOLLECTIONDOCKER_H #define KOSHAPECOLLECTIONDOCKER_H #include #include #include #include #include #include class ShapeCollectionDockerFactory : public KoDockFactoryBase { public: ShapeCollectionDockerFactory(); QString id() const override; QDockWidget *createDockWidget() override; DockPosition defaultDockPosition() const override { return DockRight; } }; class CollectionItemModel; class KoShape; class QListView; class QListWidget; class QListWidgetItem; class QToolButton; class QMenu; class QSpacerItem; class QGridLayout; class ShapeCollectionDocker : public QDockWidget, public KoCanvasObserverBase { Q_OBJECT public: explicit ShapeCollectionDocker(QWidget *parent = 0); /// reimplemented void setCanvas(KoCanvasBase *canvas) override; void unsetCanvas() override; -protected Q_SLOTS: - - /** - * Changes the current shape collection - */ - void activateShapeCollection(QListWidgetItem *item); - - /// Called when the docker changes area - void locationChanged(Qt::DockWidgetArea area); - protected: /** * Load the default calligra shapes */ void loadDefaultShapes(); - - /// Generate an icon from @p shape - QIcon generateShapeIcon(KoShape *shape); - - private: - bool addCollection(const QString &id, const QString &title, CollectionItemModel *model); - QListView *m_quickView; - QToolButton *m_moreShapes; - QMenu *m_moreShapesContainer; - QListWidget *m_collectionChooser; - QListView *m_collectionView; - QSpacerItem *m_spacer; - QGridLayout *m_layout; QMap m_modelMap; }; #endif //KOSHAPECOLLECTIONDOCKER_H diff --git a/plugins/flake/pathshapes/enhancedpath/EnhancedPathShapeFactory.cpp b/plugins/flake/pathshapes/enhancedpath/EnhancedPathShapeFactory.cpp index a549de1ef4..fa2bfe4a77 100644 --- a/plugins/flake/pathshapes/enhancedpath/EnhancedPathShapeFactory.cpp +++ b/plugins/flake/pathshapes/enhancedpath/EnhancedPathShapeFactory.cpp @@ -1,568 +1,568 @@ /* This file is part of the KDE project * Copyright (C) 2007 Jan Hambrecht * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Library General Public License for more details. * * You should have received a copy of the GNU Library General Public License * along with this library; see the file COPYING.LIB. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "enhancedpath/EnhancedPathShapeFactory.h" #include "enhancedpath/EnhancedPathShape.h" #include #include #include #include #include #include #include #include #include "kis_pointer_utils.h" #include #include EnhancedPathShapeFactory::EnhancedPathShapeFactory() : KoShapeFactoryBase(EnhancedPathShapeId, i18n("An enhanced path shape")) { setToolTip(i18n("An enhanced path")); setIconName(koIconNameCStr("enhancedpath")); setXmlElementNames(KoXmlNS::draw, QStringList("custom-shape")); setLoadingPriority(1); - addCross(); - addArrow(); - addCallout(); - addSmiley(); - addCircularArrow(); - addGearhead(); +// addCross(); +// addArrow(); +// addCallout(); +// addSmiley(); +// addCircularArrow(); +// addGearhead(); } KoShape *EnhancedPathShapeFactory::createDefaultShape(KoDocumentResourceManager *) const { EnhancedPathShape *shape = new EnhancedPathShape(QRect(0, 0, 100, 100)); shape->setStroke(toQShared(new KoShapeStroke(1.0))); shape->setShapeId(KoPathShapeId); shape->addModifiers("35"); shape->addFormula("Right", "width - $0"); shape->addFormula("Bottom", "height - $0"); shape->addFormula("Half", "min(0.5 * height, 0.5 * width)"); shape->addCommand("M $0 0"); shape->addCommand("L ?Right 0 ?Right $0 width $0 width ?Bottom ?Right ?Bottom"); shape->addCommand("L ?Right height $0 height $0 ?Bottom 0 ?Bottom 0 $0 $0 $0"); shape->addCommand("Z"); ComplexType handle; handle["draw:handle-position"] = "$0 0"; handle["draw:handle-range-x-minimum"] = '0'; handle["draw:handle-range-x-maximum"] = "?Half"; shape->addHandle(handle); shape->setSize(QSize(100, 100)); return shape; } KoShape *EnhancedPathShapeFactory::createShape(const KoProperties *params, KoDocumentResourceManager *) const { QVariant viewboxData; const QRect viewBox = (params->property(QLatin1String("viewBox"), viewboxData)) ? viewboxData.toRect() : QRect(0, 0, 100, 100); EnhancedPathShape *shape = new EnhancedPathShape(viewBox); shape->setShapeId(KoPathShapeId); shape->setStroke(toQShared(new KoShapeStroke(1.0))); shape->addModifiers(params->stringProperty("modifiers")); ListType handles = params->property("handles").toList(); foreach (const QVariant &v, handles) { shape->addHandle(v.toMap()); } ComplexType formulae = params->property("formulae").toMap(); ComplexType::const_iterator formula = formulae.constBegin(); ComplexType::const_iterator lastFormula = formulae.constEnd(); for (; formula != lastFormula; ++formula) { shape->addFormula(formula.key(), formula.value().toString()); } QStringList commands = params->property("commands").toStringList(); foreach (const QString &cmd, commands) { shape->addCommand(cmd); } QVariant color; if (params->property("background", color)) { shape->setBackground(QSharedPointer(new KoColorBackground(color.value()))); } QSizeF size = shape->size(); if (size.width() > size.height()) { shape->setSize(QSizeF(100, 100 * size.height() / size.width())); } else { shape->setSize(QSizeF(100 * size.width() / size.height(), 100)); } return shape; } KoProperties *EnhancedPathShapeFactory::dataToProperties( const QString &modifiers, const QStringList &commands, const ListType &handles, const ComplexType &formulae) const { KoProperties *props = new KoProperties(); props->setProperty("modifiers", modifiers); props->setProperty("commands", commands); props->setProperty("handles", handles); props->setProperty("formulae", formulae); props->setProperty("background", QVariant::fromValue(QColor(Qt::red))); return props; } void EnhancedPathShapeFactory::addCross() { QString modifiers("35"); QStringList commands; commands.append("M $0 0"); commands.append("L ?Right 0 ?Right $0 width $0 width ?Bottom ?Right ?Bottom"); commands.append("L ?Right height $0 height $0 ?Bottom 0 ?Bottom 0 $0 $0 $0"); commands.append("Z"); ListType handles; ComplexType handle; handle["draw:handle-position"] = "$0 0"; handle["draw:handle-range-x-minimum"] = '0'; handle["draw:handle-range-x-maximum"] = "?Half"; handles.append(QVariant(handle)); ComplexType formulae; formulae["Right"] = "width - $0"; formulae["Bottom"] = "height - $0"; formulae["Half"] = "min(0.5 * height, 0.5 * width)"; KoShapeTemplate t; t.id = KoPathShapeId; t.templateId = "cross"; t.name = i18n("Cross"); t.family = "funny"; t.toolTip = i18n("A cross"); t.iconName = koIconName("cross-shape"); t.properties = dataToProperties(modifiers, commands, handles, formulae); addTemplate(t); } void EnhancedPathShapeFactory::addArrow() { { // arrow right QString modifiers("60 35"); QStringList commands; commands.append("M $0 $1"); commands.append("L $0 0 width ?HalfHeight $0 height $0 ?LowerCorner 0 ?LowerCorner 0 $1"); commands.append("Z"); ListType handles; ComplexType handle; handle["draw:handle-position"] = "$0 $1"; handle["draw:handle-range-x-minimum"] = '0'; handle["draw:handle-range-x-maximum"] = "width"; handle["draw:handle-range-y-minimum"] = '0'; handle["draw:handle-range-y-maximum"] = "?HalfHeight"; handles.append(QVariant(handle)); ComplexType formulae; formulae["HalfHeight"] = "0.5 * height"; formulae["LowerCorner"] = "height - $1"; KoShapeTemplate t; t.id = KoPathShapeId; t.templateId = "arrow_right"; t.name = i18n("Arrow"); t.family = "arrow"; t.toolTip = i18n("An arrow"); t.iconName = koIconName("draw-arrow-forward"); t.properties = dataToProperties(modifiers, commands, handles, formulae); addTemplate(t); } { // arrow left QString modifiers("40 35"); QStringList commands; commands.append("M $0 $1"); commands.append("L $0 0 0 ?HalfHeight $0 height $0 ?LowerCorner width ?LowerCorner width $1"); commands.append("Z"); ListType handles; ComplexType handle; handle["draw:handle-position"] = "$0 $1"; handle["draw:handle-range-x-minimum"] = '0'; handle["draw:handle-range-x-maximum"] = "width"; handle["draw:handle-range-y-minimum"] = '0'; handle["draw:handle-range-y-maximum"] = "?HalfHeight"; handles.append(QVariant(handle)); ComplexType formulae; formulae["HalfHeight"] = "0.5 * height"; formulae["LowerCorner"] = "height - $1"; KoShapeTemplate t; t.id = KoPathShapeId; t.templateId = "arrow_left"; t.name = i18n("Arrow"); t.family = "arrow"; t.toolTip = i18n("An arrow"); t.iconName = koIconName("draw-arrow-back"); t.properties = dataToProperties(modifiers, commands, handles, formulae); addTemplate(t); } { // arrow top QString modifiers("35 40"); QStringList commands; commands.append("M $0 $1"); commands.append("L 0 $1 ?HalfWidth 0 width $1 ?RightCorner $1 ?RightCorner height $0 height"); commands.append("Z"); ListType handles; ComplexType handle; handle["draw:handle-position"] = "$0 $1"; handle["draw:handle-range-x-minimum"] = '0'; handle["draw:handle-range-x-maximum"] = "?HalfWidth"; handle["draw:handle-range-y-minimum"] = '0'; handle["draw:handle-range-y-maximum"] = "height"; handles.append(QVariant(handle)); ComplexType formulae; formulae["HalfWidth"] = "0.5 * width"; formulae["RightCorner"] = "width - $0"; KoShapeTemplate t; t.id = KoPathShapeId; t.templateId = "arrow_top"; t.name = i18n("Arrow"); t.family = "arrow"; t.toolTip = i18n("An arrow"); t.iconName = koIconName("draw-arrow-up"); t.properties = dataToProperties(modifiers, commands, handles, formulae); addTemplate(t); } { // arrow bottom QString modifiers("35 60"); QStringList commands; commands.append("M $0 $1"); commands.append("L 0 $1 ?HalfWidth height width $1 ?RightCorner $1 ?RightCorner 0 $0 0"); commands.append("Z"); ListType handles; ComplexType handle; handle["draw:handle-position"] = "$0 $1"; handle["draw:handle-range-x-minimum"] = '0'; handle["draw:handle-range-x-maximum"] = "?HalfWidth"; handle["draw:handle-range-y-minimum"] = '0'; handle["draw:handle-range-y-maximum"] = "height"; handles.append(QVariant(handle)); ComplexType formulae; formulae["HalfWidth"] = "0.5 * width"; formulae["RightCorner"] = "width - $0"; KoShapeTemplate t; t.id = KoPathShapeId; t.templateId = "arrow_bottom"; t.name = i18n("Arrow"); t.family = "arrow"; t.toolTip = i18n("An arrow"); t.iconName = koIconName("draw-arrow-down"); t.properties = dataToProperties(modifiers, commands, handles, formulae); addTemplate(t); } } void EnhancedPathShapeFactory::addCallout() { QString modifiers("4250 45000"); QStringList commands; commands.append("M 3590 0"); commands.append("X 0 3590"); commands.append("L ?f2 ?f3 0 8970 0 12630 ?f4 ?f5 0 18010"); commands.append("Y 3590 21600"); commands.append("L ?f6 ?f7 8970 21600 12630 21600 ?f8 ?f9 18010 21600"); commands.append("X 21600 18010"); commands.append("L ?f10 ?f11 21600 12630 21600 8970 ?f12 ?f13 21600 3590"); commands.append("Y 18010 0"); commands.append("L ?f14 ?f15 12630 0 8970 0 ?f16 ?f17"); commands.append("Z"); commands.append("N"); ComplexType formulae; formulae["f0"] = "$0 -10800"; formulae["f1"] = "$1 -10800"; formulae["f2"] = "if(?f18 ,$0 ,0)"; formulae["f3"] = "if(?f18 ,$1 ,6280)"; formulae["f4"] = "if(?f23 ,$0 ,0)"; formulae["f5"] = "if(?f23 ,$1 ,15320)"; formulae["f6"] = "if(?f26 ,$0 ,6280)"; formulae["f7"] = "if(?f26 ,$1 ,21600)"; formulae["f8"] = "if(?f29 ,$0 ,15320)"; formulae["f9"] = "if(?f29 ,$1 ,21600)"; formulae["f10"] = "if(?f32 ,$0 ,21600)"; formulae["f11"] = "if(?f32 ,$1 ,15320)"; formulae["f12"] = "if(?f34 ,$0 ,21600)"; formulae["f13"] = "if(?f34 ,$1 ,6280)"; formulae["f14"] = "if(?f36 ,$0 ,15320)"; formulae["f15"] = "if(?f36 ,$1 ,0)"; formulae["f16"] = "if(?f38 ,$0 ,6280)"; formulae["f17"] = "if(?f38 ,$1 ,0)"; formulae["f18"] = "if($0 ,-1,?f19)"; formulae["f19"] = "if(?f1 ,-1,?f22)"; formulae["f20"] = "abs(?f0)"; formulae["f21"] = "abs(?f1)"; formulae["f22"] = "?f20 -?f21"; formulae["f23"] = "if($0 ,-1,?f24)"; formulae["f24"] = "if(?f1 ,?f22 ,-1)"; formulae["f25"] = "$1 -21600"; formulae["f26"] = "if(?f25 ,?f27 ,-1)"; formulae["f27"] = "if(?f0 ,-1,?f28)"; formulae["f28"] = "?f21 -?f20"; formulae["f29"] = "if(?f25 ,?f30 ,-1)"; formulae["f30"] = "if(?f0 ,?f28 ,-1)"; formulae["f31"] = "$0 -21600"; formulae["f32"] = "if(?f31 ,?f33 ,-1)"; formulae["f33"] = "if(?f1 ,?f22 ,-1)"; formulae["f34"] = "if(?f31 ,?f35 ,-1)"; formulae["f35"] = "if(?f1 ,-1,?f22)"; formulae["f36"] = "if($1 ,-1,?f37)"; formulae["f37"] = "if(?f0 ,?f28 ,-1)"; formulae["f38"] = "if($1 ,-1,?f39)"; formulae["f39"] = "if(?f0 ,-1,?f28)"; formulae["f40"] = "$0"; formulae["f41"] = "$1"; ListType handles; ComplexType handle; handle["draw:handle-position"] = "$0 $1"; handles.append(QVariant(handle)); KoShapeTemplate t; t.id = KoPathShapeId; t.templateId = "callout"; t.name = i18n("Callout"); t.family = "funny"; t.toolTip = i18n("A callout"); t.iconName = koIconName("callout-shape"); KoProperties *properties = dataToProperties(modifiers, commands, handles, formulae); properties->setProperty(QLatin1String("viewBox"), QRect(0, 0, 21600, 21600)); t.properties = properties; addTemplate(t); } void EnhancedPathShapeFactory::addSmiley() { QString modifiers("17520"); QStringList commands; commands.append("U 10800 10800 10800 10800 0 23592960"); commands.append("Z"); commands.append("N"); commands.append("U 7305 7515 1165 1165 0 23592960"); commands.append("Z"); commands.append("N"); commands.append("U 14295 7515 1165 1165 0 23592960"); commands.append("Z"); commands.append("N"); commands.append("M 4870 ?f1"); commands.append("C 8680 ?f2 12920 ?f2 16730 ?f1"); commands.append("Z"); commands.append("F"); commands.append("N"); ComplexType formulae; formulae["f0"] = "$0 -15510"; formulae["f1"] = "17520-?f0"; formulae["f2"] = "15510+?f0"; ListType handles; ComplexType handle; handle["draw:handle-position"] = "10800 $0"; handle["draw:handle-range-y-minimum"] = "15510"; handle["draw:handle-range-y-maximum"] = "17520"; handles.append(QVariant(handle)); KoShapeTemplate t; t.id = KoPathShapeId; t.templateId = "smiley"; t.name = i18n("Smiley"); t.family = "funny"; t.toolTip = i18n("Smiley"); t.iconName = koIconName("smiley-shape"); KoProperties *properties = dataToProperties(modifiers, commands, handles, formulae); properties->setProperty(QLatin1String("viewBox"), QRect(0, 0, 21600, 21600)); t.properties = properties; addTemplate(t); } void EnhancedPathShapeFactory::addCircularArrow() { QString modifiers("180 0 5500"); QStringList commands; commands.append("B ?f3 ?f3 ?f20 ?f20 ?f19 ?f18 ?f17 ?f16"); commands.append("W 0 0 21600 21600 ?f9 ?f8 ?f11 ?f10"); commands.append("L ?f24 ?f23 ?f36 ?f35 ?f29 ?f28"); commands.append("Z"); commands.append("N"); ComplexType formulae; formulae["f0"] = "$0"; formulae["f1"] = "$1"; formulae["f2"] = "$2"; formulae["f3"] = "10800+$2"; formulae["f4"] = "10800*sin($0 *(pi/180))"; formulae["f5"] = "10800*cos($0 *(pi/180))"; formulae["f6"] = "10800*sin($1 *(pi/180))"; formulae["f7"] = "10800*cos($1 *(pi/180))"; formulae["f8"] = "?f4 +10800"; formulae["f9"] = "?f5 +10800"; formulae["f10"] = "?f6 +10800"; formulae["f11"] = "?f7 +10800"; formulae["f12"] = "?f3 *sin($0 *(pi/180))"; formulae["f13"] = "?f3 *cos($0 *(pi/180))"; formulae["f14"] = "?f3 *sin($1 *(pi/180))"; formulae["f15"] = "?f3 *cos($1 *(pi/180))"; formulae["f16"] = "?f12 +10800"; formulae["f17"] = "?f13 +10800"; formulae["f18"] = "?f14 +10800"; formulae["f19"] = "?f15 +10800"; formulae["f20"] = "21600-?f3"; formulae["f21"] = "13500*sin($1 *(pi/180))"; formulae["f22"] = "13500*cos($1 *(pi/180))"; formulae["f23"] = "?f21 +10800"; formulae["f24"] = "?f22 +10800"; formulae["f25"] = "$2 -2700"; formulae["f26"] = "?f25 *sin($1 *(pi/180))"; formulae["f27"] = "?f25 *cos($1 *(pi/180))"; formulae["f28"] = "?f26 +10800"; formulae["f29"] = "?f27 +10800"; formulae["f30"] = "($1+45)*pi/180"; formulae["f31"] = "sqrt(((?f29-?f24)*(?f29-?f24))+((?f28-?f23)*(?f28-?f23)))"; formulae["f32"] = "sqrt(2)/2*?f31"; formulae["f33"] = "?f32*sin(?f30)"; formulae["f34"] = "?f32*cos(?f30)"; formulae["f35"] = "?f28+?f33"; formulae["f36"] = "?f29+?f34"; ListType handles; ComplexType handle; handle["draw:handle-position"] = "$0 10800"; handle["draw:handle-polar"] = "10800 10800"; handle["draw:handle-radius-range-minimum"] = "10800"; handle["draw:handle-radius-range-maximum"] = "10800"; handles.append(QVariant(handle)); handle.clear(); handle["draw:handle-position"] = "$1 $2"; handle["draw:handle-polar"] = "10800 10800"; handle["draw:handle-radius-range-minimum"] = '0'; handle["draw:handle-radius-range-maximum"] = "10800"; handles.append(QVariant(handle)); KoShapeTemplate t; t.id = KoPathShapeId; t.templateId = "circulararrow"; t.name = i18n("Circular Arrow"); t.family = "arrow"; t.toolTip = i18n("A circular-arrow"); t.iconName = koIconName("circular-arrow-shape"); KoProperties *properties = dataToProperties(modifiers, commands, handles, formulae); properties->setProperty(QLatin1String("viewBox"), QRect(0, 0, 21600, 21600)); t.properties = properties; addTemplate(t); } void EnhancedPathShapeFactory::addGearhead() { QStringList commands; commands.append("M 20 70"); commands.append("L 20 100 30 100 30 50 30 70 40 70 40 40 0 40 0 70 10 70 10 50 10 100 20 100"); commands.append("Z"); commands.append("N"); uint toothCount = 10; qreal toothAngle = 360.0 / qreal(toothCount); //kDebug() <<"toothAngle =" << toothAngle; qreal outerRadius = 0.5 * 25.0; qreal innerRadius = 0.5 * 17.0; QPointF center(20, 25); qreal radian = (270.0 - 0.35 * toothAngle) * M_PI / 180.0; commands.append(QString("M %1 %2").arg(center.x() + innerRadius * cos(radian)).arg(center.y() + innerRadius * sin(radian))); QString cmd("L"); for (uint i = 0; i < toothCount; ++i) { radian += 0.15 * toothAngle * M_PI / 180.0; cmd += QString(" %1 %2").arg(center.x() + outerRadius * cos(radian)).arg(center.y() + outerRadius * sin(radian)); radian += 0.35 * toothAngle * M_PI / 180.0; cmd += QString(" %1 %2").arg(center.x() + outerRadius * cos(radian)).arg(center.y() + outerRadius * sin(radian)); radian += 0.15 * toothAngle * M_PI / 180.0; cmd += QString(" %1 %2").arg(center.x() + innerRadius * cos(radian)).arg(center.y() + innerRadius * sin(radian)); radian += 0.35 * toothAngle * M_PI / 180.0; cmd += QString(" %1 %2").arg(center.x() + innerRadius * cos(radian)).arg(center.y() + innerRadius * sin(radian)); } //kDebug() <<"gear command =" << cmd; commands.append(cmd); commands.append("Z"); commands.append("N"); KoShapeTemplate t; t.id = KoPathShapeId; t.templateId = "gearhead"; t.name = i18n("Gearhead"); t.family = "funny"; t.toolTip = i18n("A gearhead"); t.iconName = koIconName("gearhead-shape"); KoProperties *properties = dataToProperties(QString(), commands, ListType(), ComplexType()); properties->setProperty("background", QVariant::fromValue(QColor(Qt::blue))); properties->setProperty(QLatin1String("viewBox"), QRect(0, 0, 40, 90)); t.properties = properties; addTemplate(t); } bool EnhancedPathShapeFactory::supports(const KoXmlElement &e, KoShapeLoadingContext &context) const { Q_UNUSED(context); return (e.localName() == "custom-shape" && e.namespaceURI() == KoXmlNS::draw); }