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

List:       kde-commits
Subject:    koffice/kword/part
From:       Thomas Zander <zander () kde ! org>
Date:       2010-08-29 21:02:50
Message-ID: 20100829210250.0EE25AC876 () svn ! kde ! org
[Download RAW message or body]

SVN commit 1169685 by zander:

Replace the pageProperties with pageStyleProperties command

The concept of changing one page' properties using a style that is
shared between many pages doesn't make sense, and as such the old
KWPagePropertiesCommand is laid to rest and the new
KWPageStylePropertiesCommand is started.
The idea is to have a command for changing the style and taking into
account all pages that it affects.
Only basic functionality present at this time.

 M  +1 -1      CMakeLists.txt  
 M  +24 -1     KWPageStyle_p.h  
 D             commands/KWPagePropertiesCommand.cpp  
 D             commands/KWPagePropertiesCommand.h  
 A             commands/KWPageStylePropertiesCommand.cpp   \
commands/KWPagePropertiesCommand.cpp#1169684 [License: LGPL (v2+)]  A             \
commands/KWPageStylePropertiesCommand.h   commands/KWPagePropertiesCommand.h#1169684 \
[License: LGPL (v2+)]  M  +15 -8     dialogs/KWPageSettingsDialog.cpp  
 M  +31 -64    tests/TestPageCommands.cpp  
 M  +2 -3      tests/TestPageCommands.h  


--- trunk/koffice/kword/part/CMakeLists.txt #1169684:1169685
@@ -58,7 +58,7 @@
     dialogs/KWInsertPageDialog.cpp
     dockers/KWStatisticsDocker.cpp
 
-    commands/KWPagePropertiesCommand.cpp
+    commands/KWPageStylePropertiesCommand.cpp
     commands/KWPageInsertCommand.cpp
     commands/KWPageRemoveCommand.cpp
     commands/KWNewPageStyleCommand.cpp
--- trunk/koffice/kword/part/KWPageStyle_p.h #1169684:1169685
@@ -1,5 +1,5 @@
 /* This file is part of the KDE project
- * Copyright (C) 2006-2009 Thomas Zander <zander@kde.org>
+ * Copyright (C) 2006-2010 Thomas Zander <zander@kde.org>
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Library General Public
@@ -47,6 +47,29 @@
     KoText::Direction direction;
     KoShapeBackground *fullPageBackground;
     QString nextStyleName;
+
+    // called from the command
+    void copyProperties(KWPageStylePrivate *other) {
+        columns = other->columns;
+        pageLayout = other->pageLayout;
+        //name = other->name;
+        mainFrame = other->mainFrame;
+        headerDistance = other->headerDistance;
+        footerDistance = other->footerDistance;
+        footNoteDistance = other->footNoteDistance;
+        endNoteDistance = other->endNoteDistance;
+        headerMinimumHeight = other->headerMinimumHeight;
+        footerMinimumHeight = other->footerMinimumHeight;
+        headers = other->headers;
+        footers = other->footers;
+        footNoteSeparatorLineWidth = other->footNoteSeparatorLineWidth;
+        footNoteSeparatorLineLength = other->footNoteSeparatorLineLength;
+        footNoteSeparatorLineType = other->footNoteSeparatorLineType;
+        footNoteSeparatorLinePos = other->footNoteSeparatorLinePos;
+        direction = other->direction;
+        fullPageBackground = other->fullPageBackground;
+        nextStyleName = other->nextStyleName;
+    }
 };
 
 #endif
--- trunk/koffice/kword/part/dialogs/KWPageSettingsDialog.cpp #1169684:1169685
@@ -23,7 +23,7 @@
 #include "KWDocumentColumns.h"
 
 #include <KWDocument.h>
-#include <commands/KWPagePropertiesCommand.h>
+#include <commands/KWPageStylePropertiesCommand.h>
 #include <commands/KWNewPageStyleCommand.h>
 #include <commands/KWChangePageStyleCommand.h>
 
@@ -90,16 +90,20 @@
 void KWPageSettingsDialog::accept()
 {
     QUndoCommand *cmd = new QUndoCommand(i18n("Change Page Properties"));;
+    KWPageStyle styleToUpdate = m_page.pageStyle();
     // TODO rename 'applyToDocument' to 'onlyThisPage'
     if (!applyToDocument()) {
-        KWPageStyle newStyle = m_page.pageStyle();
-        newStyle.detach(QString("AutogeneratedStyle%1").arg(m_page.pageNumber())); \
                // TODO generate unique name
-        Q_ASSERT(newStyle.name() != m_page.pageStyle().name());
-        new KWNewPageStyleCommand(m_document, newStyle, cmd);
-        new KWChangePageStyleCommand(m_page, newStyle, cmd);
+        // detach to create a style specifically for this page.
+        styleToUpdate.detach(QString("AutogeneratedStyle%1").arg(m_page.pageNumber())); \
// TODO generate unique name +        Q_ASSERT(styleToUpdate.name() != \
m_page.pageStyle().name()); +        new KWNewPageStyleCommand(m_document, \
styleToUpdate, cmd); +        new KWChangePageStyleCommand(m_page, styleToUpdate, \
cmd); +    } else {
+        // otherwise we change it and the command below then assigns it.
+        styleToUpdate.detach(styleToUpdate.name());
     }
 
-    KoText::Direction newDir = textDirection();
+    styleToUpdate.setDirection(textDirection());
     KoPageLayout lay = pageLayout();
     if (lay.pageEdge >= 0 || lay.bindingSide >= 0) {
         // asserts check if our super didn't somehow mess up
@@ -112,7 +116,10 @@
         // normal page size and assume that the page object will do the right thing
         lay.width /= (qreal) 2;
     }
-    new KWPagePropertiesCommand(m_document, m_page, lay, newDir, \
m_columns->columns(), cmd); +    styleToUpdate.setPageLayout(lay);
+    styleToUpdate.setColumns(m_columns->columns());
+
+    new KWPageStylePropertiesCommand(m_document, m_page.pageStyle(), styleToUpdate, \
cmd);  m_document->addCommand(cmd);
 
     KoPageLayoutDialog::accept();
--- trunk/koffice/kword/part/tests/TestPageCommands.cpp #1169684:1169685
@@ -1,5 +1,5 @@
 /* This file is part of the KOffice project
- * Copyright (C) 2005,2008, 2010 Thomas Zander <zander@kde.org>
+ * Copyright (C) 2005-2010 Thomas Zander <zander@kde.org>
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Library General Public
@@ -22,7 +22,7 @@
 #include <KWDocument.h>
 #include <commands/KWPageInsertCommand.h>
 #include <commands/KWPageRemoveCommand.h>
-#include <commands/KWPagePropertiesCommand.h>
+#include <commands/KWPageStylePropertiesCommand.h>
 #include <commands/KWNewPageStyleCommand.h>
 #include <frames/KWTextFrame.h>
 #include <frames/KWTextFrameSet.h>
@@ -432,7 +432,7 @@
     QCOMPARE(header->frameCount(), 0); // doesn't get auto-added
 }
 
-void TestPageCommands::testPagePropertiesCommand() // basic properties change
+void TestPageCommands::testPageStylePropertiesCommand() // basic properties change
 {
     KWDocument document;
     KWPageManager *manager = document.pageManager();
@@ -465,6 +465,7 @@
     QCOMPARE(page1.pageSide(), KWPage::Right);
 
     // new ;)
+    KWPageStyle style2("pagestyle2");
     KoPageLayout newLayout;
     newLayout.width = 401;
     newLayout.height = 405;
@@ -472,11 +473,14 @@
     newLayout.rightMargin = 18;
     newLayout.pageEdge = -1;
     newLayout.bindingSide = -1;
+    style2.setPageLayout(newLayout);
     KoColumns newColumns;
     newColumns.columns = 2;
     newColumns.columnSpacing = 12;
+    style2.setColumns(newColumns);
+    style2.setDirection(KoText::RightLeftTopBottom);
 
-    KWPagePropertiesCommand command(&document, page1, newLayout, \
KoText::RightLeftTopBottom, newColumns); +    KWPageStylePropertiesCommand \
command1(&document, style, style2);  
     // nothing changed before the redo
     QCOMPARE(page1.width(), 101.);
@@ -485,11 +489,16 @@
     QCOMPARE(page1.pageEdgeMargin(), 7.);
     QCOMPARE(page1.directionHint(), KoText::LeftRightTopBottom);
 
-    command.redo();
+    // redo
+    command1.redo();
+    QCOMPARE(page1.pageStyle().name(), QString("pagestyle1")); // name didn't change
     QCOMPARE(page1.width(), 401.);
     QCOMPARE(page1.height(), 405.);
     QCOMPARE(page1.leftMargin(), 11.);
     QCOMPARE(page1.pageEdgeMargin(), -1.); // its a right-sided page
+    QCOMPARE(page1.pageStyle().direction(), KoText::RightLeftTopBottom);
+    QCOMPARE(page1.directionHint(), KoText::LeftRightTopBottom);
+    page1.setDirectionHint(KoText::InheritDirection); // reset to what the style \
says  QCOMPARE(page1.directionHint(), KoText::RightLeftTopBottom);
     QCOMPARE(style.pageLayout().width, 401.); // style changed
     QCOMPARE(page1.pageStyle().columns().columns, 2);
@@ -507,70 +516,28 @@
     QVERIFY(!manager->page(3).isValid());
     QCOMPARE(page2.pageNumber(), 2);
     QCOMPARE(page2.pageSide(), KWPage::Left);
-}
 
-void TestPageCommands::testMakePageSpread()
-{
-    KWDocument document;
-    KWPageManager *manager = document.pageManager();
-
-    KWPageStyle style("pagestyle1");
-    KoPageLayout layout = style.pageLayout();
-
-    manager->addPageStyle(style);
-    KWPage page1 = manager->appendPage(style);
-    QCOMPARE(page1.width(), layout.width);
+    // undo
+    command1.undo();
+    QCOMPARE(page1.pageStyle().name(), QString("pagestyle1")); // name didn't change
+    QCOMPARE(page1.width(), 101.);
+    QCOMPARE(page1.height(), 102.);
+    QCOMPARE(page1.leftMargin(), 13.);
+    QCOMPARE(page1.directionHint(), KoText::AutoDirection);
+    QCOMPARE(style.pageLayout().width, 101.);
+    QCOMPARE(page1.pageStyle().columns().columns, 4);
     QCOMPARE(page1.pageNumber(), 1);
     QCOMPARE(page1.pageSide(), KWPage::Right);
-    QCOMPARE(manager->pageCount(), 1);
-    // make it a pagespread
-    layout.leftMargin = -1;
-    layout.rightMargin = -1;
-    layout.pageEdge = 7;
-    layout.bindingSide = 13;
-    KWPagePropertiesCommand cmd1(&document, page1, layout,
-        style.direction(), style.columns());
-    cmd1.redo();
-    QCOMPARE(page1.pageNumber(), 1);
-    QCOMPARE(page1.pageSide(), KWPage::Right);
-    QCOMPARE(page1.width(), style.pageLayout().width);
-    QCOMPARE(manager->pageCount(), 1);
-    KoPageLayout newLayout = style.pageLayout();
-    QCOMPARE(newLayout.width, layout.width);
-    QCOMPARE(newLayout.leftMargin, layout.leftMargin);
-    QCOMPARE(newLayout.rightMargin, layout.rightMargin);
-    QCOMPARE(newLayout.pageEdge, layout.pageEdge);
-    QCOMPARE(newLayout.bindingSide, layout.bindingSide);
-
-    cmd1.undo();
-    QCOMPARE(page1.width(), style.pageLayout().width);
-    QCOMPARE(page1.pageNumber(), 1);
-    QCOMPARE(page1.pageSide(), KWPage::Right);
-    QCOMPARE(manager->pageCount(), 1);
-
-    // create another page. So we have 2 single sided pages. (Right/Left)
-    KWPage page2 = manager->appendPage(style);
-    QCOMPARE(page2.width(), style.pageLayout().width);
-    QCOMPARE(page2.pageNumber(), 2);
-    QCOMPARE(page2.pageSide(), KWPage::Left);
     QCOMPARE(manager->pageCount(), 2);
-
-    // avoid reusing cmd1 as that assumes the constructor doens't do anything. Which \
                is
-    // not a restriction we put on the command. (i.e. that doesn't *have* to work)
-    KWPagePropertiesCommand cmd2(&document, page1, layout,
-        style.direction(), style.columns());
-    cmd2.redo();
-
-    QCOMPARE(page1.width(), style.pageLayout().width);
-    QCOMPARE(page1.pageNumber(), 1);
-    QCOMPARE(page1.pageSide(), KWPage::Right);
+    QVERIFY(manager->page(1).isValid());
+    QVERIFY(manager->page(2).isValid());
+    QVERIFY(!manager->page(3).isValid());
     QCOMPARE(page2.pageNumber(), 2);
-    QCOMPARE(page2.pageSide(), KWPage::PageSpread);
-    QCOMPARE(page2.width(), style.pageLayout().width * 2);
-    QCOMPARE(manager->pageCount(), 3);
-
-    cmd2.undo();
-    // test for page side etc.
+    QCOMPARE(page2.pageSide(), KWPage::Left);
+    QCOMPARE(page2.width(), 101.); // same style
+    QCOMPARE(page2.height(), 102.);
+    QCOMPARE(page2.leftMargin(), 7.);
+    QCOMPARE(page2.directionHint(), KoText::AutoDirection);
 }
 
 void TestPageCommands::testNewPageStyleCommand()
--- trunk/koffice/kword/part/tests/TestPageCommands.h #1169684:1169685
@@ -1,5 +1,5 @@
 /* This file is part of the KOffice project
- * Copyright (C) 2005-2006,2008 Thomas Zander <zander@kde.org>
+ * Copyright (C) 2005-2010 Thomas Zander <zander@kde.org>
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Library General Public
@@ -36,8 +36,7 @@
     void testRemovePageCommand2();
     void testRemovePageCommand3();
     void testRemovePageCommand4();
-    void testPagePropertiesCommand();
-    void testMakePageSpread();
+    void testPageStylePropertiesCommand();
     void testNewPageStyleCommand();
 };
 


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

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