File indexing completed on 2024-05-12 16:34:16
0001 /* This file is part of the KDE project 0002 * Copyright 2007 Marijn Kruisselbrink <mkruisselbrink@kde.org> 0003 * 0004 * This library is free software; you can redistribute it and/or 0005 * modify it under the terms of the GNU Library General Public 0006 * License as published by the Free Software Foundation; either 0007 * version 2 of the License, or (at your option) any later version. 0008 * 0009 * This library is distributed in the hope that it will be useful, 0010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0012 * Library General Public License for more details. 0013 * 0014 * You should have received a copy of the GNU Library General Public License 0015 * along with this library; see the file COPYING.LIB. If not, write to 0016 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0017 * Boston, MA 02110-1301, USA. 0018 */ 0019 #include <QStringList> 0020 #include <QFontDatabase> 0021 0022 #include <kpluginfactory.h> 0023 #include <klocalizedstring.h> 0024 #include "MusicDebug.h" 0025 #include <KoResourcePaths.h> 0026 #include <KoIcon.h> 0027 #include <KoToolRegistry.h> 0028 #include <KoShapeRegistry.h> 0029 #include <KoShapeLoadingContext.h> 0030 0031 #include "MusicShape.h" 0032 #include "MusicToolFactory.h" 0033 #include "SimpleEntryToolFactory.h" 0034 0035 #include "MusicShapeFactory.h" 0036 0037 K_PLUGIN_FACTORY_WITH_JSON(MusicShapePluginFactory, "calligra_shape_music.json", 0038 registerPlugin<MusicShapePlugin>();) 0039 0040 MusicShapePlugin::MusicShapePlugin( QObject *, const QVariantList& ) 0041 { 0042 KoShapeRegistry::instance()->add( new MusicShapeFactory() ); 0043 KoToolRegistry::instance()->add( new MusicToolFactory() ); 0044 KoToolRegistry::instance()->add( new SimpleEntryToolFactory() ); 0045 } 0046 0047 0048 MusicShapeFactory::MusicShapeFactory() 0049 : KoShapeFactoryBase(MusicShapeId, i18n( "Music Shape" ) ) 0050 { 0051 setToolTip( i18n( "A shape which provides a music editor" ) ); 0052 setIconName(koIconNameNeededWithSubs("icon for the Music Shape","musicshape", "music-note-16th")); 0053 setXmlElementNames( "http://www.calligra.org/music", QStringList("shape") ); 0054 setLoadingPriority( 1 ); 0055 } 0056 0057 KoShape *MusicShapeFactory::createDefaultShape(KoDocumentResourceManager *) const 0058 { 0059 static bool loadedFont = false; 0060 if (!loadedFont) { 0061 QString fontFile = KoResourcePaths::locate("data", "calligra_shape_music/fonts/Emmentaler-14.ttf"); 0062 if (QFontDatabase::addApplicationFont(fontFile) == -1) { 0063 warnMusic << "Could not load emmentaler font"; 0064 } 0065 loadedFont = true; 0066 } 0067 MusicShape* shape = new MusicShape(); 0068 shape->setSize(QSizeF(400, 300)); 0069 shape->setShapeId(MusicShapeId); 0070 return shape; 0071 } 0072 0073 bool MusicShapeFactory::supports(const KoXmlElement & e, KoShapeLoadingContext &context) const 0074 { 0075 Q_UNUSED(context); 0076 return ( e.localName() == "shape" ) && ( e.namespaceURI() == "http://www.calligra.org/music" ); 0077 } 0078 0079 #include "MusicShapeFactory.moc"