[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    koffice
From:       Thorsten Zachmann <t.zachmann () zagge ! de>
Date:       2007-12-01 11:04:19
Message-ID: 1196507059.820720.2706.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 743552 by zachmann:

o Implement copy and paste of shapes.
  With that the basis for copy and paste of shapes between different applications is \
done.  It is now possible to copy a shape e.g. in kpresenter and insert it in karbon.

  This does not yet work with text shapes as there is an assert in the text shape \
loading  code that checks that there is a valid KoDocument in KoOasisLoadinContext. \
The KoDocument  in the KoOasisLoadingContext is not yet used in koffice 2.0. It was \
used in koffice 1.6 for  loading in the KoFieldVariable to access the url of a \
document and some other document  related stuff. How will this be done in koffice \
2.0? Will we still need the KoDocument  for doing that or can the KoDocument be \
removed from The KoOasisLoadingContext?

CCMAIL: koffice-devel@kde.org



 M  +9 -0      karbon/karbon_view.cc  
 M  +1 -0      kivio/src/part/kivio.rc  
 M  +1 -0      kpresenter/part/kpresenter.rc  
 M  +2 -0      libs/flake/CMakeLists.txt  
 A             libs/flake/KoShapeOdfSaveHelper.cpp   [License: LGPL (v2+)]
 A             libs/flake/KoShapeOdfSaveHelper.h   [License: LGPL (v2+)]
 A             libs/flake/KoShapePaste.cpp   [License: LGPL (v2+)]
 A             libs/flake/KoShapePaste.h   [License: LGPL (v2+)]
 M  +30 -15    libs/kopageapp/KoPAView.cpp  
 M  +4 -0      libs/kopageapp/KoPAView.h  
 M  +50 -1     plugins/defaultTools/defaulttool/DefaultTool.cpp  
 M  +11 -1     plugins/defaultTools/defaulttool/DefaultTool.h  


--- trunk/koffice/karbon/karbon_view.cc #743551:743552
@@ -73,6 +73,7 @@
 // #include <KoPageLayoutDia.h>
 #include <KoRuler.h>
 #include <KoToolManager.h>
+#include <KoToolProxy.h>
 #include <KoToolDocker.h>
 #include <KoToolDockerFactory.h>
 #include <KoShapeManager.h>
@@ -417,17 +418,23 @@
 {
     debugView("KarbonView::editCut()");
 
+    m_canvas->toolProxy()->cut();
+    /*
     addSelectionToClipboard();
     // remove selection
     editDeleteSelection();
+    */
 }
 
 void
 KarbonView::editCopy()
 {
     debugView("KarbonView::editCopy()");
+    m_canvas->toolProxy()->copy();
 
+    /*
     addSelectionToClipboard();
+    */
 }
 
 void
@@ -449,6 +456,8 @@
 KarbonView::editPaste()
 {
     debugView("KarbonView::editPaste()");
+
+    m_canvas->toolProxy()->paste();
     /*
     KarbonDrag kd;
     VObjectList objects;
--- trunk/koffice/kivio/src/part/kivio.rc #743551:743552
@@ -11,6 +11,7 @@
       <Action name="edit_paste"/>
       <Separator/>
       <Action name="edit_insertpage"/>
+      <Action name="edit_copypage"/>
       <Action name="edit_deletepage"/>
     </Menu>
     <Menu name="view"><text>&amp;View</text>
--- trunk/koffice/kpresenter/part/kpresenter.rc #743551:743552
@@ -11,6 +11,7 @@
             <Action name="edit_paste"/>
             <Separator/>
             <Action name="edit_insertpage"/>
+            <Action name="edit_copypage"/>
             <Action name="edit_deletepage"/>
             <Separator/>
             <Action name="edit_createanimation"/>
--- trunk/koffice/libs/flake/CMakeLists.txt #743551:743552
@@ -77,6 +77,8 @@
     KoShapeConfigWidgetBase.cpp
     KoDrag.cpp
     KoDragOdfSaveHelper.cpp
+    KoShapeOdfSaveHelper.cpp
+    KoShapePaste.cpp
     KoConnectionShape.cpp
     KoConnectionShapeFactory.cpp
     KoConnectionShapeConfigWidget.cpp
--- trunk/koffice/libs/kopageapp/KoPAView.cpp #743551:743552
@@ -54,6 +54,9 @@
 #include "commands/KoPAPageInsertCommand.h"
 #include "commands/KoPAPageDeleteCommand.h"
 
+#include "KoShapeOdfSaveHelper.h"
+#include "KoShapePaste.h"
+
 #include <kdebug.h>
 #include <klocale.h>
 #include <kicon.h>
@@ -189,6 +192,12 @@
     m_actionInsertPage->setWhatsThis( i18n( "Insert a new page after the current \
                one" ) );
     connect( m_actionInsertPage, SIGNAL( triggered() ), this, SLOT( insertPage() ) \
);  
+    m_actionCopyPage = new KAction( i18n( "Copy Page" ), this );
+    actionCollection()->addAction( "edit_copypage", m_actionCopyPage );
+    m_actionCopyPage->setToolTip( i18n( "Copy the current page" ) );
+    m_actionCopyPage->setWhatsThis( i18n( "Copy the current page" ) );
+    connect( m_actionCopyPage, SIGNAL( triggered() ), this, SLOT( copyPage() ) );
+
     m_actionDeletePage = new KAction( i18n( "Delete Page" ), this );
     actionCollection()->addAction( "edit_deletepage", m_actionDeletePage );
     m_actionDeletePage->setToolTip( i18n( "Delete a new page after the current one" \
) ); @@ -207,35 +216,32 @@
 
 void KoPAView::viewGrid()
 {
-
 }
 
 void KoPAView::editCut()
 {
+    m_canvas->toolProxy()->cut();
 }
 
 void KoPAView::editCopy()
 {
-    QList<KoPAPageBase *> pages;
-    pages.append( m_activePage );
-    KoPAOdfPageSaveHelper saveHelper( m_doc, pages );
-    KoDrag drag;
-    drag.setOdf( KoOdf::mimeType( m_doc->documentType() ), saveHelper );
-    //drag.setData( "text/plain", "Test" );
-    drag.addToClipboard();
+    m_canvas->toolProxy()->copy();
 }
 
 void KoPAView::editPaste()
 {
-    const QMimeData * data = QApplication::clipboard()->mimeData();
+    if ( !m_canvas->toolProxy()->paste() ) {
+        const QMimeData * data = QApplication::clipboard()->mimeData();
 
-    KoOdf::DocumentType documentTypes[] = { KoOdf::Graphics, KoOdf::Presentation };
+        KoOdf::DocumentType documentTypes[] = { KoOdf::Graphics, KoOdf::Presentation \
};  
-    for ( unsigned int i = 0; i < sizeof( documentTypes ) / sizeof( \
                KoOdf::DocumentType ); ++i )
-    {
-        if ( data->hasFormat( KoOdf::mimeType( documentTypes[i] ) ) ) {
-            KoPAPastePage paste( m_doc, m_activePage );
-            paste.paste( documentTypes[i], data );
+        for ( unsigned int i = 0; i < sizeof( documentTypes ) / sizeof( \
KoOdf::DocumentType ); ++i ) +        {
+            if ( data->hasFormat( KoOdf::mimeType( documentTypes[i] ) ) ) {
+                KoPAPastePage paste( m_doc, m_activePage );
+                paste.paste( documentTypes[i], data );
+                break;
+            }
         }
     }
 }
@@ -396,6 +402,15 @@
     m_canvas->addCommand( command );
 }
 
+void KoPAView::copyPage()
+{
+    QList<KoPAPageBase *> pages;
+    pages.append( m_activePage );
+    KoPAOdfPageSaveHelper saveHelper( m_doc, pages );
+    KoDrag drag;
+    drag.setOdf( KoOdf::mimeType( m_doc->documentType() ), saveHelper );
+    drag.addToClipboard();
+}
 
 void KoPAView::deletePage()
 {
--- trunk/koffice/libs/kopageapp/KoPAView.h #743551:743552
@@ -141,6 +141,9 @@
     /// Insert a new page after the current one
     void insertPage();
 
+    /// Copy Page
+    void copyPage();
+
     /// Delete the current page
     void deletePage();
 
@@ -163,6 +166,7 @@
     KToggleAction *m_actionViewShowMasterPages;
 
     KAction * m_actionInsertPage;
+    KAction * m_actionCopyPage;
     KAction * m_actionDeletePage;
 
     KoRuler *m_horizontalRuler;
--- trunk/koffice/plugins/defaultTools/defaulttool/DefaultTool.cpp #743551:743552
@@ -1,6 +1,6 @@
 /* This file is part of the KDE project
 
-   Copyright (C) 2006 Thorsten Zachmann <zachmann@kde.org>
+   Copyright (C) 2006-2007 Thorsten Zachmann <zachmann@kde.org>
    Copyright (C) 2006-2007 Thomas Zander <zander@kde.org>
 
    This library is free software; you can redistribute it and/or
@@ -30,15 +30,23 @@
 #include <KoPointerEvent.h>
 #include <KoToolManager.h>
 #include <KoSelection.h>
+#include <KoShapeController.h>
 #include <KoShapeManager.h>
 #include <KoShapeGroup.h>
+#include <KoShapeLayer.h>
+#include <KoShapePaste.h>
+#include <KoShapeOdfSaveHelper.h>
+#include <KoDrag.h>
+#include <KoDocument.h>
 #include <KoCanvasBase.h>
 #include <KoCanvasResourceProvider.h>
 #include <KoShapeRubberSelectStrategy.h>
 #include <commands/KoShapeMoveCommand.h>
+#include <commands/KoShapeDeleteCommand.h>
 
 #include <QAction>
 #include <QKeyEvent>
+#include <QClipboard>
 #include <kstandarddirs.h>
 
 #include <math.h>
@@ -493,6 +501,47 @@
         m_canvas->updateCanvas(handlesSize());
 }
 
+void DefaultTool::copy() const
+{
+    QList<KoShape *> shapes = m_canvas->shapeManager()->selection()->selectedShapes( \
KoFlake::StrippedSelection ); +    if ( !shapes.empty() ) {
+        KoShapeOdfSaveHelper saveHelper( shapes );
+        KoDrag drag;
+        drag.setOdf( KoOdf::mimeType( KoOdf::Text ), saveHelper );
+        drag.addToClipboard();
+    }
+}
+
+void DefaultTool::deleteSelection()
+{
+    // tz: TODO is StrippedSelection the right one?
+    QList<KoShape *> shapes = m_canvas->shapeManager()->selection()->selectedShapes( \
KoFlake::StrippedSelection ); +    if ( !shapes.empty() ) {
+        m_canvas->addCommand( new KoShapeDeleteCommand( \
m_canvas->shapeController()->shapeControllerBase(), shapes ) ); +    }
+}
+
+bool DefaultTool::paste()
+{
+    const QMimeData * data = QApplication::clipboard()->mimeData();
+
+    bool success = false;
+    if ( data->hasFormat( KoOdf::mimeType( KoOdf::Text ) ) ) {
+        KoShapeManager * shapeManager = m_canvas->shapeManager();
+        int zIndex = 0;
+        foreach ( KoShape *shape, shapeManager->shapes() )
+        {
+            zIndex = qMax( zIndex, shape->zIndex() );
+        }
+
+        // TODO it is not possible to get the doc
+        KoShapePaste paste( static_cast<KoDocument*>( 0 ), m_canvas,
+                            zIndex + 1, shapeManager->selection()->activeLayer() );
+        success = paste.paste( KoOdf::Text, data );
+    }
+    return success;
+}
+
 KoSelection *DefaultTool::koSelection() {
     Q_ASSERT(m_canvas);
     Q_ASSERT(m_canvas->shapeManager());
--- trunk/koffice/plugins/defaultTools/defaulttool/DefaultTool.h #743551:743552
@@ -1,6 +1,6 @@
 /* This file is part of the KDE project
 
-   Copyright (C) 2006 Thorsten Zachmann <zachmann@kde.org>
+   Copyright (C) 2006-2007 Thorsten Zachmann <zachmann@kde.org>
    Copyright (C) 2006-2007 Thomas Zander <zander@kde.org>
 
    This library is free software; you can redistribute it and/or
@@ -60,6 +60,16 @@
     virtual void paint( QPainter &painter, const KoViewConverter &converter );
 
     virtual void repaintDecorations();
+
+    ///reimplemented
+    virtual void copy() const;
+
+    ///reimplemented
+    virtual void deleteSelection();
+
+    ///reimplemented
+    virtual bool paste();
+
     /**
      * Returns which selection handle is at params point (or NoHandle if none).
      * @return which selection handle is at params point (or NoHandle if none).


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic