[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: [calligra/karbon-flow-refactor-yue] /: merged KarbonDocument and KarbonKoDocument
From: Yue Liu <yue.liu () mail ! com>
Date: 2013-01-01 8:13:53
Message-ID: 20130101081353.04126A6091 () git ! kde ! org
[Download RAW message or body]
Git commit f41350c0a352af7d38bf1c7c116938307d98549a by Yue Liu.
Committed on 01/01/2013 at 08:59.
Pushed by liu into branch 'karbon-flow-refactor-yue'.
merged KarbonDocument and KarbonKoDocument
M +2 -2 filters/karbon/image/CMakeLists.txt
M +50 -45 filters/karbon/image/ImageExport.cpp
M +1 -1 filters/karbon/image/ImageExportOptionsWidget.cpp
M +2 -4 filters/karbon/svg/SvgExport.cpp
M +0 -5 filters/karbon/svg/SvgExport.h
M +2 -5 filters/karbon/svg/SvgImport.cpp
M +5 -6 filters/karbon/wmf/WmfExport.cpp
M +2 -2 filters/karbon/wmf/WmfExport.h
M +2 -1 flow/part/FlowDocument.h
M +1 -3 karbon/common/CMakeLists.txt
D +0 -436 karbon/common/KarbonDocument.cpp
M +4 -1 karbon/ui/CMakeLists.txt
A +779 -0 karbon/ui/KarbonDocument.cpp [License: LGPL (v2+)]
R +101 -65 karbon/ui/KarbonDocument.h [from: karbon/common/KarbonDocument.h - \
051% similarity] M +5 -5 karbon/ui/KarbonDocumentMergeCommand.cpp
M +2 -2 karbon/ui/KarbonDocumentMergeCommand.h
M +2 -2 karbon/ui/KarbonFactory.cpp
D +0 -458 karbon/ui/KarbonKoDocument.cpp
D +0 -125 karbon/ui/KarbonKoDocument.h
M +4 -4 karbon/ui/KarbonPart.cpp
M +3 -3 karbon/ui/KarbonPrintJob.cpp
M +17 -18 karbon/ui/KarbonView.cpp
M +3 -3 karbon/ui/KarbonView.h
R +1 -1 karbon/ui/commands/KarbonLayerReorderCommand.cpp [from: \
karbon/common/commands/KarbonLayerReorderCommand.cpp - 098% similarity] R +2 -2 \
karbon/ui/commands/KarbonLayerReorderCommand.h [from: \
karbon/common/commands/KarbonLayerReorderCommand.h - 096% similarity] M +1 -1 \
karbon/ui/dialogs/KarbonConfigureDialog.cpp M +11 -12 \
karbon/ui/dockers/KarbonLayerDocker.cpp M +2 -2 \
karbon/ui/dockers/KarbonLayerDocker.h M +9 -13 \
karbon/ui/widgets/KarbonCanvas.cpp M +3 -3 karbon/ui/widgets/KarbonCanvas.h
M +2 -2 karbon/ui/widgets/KarbonConfigInterfacePage.cpp
http://commits.kde.org/calligra/f41350c0a352af7d38bf1c7c116938307d98549a
diff --git a/filters/karbon/image/CMakeLists.txt \
b/filters/karbon/image/CMakeLists.txt index e930bc4..4a5fee7 100644
--- a/filters/karbon/image/CMakeLists.txt
+++ b/filters/karbon/image/CMakeLists.txt
@@ -1,6 +1,6 @@
-include_directories( ${CMAKE_SOURCE_DIR}/karbon ${CMAKE_SOURCE_DIR}/karbon/core \
${KDE4_INCLUDES} ) +include_directories( ${CMAKE_SOURCE_DIR}/karbon \
${CMAKE_SOURCE_DIR}/flow/part ${KDE4_INCLUDES} )
########### next target ###############
@@ -11,7 +11,7 @@ kde4_add_ui_files( karbonimageexport_PART_SRCS \
ImageExportOptionsWidget.ui )
kde4_add_plugin(karbonimageexport ${karbonimageexport_PART_SRCS})
-target_link_libraries(karbonimageexport karbonui komain)
+target_link_libraries(karbonimageexport karbonui flowprivate komain)
install(TARGETS karbonimageexport DESTINATION ${PLUGIN_INSTALL_DIR})
diff --git a/filters/karbon/image/ImageExport.cpp \
b/filters/karbon/image/ImageExport.cpp index 0f74dc5..f5f02c9 100644
--- a/filters/karbon/image/ImageExport.cpp
+++ b/filters/karbon/image/ImageExport.cpp
@@ -31,8 +31,8 @@
#include "ImageExportOptionsWidget.h"
#include <KarbonDocument.h>
-#include <KarbonPart.h>
-#include <KarbonKoDocument.h>
+#include <FlowDocument.h>
+#include <KoDocument.h>
#include <KoShapePainter.h>
#include <KoFilter.h>
@@ -69,52 +69,57 @@ ImageExport::convert(const QByteArray& from, const QByteArray& \
to) return KoFilter::NotImplemented;
}
- KoDocument * document = m_chain->inputDocument();
+ KoDocument* document = m_chain->inputDocument();
if (! document)
return KoFilter::ParsingError;
- KarbonKoDocument * karbonPart = dynamic_cast<KarbonKoDocument*>(document);
- if (! karbonPart)
- return KoFilter::WrongFormat;
-
- KoShapePainter painter;
- painter.setShapes(karbonPart->document().shapes());
-
- // get the bounding rect of the content
- QRectF shapesRect = painter.contentRect();
- // get the size in point
- QSizeF pointSize = shapesRect.size();
- // get the size in pixel (100% zoom)
- KoZoomHandler zoomHandler;
- QSize pixelSize = zoomHandler.documentToView(pointSize).toSize();
- QColor backgroundColor(Qt::white);
-
- if (! m_chain->manager()->getBatchMode()) {
- ImageExportOptionsWidget * widget = new ImageExportOptionsWidget(pointSize);
- widget->setUnit(karbonPart->unit());
- widget->setBackgroundColor(backgroundColor);
- widget->enableBackgroundOpacity(format == "PNG");
-
- KDialog dlg;
- dlg.setCaption(i18n("PNG Export Options"));
- dlg.setButtons(KDialog::Ok | KDialog::Cancel);
- dlg.setMainWidget(widget);
- if (dlg.exec() != QDialog::Accepted)
- return KoFilter::UserCancelled;
-
- pixelSize = widget->pixelSize();
- backgroundColor = widget->backgroundColor();
- }
- QImage image(pixelSize, QImage::Format_ARGB32);
-
- // draw the background of the image
- image.fill(backgroundColor.rgba());
-
- // paint the shapes
- painter.paint(image);
-
- if(!image.save(m_chain->outputFile(), format.toLatin1())) {
- return KoFilter::CreationError;
+ KarbonDocument* doc = dynamic_cast<KarbonDocument*>(document);
+ if (doc) {
+ KoShapePainter painter;
+ painter.setShapes(doc->shapes());
+
+ // get the bounding rect of the content
+ QRectF shapesRect = painter.contentRect();
+ // get the size in point
+ QSizeF pointSize = shapesRect.size();
+ // get the size in pixel (100% zoom)
+ KoZoomHandler zoomHandler;
+ QSize pixelSize = zoomHandler.documentToView(pointSize).toSize();
+ //transparent white by default
+ QColor backgroundColor(QColor(255, 255, 255, 0));
+
+ if (! m_chain->manager()->getBatchMode()) {
+ ImageExportOptionsWidget * widget = new \
ImageExportOptionsWidget(pointSize); + widget->setUnit(document->unit());
+ widget->setBackgroundColor(backgroundColor);
+ widget->enableBackgroundOpacity(format == "PNG");
+
+ KDialog dlg;
+ dlg.setCaption(i18n("PNG Export Options"));
+ dlg.setButtons(KDialog::Ok | KDialog::Cancel);
+ dlg.setMainWidget(widget);
+ if (dlg.exec() != QDialog::Accepted)
+ return KoFilter::UserCancelled;
+
+ pixelSize = widget->pixelSize();
+ backgroundColor = widget->backgroundColor();
+ }
+ QImage image(pixelSize, QImage::Format_ARGB32);
+
+ // draw the background of the image
+ image.fill(backgroundColor.rgba());
+
+ // paint the shapes
+ painter.paint(image);
+
+ if(!image.save(m_chain->outputFile(), format.toLatin1())) {
+ return KoFilter::CreationError;
+ }
+
+ } else {
+ FlowDocument* doc = dynamic_cast<FlowDocument*>(document);
+ if (! doc)
+ return KoFilter::WrongFormat;
}
return KoFilter::OK;
diff --git a/filters/karbon/image/ImageExportOptionsWidget.cpp \
b/filters/karbon/image/ImageExportOptionsWidget.cpp index 52c7ec6..497d1d6 100644
--- a/filters/karbon/image/ImageExportOptionsWidget.cpp
+++ b/filters/karbon/image/ImageExportOptionsWidget.cpp
@@ -48,7 +48,7 @@ ImageExportOptionsWidget::ImageExportOptionsWidget(QSizeF \
pointSize, QWidget * p widget.backColor->setColor(Qt::white);
widget.opacity->setMinimum(0.0);
widget.opacity->setMaximum(100.0);
- widget.opacity->setValue(100.0);
+ widget.opacity->setValue(0.0);
widget.unitWidth->changeValue(pointSize.width());
widget.unitHeight->changeValue(pointSize.height());
updateFromPointSize(pointSize);
diff --git a/filters/karbon/svg/SvgExport.cpp b/filters/karbon/svg/SvgExport.cpp
index aa5fdae..fb34db7 100644
--- a/filters/karbon/svg/SvgExport.cpp
+++ b/filters/karbon/svg/SvgExport.cpp
@@ -38,7 +38,6 @@
#include <KarbonDocument.h>
#include <KarbonPart.h>
-#include <KarbonKoDocument.h>
#include <KoDocument.h>
#include <KoFilterChain.h>
@@ -64,12 +63,11 @@ KoFilter::ConversionStatus SvgExport::convert(const QByteArray& \
from, const QByt if (!document)
return KoFilter::ParsingError;
- KarbonKoDocument * karbonPart = dynamic_cast<KarbonKoDocument*>(document);
+ KarbonDocument * karbonPart = dynamic_cast<KarbonDocument*>(document);
if (!karbonPart)
return KoFilter::WrongFormat;
- const KarbonDocument &data = karbonPart->document();
- SvgWriter writer(data.layers(), data.pageSize());
+ SvgWriter writer(karbonPart->layers(), karbonPart->pageSize());
if (!writer.save(m_chain->outputFile(), true))
return KoFilter::CreationError;
diff --git a/filters/karbon/svg/SvgExport.h b/filters/karbon/svg/SvgExport.h
index 65fb5ad..d579936 100644
--- a/filters/karbon/svg/SvgExport.h
+++ b/filters/karbon/svg/SvgExport.h
@@ -32,8 +32,6 @@
#include <KoFilter.h>
#include <QVariantList>
-class KarbonDocument;
-
class SvgExport : public KoFilter
{
Q_OBJECT
@@ -43,9 +41,6 @@ public:
virtual ~SvgExport() {}
virtual KoFilter::ConversionStatus convert(const QByteArray& from, const \
QByteArray& to);
-
-private:
- void saveDocument(KarbonDocument& document);
};
#endif
diff --git a/filters/karbon/svg/SvgImport.cpp b/filters/karbon/svg/SvgImport.cpp
index b83883c..4e5044b 100644
--- a/filters/karbon/svg/SvgImport.cpp
+++ b/filters/karbon/svg/SvgImport.cpp
@@ -28,7 +28,6 @@
#include <KarbonPart.h>
#include <KarbonDocument.h>
-#include <KarbonKoDocument.h>
#include <KoShape.h>
#include <KoShapeLayer.h>
@@ -108,12 +107,10 @@ KoFilter::ConversionStatus SvgImport::convert(const QByteArray& \
from, const QByt return KoFilter::ParsingError;
}
- KarbonKoDocument * part = \
dynamic_cast<KarbonKoDocument*>(m_chain->outputDocument());
- if (! part)
+ m_document = dynamic_cast<KarbonDocument*>(m_chain->outputDocument());
+ if (! m_document)
return KoFilter::CreationError;
- m_document = &part->document();
-
// Do the conversion!
convert(inputDoc.documentElement());
diff --git a/filters/karbon/wmf/WmfExport.cpp b/filters/karbon/wmf/WmfExport.cpp
index 017c528..bf0aa85 100644
--- a/filters/karbon/wmf/WmfExport.cpp
+++ b/filters/karbon/wmf/WmfExport.cpp
@@ -22,7 +22,6 @@
#include <KarbonDocument.h>
#include <KarbonPart.h>
-#include <KarbonKoDocument.h>
#include <kdebug.h>
#include <kpluginfactory.h>
@@ -60,7 +59,7 @@ KoFilter::ConversionStatus WmfExport::convert(const QByteArray& \
from, const QByt if (! doc)
return KoFilter::ParsingError;
- KarbonKoDocument * karbonPart = dynamic_cast<KarbonKoDocument*>(doc);
+ KarbonDocument * karbonPart = dynamic_cast<KarbonDocument*>(doc);
if (! karbonPart)
return KoFilter::WrongFormat;
@@ -71,7 +70,7 @@ KoFilter::ConversionStatus WmfExport::convert(const QByteArray& \
from, const QByt return KoFilter::WrongFormat;
}
- paintDocument(karbonPart->document());
+ paintDocument(karbonPart);
mWmf->end();
@@ -80,13 +79,13 @@ KoFilter::ConversionStatus WmfExport::convert(const QByteArray& \
from, const QByt return KoFilter::OK;
}
-void WmfExport::paintDocument(KarbonDocument& document)
+void WmfExport::paintDocument(KarbonDocument* document)
{
// resolution
mDpi = 1000;
- QSizeF pageSize = document.pageSize();
+ QSizeF pageSize = document->pageSize();
int width = static_cast<int>(POINT_TO_INCH(pageSize.width()) * mDpi);
int height = static_cast<int>(POINT_TO_INCH(pageSize.height()) * mDpi);
@@ -98,7 +97,7 @@ void WmfExport::paintDocument(KarbonDocument& document)
mScaleY = static_cast<double>(height) / pageSize.height();
}
- QList<KoShape*> shapes = document.shapes();
+ QList<KoShape*> shapes = document->shapes();
qSort(shapes.begin(), shapes.end(), KoShape::compareShapeZIndex);
// Export layers.
diff --git a/filters/karbon/wmf/WmfExport.h b/filters/karbon/wmf/WmfExport.h
index bdf1987..fa535da 100644
--- a/filters/karbon/wmf/WmfExport.h
+++ b/filters/karbon/wmf/WmfExport.h
@@ -42,8 +42,8 @@ public:
virtual KoFilter::ConversionStatus convert(const QByteArray& from, const \
QByteArray& to);
private:
- void paintDocument(KarbonDocument& document);
- void paintShape(KoShape * shape);
+ void paintDocument(KarbonDocument* document);
+ void paintShape(KoShape* shape);
QPen getPen(const KoShapeStrokeModel *stroke);
diff --git a/flow/part/FlowDocument.h b/flow/part/FlowDocument.h
index b00702c..716b171 100644
--- a/flow/part/FlowDocument.h
+++ b/flow/part/FlowDocument.h
@@ -23,10 +23,11 @@
#define FLOWDOCUMENT_H
#include <KoPADocument.h>
+#include "flow_export.h"
class KoPart;
-class FlowDocument : public KoPADocument
+class FLOW_EXPORT FlowDocument : public KoPADocument
{
Q_OBJECT
diff --git a/karbon/common/CMakeLists.txt b/karbon/common/CMakeLists.txt
index 75be550..f6fd364 100644
--- a/karbon/common/CMakeLists.txt
+++ b/karbon/common/CMakeLists.txt
@@ -1,11 +1,9 @@
-set(karboncommon_LIB_SRCS
- KarbonDocument.cpp
+set(karboncommon_LIB_SRCS
KarbonGlobal.cpp
KarbonGradientHelper.cpp
KarbonCursor.cpp
KarbonOutlinePaintingStrategy.cpp
- commands/KarbonLayerReorderCommand.cpp
commands/KarbonBooleanCommand.cpp
)
diff --git a/karbon/common/KarbonDocument.cpp b/karbon/common/KarbonDocument.cpp
deleted file mode 100644
index 364618e..0000000
--- a/karbon/common/KarbonDocument.cpp
+++ /dev/null
@@ -1,436 +0,0 @@
-/* This file is part of the KDE project
- Copyright (C) 2002 Lennart Kudling <kudling@kde.org>
- Copyright (C) 2002 Benoit Vautrin <benoit.vautrin@free.fr>
- Copyright (C) 2002-2007 Rob Buis <buis@kde.org>
- Copyright (C) 2002,2005 David Faure <faure@kde.org>
- Copyright (C) 2002 Laurent Montel <montel@kde.org>
- Copyright (C) 2004 Waldo Bastian <bastian@kde.org>
- Copyright (C) 2005 Thomas Zander <zander@kde.org>
- Copyright (C) 2005 Peter Simonsson <psn@linux.se>
- Copyright (C) 2006-2007 Jan Hambrecht <jaham@gmx.net>
- Copyright (C) 2006 Tim Beaulen <tbscope@gmail.com>
- Copyright (C) 2006 Inge Wallin <inge@lysator.liu.se>
- Copyright (C) 2006 C. Boemann <cbo@boemann.dk>
- Copyright (C) 2006 Gabor Lehel <illissius@gmail.com>
- Copyright (C) 2007 Thorsten Zachmann <zachmann@kde.org>
-
- 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 "KarbonDocument.h"
-
-#include <KoStore.h>
-#include <KoPageLayout.h>
-#include <KoXmlWriter.h>
-#include <KoXmlNS.h>
-#include <KoOdfLoadingContext.h>
-#include <KoOdfStylesReader.h>
-#include <KoShapeSavingContext.h>
-#include <KoDocumentResourceManager.h>
-#include <KoShapeLoadingContext.h>
-#include <KoShapeLayer.h>
-#include <KoShapeRegistry.h>
-#include <KoStoreDevice.h>
-#include <KoOdfWriteStore.h>
-#include <KoEmbeddedDocumentSaver.h>
-#include <KoImageCollection.h>
-#include <KoDataCenterBase.h>
-#include <KoText.h>
-#include <KoStyleManager.h>
-#include <KoTextSharedLoadingData.h>
-
-#include <ktemporaryfile.h>
-#include <kdebug.h>
-
-#include <QDomDocument>
-#include <QRectF>
-
-class KarbonDocument::Private
-{
-public:
- Private()
- : pageSize(0.0, 0.0)
- , hasExternalDataCenterMap(false),
- resourceManager(0)
- {
- }
-
- ~Private()
- {
- qDeleteAll(layers);
- layers.clear();
- qDeleteAll(objects);
- objects.clear();
- if (!hasExternalDataCenterMap)
- qDeleteAll(dataCenterMap);
- }
-
- QSizeF pageSize; ///< the documents page size
-
- QList<KoShape*> objects; ///< The list of all object of the document.
- QList<KoShapeLayer*> layers; ///< The layers in this document.
-
- QMap<QString, KoDataCenterBase*> dataCenterMap;
- bool hasExternalDataCenterMap;
- KoDocumentResourceManager *resourceManager;
-};
-
-KarbonDocument::KarbonDocument()
- : d(new Private)
-{
- // create a layer. we need at least one:
- insertLayer(new KoShapeLayer());
-}
-
-KarbonDocument::KarbonDocument(const KarbonDocument& document)
- : d(new Private)
-{
- d->layers = document.layers();
-// TODO
-}
-
-KarbonDocument::~KarbonDocument()
-{
- delete d;
-}
-
-void KarbonDocument::insertLayer(KoShapeLayer* layer)
-{
- if (!d->layers.contains(layer)) {
- if (d->layers.count()) {
- layer->setZIndex(d->layers.last()->zIndex() + 1);
- } else {
- layer->setZIndex(d->layers.count());
- }
- d->layers.append(layer);
- }
-}
-
-void KarbonDocument::removeLayer(KoShapeLayer* layer)
-{
- d->layers.removeAt(d->layers.indexOf(layer));
- if (d->layers.count() == 0)
- d->layers.append(new KoShapeLayer());
-}
-
-bool KarbonDocument::canRaiseLayer(KoShapeLayer* layer)
-{
- int pos = d->layers.indexOf(layer);
- return (pos != int(d->layers.count()) - 1 && pos >= 0);
-}
-
-bool KarbonDocument::canLowerLayer(KoShapeLayer* layer)
-{
- int pos = d->layers.indexOf(layer);
- return (pos > 0);
-}
-
-void KarbonDocument::raiseLayer(KoShapeLayer* layer)
-{
- int pos = d->layers.indexOf(layer);
- if (pos != int(d->layers.count()) - 1 && pos >= 0) {
- KoShapeLayer * layerAbove = d->layers.at(pos + 1);
- int lowerZIndex = layer->zIndex();
- int upperZIndex = layerAbove->zIndex();
- layer->setZIndex(upperZIndex);
- layerAbove->setZIndex(lowerZIndex);
- d->layers.move(pos, pos + 1);
- }
-}
-
-void KarbonDocument::lowerLayer(KoShapeLayer* layer)
-{
- int pos = d->layers.indexOf(layer);
- if (pos > 0) {
- KoShapeLayer * layerBelow = d->layers.at(pos - 1);
- int upperZIndex = layer->zIndex();
- int lowerZIndex = layerBelow->zIndex();
- layer->setZIndex(lowerZIndex);
- layerBelow->setZIndex(upperZIndex);
- d->layers.move(pos, pos - 1);
- }
-}
-
-int KarbonDocument::layerPos(KoShapeLayer* layer)
-{
- return d->layers.indexOf(layer);
-}
-
-void KarbonDocument::add(KoShape* shape)
-{
- if (! d->objects.contains(shape))
- d->objects.append(shape);
-}
-
-void KarbonDocument::remove(KoShape* shape)
-{
- d->objects.removeAt(d->objects.indexOf(shape));
-}
-
-void KarbonDocument::saveOasis(KoShapeSavingContext & context) const
-{
- context.xmlWriter().startElement("draw:page");
- context.xmlWriter().addAttribute("draw:name", "");
- context.xmlWriter().addAttribute("draw:id", "page1");
- context.xmlWriter().addAttribute("xml:id", "page1");
- context.xmlWriter().addAttribute("draw:master-page-name", "Default");
-
- foreach(KoShapeLayer * layer, d->layers) {
- context.addLayerForSaving(layer);
- }
- context.saveLayerSet(context.xmlWriter());
-
- foreach(KoShapeLayer * layer, d->layers) {
- layer->saveOdf(context);
- }
-
- context.xmlWriter().endElement(); // draw:page
-}
-
-bool KarbonDocument::loadOasis(const KoXmlElement &element, KoShapeLoadingContext \
&context)
-{
- // load text styles used by text shapes
- loadOdfStyles(context);
-
- qDeleteAll(d->layers);
- d->layers.clear();
- qDeleteAll(d->objects);
- d->objects.clear();
-
- const KoXmlElement & pageLayerSet = KoXml::namedItemNS(element, KoXmlNS::draw, \
"layer-set");
- const KoXmlElement & usedPageLayerSet = pageLayerSet.isNull() ? \
context.odfLoadingContext().stylesReader().layerSet() : pageLayerSet;
-
- KoXmlElement layerElement;
- forEachElement(layerElement, usedPageLayerSet) {
- KoShapeLayer * l = new KoShapeLayer();
- if (l->loadOdf(layerElement, context))
- insertLayer(l);
- }
-
- KoShapeLayer * defaultLayer = 0;
-
- // check if we have to insert a default layer
- if (d->layers.count() == 0)
- defaultLayer = new KoShapeLayer();
-
- KoXmlElement child;
- forEachElement(child, element) {
- kDebug(38000) << "loading shape" << child.localName();
-
- KoShape * shape = KoShapeRegistry::instance()->createShapeFromOdf(child, \
context);
- if (shape)
- d->objects.append(shape);
- }
-
- // add all toplevel shapes to the default layer
- foreach(KoShape * shape, d->objects) {
- if (! shape->parent()) {
- if (! defaultLayer)
- defaultLayer = new KoShapeLayer();
-
- defaultLayer->addShape(shape);
- }
- }
-
- if (defaultLayer)
- insertLayer(defaultLayer);
-
- KoOdfStylesReader & styleReader = context.odfLoadingContext().stylesReader();
- QHash<QString, KoXmlElement*> masterPages = styleReader.masterPages();
-
- KoXmlElement * master = 0;
- if( masterPages.contains( "Standard" ) )
- master = masterPages.value( "Standard" );
- else if( masterPages.contains( "Default" ) )
- master = masterPages.value( "Default" );
- else if( ! masterPages.empty() )
- master = masterPages.begin().value();
-
- if (master) {
- context.odfLoadingContext().setUseStylesAutoStyles( true );
-
- QList<KoShape*> masterPageShapes;
- KoXmlElement child;
- forEachElement(child, (*master)) {
- kDebug(38000) <<"loading master page shape" << child.localName();
- KoShape * shape = KoShapeRegistry::instance()->createShapeFromOdf( \
child, context );
- if( shape )
- masterPageShapes.append( shape );
- }
-
- KoShapeLayer * masterPageLayer = 0;
- // add all toplevel shapes to the master page layer
- foreach(KoShape * shape, masterPageShapes) {
- d->objects.append( shape );
- if(!shape->parent()) {
- if( ! masterPageLayer ) {
- masterPageLayer = new KoShapeLayer();
- masterPageLayer->setName(i18n("Master Page"));
- }
-
- masterPageLayer->addShape(shape);
- }
- }
-
- if( masterPageLayer )
- insertLayer( masterPageLayer );
-
- context.odfLoadingContext().setUseStylesAutoStyles( false );
- }
-
- return true;
-}
-
-QRectF KarbonDocument::boundingRect() const
-{
- return contentRect().united(QRectF(QPointF(0, 0), d->pageSize));
-}
-
-QRectF KarbonDocument::contentRect() const
-{
- QRectF bb;
- foreach(KoShape* layer, d->layers) {
- if (bb.isNull())
- bb = layer->boundingRect();
- else
- bb = bb.united(layer->boundingRect());
- }
-
- return bb;
-}
-
-QSizeF KarbonDocument::pageSize() const
-{
- return d->pageSize;
-}
-
-void KarbonDocument::setPageSize(QSizeF pageSize)
-{
- d->pageSize = pageSize;
-}
-
-const QList<KoShape*> KarbonDocument::shapes() const
-{
- return d->objects;
-}
-
-const QList<KoShapeLayer*> KarbonDocument::layers() const
-{
- return d->layers;
-}
-
-KoImageCollection * KarbonDocument::imageCollection()
-{
- return resourceManager()->imageCollection();
-}
-
-QMap<QString, KoDataCenterBase*> KarbonDocument::dataCenterMap() const
-{
- return d->dataCenterMap;
-}
-
-void KarbonDocument::useExternalDataCenterMap(QMap<QString, KoDataCenterBase*> \
dataCenters)
-{
- qDeleteAll(d->dataCenterMap);
- d->dataCenterMap = dataCenters;
- d->hasExternalDataCenterMap = true;
-}
-
-//#############################################################################
-// ODF saving
-//#############################################################################
-
-bool KarbonDocument::saveOdf(KoDocument::SavingContext &documentContext, const \
KoPageLayout &layout)
-{
- KoStore * store = documentContext.odfStore.store();
- KoXmlWriter* contentWriter = documentContext.odfStore.contentWriter();
- if (!contentWriter)
- return false;
-
- KoGenStyles mainStyles;
- KoXmlWriter * bodyWriter = documentContext.odfStore.bodyWriter();
-
- KoShapeSavingContext shapeContext(*bodyWriter, mainStyles, \
documentContext.embeddedSaver);
-
- // save text styles
- saveOdfStyles(shapeContext);
-
- // save page
- QString layoutName = mainStyles.insert(layout.saveOdf(), "PL");
- KoGenStyle masterPage(KoGenStyle::MasterPageStyle);
- masterPage.addAttribute("style:page-layout-name", layoutName);
- mainStyles.insert(masterPage, "Default", KoGenStyles::DontAddNumberToName);
-
- bodyWriter->startElement("office:body");
- bodyWriter->startElement("office:drawing");
-
- saveOasis(shapeContext); // Save contents
-
- bodyWriter->endElement(); // office:drawing
- bodyWriter->endElement(); // office:body
-
- mainStyles.saveOdfStyles(KoGenStyles::DocumentAutomaticStyles, contentWriter);
-
- documentContext.odfStore.closeContentWriter();
-
- //add manifest line for content.xml
- documentContext.odfStore.manifestWriter()->addManifestEntry("content.xml", \
"text/xml");
-
- if (!shapeContext.saveDataCenter(store, \
documentContext.odfStore.manifestWriter())) {
- return false;
- }
-
- return mainStyles.saveOdfStylesDotXml(store, \
documentContext.odfStore.manifestWriter());
-}
-
-void KarbonDocument::loadOdfStyles(KoShapeLoadingContext & context)
-{
- KoStyleManager *styleManager = \
resourceManager()->resource(KoText::StyleManager).value<KoStyleManager*>();
-
- if (! styleManager)
- return;
-
- KoTextSharedLoadingData * sharedData = new KoTextSharedLoadingData();
- if (! sharedData)
- return;
-
- sharedData->loadOdfStyles(context, styleManager);
- context.addSharedData(KOTEXT_SHARED_LOADING_ID, sharedData);
-}
-
-void KarbonDocument::saveOdfStyles(KoShapeSavingContext & context)
-{
- KoStyleManager * styleManager = \
dynamic_cast<KoStyleManager*>(dataCenterMap()["StyleManager"]);
- if (! styleManager)
- return;
-
- styleManager->saveOdf(context);
-}
-
-void KarbonDocument::addToDataCenterMap(const QString &key, KoDataCenterBase* \
dataCenter)
-{
- d->dataCenterMap.insert(key, dataCenter);
-}
-
-KoDocumentResourceManager *KarbonDocument::resourceManager() const
-{
- return d->resourceManager;
-}
-
-void KarbonDocument::setResourceManager(KoDocumentResourceManager *rm)
-{
- d->resourceManager = rm;
-}
diff --git a/karbon/ui/CMakeLists.txt b/karbon/ui/CMakeLists.txt
index a332724..2d5d5b2 100644
--- a/karbon/ui/CMakeLists.txt
+++ b/karbon/ui/CMakeLists.txt
@@ -7,17 +7,20 @@ include_directories(
${CMAKE_SOURCE_DIR}/karbon/ui/dialogs
${CMAKE_SOURCE_DIR}/karbon/ui/dockers
${CMAKE_SOURCE_DIR}/karbon/ui/widgets
+ ${CMAKE_SOURCE_DIR}/karbon/ui/commands
)
set(karbonui_SRCS
KarbonFactory.cpp
- KarbonKoDocument.cpp
+ KarbonDocument.cpp
KarbonPart.cpp
KarbonView.cpp
KarbonPrintJob.cpp
KarbonZoomController.cpp
KarbonDocumentMergeCommand.cpp
+ commands/KarbonLayerReorderCommand.cpp
+
dialogs/KarbonConfigureDialog.cpp
dockers/KarbonLayerDocker.cpp
diff --git a/karbon/ui/KarbonDocument.cpp b/karbon/ui/KarbonDocument.cpp
new file mode 100644
index 0000000..68558e1
--- /dev/null
+++ b/karbon/ui/KarbonDocument.cpp
@@ -0,0 +1,779 @@
+/* This file is part of the KDE project
+ * Copyright (C) 2001-2002 Lennart Kudling <kudling@kde.org>
+ * Copyright (C) 2001-2007 Rob Buis <buis@kde.org>
+ * Copyright (C) 2002-2006 Laurent Montel <montel@kde.org>
+ * Copyright (C) 2002 Werner Trobin <trobin@kde.org>
+ * Copyright (C) 2002-2006 David Faure <faure@kde.org>
+ * Copyright (C) 2002 Stephan Kulow <coolo@kde.org>
+ * Copyright (C) 2002 Benoit Vautrin <benoit.vautrin@free.fr>
+ * Copyright (C) 2003 Thomas Nagy <tnagyemail-mail@yahoo.fr>
+ * Copyright (C) 2003,2006 Dirk Mueller <mueller@kde.org>
+ * Copyright (C) 2004 Brad Hards <bradh@frogmouth.net>
+ * Copyright (C) 2004-2006 Peter Simonsson <psn@linux.se>
+ * Copyright (C) 2004-2005 Fredrik Edemar <f_edemar@linux.se>
+ * Copyright (C) 2005-2006 Tim Beaulen <tbscope@gmail.com>
+ * Copyright (C) 2005 Sven Langkamp <sven.langkamp@gmail.com>
+ * Copyright (C) 2005-2007 Jan Hambrecht <jaham@gmx.net>
+ * Copyright (C) 2005-2007 Thomas Zander <zander@kde.org>
+ * Copyright (C) 2005-2006 Inge Wallin <inge@lysator.liu.se>
+ * Copyright (C) 2005 Johannes Schaub <johannes.schaub@kdemail.net>
+ * Copyright (C) 2006 Gabor Lehel <illissius@gmail.com>
+ * Copyright (C) 2006 Stefan Nikolaus <stefan.nikolaus@kdemail.net>
+ * Copyright (C) 2006 Jaison Lee <lee.jaison@gmail.com>
+ * Copyright (C) 2006 Casper Boemann <cbr@boemann.dk>
+ * Copyright (C) 2006-2007 Thorsten Zachmann <t.zachmann@zagge.de>
+ * Copyright (C) 2007 Matthias Kretz <kretz@kde.org>
+ * Copyright (C) 2012 Yue Liu <yue.liu@mail.com>
+ *
+ * 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 "KarbonDocument.h"
+#include "KarbonPart.h"
+#include "KarbonFactory.h"
+#include "KarbonView.h"
+#include <KarbonCanvas.h>
+#include <KarbonDocument.h>
+
+#include <KoApplication.h>
+#include <KoImageCollection.h>
+#include <KoDataCenterBase.h>
+#include <KoText.h>
+#include <KoStyleManager.h>
+#include <KoTextSharedLoadingData.h>
+#include <KoOdfStylesReader.h>
+#include <KoOdfLoadingContext.h>
+#include <KoOdfReadStore.h>
+#include <KoOdfWriteStore.h>
+#include <KoShapeSavingContext.h>
+#include <KoShapeLoadingContext.h>
+#include <KoPageLayout.h>
+#include <KoXmlWriter.h>
+#include <KoXmlNS.h>
+#include <KoOasisSettings.h>
+#include <KoMainWindow.h>
+#include <KoCanvasController.h>
+#include <KoToolManager.h>
+#include <KoShapeManager.h>
+#include <KoShapeLayer.h>
+#include <KoShapeRegistry.h>
+#include <KoCanvasResourceManager.h>
+#include <KoDocumentResourceManager.h>
+#include <KoEmbeddedDocumentSaver.h>
+#include <KoStoreDevice.h>
+#include <KoStore.h>
+#include <KoShapePainter.h>
+#include <SvgShapeFactory.h>
+
+#include <kconfig.h>
+#include <kconfiggroup.h>
+#include <ktemporaryfile.h>
+#include <kdebug.h>
+#include <klocale.h>
+#include <kundo2stack.h>
+
+#include <QDomDocument>
+#include <QDomElement>
+#include <QFileInfo>
+#include <QRectF>
+#include <QPainter>
+
+// Make sure an appropriate DTD is available in www/calligra/DTD if changing this \
value +// static const char * CURRENT_DTD_VERSION = "1.2";
+
+class KarbonDocument::Private
+{
+public:
+ Private()
+ : pageSize(0.0, 0.0),
+ hasExternalDataCenterMap(false),
+ showStatusBar(true),
+ merge(false),
+ maxRecentFiles(10)
+ {}
+
+ ~Private()
+ {
+ qDeleteAll(layers);
+ layers.clear();
+ qDeleteAll(objects);
+ objects.clear();
+ if (!hasExternalDataCenterMap)
+ qDeleteAll(dataCenterMap);
+ }
+
+ qreal getAttribute(KoXmlElement &element, const char *attributeName, qreal \
defaultValue) + {
+ QString value = element.attribute(attributeName);
+ if (! value.isEmpty())
+ return value.toDouble();
+ else
+ return defaultValue;
+ }
+
+ int getAttribute(KoXmlElement &element, const char *attributeName, int \
defaultValue) + {
+ QString value = element.attribute(attributeName);
+ if (! value.isEmpty())
+ return value.toInt();
+ else
+ return defaultValue;
+ }
+
+ // KarbonDocument document; ///< store non-visual doc info
+ QSizeF pageSize; ///< the documents page size
+
+ QList<KoShape*> objects; ///< The list of all object of the document.
+ QList<KoShapeLayer*> layers; ///< The layers in this document.
+
+ QMap<QString, KoDataCenterBase*> dataCenterMap;
+ bool hasExternalDataCenterMap;
+ bool showStatusBar; ///< enable/disable status bar in attached view(s)
+ bool merge;
+ uint maxRecentFiles; ///< max. number of files shown in open recent menu \
item +};
+
+
+KarbonDocument::KarbonDocument(KarbonPart* part)
+ : KoDocument(part)
+ , d(new Private())
+{
+ resourceManager()->setUndoStack(undoStack());
+
+ initConfig();
+
+ SvgShapeFactory::addToRegistry();
+
+ // set as default paper
+ KoPageLayout pl = pageLayout();
+ pl.format = KoPageFormat::defaultFormat();
+ pl.orientation = KoPageFormat::Portrait;
+ pl.width = MM_TO_POINT(KoPageFormat::width(pl.format, pl.orientation));
+ pl.height = MM_TO_POINT(KoPageFormat::height(pl.format, pl.orientation));
+ setPageLayout(pl);
+}
+
+KarbonDocument::~KarbonDocument()
+{
+ delete d;
+}
+
+void KarbonDocument::setPageLayout(const KoPageLayout& layout)
+{
+ KoDocument::setPageLayout(layout);
+ setPageSize(QSizeF(layout.width, layout.height));
+}
+
+bool KarbonDocument::loadXML(const KoXmlDocument&, KoStore*)
+{
+ return false;
+}
+
+bool KarbonDocument::loadOdf(KoOdfReadStore & odfStore)
+{
+ kDebug(38000) << "Start loading OASIS document..." /*<< doc.toString()*/;
+
+ KoXmlElement contents = odfStore.contentDoc().documentElement();
+ kDebug(38000) << "Start loading OASIS document..." << contents.text();
+ kDebug(38000) << "Start loading OASIS contents..." << \
contents.lastChild().localName(); + kDebug(38000) << "Start loading OASIS \
contents..." << contents.lastChild().namespaceURI(); + kDebug(38000) << "Start \
loading OASIS contents..." << contents.lastChild().isElement(); + KoXmlElement \
body(KoXml::namedItemNS(contents, KoXmlNS::office, "body")); + if (body.isNull()) \
{ + kDebug(38000) << "No office:body found!";
+ setErrorMessage(i18n("Invalid OASIS document. No office:body tag found."));
+ return false;
+ }
+
+ body = KoXml::namedItemNS(body, KoXmlNS::office, "drawing");
+ if (body.isNull()) {
+ kDebug(38000) << "No office:drawing found!";
+ setErrorMessage(i18n("Invalid OASIS document. No office:drawing tag \
found.")); + return false;
+ }
+
+ KoXmlElement page(KoXml::namedItemNS(body, KoXmlNS::draw, "page"));
+ if (page.isNull()) {
+ kDebug(38000) << "No office:drawing found!";
+ setErrorMessage(i18n("Invalid OASIS document. No draw:page tag found."));
+ return false;
+ }
+
+ KoXmlElement * master = 0;
+ if (odfStore.styles().masterPages().contains("Standard"))
+ master = odfStore.styles().masterPages().value("Standard");
+ else if (odfStore.styles().masterPages().contains("Default"))
+ master = odfStore.styles().masterPages().value("Default");
+ else if (! odfStore.styles().masterPages().empty())
+ master = odfStore.styles().masterPages().begin().value();
+
+ if (master) {
+ const QString pageStyleName = master->attributeNS(KoXmlNS::style, \
"page-layout-name", QString()); + const KoXmlElement *style = \
odfStore.styles().findStyle(pageStyleName); + if (style) {
+ KoPageLayout layout;
+ layout.loadOdf(*style);
+ setPageLayout(layout);
+ }
+ } else {
+ kWarning() << "No master page found!";
+ return false;
+ }
+
+ KoOdfLoadingContext context(odfStore.styles(), odfStore.store());
+ KoShapeLoadingContext shapeContext(context, resourceManager());
+
+ loadOasis(page, shapeContext);
+
+ if (pageSize().isEmpty()) {
+ QSizeF pageSize = contentRect().united(QRectF(0, 0, 1, 1)).size();
+ setPageSize(pageSize);
+ }
+
+ loadOasisSettings(odfStore.settingsDoc());
+
+ return true;
+}
+
+bool KarbonDocument::completeLoading(KoStore* store)
+{
+ bool ok = true;
+ foreach(KoDataCenterBase *dataCenter, dataCenterMap()) {
+ ok = ok && dataCenter->completeLoading(store);
+ }
+ return ok;
+}
+
+void KarbonDocument::loadOasisSettings(const KoXmlDocument & settingsDoc)
+{
+ if (settingsDoc.isNull())
+ return ; // not an error if some file doesn't have settings.xml
+ KoOasisSettings settings(settingsDoc);
+ KoOasisSettings::Items viewSettings = settings.itemSet("view-settings");
+ if (!viewSettings.isNull()) {
+ setUnit(KoUnit::fromSymbol(viewSettings.parseConfigItemString("unit")));
+ // FIXME: add other config here.
+ }
+ guidesData().loadOdfSettings(settingsDoc);
+ gridData().loadOdfSettings(settingsDoc);
+}
+
+void KarbonDocument::saveOasisSettings(KoStore * store)
+{
+ KoStoreDevice settingsDev(store);
+ KoXmlWriter * settingsWriter = \
KoOdfWriteStore::createOasisXmlWriter(&settingsDev, "office:document-settings"); +
+ settingsWriter->startElement("office:settings");
+ settingsWriter->startElement("config:config-item-set");
+ settingsWriter->addAttribute("config:name", "view-settings");
+
+ saveUnitOdf(settingsWriter);
+
+ settingsWriter->endElement(); // config:config-item-set
+
+ settingsWriter->startElement("config:config-item-set");
+ settingsWriter->addAttribute("config:name", "ooo:view-settings");
+ settingsWriter->startElement("config:config-item-map-indexed");
+ settingsWriter->addAttribute("config:name", "Views");
+ settingsWriter->startElement("config:config-item-map-entry");
+
+ guidesData().saveOdfSettings(*settingsWriter);
+ gridData().saveOdfSettings(*settingsWriter);
+
+ settingsWriter->endElement(); // config:config-item-map-entry
+ settingsWriter->endElement(); // config:config-item-map-indexed
+ settingsWriter->endElement(); // config:config-item-set
+
+ settingsWriter->endElement(); // office:settings
+ settingsWriter->endElement(); // office:document-settings
+
+ settingsWriter->endDocument();
+
+ delete settingsWriter;
+}
+
+bool KarbonDocument::saveOdf(SavingContext &documentContext)
+{
+ KoStore * store = documentContext.odfStore.store();
+ KoXmlWriter* contentWriter = documentContext.odfStore.contentWriter();
+ if (!contentWriter)
+ return false;
+
+ KoGenStyles mainStyles;
+ KoXmlWriter * bodyWriter = documentContext.odfStore.bodyWriter();
+
+ KoShapeSavingContext shapeContext(*bodyWriter, mainStyles, \
documentContext.embeddedSaver); +
+ // save text styles
+ saveOdfStyles(shapeContext);
+
+ // save page
+ QString layoutName = mainStyles.insert(pageLayout().saveOdf(), "PL");
+ KoGenStyle masterPage(KoGenStyle::MasterPageStyle);
+ masterPage.addAttribute("style:page-layout-name", layoutName);
+ mainStyles.insert(masterPage, "Default", KoGenStyles::DontAddNumberToName);
+
+ bodyWriter->startElement("office:body");
+ bodyWriter->startElement("office:drawing");
+
+ saveOasis(shapeContext); // Save contents
+
+ bodyWriter->endElement(); // office:drawing
+ bodyWriter->endElement(); // office:body
+
+ mainStyles.saveOdfStyles(KoGenStyles::DocumentAutomaticStyles, contentWriter);
+
+ documentContext.odfStore.closeContentWriter();
+
+ //add manifest line for content.xml
+ documentContext.odfStore.manifestWriter()->addManifestEntry("content.xml", \
"text/xml"); +
+ if (!shapeContext.saveDataCenter(store, \
documentContext.odfStore.manifestWriter())) { + return false;
+ }
+
+ if (! mainStyles.saveOdfStylesDotXml(store, \
documentContext.odfStore.manifestWriter())) + return false;
+
+ if (! store->open("settings.xml"))
+ return false;
+
+ saveOasisSettings(store);
+
+ if (! store->close())
+ return false;
+
+ documentContext.odfStore.manifestWriter()->addManifestEntry("settings.xml", \
"text/xml"); +
+ setModified(false);
+
+ return true;
+}
+
+void KarbonDocument::slotDocumentRestored()
+{
+ setModified(false);
+}
+
+void KarbonDocument::paintContent(QPainter &painter, const QRect& rect)
+{
+ KoShapePainter shapePainter;
+ shapePainter.setShapes(shapes());
+ shapePainter.paint(painter, rect, QRectF(QPointF(), pageSize()));
+}
+
+bool KarbonDocument::showStatusBar() const
+{
+ return d->showStatusBar;
+}
+
+void KarbonDocument::setShowStatusBar(bool b)
+{
+ d->showStatusBar = b;
+}
+
+uint KarbonDocument::maxRecentFiles() const
+{
+ return d->maxRecentFiles;
+}
+
+void KarbonDocument::reorganizeGUI()
+{
+ foreach(KoView* view, documentPart()->views()) {
+ KarbonView * kv = qobject_cast<KarbonView*>(view);
+ if (kv) {
+ kv->reorganizeGUI();
+ emit applyCanvasConfiguration(kv->canvasWidget());
+ }
+ }
+}
+
+void KarbonDocument::initConfig()
+{
+ KSharedConfigPtr config = KarbonFactory::componentData().config();
+
+ // disable grid by default
+ gridData().setShowGrid(false);
+
+ if (config->hasGroup("Interface")) {
+ KConfigGroup interfaceGroup = config->group("Interface");
+ setAutoSave(interfaceGroup.readEntry("AutoSave", defaultAutoSave() / 60) * \
60); + d->maxRecentFiles = interfaceGroup.readEntry("NbRecentFile", 10);
+ setShowStatusBar(interfaceGroup.readEntry("ShowStatusBar" , true));
+ setBackupFile(interfaceGroup.readEntry("BackupFile", true));
+ }
+ int undos = 30;
+
+ QString defaultUnitSymbol =
+ QLatin1String((KGlobal::locale()->measureSystem() == \
KLocale::Imperial)?"in":"cm"); +
+ if (config->hasGroup("Misc")) {
+ KConfigGroup miscGroup = config->group("Misc");
+ undos = miscGroup.readEntry("UndoRedo", -1);
+ defaultUnitSymbol = miscGroup.readEntry("Units", defaultUnitSymbol);
+ }
+ undoStack()->setUndoLimit(undos);
+ setUnit(KoUnit::fromSymbol(defaultUnitSymbol));
+
+ if (config->hasGroup("Grid")) {
+ KoGridData defGrid;
+ KConfigGroup gridGroup = config->group("Grid");
+ qreal spacingX = gridGroup.readEntry<qreal>("SpacingX", defGrid.gridX());
+ qreal spacingY = gridGroup.readEntry<qreal>("SpacingY", defGrid.gridY());
+ gridData().setGrid(spacingX, spacingY);
+ QColor color = gridGroup.readEntry("Color", defGrid.gridColor());
+ gridData().setGridColor(color);
+ }
+}
+
+bool KarbonDocument::mergeNativeFormat(const QString &file)
+{
+ d->merge = true;
+ bool result = loadNativeFormat(file);
+ if (!result)
+ documentPart()->showLoadingErrorDialog();
+ d->merge = false;
+ return result;
+}
+
+void KarbonDocument::addShape(KoShape* shape)
+{
+ KoCanvasController* canvasController = \
KoToolManager::instance()->activeCanvasController(); +
+ KoShapeLayer *layer = dynamic_cast<KoShapeLayer*>(shape);
+ if (layer) {
+ insertLayer(layer);
+ if (canvasController) {
+ KoSelection *selection = \
canvasController->canvas()->shapeManager()->selection(); + \
selection->setActiveLayer(layer); + }
+ } else {
+ // only add shape to active layer if it has no parent yet
+ if (! shape->parent()) {
+ kDebug(38000) << "shape has no parent, adding to the active layer!";
+ KoShapeLayer *activeLayer = 0;
+ if (canvasController)
+ activeLayer = \
canvasController->canvas()->shapeManager()->selection()->activeLayer(); + \
else if (layers().count()) + activeLayer = layers().first();
+
+ if (activeLayer)
+ activeLayer->addShape(shape);
+ }
+
+ add(shape);
+
+ foreach(KoView *view, documentPart()->views()) {
+ KarbonCanvas *canvas = ((KarbonView*)view)->canvasWidget();
+ canvas->shapeManager()->addShape(shape);
+ }
+ }
+
+ setModified(true);
+ emit shapeCountChanged();
+}
+
+void KarbonDocument::removeShape(KoShape* shape)
+{
+ KoShapeLayer *layer = dynamic_cast<KoShapeLayer*>(shape);
+ if (layer) {
+ removeLayer(layer);
+ } else {
+ remove(shape);
+ foreach(KoView *view, documentPart()->views()) {
+ KarbonCanvas *canvas = ((KarbonView*)view)->canvasWidget();
+ canvas->shapeManager()->remove(shape);
+ }
+ }
+ setModified(true);
+ emit shapeCountChanged();
+}
+
+void KarbonDocument::setPageSize(const QSizeF &pageSize)
+{
+ d->pageSize = pageSize;
+ foreach(KoView *view, documentPart()->views()) {
+ KarbonCanvas *canvas = ((KarbonView*)view)->canvasWidget();
+ canvas->resourceManager()->setResource(KoCanvasResourceManager::PageSize, \
pageSize); + }
+}
+
+QSizeF KarbonDocument::pageSize() const
+{
+ return d->pageSize;
+}
+
+void KarbonDocument::insertLayer(KoShapeLayer* layer)
+{
+ if (!d->layers.contains(layer)) {
+ if (d->layers.count()) {
+ layer->setZIndex(d->layers.last()->zIndex() + 1);
+ } else {
+ layer->setZIndex(d->layers.count());
+ }
+ d->layers.append(layer);
+ }
+}
+
+void KarbonDocument::removeLayer(KoShapeLayer* layer)
+{
+ d->layers.removeAt(d->layers.indexOf(layer));
+ if (d->layers.count() == 0)
+ d->layers.append(new KoShapeLayer());
+}
+
+bool KarbonDocument::canRaiseLayer(KoShapeLayer* layer)
+{
+ int pos = d->layers.indexOf(layer);
+ return (pos != int(d->layers.count()) - 1 && pos >= 0);
+}
+
+bool KarbonDocument::canLowerLayer(KoShapeLayer* layer)
+{
+ int pos = d->layers.indexOf(layer);
+ return (pos > 0);
+}
+
+void KarbonDocument::raiseLayer(KoShapeLayer* layer)
+{
+ int pos = d->layers.indexOf(layer);
+ if (pos != int(d->layers.count()) - 1 && pos >= 0) {
+ KoShapeLayer * layerAbove = d->layers.at(pos + 1);
+ int lowerZIndex = layer->zIndex();
+ int upperZIndex = layerAbove->zIndex();
+ layer->setZIndex(upperZIndex);
+ layerAbove->setZIndex(lowerZIndex);
+ d->layers.move(pos, pos + 1);
+ }
+}
+
+void KarbonDocument::lowerLayer(KoShapeLayer* layer)
+{
+ int pos = d->layers.indexOf(layer);
+ if (pos > 0) {
+ KoShapeLayer * layerBelow = d->layers.at(pos - 1);
+ int upperZIndex = layer->zIndex();
+ int lowerZIndex = layerBelow->zIndex();
+ layer->setZIndex(lowerZIndex);
+ layerBelow->setZIndex(upperZIndex);
+ d->layers.move(pos, pos - 1);
+ }
+}
+
+int KarbonDocument::layerPos(KoShapeLayer* layer)
+{
+ return d->layers.indexOf(layer);
+}
+
+void KarbonDocument::add(KoShape* shape)
+{
+ if (! d->objects.contains(shape))
+ d->objects.append(shape);
+}
+
+void KarbonDocument::remove(KoShape* shape)
+{
+ d->objects.removeAt(d->objects.indexOf(shape));
+}
+
+void KarbonDocument::saveOasis(KoShapeSavingContext & context) const
+{
+ context.xmlWriter().startElement("draw:page");
+ context.xmlWriter().addAttribute("draw:name", "");
+ context.xmlWriter().addAttribute("draw:id", "page1");
+ context.xmlWriter().addAttribute("xml:id", "page1");
+ context.xmlWriter().addAttribute("draw:master-page-name", "Default");
+
+ foreach(KoShapeLayer * layer, d->layers) {
+ context.addLayerForSaving(layer);
+ }
+ context.saveLayerSet(context.xmlWriter());
+
+ foreach(KoShapeLayer * layer, d->layers) {
+ layer->saveOdf(context);
+ }
+
+ context.xmlWriter().endElement(); // draw:page
+}
+
+bool KarbonDocument::loadOasis(const KoXmlElement &element, KoShapeLoadingContext \
&context) +{
+ // load text styles used by text shapes
+ loadOdfStyles(context);
+
+ qDeleteAll(d->layers);
+ d->layers.clear();
+ qDeleteAll(d->objects);
+ d->objects.clear();
+
+ const KoXmlElement & pageLayerSet = KoXml::namedItemNS(element, KoXmlNS::draw, \
"layer-set"); + const KoXmlElement & usedPageLayerSet = pageLayerSet.isNull() ? \
context.odfLoadingContext().stylesReader().layerSet() : pageLayerSet; +
+ KoXmlElement layerElement;
+ forEachElement(layerElement, usedPageLayerSet) {
+ KoShapeLayer * l = new KoShapeLayer();
+ if (l->loadOdf(layerElement, context))
+ insertLayer(l);
+ }
+
+ KoShapeLayer * defaultLayer = 0;
+
+ // check if we have to insert a default layer
+ if (d->layers.count() == 0)
+ defaultLayer = new KoShapeLayer();
+
+ KoXmlElement child;
+ forEachElement(child, element) {
+ kDebug(38000) << "loading shape" << child.localName();
+
+ KoShape * shape = KoShapeRegistry::instance()->createShapeFromOdf(child, \
context); + if (shape)
+ d->objects.append(shape);
+ }
+
+ // add all toplevel shapes to the default layer
+ foreach(KoShape * shape, d->objects) {
+ if (! shape->parent()) {
+ if (! defaultLayer)
+ defaultLayer = new KoShapeLayer();
+
+ defaultLayer->addShape(shape);
+ }
+ }
+
+ if (defaultLayer)
+ insertLayer(defaultLayer);
+
+ KoOdfStylesReader & styleReader = context.odfLoadingContext().stylesReader();
+ QHash<QString, KoXmlElement*> masterPages = styleReader.masterPages();
+
+ KoXmlElement * master = 0;
+ if( masterPages.contains( "Standard" ) )
+ master = masterPages.value( "Standard" );
+ else if( masterPages.contains( "Default" ) )
+ master = masterPages.value( "Default" );
+ else if( ! masterPages.empty() )
+ master = masterPages.begin().value();
+
+ if (master) {
+ context.odfLoadingContext().setUseStylesAutoStyles( true );
+
+ QList<KoShape*> masterPageShapes;
+ KoXmlElement child;
+ forEachElement(child, (*master)) {
+ kDebug(38000) <<"loading master page shape" << child.localName();
+ KoShape * shape = KoShapeRegistry::instance()->createShapeFromOdf( \
child, context ); + if( shape )
+ masterPageShapes.append( shape );
+ }
+
+ KoShapeLayer * masterPageLayer = 0;
+ // add all toplevel shapes to the master page layer
+ foreach(KoShape * shape, masterPageShapes) {
+ d->objects.append( shape );
+ if(!shape->parent()) {
+ if( ! masterPageLayer ) {
+ masterPageLayer = new KoShapeLayer();
+ masterPageLayer->setName(i18n("Master Page"));
+ }
+
+ masterPageLayer->addShape(shape);
+ }
+ }
+
+ if( masterPageLayer )
+ insertLayer( masterPageLayer );
+
+ context.odfLoadingContext().setUseStylesAutoStyles( false );
+ }
+
+ return true;
+}
+
+QRectF KarbonDocument::boundingRect() const
+{
+ return contentRect().united(QRectF(QPointF(0, 0), d->pageSize));
+}
+
+QRectF KarbonDocument::contentRect() const
+{
+ QRectF bb;
+ foreach(KoShape* layer, d->layers) {
+ if (bb.isNull())
+ bb = layer->boundingRect();
+ else
+ bb = bb.united(layer->boundingRect());
+ }
+
+ return bb;
+}
+
+const QList<KoShape*> KarbonDocument::shapes() const
+{
+ return d->objects;
+}
+
+const QList<KoShapeLayer*> KarbonDocument::layers() const
+{
+ return d->layers;
+}
+
+KoImageCollection * KarbonDocument::imageCollection()
+{
+ return resourceManager()->imageCollection();
+}
+
+QMap<QString, KoDataCenterBase*> KarbonDocument::dataCenterMap() const
+{
+ return d->dataCenterMap;
+}
+
+void KarbonDocument::useExternalDataCenterMap(QMap<QString, KoDataCenterBase*> \
dataCenters) +{
+ qDeleteAll(d->dataCenterMap);
+ d->dataCenterMap = dataCenters;
+ d->hasExternalDataCenterMap = true;
+}
+
+void KarbonDocument::loadOdfStyles(KoShapeLoadingContext & context)
+{
+ KoStyleManager *styleManager = \
resourceManager()->resource(KoText::StyleManager).value<KoStyleManager*>(); +
+ if (! styleManager)
+ return;
+
+ KoTextSharedLoadingData * sharedData = new KoTextSharedLoadingData();
+ if (! sharedData)
+ return;
+
+ sharedData->loadOdfStyles(context, styleManager);
+ context.addSharedData(KOTEXT_SHARED_LOADING_ID, sharedData);
+}
+
+void KarbonDocument::saveOdfStyles(KoShapeSavingContext & context)
+{
+ KoStyleManager * styleManager = \
dynamic_cast<KoStyleManager*>(dataCenterMap()["StyleManager"]); + if (! \
styleManager) + return;
+
+ styleManager->saveOdf(context);
+}
+
+void KarbonDocument::addToDataCenterMap(const QString &key, KoDataCenterBase* \
dataCenter) +{
+ d->dataCenterMap.insert(key, dataCenter);
+}
+
diff --git a/karbon/common/KarbonDocument.h b/karbon/ui/KarbonDocument.h
similarity index 51%
rename from karbon/common/KarbonDocument.h
rename to karbon/ui/KarbonDocument.h
index 8290f4a..88a5e35 100644
--- a/karbon/common/KarbonDocument.h
+++ b/karbon/ui/KarbonDocument.h
@@ -1,79 +1,106 @@
/* This file is part of the KDE project
- Copyright (C) 2002 Lennart Kudling <kudling@kde.org>
- Copyright (C) 2002 Benoit Vautrin <benoit.vautrin@free.fr>
- Copyright (C) 2002-2005,2007 Rob Buis <buis@kde.org>
- Copyright (C) 2002,2005-2006 Laurent Montel <montel@kde.org>
- Copyright (C) 2005,2007 David Faure <faure@kde.org>
- Copyright (C) 2005-2006 Thomas Zander <zander@kde.org>
- Copyright (C) 2005-2007 Jan Hambrecht <jaham@gmx.net>
- Copyright (C) 2006 Inge Wallin <inge@lysator.liu.se>
- Copyright (C) 2006 Adriaan de Groot <groot@kde.org>
- Copyright (C) 2006 C. Boemann <cbo@boemann.dk>
- Copyright (C) 2006 Tim Beaulen <tbscope@gmail.com>
-
- 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,
+ * Copyright (C) 2001-2002 Lennart Kudling <kudling@kde.org>
+ * Copyright (C) 2001-2005,2007 Rob Buis <buis@kde.org>
+ * Copyright (C) 2002,2004-2005 Laurent Montel <montel@kde.org>
+ * Copyright (C) 2002 Benoit Vautrin <benoit.vautrin@free.fr>
+ * Copyright (C) 2004-2005,2007 David Faure <faure@kde.org>
+ * Copyright (C) 2004,2006 Peter Simonsson <psn@linux.se>
+ * Copyright (C) 2004-2005 Fredrik Edemar <f_edemar@linux.se>
+ * Copyright (C) 2005-2007 Jan Hambrecht <jaham@gmx.net>
+ * Copyright (C) 2005-2007 Thomas Zander <zander@kde.org>
+ * Copyright (C) 2006 Inge Wallin <inge@lysator.liu.se>
+ * Copyright (C) 2006 Tim Beaulen <tbscope@gmail.com>
+ * Copyright (C) 2006 Casper Boemann <cbr@boemann.dk>
+ * Copyright (C) 2006-2007 Thorsten Zachmann <t.zachmann@zagge.de>
+ * Copyright (C) 2012 Yue Liu <yue.liu@mail.com>
+ *
+ * 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 KARBONDOCUMENT_H
-#define KARBONDOCUMENT_H
+#ifndef KARBON_DOCUMENT_H
+#define KARBON_DOCUMENT_H
#include <QString>
#include <QMap>
#include <QRectF>
-#include <karboncommon_export.h>
+#include <KoShapeBasedDocumentBase.h>
+
+#include <KoDocument.h>
+#include <KoUnit.h>
#include <KoShapeLoadingContext.h>
#include <KoGenStyle.h>
#include <KoXmlReader.h>
-#include <KoDocument.h>
+#include <karbonui_export.h>
+
+class QRect;
+class KarbonPart;
+class KarbonCanvas;
+class KoDataCenterBase;
class KoShape;
class KoShapeSavingContext;
class KoShapeLayer;
class KoImageCollection;
class KoStore;
-class KoDataCenterBase;
-class KoDocumentResourceManager;
/**
- * All non-visual, static doc info is in here.
- * The karbon part uses this class.
- * Filters can use this class as well instead of
- * the visually oriented karbon part.
+ * Keeps track of visual per document properties.
+ * It loads initial settings and applies them to the document and its views.
*/
-class KARBONCOMMON_EXPORT KarbonDocument
+class KARBONUI_EXPORT KarbonDocument : public KoDocument, public \
KoShapeBasedDocumentBase {
+ Q_OBJECT
public:
+ explicit KarbonDocument(KarbonPart *part);
+ virtual ~KarbonDocument();
- /**
- * Constructs a new document.
- */
- KarbonDocument();
+ /// reimplemented form KoDocument
+ virtual void paintContent(QPainter& painter, const QRect& rect);
+ /// reimplemented form KoDocument
+ virtual bool loadXML(const KoXmlDocument& document, KoStore *store);
+ /// reimplemented form KoDocument
+ virtual bool loadOdf(KoOdfReadStore & odfStore);
+ /// reimplemented form KoDocument
+ virtual bool completeLoading(KoStore* store);
+ /// reimplemented form KoDocument
+ virtual bool saveOdf(SavingContext &documentContext);
- /**
- * Copy constructor.
- *
- * @param document the document to copy properties from
- */
- KarbonDocument(const KarbonDocument& document);
+ /// implemented from KoShapeController
+ virtual void addShape(KoShape* shape);
+ /// implemented from KoShapeController
+ virtual void removeShape(KoShape* shape);
- /**
- * Destroys the document and all of the layers.
- */
- virtual ~KarbonDocument();
+ /// Returns if status bar is shown
+ bool showStatusBar() const;
+ /// Shows/hides status bar
+ void setShowStatusBar(bool b);
+ /// update attached view(s) on the current doc settings
+ /// at this time only the status bar is handled
+ void reorganizeGUI();
+
+ /// Returns maximum number of recent files
+ uint maxRecentFiles() const;
+
+ /// Sets page layout of the document
+ virtual void setPageLayout(const KoPageLayout& layout);
+
+ bool mergeNativeFormat(const QString & file);
+
+ // merged from original KarbonDocument
/**
* Checks if specified layer can be raised.
@@ -155,7 +182,6 @@ public:
const QList<KoShape*> shapes() const;
void saveOasis(KoShapeSavingContext & context) const;
- bool saveOdf(KoDocument::SavingContext & documentContext, const KoPageLayout \
&layout);
bool loadOasis(const KoXmlElement &element, KoShapeLoadingContext &context);
void loadOdfStyles(KoShapeLoadingContext & context);
void saveOdfStyles(KoShapeSavingContext & context);
@@ -174,16 +200,6 @@ public:
*/
void remove(KoShape* shape);
- /**
- * Fetch the current resourceManager.
- * See KoShapeController::resourceManager() for more details.
- */
- KoDocumentResourceManager *resourceManager() const;
- /**
- * Set a new resource manager.
- */
- void setResourceManager(KoDocumentResourceManager *rm);
-
/// Returns the united bounding rectangle of the documents content and the \
document page QRectF boundingRect() const;
@@ -193,8 +209,11 @@ public:
/// Returns the documents page size
QSizeF pageSize() const;
+ /// Sets given page size to all attached views/canvases
+ void setPageSize(const QSizeF &pageSize);
+
/// Sets the documents page size
- void setPageSize(QSizeF pageSize);
+ //void setDocumentPageSize(QSizeF pageSize);
/// Returns the documents image collection
KoImageCollection * imageCollection();
@@ -207,11 +226,28 @@ public:
void addToDataCenterMap(const QString &key, KoDataCenterBase* dataCenter);
-private:
+public slots:
+ void slotDocumentRestored();
+
+signals:
+ void shapeCountChanged();
+ void applyCanvasConfiguration(KarbonCanvas *canvas);
+
+protected:
+ /// Loads settings like grid and guide lines from given xml document
+ void loadOasisSettings(const KoXmlDocument & settingsDoc);
+ /// Saves settings like grid and guide lines to store
+ void saveOasisSettings(KoStore * store);
+
+ /// Reads settings from config file
+ void initConfig();
+
+
+private:
class Private;
Private * const d;
};
-#endif // KARBONDOCUMENT_H
+#endif // KARBON_DOCUMENT_H
diff --git a/karbon/ui/KarbonDocumentMergeCommand.cpp \
b/karbon/ui/KarbonDocumentMergeCommand.cpp index 7b331db..e88a2d5 100644
--- a/karbon/ui/KarbonDocumentMergeCommand.cpp
+++ b/karbon/ui/KarbonDocumentMergeCommand.cpp
@@ -19,7 +19,7 @@
#include "KarbonDocumentMergeCommand.h"
#include "KarbonPart.h"
-#include "KarbonKoDocument.h"
+#include "KarbonDocument.h"
#include "KarbonDocument.h"
#include "KoShapeLayer.h"
#include <KLocale>
@@ -39,18 +39,18 @@ public:
}
}
- KarbonKoDocument * targetPart;
+ KarbonDocument * targetPart;
QList<KoShapeLayer*> layers;
QList<KoShape*> shapes;
bool hasMerged;
};
-KarbonDocumentMergeCommand::KarbonDocumentMergeCommand(KarbonKoDocument * \
targetPart, KarbonKoDocument * sourcePart) \
+KarbonDocumentMergeCommand::KarbonDocumentMergeCommand(KarbonDocument *targetPart, \
KarbonDocument *sourcePart) : KUndo2Command(0), d(new Private())
{
d->targetPart = targetPart;
- d->layers = sourcePart->document().layers();
- d->shapes = sourcePart->document().shapes();
+ d->layers = sourcePart->layers();
+ d->shapes = sourcePart->shapes();
foreach(KoShapeLayer * layer, d->layers) {
sourcePart->removeShape(layer);
}
diff --git a/karbon/ui/KarbonDocumentMergeCommand.h \
b/karbon/ui/KarbonDocumentMergeCommand.h index 1eed437..561af0a 100644
--- a/karbon/ui/KarbonDocumentMergeCommand.h
+++ b/karbon/ui/KarbonDocumentMergeCommand.h
@@ -22,12 +22,12 @@
#include <kundo2command.h>
-class KarbonKoDocument;
+class KarbonDocument;
class KarbonDocumentMergeCommand : public KUndo2Command
{
public:
- KarbonDocumentMergeCommand(KarbonKoDocument * targetPart, KarbonKoDocument * \
sourcePart); + KarbonDocumentMergeCommand(KarbonDocument * targetPart, \
KarbonDocument * sourcePart); virtual ~KarbonDocumentMergeCommand();
virtual void redo();
virtual void undo();
diff --git a/karbon/ui/KarbonFactory.cpp b/karbon/ui/KarbonFactory.cpp
index 5b740ac..8bbabbe 100644
--- a/karbon/ui/KarbonFactory.cpp
+++ b/karbon/ui/KarbonFactory.cpp
@@ -32,7 +32,7 @@
#include "KarbonFactory.h"
#include "KarbonPart.h"
-#include "KarbonKoDocument.h"
+#include "KarbonDocument.h"
#include "KarbonAboutData.h"
#include <kaboutdata.h>
@@ -69,7 +69,7 @@ QObject* KarbonFactory::create(const char* /*iface*/, QWidget* \
/*parentWidget*/, Q_UNUSED(keyword);
KarbonPart *part = new KarbonPart(parent);
- KarbonKoDocument* doc = new KarbonKoDocument(part);
+ KarbonDocument* doc = new KarbonDocument(part);
part->setDocument(doc);;
return part;
}
diff --git a/karbon/ui/KarbonKoDocument.cpp b/karbon/ui/KarbonKoDocument.cpp
deleted file mode 100644
index d16b84d..0000000
--- a/karbon/ui/KarbonKoDocument.cpp
+++ /dev/null
@@ -1,458 +0,0 @@
-/* This file is part of the KDE project
- * Copyright (C) 2001-2002 Lennart Kudling <kudling@kde.org>
- * Copyright (C) 2001-2007 Rob Buis <buis@kde.org>
- * Copyright (C) 2002-2006 Laurent Montel <montel@kde.org>
- * Copyright (C) 2002 Werner Trobin <trobin@kde.org>
- * Copyright (C) 2002-2006 David Faure <faure@kde.org>
- * Copyright (C) 2002 Stephan Kulow <coolo@kde.org>
- * Copyright (C) 2002 Benoit Vautrin <benoit.vautrin@free.fr>
- * Copyright (C) 2003 Thomas Nagy <tnagyemail-mail@yahoo.fr>
- * Copyright (C) 2003,2006 Dirk Mueller <mueller@kde.org>
- * Copyright (C) 2004 Brad Hards <bradh@frogmouth.net>
- * Copyright (C) 2004-2006 Peter Simonsson <psn@linux.se>
- * Copyright (C) 2004-2005 Fredrik Edemar <f_edemar@linux.se>
- * Copyright (C) 2005-2006 Tim Beaulen <tbscope@gmail.com>
- * Copyright (C) 2005 Sven Langkamp <sven.langkamp@gmail.com>
- * Copyright (C) 2005-2007 Jan Hambrecht <jaham@gmx.net>
- * Copyright (C) 2005-2007 Thomas Zander <zander@kde.org>
- * Copyright (C) 2005-2006 Inge Wallin <inge@lysator.liu.se>
- * Copyright (C) 2005 Johannes Schaub <johannes.schaub@kdemail.net>
- * Copyright (C) 2006 Gabor Lehel <illissius@gmail.com>
- * Copyright (C) 2006 Stefan Nikolaus <stefan.nikolaus@kdemail.net>
- * Copyright (C) 2006 Jaison Lee <lee.jaison@gmail.com>
- * Copyright (C) 2006 Casper Boemann <cbr@boemann.dk>
- * Copyright (C) 2006-2007 Thorsten Zachmann <t.zachmann@zagge.de>
- * Copyright (C) 2007 Matthias Kretz <kretz@kde.org>
- *
- * 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 "KarbonKoDocument.h"
-#include "KarbonPart.h"
-#include "KarbonFactory.h"
-#include "KarbonView.h"
-#include <KarbonCanvas.h>
-#include <KarbonDocument.h>
-
-#include <KoApplication.h>
-#include <KoDataCenterBase.h>
-#include <KoOdfStylesReader.h>
-#include <KoOdfLoadingContext.h>
-#include <KoOdfReadStore.h>
-#include <KoOdfWriteStore.h>
-#include <KoShapeSavingContext.h>
-#include <KoXmlWriter.h>
-#include <KoXmlNS.h>
-#include <KoOasisSettings.h>
-#include <KoMainWindow.h>
-#include <KoCanvasController.h>
-#include <KoToolManager.h>
-#include <KoShapeManager.h>
-#include <KoShapeLayer.h>
-#include <KoShapeRegistry.h>
-#include <KoCanvasResourceManager.h>
-#include <KoDocumentResourceManager.h>
-#include <KoStoreDevice.h>
-#include <KoShapePainter.h>
-#include <SvgShapeFactory.h>
-
-#include <kconfig.h>
-#include <kconfiggroup.h>
-#include <kdebug.h>
-#include <klocale.h>
-#include <kundo2stack.h>
-
-#include <QDomDocument>
-#include <QDomElement>
-#include <QFileInfo>
-#include <QRectF>
-#include <QPainter>
-
-// Make sure an appropriate DTD is available in www/calligra/DTD if changing this \
value
-// static const char * CURRENT_DTD_VERSION = "1.2";
-
-class KarbonKoDocument::Private
-{
-public:
- Private()
- : showStatusBar(true), merge(false), maxRecentFiles(10) {}
-
- qreal getAttribute(KoXmlElement &element, const char *attributeName, qreal \
defaultValue)
- {
- QString value = element.attribute(attributeName);
- if (! value.isEmpty())
- return value.toDouble();
- else
- return defaultValue;
- }
-
- int getAttribute(KoXmlElement &element, const char *attributeName, int \
defaultValue)
- {
- QString value = element.attribute(attributeName);
- if (! value.isEmpty())
- return value.toInt();
- else
- return defaultValue;
- }
-
- KarbonDocument document; ///< store non-visual doc info
- bool showStatusBar; ///< enable/disable status bar in attached view(s)
- bool merge;
- uint maxRecentFiles; ///< max. number of files shown in open recent menu \
item
-};
-
-
-KarbonKoDocument::KarbonKoDocument(KarbonPart* part)
- : KoDocument(part)
- , d(new Private())
-{
- d->document.setResourceManager(resourceManager());
- resourceManager()->setUndoStack(undoStack());
-
- initConfig();
-
- SvgShapeFactory::addToRegistry();
-
- // set as default paper
- KoPageLayout pl = pageLayout();
- pl.format = KoPageFormat::defaultFormat();
- pl.orientation = KoPageFormat::Portrait;
- pl.width = MM_TO_POINT(KoPageFormat::width(pl.format, pl.orientation));
- pl.height = MM_TO_POINT(KoPageFormat::height(pl.format, pl.orientation));
- setPageLayout(pl);
-}
-
-KarbonKoDocument::~KarbonKoDocument()
-{
- delete d;
-}
-
-void KarbonKoDocument::setPageLayout(const KoPageLayout& layout)
-{
- KoDocument::setPageLayout(layout);
- setPageSize(QSizeF(layout.width, layout.height));
-}
-
-
-bool KarbonKoDocument::loadXML(const KoXmlDocument&, KoStore*)
-{
- return false;
-}
-
-bool KarbonKoDocument::loadOdf(KoOdfReadStore & odfStore)
-{
- kDebug(38000) << "Start loading OASIS document..." /*<< doc.toString()*/;
-
- KoXmlElement contents = odfStore.contentDoc().documentElement();
- kDebug(38000) << "Start loading OASIS document..." << contents.text();
- kDebug(38000) << "Start loading OASIS contents..." << \
contents.lastChild().localName();
- kDebug(38000) << "Start loading OASIS contents..." << \
contents.lastChild().namespaceURI();
- kDebug(38000) << "Start loading OASIS contents..." << \
contents.lastChild().isElement();
- KoXmlElement body(KoXml::namedItemNS(contents, KoXmlNS::office, "body"));
- if (body.isNull()) {
- kDebug(38000) << "No office:body found!";
- setErrorMessage(i18n("Invalid OASIS document. No office:body tag found."));
- return false;
- }
-
- body = KoXml::namedItemNS(body, KoXmlNS::office, "drawing");
- if (body.isNull()) {
- kDebug(38000) << "No office:drawing found!";
- setErrorMessage(i18n("Invalid OASIS document. No office:drawing tag \
found."));
- return false;
- }
-
- KoXmlElement page(KoXml::namedItemNS(body, KoXmlNS::draw, "page"));
- if (page.isNull()) {
- kDebug(38000) << "No office:drawing found!";
- setErrorMessage(i18n("Invalid OASIS document. No draw:page tag found."));
- return false;
- }
-
- KoXmlElement * master = 0;
- if (odfStore.styles().masterPages().contains("Standard"))
- master = odfStore.styles().masterPages().value("Standard");
- else if (odfStore.styles().masterPages().contains("Default"))
- master = odfStore.styles().masterPages().value("Default");
- else if (! odfStore.styles().masterPages().empty())
- master = odfStore.styles().masterPages().begin().value();
-
- if (master) {
- const QString pageStyleName = master->attributeNS(KoXmlNS::style, \
"page-layout-name", QString());
- const KoXmlElement *style = odfStore.styles().findStyle(pageStyleName);
- if (style) {
- KoPageLayout layout;
- layout.loadOdf(*style);
- setPageLayout(layout);
- }
- } else {
- kWarning() << "No master page found!";
- return false;
- }
-
- KoOdfLoadingContext context(odfStore.styles(), odfStore.store());
- KoShapeLoadingContext shapeContext(context, resourceManager());
-
- d->document.loadOasis(page, shapeContext);
-
- if (d->document.pageSize().isEmpty()) {
- QSizeF pageSize = d->document.contentRect().united(QRectF(0, 0, 1, \
1)).size();
- setPageSize(pageSize);
- }
-
- loadOasisSettings(odfStore.settingsDoc());
-
- return true;
-}
-
-bool KarbonKoDocument::completeLoading(KoStore* store)
-{
- bool ok = true;
- foreach(KoDataCenterBase *dataCenter, dataCenterMap()) {
- ok = ok && dataCenter->completeLoading(store);
- }
- return ok;
-}
-
-void KarbonKoDocument::loadOasisSettings(const KoXmlDocument & settingsDoc)
-{
- if (settingsDoc.isNull())
- return ; // not an error if some file doesn't have settings.xml
- KoOasisSettings settings(settingsDoc);
- KoOasisSettings::Items viewSettings = settings.itemSet("view-settings");
- if (!viewSettings.isNull()) {
- setUnit(KoUnit::fromSymbol(viewSettings.parseConfigItemString("unit")));
- // FIXME: add other config here.
- }
- guidesData().loadOdfSettings(settingsDoc);
- gridData().loadOdfSettings(settingsDoc);
-}
-
-void KarbonKoDocument::saveOasisSettings(KoStore * store)
-{
- KoStoreDevice settingsDev(store);
- KoXmlWriter * settingsWriter = \
KoOdfWriteStore::createOasisXmlWriter(&settingsDev, \
"office:document-settings");
-
- settingsWriter->startElement("office:settings");
- settingsWriter->startElement("config:config-item-set");
- settingsWriter->addAttribute("config:name", "view-settings");
-
- saveUnitOdf(settingsWriter);
-
- settingsWriter->endElement(); // config:config-item-set
-
- settingsWriter->startElement("config:config-item-set");
- settingsWriter->addAttribute("config:name", "ooo:view-settings");
- settingsWriter->startElement("config:config-item-map-indexed");
- settingsWriter->addAttribute("config:name", "Views");
- settingsWriter->startElement("config:config-item-map-entry");
-
- guidesData().saveOdfSettings(*settingsWriter);
- gridData().saveOdfSettings(*settingsWriter);
-
- settingsWriter->endElement(); // config:config-item-map-entry
- settingsWriter->endElement(); // config:config-item-map-indexed
- settingsWriter->endElement(); // config:config-item-set
-
- settingsWriter->endElement(); // office:settings
- settingsWriter->endElement(); // office:document-settings
-
- settingsWriter->endDocument();
-
- delete settingsWriter;
-}
-
-bool KarbonKoDocument::saveOdf(SavingContext &documentContext)
-{
- if (! d->document.saveOdf(documentContext, pageLayout()))
- return false;
-
- KoStore * store = documentContext.odfStore.store();
- if (! store->open("settings.xml"))
- return false;
-
- saveOasisSettings(store);
-
- if (! store->close())
- return false;
-
- documentContext.odfStore.manifestWriter()->addManifestEntry("settings.xml", \
"text/xml");
-
- setModified(false);
-
- return true;
-}
-
-void KarbonKoDocument::slotDocumentRestored()
-{
- setModified(false);
-}
-
-void KarbonKoDocument::paintContent(QPainter &painter, const QRect& rect)
-{
- KoShapePainter shapePainter;
- shapePainter.setShapes(d->document.shapes());
- shapePainter.paint(painter, rect, QRectF(QPointF(), d->document.pageSize()));
-}
-
-KarbonDocument& KarbonKoDocument::document()
-{
- return d->document;
-}
-
-bool KarbonKoDocument::showStatusBar() const
-{
- return d->showStatusBar;
-}
-
-void KarbonKoDocument::setShowStatusBar(bool b)
-{
- d->showStatusBar = b;
-}
-
-uint KarbonKoDocument::maxRecentFiles() const
-{
- return d->maxRecentFiles;
-}
-
-void KarbonKoDocument::reorganizeGUI()
-{
- foreach(KoView* view, documentPart()->views()) {
- KarbonView * kv = qobject_cast<KarbonView*>(view);
- if (kv) {
- kv->reorganizeGUI();
- emit applyCanvasConfiguration(kv->canvasWidget());
- }
- }
-}
-
-void KarbonKoDocument::initConfig()
-{
- KSharedConfigPtr config = KarbonFactory::componentData().config();
-
- // disable grid by default
- gridData().setShowGrid(false);
-
- if (config->hasGroup("Interface")) {
- KConfigGroup interfaceGroup = config->group("Interface");
- setAutoSave(interfaceGroup.readEntry("AutoSave", defaultAutoSave() / 60) * \
60);
- d->maxRecentFiles = interfaceGroup.readEntry("NbRecentFile", 10);
- setShowStatusBar(interfaceGroup.readEntry("ShowStatusBar" , true));
- setBackupFile(interfaceGroup.readEntry("BackupFile", true));
- }
- int undos = 30;
-
- QString defaultUnitSymbol =
- QLatin1String((KGlobal::locale()->measureSystem() == \
KLocale::Imperial)?"in":"cm");
-
- if (config->hasGroup("Misc")) {
- KConfigGroup miscGroup = config->group("Misc");
- undos = miscGroup.readEntry("UndoRedo", -1);
- defaultUnitSymbol = miscGroup.readEntry("Units", defaultUnitSymbol);
- }
- undoStack()->setUndoLimit(undos);
- setUnit(KoUnit::fromSymbol(defaultUnitSymbol));
-
- if (config->hasGroup("Grid")) {
- KoGridData defGrid;
- KConfigGroup gridGroup = config->group("Grid");
- qreal spacingX = gridGroup.readEntry<qreal>("SpacingX", defGrid.gridX());
- qreal spacingY = gridGroup.readEntry<qreal>("SpacingY", defGrid.gridY());
- gridData().setGrid(spacingX, spacingY);
- QColor color = gridGroup.readEntry("Color", defGrid.gridColor());
- gridData().setGridColor(color);
- }
-}
-
-bool KarbonKoDocument::mergeNativeFormat(const QString &file)
-{
- d->merge = true;
- bool result = loadNativeFormat(file);
- if (!result)
- documentPart()->showLoadingErrorDialog();
- d->merge = false;
- return result;
-}
-
-void KarbonKoDocument::addShape(KoShape* shape)
-{
- KoCanvasController* canvasController = \
KoToolManager::instance()->activeCanvasController();
-
- KoShapeLayer *layer = dynamic_cast<KoShapeLayer*>(shape);
- if (layer) {
- d->document.insertLayer(layer);
- if (canvasController) {
- KoSelection *selection = \
canvasController->canvas()->shapeManager()->selection();
- selection->setActiveLayer(layer);
- }
- } else {
- // only add shape to active layer if it has no parent yet
- if (! shape->parent()) {
- kDebug(38000) << "shape has no parent, adding to the active layer!";
- KoShapeLayer *activeLayer = 0;
- if (canvasController)
- activeLayer = \
canvasController->canvas()->shapeManager()->selection()->activeLayer();
- else if (d->document.layers().count())
- activeLayer = d->document.layers().first();
-
- if (activeLayer)
- activeLayer->addShape(shape);
- }
-
- d->document.add(shape);
-
- foreach(KoView *view, documentPart()->views()) {
- KarbonCanvas *canvas = ((KarbonView*)view)->canvasWidget();
- canvas->shapeManager()->addShape(shape);
- }
- }
-
- setModified(true);
- emit shapeCountChanged();
-}
-
-void KarbonKoDocument::removeShape(KoShape* shape)
-{
- KoShapeLayer *layer = dynamic_cast<KoShapeLayer*>(shape);
- if (layer) {
- d->document.removeLayer(layer);
- } else {
- d->document.remove(shape);
- foreach(KoView *view, documentPart()->views()) {
- KarbonCanvas *canvas = ((KarbonView*)view)->canvasWidget();
- canvas->shapeManager()->remove(shape);
- }
- }
- setModified(true);
- emit shapeCountChanged();
-}
-
-QMap<QString, KoDataCenterBase*> KarbonKoDocument::dataCenterMap() const
-{
- return d->document.dataCenterMap();
-}
-
-void KarbonKoDocument::setPageSize(const QSizeF &pageSize)
-{
- d->document.setPageSize(pageSize);
- foreach(KoView *view, documentPart()->views()) {
- KarbonCanvas *canvas = ((KarbonView*)view)->canvasWidget();
- canvas->resourceManager()->setResource(KoCanvasResourceManager::PageSize, \
pageSize);
- }
-}
-
-#include "KarbonKoDocument.moc"
-
diff --git a/karbon/ui/KarbonKoDocument.h b/karbon/ui/KarbonKoDocument.h
deleted file mode 100644
index 1e7e37b..0000000
--- a/karbon/ui/KarbonKoDocument.h
+++ /dev/null
@@ -1,125 +0,0 @@
-/* This file is part of the KDE project
- * Copyright (C) 2001-2002 Lennart Kudling <kudling@kde.org>
- * Copyright (C) 2001-2005,2007 Rob Buis <buis@kde.org>
- * Copyright (C) 2002,2004-2005 Laurent Montel <montel@kde.org>
- * Copyright (C) 2002 Benoit Vautrin <benoit.vautrin@free.fr>
- * Copyright (C) 2004-2005,2007 David Faure <faure@kde.org>
- * Copyright (C) 2004,2006 Peter Simonsson <psn@linux.se>
- * Copyright (C) 2004-2005 Fredrik Edemar <f_edemar@linux.se>
- * Copyright (C) 2005-2007 Jan Hambrecht <jaham@gmx.net>
- * Copyright (C) 2005-2007 Thomas Zander <zander@kde.org>
- * Copyright (C) 2006 Inge Wallin <inge@lysator.liu.se>
- * Copyright (C) 2006 Tim Beaulen <tbscope@gmail.com>
- * Copyright (C) 2006 Casper Boemann <cbr@boemann.dk>
- * Copyright (C) 2006-2007 Thorsten Zachmann <t.zachmann@zagge.de>
- *
- * 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 KARBON_KODOCUMENT_H
-#define KARBON_KODOCUMENT_H
-
-#include <QMap>
-
-#include <KoShapeBasedDocumentBase.h>
-
-#include <KoDocument.h>
-#include <KoUnit.h>
-
-#include <karbonui_export.h>
-
-class QRect;
-class KarbonDocument;
-class KarbonPart;
-class KarbonCanvas;
-class KoDataCenterBase;
-
-/**
- * Keeps track of visual per document properties.
- * It loads initial settings and applies them to the document and its views.
- */
-class KARBONUI_EXPORT KarbonKoDocument : public KoDocument, public \
KoShapeBasedDocumentBase
-{
- Q_OBJECT
-public:
- explicit KarbonKoDocument(KarbonPart *part);
- virtual ~KarbonKoDocument();
-
- /// reimplemented form KoDocument
- virtual void paintContent(QPainter& painter, const QRect& rect);
- /// reimplemented form KoDocument
- virtual bool loadXML(const KoXmlDocument& document, KoStore *store);
- /// reimplemented form KoDocument
- virtual bool loadOdf(KoOdfReadStore & odfStore);
- /// reimplemented form KoDocument
- virtual bool completeLoading(KoStore* store);
- /// reimplemented form KoDocument
- virtual bool saveOdf(SavingContext &documentContext);
-
- /// implemented from KoShapeController
- virtual void addShape(KoShape* shape);
- /// implemented from KoShapeController
- virtual void removeShape(KoShape* shape);
- /// implemented from KoShapeController
- virtual QMap<QString, KoDataCenterBase*> dataCenterMap() const;
-
- /// Gives access to document content
- KarbonDocument& document();
-
- /// Returns if status bar is shown
- bool showStatusBar() const;
- /// Shows/hides status bar
- void setShowStatusBar(bool b);
- /// update attached view(s) on the current doc settings
- /// at this time only the status bar is handled
- void reorganizeGUI();
-
- /// Returns maximum number of recent files
- uint maxRecentFiles() const;
-
- /// Sets page layout of the document
- virtual void setPageLayout(const KoPageLayout& layout);
-
- bool mergeNativeFormat(const QString & file);
-
-public slots:
- void slotDocumentRestored();
-
-signals:
- void shapeCountChanged();
- void applyCanvasConfiguration(KarbonCanvas *canvas);
-
-protected:
-
- /// Loads settings like grid and guide lines from given xml document
- void loadOasisSettings(const KoXmlDocument & settingsDoc);
- /// Saves settings like grid and guide lines to store
- void saveOasisSettings(KoStore * store);
-
- /// Sets given page size to all attached views/canvases
- void setPageSize(const QSizeF &pageSize);
-
- /// Reads settings from config file
- void initConfig();
-
-
-private:
- class Private;
- Private * const d;
-};
-
-#endif // KARBON_PART_H
-
diff --git a/karbon/ui/KarbonPart.cpp b/karbon/ui/KarbonPart.cpp
index 4cb62f1..c148fb7 100644
--- a/karbon/ui/KarbonPart.cpp
+++ b/karbon/ui/KarbonPart.cpp
@@ -44,7 +44,7 @@
#include "KarbonView.h"
#include "KarbonDocument.h"
-#include "KarbonKoDocument.h"
+#include "KarbonDocument.h"
#include "KarbonFactory.h"
#include "KarbonCanvas.h"
@@ -73,18 +73,18 @@ KarbonPart::~KarbonPart()
void KarbonPart::setDocument(KoDocument *document)
{
KoPart::setDocument(document);
- KarbonKoDocument *doc = qobject_cast<KarbonKoDocument*>(document);
+ KarbonDocument *doc = qobject_cast<KarbonDocument*>(document);
connect(doc, SIGNAL(applyCanvasConfiguration(KarbonCanvas*)), \
SLOT(applyCanvasConfiguration(KarbonCanvas*))); }
KoView * KarbonPart::createViewInstance(QWidget *parent)
{
- KarbonKoDocument *doc = qobject_cast<KarbonKoDocument*>(document());
+ KarbonDocument *doc = qobject_cast<KarbonDocument*>(document());
KarbonView *result = new KarbonView(this, doc, parent);
KoCanvasResourceManager * provider = result->canvasWidget()->resourceManager();
- provider->setResource(KoCanvasResourceManager::PageSize, \
doc->document().pageSize()); + \
provider->setResource(KoCanvasResourceManager::PageSize, doc->pageSize());
applyCanvasConfiguration(result->canvasWidget());
diff --git a/karbon/ui/KarbonPrintJob.cpp b/karbon/ui/KarbonPrintJob.cpp
index 6c2bf8a..774d36c 100644
--- a/karbon/ui/KarbonPrintJob.cpp
+++ b/karbon/ui/KarbonPrintJob.cpp
@@ -22,7 +22,7 @@
#include "KarbonView.h"
#include "KarbonCanvas.h"
#include "KarbonPart.h"
-#include "KarbonKoDocument.h"
+#include "KarbonDocument.h"
#include "KarbonDocument.h"
#include <KoShapeManager.h>
@@ -36,7 +36,7 @@ KarbonPrintJob::KarbonPrintJob(KarbonView *view, PrintMode \
printMode) setShapeManager(m_view->canvasWidget()->shapeManager());
printer().setFromTo(1, 1);
- QSizeF pageSize = m_view->part()->document().pageSize();
+ QSizeF pageSize = m_view->part()->pageSize();
if (pageSize.width() > pageSize.height())
printer().setOrientation(QPrinter::Landscape);
else
@@ -52,7 +52,7 @@ QRectF KarbonPrintJob::preparePage(int)
{
// if we have any custom tabs, here is where can can read them out and do our \
thing.
- const QSizeF contentSize = m_view->part()->document().pageSize();
+ const QSizeF contentSize = m_view->part()->pageSize();
const QRectF pageRectPt = printer().pageRect(QPrinter::Point);
const double scale = POINT_TO_INCH(printer().resolution());
diff --git a/karbon/ui/KarbonView.cpp b/karbon/ui/KarbonView.cpp
index 6f8bf72..11e6135 100644
--- a/karbon/ui/KarbonView.cpp
+++ b/karbon/ui/KarbonView.cpp
@@ -57,7 +57,6 @@
#include "KarbonPart.h"
#include "KarbonCanvas.h"
#include "KarbonDocument.h"
-#include "KarbonKoDocument.h"
#include "KarbonPrintJob.h"
#include "KarbonZoomController.h"
#include "KarbonSmallStylePreview.h"
@@ -152,7 +151,7 @@
class KarbonView::Private
{
public:
- Private(KarbonPart *part, KarbonKoDocument * doc)
+ Private(KarbonPart *part, KarbonDocument * doc)
: karbonPart(part), part(doc), canvas(0), canvasController(0), \
horizRuler(0), vertRuler(0) , colorBar(0), closePath(0), combinePath(0)
, separatePath(0), reversePath(0), intersectPath(0), subtractPath(0)
@@ -165,7 +164,7 @@ public:
{}
KarbonPart * karbonPart;
- KarbonKoDocument * part;
+ KarbonDocument * part;
KarbonCanvas * canvas;
KoCanvasController * canvasController;
KoRuler * horizRuler;
@@ -203,7 +202,7 @@ public:
QWidget * zoomActionWidget; ///< zoom action widget
};
-KarbonView::KarbonView(KarbonPart *karbonPart, KarbonKoDocument* doc, QWidget* \
parent) +KarbonView::KarbonView(KarbonPart *karbonPart, KarbonDocument* doc, QWidget* \
parent)
: KoView(karbonPart, doc, parent), d(new Private(karbonPart, doc))
{
setComponentData(KarbonFactory::componentData(), true);
@@ -244,7 +243,7 @@ KarbonView::KarbonView(KarbonPart *karbonPart, KarbonKoDocument* \
doc, QWidget* p
// TODO maybe the zoomHandler should be a member of the view and not the canvas.
// set up the zoom controller
KarbonZoomController * zoomController = new \
KarbonZoomController(d->canvasController, actionCollection(), this);
- zoomController->setPageSize(d->part->document().pageSize());
+ zoomController->setPageSize(d->part->pageSize());
d->zoomActionWidget = zoomController->zoomAction()->createWidget(statusBar());
addStatusBarItem(d->zoomActionWidget, 0);
zoomController->setZoomMode(KoZoomMode::ZOOM_PAGE);
@@ -296,7 +295,7 @@ KarbonView::KarbonView(KarbonPart *karbonPart, KarbonKoDocument* \
doc, QWidget* p
if (shell()) {
// set the first layer active
- d->canvasController->canvas()->shapeManager()->selection()->setActiveLayer(part()->document().layers().first());
+ d->canvasController->canvas()->shapeManager()->selection()->setActiveLayer(part()->layers().first());
//Create Dockers
createLayersTabDock();
@@ -350,7 +349,7 @@ KarbonView::~KarbonView()
delete d;
}
-KarbonKoDocument * KarbonView::part() const
+KarbonDocument * KarbonView::part() const
{
return d->part;
}
@@ -442,7 +441,7 @@ void KarbonView::addImages(const QList<QImage> &imageList, const \
QPoint &insertA v.setValue<QImage>(image);
params.setProperty("qimage", v);
- KoShape *shape = factory->createShape(¶ms, \
part()->document().resourceManager()); + KoShape *shape = \
factory->createShape(¶ms, part()->resourceManager());
if (!shape) {
kWarning(30003) << "Could not create a shape from the image";
@@ -487,14 +486,14 @@ void KarbonView::fileImportGraphic()
QString currentMimeFilter = dialog ? dialog->currentMimeFilter() : QString();
delete dialog;
- QMap<QString, KoDataCenterBase*> dataCenters = \
part()->document().dataCenterMap(); + QMap<QString, KoDataCenterBase*> dataCenters \
= part()->dataCenterMap();
KarbonPart importPart(0);
- KarbonKoDocument importDocument(&importPart);
+ KarbonDocument importDocument(&importPart);
importPart.setDocument(&importDocument);
// use data centers of this document for importing
- importDocument.document().useExternalDataCenterMap(dataCenters);
+ importDocument.useExternalDataCenterMap(dataCenters);
bool success = true;
@@ -530,8 +529,8 @@ void KarbonView::fileImportGraphic()
return;
}
- KoShape *picture = \
factory->createDefaultShape(part()->document().resourceManager());
- KoImageCollection *imageCollection = \
part()->document().resourceManager()->imageCollection(); + KoShape *picture = \
factory->createDefaultShape(part()->resourceManager()); + KoImageCollection \
*imageCollection = part()->resourceManager()->imageCollection(); if (!picture || \
!imageCollection) {
KMessageBox::error(0, i18n("Could not create image shape."), \
i18n("Import graphic"), 0); return;
@@ -582,7 +581,7 @@ void KarbonView::fileImportGraphic()
}
if (success) {
- QList<KoShape*> importedShapes = importDocument.document().shapes();
+ QList<KoShape*> importedShapes = importDocument.shapes();
KarbonDocumentMergeCommand * cmd = new KarbonDocumentMergeCommand(part(), \
&importDocument); d->canvas->addCommand(cmd);
@@ -605,7 +604,7 @@ void KarbonView::editSelectAll()
if (! selection)
return;
- QList<KoShape*> shapes = part()->document().shapes();
+ QList<KoShape*> shapes = part()->shapes();
kDebug(38000) << "shapes.size() =" << shapes.size();
foreach(KoShape* shape, shapes) {
@@ -1001,7 +1000,7 @@ void KarbonView::zoomDrawing()
if (! zoomHandler)
return;
- QRectF bbox = d->part->document().contentRect();
+ QRectF bbox = d->part->contentRect();
if (bbox.isNull())
return;
@@ -1280,8 +1279,8 @@ void KarbonView::pageOffsetChanged()
void KarbonView::updateRuler()
{
- d->horizRuler->setRulerLength(part()->document().pageSize().width());
- d->vertRuler->setRulerLength(part()->document().pageSize().height());
+ d->horizRuler->setRulerLength(part()->pageSize().width());
+ d->vertRuler->setRulerLength(part()->pageSize().height());
}
void KarbonView::showGuides()
diff --git a/karbon/ui/KarbonView.h b/karbon/ui/KarbonView.h
index 6c2556d..e512f1c 100644
--- a/karbon/ui/KarbonView.h
+++ b/karbon/ui/KarbonView.h
@@ -51,7 +51,7 @@ class QRectF;
class QPrinter;
class KAction;
-class KarbonKoDocument;
+class KarbonDocument;
class KSelectAction;
class KToggleAction;
@@ -71,11 +71,11 @@ class KARBONUI_EXPORT KarbonView : public KoView
Q_OBJECT
public:
- KarbonView(KarbonPart *part, KarbonKoDocument* doc, QWidget* parent = 0);
+ KarbonView(KarbonPart *part, KarbonDocument* doc, QWidget* parent = 0);
virtual ~KarbonView();
/// Returns the view is attached to
- KarbonKoDocument * part() const;
+ KarbonDocument * part() const;
/// Returns the canvas widget of this view
KarbonCanvas * canvasWidget() const;
diff --git a/karbon/common/commands/KarbonLayerReorderCommand.cpp \
b/karbon/ui/commands/KarbonLayerReorderCommand.cpp similarity index 98%
rename from karbon/common/commands/KarbonLayerReorderCommand.cpp
rename to karbon/ui/commands/KarbonLayerReorderCommand.cpp
index 1931f9b..f8635e3 100644
--- a/karbon/common/commands/KarbonLayerReorderCommand.cpp
+++ b/karbon/ui/commands/KarbonLayerReorderCommand.cpp
@@ -24,7 +24,7 @@
*/
#include "KarbonLayerReorderCommand.h"
-#include "KarbonDocument.h"
+#include <KarbonDocument.h>
#include <KoShapeLayer.h>
#include <klocale.h>
diff --git a/karbon/common/commands/KarbonLayerReorderCommand.h \
b/karbon/ui/commands/KarbonLayerReorderCommand.h similarity index 96%
rename from karbon/common/commands/KarbonLayerReorderCommand.h
rename to karbon/ui/commands/KarbonLayerReorderCommand.h
index 5167ec2..29749a9 100644
--- a/karbon/common/commands/KarbonLayerReorderCommand.h
+++ b/karbon/ui/commands/KarbonLayerReorderCommand.h
@@ -26,13 +26,13 @@
#define KARBONLAYERREORDERCOMMAND_H
#include <kundo2command.h>
-#include <karboncommon_export.h>
+#include <karbonui_export.h>
class KarbonDocument;
class KoShapeLayer;
/// Command for raising or lowering layers
-class KARBONCOMMON_EXPORT KarbonLayerReorderCommand : public KUndo2Command
+class KARBONUI_EXPORT KarbonLayerReorderCommand : public KUndo2Command
{
public:
/// The different types of layer commands.
diff --git a/karbon/ui/dialogs/KarbonConfigureDialog.cpp \
b/karbon/ui/dialogs/KarbonConfigureDialog.cpp index 0066c33..a88a4e8 100644
--- a/karbon/ui/dialogs/KarbonConfigureDialog.cpp
+++ b/karbon/ui/dialogs/KarbonConfigureDialog.cpp
@@ -22,7 +22,7 @@ the Free Software Foundation, Inc., 51 Franklin Street, Fifth \
Floor,
#include "KarbonView.h"
#include "KarbonPart.h"
-#include "KarbonKoDocument.h"
+#include "KarbonDocument.h"
#include "KarbonConfigInterfacePage.h"
#include <KoIcon.h>
diff --git a/karbon/ui/dockers/KarbonLayerDocker.cpp \
b/karbon/ui/dockers/KarbonLayerDocker.cpp index 9a1daca..27338f9 100644
--- a/karbon/ui/dockers/KarbonLayerDocker.cpp
+++ b/karbon/ui/dockers/KarbonLayerDocker.cpp
@@ -23,9 +23,8 @@
#include "KarbonFactory.h"
#include <KarbonCanvas.h>
-#include <KarbonDocument.h>
#include <KarbonPart.h>
-#include <KarbonKoDocument.h>
+#include <KarbonDocument.h>
#include <KarbonLayerReorderCommand.h>
#include <KoShapeManager.h>
@@ -144,9 +143,9 @@ KarbonLayerDocker::KarbonLayerDocker()
connect(buttonGroup, SIGNAL(buttonClicked(int)), this, \
SLOT(slotButtonClicked(int)));
m_model = new KarbonLayerModel(this);
- m_model->setDocument(m_doc ? &m_doc->document() : 0);
+ m_model->setDocument(m_doc ? m_doc : 0);
m_sortModel = new KarbonLayerSortingModel(this);
- m_sortModel->setDocument(m_doc ? &m_doc->document() : 0);
+ m_sortModel->setDocument(m_doc ? m_doc : 0);
m_sortModel->setSourceModel(m_model);
m_layerView->setItemsExpandable(true);
@@ -206,8 +205,8 @@ void KarbonLayerDocker::setCanvas(KoCanvasBase* canvas)
KarbonCanvas *c = dynamic_cast<KarbonCanvas*>(canvas);
if (c) {
m_doc = c->document();
- m_sortModel->setDocument(m_doc ? &m_doc->document() : 0);
- m_model->setDocument(m_doc ? &m_doc->document() : 0);
+ m_sortModel->setDocument(m_doc ? m_doc : 0);
+ m_model->setDocument(m_doc ? m_doc : 0);
m_model->update();
}
}
@@ -305,7 +304,7 @@ void KarbonLayerDocker::deleteItem()
KUndo2Command *cmd = 0;
if (selectedLayers.count()) {
- if (m_doc->document().layers().count() > selectedLayers.count()) {
+ if (m_doc->layers().count() > selectedLayers.count()) {
QList<KoShape*> deleteShapes;
foreach(KoShapeLayer* layer, selectedLayers) {
deleteShapes += layer->shapes();
@@ -342,10 +341,10 @@ void KarbonLayerDocker::raiseItem()
if (selectedLayers.count()) {
// check if all layers could be raised
foreach(KoShapeLayer* layer, selectedLayers)
- if (! m_doc->document().canRaiseLayer(layer))
+ if (! m_doc->canRaiseLayer(layer))
return;
- cmd = new KarbonLayerReorderCommand(&m_doc->document(), selectedLayers, \
KarbonLayerReorderCommand::RaiseLayer); + cmd = new \
KarbonLayerReorderCommand(m_doc, selectedLayers, \
KarbonLayerReorderCommand::RaiseLayer); } else if (selectedShapes.count()) {
cmd = KoShapeReorderCommand::createCommand(selectedShapes, \
canvas->shapeManager(), KoShapeReorderCommand::RaiseShape); }
@@ -376,10 +375,10 @@ void KarbonLayerDocker::lowerItem()
if (selectedLayers.count()) {
// check if all layers could be raised
foreach(KoShapeLayer* layer, selectedLayers)
- if (! m_doc->document().canLowerLayer(layer))
+ if (! m_doc->canLowerLayer(layer))
return;
- cmd = new KarbonLayerReorderCommand(&m_doc->document(), selectedLayers, \
KarbonLayerReorderCommand::LowerLayer); + cmd = new \
KarbonLayerReorderCommand(m_doc, selectedLayers, \
KarbonLayerReorderCommand::LowerLayer); } else if (selectedShapes.count()) {
cmd = KoShapeReorderCommand::createCommand(selectedShapes, \
canvas->shapeManager(), KoShapeReorderCommand::LowerShape); }
@@ -401,7 +400,7 @@ void KarbonLayerDocker::selectLayers(QList<KoShapeLayer*> layers)
QItemSelectionModel * selModel = m_layerView->selectionModel();
selModel->clearSelection();
foreach(KoShapeLayer * layer, layers) {
- int layerPos = m_doc->document().layerPos(layer);
+ int layerPos = m_doc->layerPos(layer);
QModelIndex child = m_model->index(layerPos, 0);
selModel->select(m_sortModel->mapFromSource(child), \
QItemSelectionModel::Select); }
diff --git a/karbon/ui/dockers/KarbonLayerDocker.h \
b/karbon/ui/dockers/KarbonLayerDocker.h index 37547c4..1161a7f 100644
--- a/karbon/ui/dockers/KarbonLayerDocker.h
+++ b/karbon/ui/dockers/KarbonLayerDocker.h
@@ -31,7 +31,7 @@ class KoShapeLayer;
class KoShapeGroup;
class KarbonLayerModel;
class KarbonLayerSortingModel;
-class KarbonKoDocument;
+class KarbonDocument;
class QModelIndex;
namespace KParts
@@ -81,7 +81,7 @@ private:
void setViewMode(KoDocumentSectionView::DisplayMode mode);
void selectLayers(QList<KoShapeLayer*> layers);
- KarbonKoDocument * m_doc;
+ KarbonDocument * m_doc;
KarbonLayerModel * m_model;
KarbonLayerSortingModel * m_sortModel;
KoDocumentSectionView * m_layerView;
diff --git a/karbon/ui/widgets/KarbonCanvas.cpp b/karbon/ui/widgets/KarbonCanvas.cpp
index dcb588b..03c8d19 100644
--- a/karbon/ui/widgets/KarbonCanvas.cpp
+++ b/karbon/ui/widgets/KarbonCanvas.cpp
@@ -30,9 +30,8 @@
*/
#include "KarbonCanvas.h"
-#include "KarbonDocument.h"
-#include <KarbonKoDocument.h>
-#include "KarbonPart.h"
+#include <KarbonDocument.h>
+#include <KarbonPart.h>
#include <KarbonOutlinePaintingStrategy.h>
#include <KoZoomHandler.h>
@@ -58,7 +57,6 @@ class KarbonCanvas::KarbonCanvasPrivate {
public:
KarbonCanvasPrivate()
: zoomHandler()
- , document(0)
, part(0)
, showMargins(false)
, documentOffset(0, 0)
@@ -79,8 +77,7 @@ public:
KoToolProxy *toolProxy;
- KarbonDocument *document;
- KarbonKoDocument *part;
+ KarbonDocument *part;
QPoint origin; ///< the origin of the document page rect
bool showMargins; ///< should page margins be shown
QPoint documentOffset; ///< the offset of the virtual canvas from the viewport
@@ -89,13 +86,12 @@ public:
KoGridData pixelGrid; ///< pixel grid data
};
-KarbonCanvas::KarbonCanvas(KarbonKoDocument *p)
+KarbonCanvas::KarbonCanvas(KarbonDocument *p)
: QWidget() , KoCanvasBase(p), d(new KarbonCanvasPrivate())
{
d->part = p;
- d->document = &p->document();
d->toolProxy = new KoToolProxy(this);
- d->shapeManager = new KoShapeManager(this, d->document->shapes());
+ d->shapeManager = new KoShapeManager(this, d->part->shapes());
connect(d->shapeManager, SIGNAL(selectionChanged()), this, \
SLOT(updateSizeAndOffset()));
setBackgroundRole(QPalette::Base);
@@ -158,7 +154,7 @@ void KarbonCanvas::paintEvent(QPaintEvent * ev)
painter.setPen(Qt::black);
// paint the page rect
- painter.drawRect(d->zoomHandler.documentToView(QRectF(QPointF(0.0, 0.0), \
d->document->pageSize()))); + \
painter.drawRect(d->zoomHandler.documentToView(QRectF(QPointF(0.0, 0.0), \
d->part->pageSize())));
// paint the page margins
paintMargins(painter, d->zoomHandler);
@@ -196,7 +192,7 @@ void KarbonCanvas::paintMargins(QPainter &painter, const \
KoViewConverter &conver
KoPageLayout pl = d->part->pageLayout();
- QSizeF pageSize = d->document->pageSize();
+ QSizeF pageSize = d->part->pageSize();
QRectF marginRect(pl.leftMargin, pl.topMargin,
pageSize.width() - pl.leftMargin - pl.rightMargin,
pageSize.height() - pl.topMargin - pl.bottomMargin);
@@ -374,7 +370,7 @@ const QPoint &KarbonCanvas::documentOffset() const
return d->documentOffset;
}
-KarbonKoDocument *KarbonCanvas::document() const
+KarbonDocument *KarbonCanvas::document() const
{
return d->part;
}
@@ -435,7 +431,7 @@ int KarbonCanvas::documentViewMargin() const
QRectF KarbonCanvas::documentViewRect()
{
- QRectF bbox = d->document->boundingRect();
+ QRectF bbox = d->part->boundingRect();
d->documentViewRect = bbox.adjusted(-d->viewMargin, -d->viewMargin, \
d->viewMargin, d->viewMargin); return d->documentViewRect;
}
diff --git a/karbon/ui/widgets/KarbonCanvas.h b/karbon/ui/widgets/KarbonCanvas.h
index 4b59ced..2c6ad3c 100644
--- a/karbon/ui/widgets/KarbonCanvas.h
+++ b/karbon/ui/widgets/KarbonCanvas.h
@@ -40,7 +40,7 @@
#include <QList>
#include <QBrush>
-class KarbonKoDocument;
+class KarbonDocument;
class KoViewConverter;
class KoShapeManager;
class KoToolProxy;
@@ -56,7 +56,7 @@ class KarbonCanvas: public QWidget, public KoCanvasBase
Q_OBJECT
public:
- explicit KarbonCanvas(KarbonKoDocument *p);
+ explicit KarbonCanvas(KarbonDocument *p);
virtual ~KarbonCanvas();
/// reimplemented from KoCanvasBase
@@ -112,7 +112,7 @@ public:
const QPoint &documentOffset() const;
/// @return the document used by the canvas.
- KarbonKoDocument *document() const;
+ KarbonDocument *document() const;
public slots:
diff --git a/karbon/ui/widgets/KarbonConfigInterfacePage.cpp \
b/karbon/ui/widgets/KarbonConfigInterfacePage.cpp index 77eb5be..f85fa05 100644
--- a/karbon/ui/widgets/KarbonConfigInterfacePage.cpp
+++ b/karbon/ui/widgets/KarbonConfigInterfacePage.cpp
@@ -22,7 +22,7 @@ the Free Software Foundation, Inc., 51 Franklin Street, Fifth \
Floor,
#include "KarbonView.h"
#include "KarbonPart.h"
-#include "KarbonKoDocument.h"
+#include "KarbonDocument.h"
#include "KarbonFactory.h"
#include <KoUnitDoubleSpinBox.h>
@@ -91,7 +91,7 @@ void KarbonConfigInterfacePage::apply()
{
bool showStatusBar = m_showStatusBar->isChecked();
- KarbonKoDocument* part = m_view->part();
+ KarbonDocument* part = m_view->part();
KConfigGroup interfaceGroup = m_config->group("Interface");
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic