1 /* This file is part of the KDE project
2 * Copyright (C) 2007 Thomas Zander <zander@kde.org>
3 * Copyright (C) 2008 Thorsten Zachmann <zachmann@kde.org>
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
14 *
15 * You should have received a copy of the GNU Library General Public License
16 * along with this library; see the file COPYING.LIB. If not, write to
17 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
19 */
20
21 #include "InsertVariableAction_p.h"
22 #include "KoVariable.h"
23 #include "KoInlineObjectFactoryBase.h"
24 #include "KoText.h"
25
26 #include <KoCanvasBase.h>
27 #include <KoShapeController.h>
28 #include <KoInlineTextObjectManager.h>
29
30 #include <kpagedialog.h>
31
32 #include <klocalizedstring.h>
33 #include <QLayout>
34
InsertVariableAction(KoCanvasBase * base,KoInlineObjectFactoryBase * factory,const KoInlineObjectTemplate & templ)35 InsertVariableAction::InsertVariableAction(KoCanvasBase *base, KoInlineObjectFactoryBase *factory, const KoInlineObjectTemplate &templ)
36 : InsertInlineObjectActionBase(base, templ.name)
37 , m_factory(factory)
38 , m_templateId(templ.id)
39 , m_properties(templ.properties)
40 , m_templateName(templ.name)
41 {
42 }
43
createInlineObject()44 KoInlineObject *InsertVariableAction::createInlineObject()
45 {
46 KoInlineObject *io = m_factory->createInlineObject(m_properties);
47 KoVariable *variable = dynamic_cast<KoVariable*>(io);
48 Q_ASSERT(variable);
49 KoInlineTextObjectManager *objManager = m_canvas->shapeController()->resourceManager()->resource(KoText::InlineTextObjectManager).value<KoInlineTextObjectManager*>();
50 Q_ASSERT(objManager);
51 variable->setManager(objManager);
52 QWidget *widget = variable->createOptionsWidget();
53 if (widget) {
54 if (widget->layout()) {
55 widget->layout()->setMargin(0);
56 }
57 KPageDialog *dialog = new KPageDialog(m_canvas->canvasWidget());
58 dialog->setWindowTitle(i18n("%1 Options", m_templateName));
59 dialog->addPage(widget, QString());
60 if (dialog->exec() != KPageDialog::Accepted) {
61 delete variable;
62 variable = 0;
63 }
64 delete dialog;
65 }
66 return variable;
67 }
68