1 /* This file is part of the KDE project
2 * Copyright 2007 Marijn Kruisselbrink <mkruisselbrink@kde.org>
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
13 *
14 * You should have received a copy of the GNU Library General Public License
15 * along with this library; see the file COPYING.LIB. If not, write to
16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18 */
19 #include <QStringList>
20 #include <QFontDatabase>
21
22 #include <kpluginfactory.h>
23 #include <klocalizedstring.h>
24 #include "MusicDebug.h"
25 #include <KoResourcePaths.h>
26 #include <KoIcon.h>
27 #include <KoToolRegistry.h>
28 #include <KoShapeRegistry.h>
29 #include <KoShapeLoadingContext.h>
30
31 #include "MusicShape.h"
32 #include "MusicToolFactory.h"
33 #include "SimpleEntryToolFactory.h"
34
35 #include "MusicShapeFactory.h"
36
37 K_PLUGIN_FACTORY_WITH_JSON(MusicShapePluginFactory, "calligra_shape_music.json",
38 registerPlugin<MusicShapePlugin>();)
39
MusicShapePlugin(QObject *,const QVariantList &)40 MusicShapePlugin::MusicShapePlugin( QObject *, const QVariantList& )
41 {
42 KoShapeRegistry::instance()->add( new MusicShapeFactory() );
43 KoToolRegistry::instance()->add( new MusicToolFactory() );
44 KoToolRegistry::instance()->add( new SimpleEntryToolFactory() );
45 }
46
47
MusicShapeFactory()48 MusicShapeFactory::MusicShapeFactory()
49 : KoShapeFactoryBase(MusicShapeId, i18n( "Music Shape" ) )
50 {
51 setToolTip( i18n( "A shape which provides a music editor" ) );
52 setIconName(koIconNameNeededWithSubs("icon for the Music Shape","musicshape", "music-note-16th"));
53 setXmlElementNames( "http://www.calligra.org/music", QStringList("shape") );
54 setLoadingPriority( 1 );
55 }
56
createDefaultShape(KoDocumentResourceManager *) const57 KoShape *MusicShapeFactory::createDefaultShape(KoDocumentResourceManager *) const
58 {
59 static bool loadedFont = false;
60 if (!loadedFont) {
61 QString fontFile = KoResourcePaths::locate("data", "calligra_shape_music/fonts/Emmentaler-14.ttf");
62 if (QFontDatabase::addApplicationFont(fontFile) == -1) {
63 warnMusic << "Could not load emmentaler font";
64 }
65 loadedFont = true;
66 }
67 MusicShape* shape = new MusicShape();
68 shape->setSize(QSizeF(400, 300));
69 shape->setShapeId(MusicShapeId);
70 return shape;
71 }
72
supports(const KoXmlElement & e,KoShapeLoadingContext & context) const73 bool MusicShapeFactory::supports(const KoXmlElement & e, KoShapeLoadingContext &context) const
74 {
75 Q_UNUSED(context);
76 return ( e.localName() == "shape" ) && ( e.namespaceURI() == "http://www.calligra.org/music" );
77 }
78
79 #include "MusicShapeFactory.moc"
80