Warning, file /office/calligra/libs/rdf/KoRdfSemanticTreeWidgetItem.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001 /* This file is part of the KDE project 0002 Copyright (C) 2010 KO GmbH <ben.martin@kogmbh.com> 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 0020 #include "KoRdfSemanticTreeWidgetItem.h" 0021 0022 #include "KoDocumentRdf.h" 0023 // main 0024 #include <KoCanvasBase.h> 0025 #include <KoToolProxy.h> 0026 #include <KoDocumentResourceManager.h> 0027 #include <KoTextEditor.h> 0028 // KF5 0029 #include <kactionmenu.h> 0030 #include <kpagedialog.h> 0031 #include <kdebug.h> 0032 #include <klocalizedstring.h> 0033 // Qt 0034 #include <QVBoxLayout> 0035 0036 using namespace Soprano; 0037 0038 class RdfSemanticTreeWidgetApplyStylesheet : public RdfSemanticTreeWidgetAction 0039 { 0040 hKoRdfSemanticItem si; 0041 hKoSemanticStylesheet ss; 0042 0043 public: 0044 0045 RdfSemanticTreeWidgetApplyStylesheet(QWidget *parent, KoCanvasBase *canvas, 0046 const QString &name, 0047 hKoRdfSemanticItem si, 0048 hKoSemanticStylesheet ss = hKoSemanticStylesheet(0)); 0049 virtual ~RdfSemanticTreeWidgetApplyStylesheet(); 0050 virtual void activated(); 0051 }; 0052 0053 RdfSemanticTreeWidgetApplyStylesheet::RdfSemanticTreeWidgetApplyStylesheet(QWidget *parent, 0054 KoCanvasBase *canvas, const QString &name, hKoRdfSemanticItem si, hKoSemanticStylesheet ss ) 0055 : RdfSemanticTreeWidgetAction(parent, canvas, name) 0056 , si(si) 0057 , ss(ss) 0058 { 0059 } 0060 0061 RdfSemanticTreeWidgetApplyStylesheet::~RdfSemanticTreeWidgetApplyStylesheet() 0062 { 0063 } 0064 0065 void RdfSemanticTreeWidgetApplyStylesheet::activated() 0066 { 0067 kDebug(30015) << "apply selected stylesheet for semantic item..."; 0068 KoTextEditor *editor = KoTextEditor::getTextEditorFromCanvas(m_canvas); 0069 const KoDocumentRdf *rdf = si->documentRdf(); 0070 QString xmlid = rdf->findXmlId(editor); 0071 kDebug(30015) << "semItem:" << si->name() << "xmlid:" << xmlid; 0072 KoRdfSemanticItemViewSite vs(si, xmlid); 0073 if (ss) { 0074 kDebug(30015) << "apply stylesheet, format(), sheet:" << ss->name() 0075 << " xmlid:" << xmlid; 0076 vs.applyStylesheet(editor, ss); 0077 } else { 0078 vs.disassociateStylesheet(); 0079 } 0080 } 0081 0082 0083 KoRdfSemanticTreeWidgetItem::KoRdfSemanticTreeWidgetItem(QTreeWidgetItem *parent) 0084 : QTreeWidgetItem(parent) 0085 { 0086 } 0087 0088 KoRdfSemanticTreeWidgetItem::~KoRdfSemanticTreeWidgetItem() 0089 { 0090 } 0091 0092 QAction *KoRdfSemanticTreeWidgetItem::createAction(QWidget *parent, KoCanvasBase *host, const QString &text) 0093 { 0094 return new RdfSemanticTreeWidgetAction(parent, host, text); 0095 } 0096 0097 void KoRdfSemanticTreeWidgetItem::addApplyStylesheetActions(QWidget *parent, 0098 QList<QAction *> &actions, KoCanvasBase *host) 0099 { 0100 if (!host) { 0101 return; 0102 } 0103 KoTextEditor *editor = KoTextEditor::getTextEditorFromCanvas(host); 0104 kDebug(30015) << " semanticItem:" << semanticItem(); 0105 kDebug(30015) << " semanticItem.name:" << semanticItem()->name(); 0106 if (!editor) { 0107 return; 0108 } 0109 QString xmlid = semanticItem()->documentRdf()->findXmlId(editor); 0110 if (!xmlid.size()) { 0111 return; 0112 } 0113 kDebug(30015) << "xmlid:" << xmlid; 0114 KActionMenu *topMenu = new KActionMenu(i18n("Apply Stylesheet"), parent); 0115 actions.append(topMenu); 0116 KActionMenu *subMenu = new KActionMenu(i18n("System"), topMenu); 0117 topMenu->addAction(subMenu); 0118 foreach (hKoSemanticStylesheet ss, semanticItem()->stylesheets()) { 0119 kDebug(30015) << "format(), sheet:" << ss->name() << " xmlid:" << xmlid; 0120 QAction * action = new RdfSemanticTreeWidgetApplyStylesheet(parent, 0121 host, ss->name(), 0122 semanticItem(), ss); 0123 subMenu->addAction(action); 0124 } 0125 subMenu = new KActionMenu(i18n("User"), topMenu); 0126 topMenu->addAction(subMenu); 0127 foreach (hKoSemanticStylesheet ss, semanticItem()->userStylesheets()) { 0128 kDebug(30015) << "format(), sheet:" << ss->name() << " xmlid:" << xmlid; 0129 QAction *action = new RdfSemanticTreeWidgetApplyStylesheet(parent, 0130 host, ss->name(), 0131 semanticItem(), ss); 0132 subMenu->addAction(action); 0133 } 0134 // add reapply current sheet option 0135 topMenu->addSeparator(); 0136 KoRdfSemanticItemViewSite vs(semanticItem(), xmlid); 0137 if (hKoSemanticStylesheet ss = vs.stylesheet()) { 0138 QAction *action = new RdfSemanticTreeWidgetApplyStylesheet(parent, 0139 host, i18n("Reapply Current"), 0140 semanticItem(), ss); 0141 topMenu->addAction(action); 0142 } 0143 QAction *action = new RdfSemanticTreeWidgetApplyStylesheet(parent, 0144 host, i18n("Disassociate"), 0145 semanticItem(), hKoSemanticStylesheet(0)); 0146 topMenu->addAction(action); 0147 } 0148 0149 QList<QAction *> KoRdfSemanticTreeWidgetItem::actions(QWidget *parent, KoCanvasBase *host) 0150 { 0151 Q_UNUSED(parent); 0152 Q_UNUSED(host); 0153 return QList<QAction *>(); 0154 } 0155 0156 void KoRdfSemanticTreeWidgetItem::insert(KoCanvasBase *host) 0157 { 0158 Q_UNUSED(host); 0159 kDebug(30015) << "KoRdfSemanticTreeWidgetItem::insert"; 0160 } 0161 0162 void KoRdfSemanticTreeWidgetItem::edit() 0163 { 0164 QString caption = i18n("Edit %1",uIObjectName()); 0165 QWidget *widget = new QWidget(); 0166 QVBoxLayout *lay = new QVBoxLayout(widget); 0167 widget->setLayout(lay); 0168 lay->setMargin(0); 0169 QWidget *w = semanticItem()->createEditor(widget); 0170 lay->addWidget(w); 0171 KPageDialog dialog; 0172 dialog.setWindowTitle(caption); 0173 dialog.addPage(widget, QString()); 0174 if (dialog.exec() == KPageDialog::Accepted) { 0175 kDebug(30015) << "KoRdfSemanticTreeWidgetItem::edit() accepted..."; 0176 semanticItem()->updateFromEditorData(); 0177 } 0178 }