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

List:       koffice-devel
Subject:    Re: patch: (preliminary) fix for #31732
From:       Emmanuel Touzery <emmanuel.touzery () wanadoo ! fr>
Date:       2002-01-21 20:41:39
[Download RAW message or body]

Hello,

	this patch groups the undo, but it does break kpresenter (I did not correct 
it, waiting for Laurent Montel to commit his changes). unfortunately I'll be 
offline very soon for a long time, so i'll stop now.
	Actually i haven't touched this for a while, and i'm not too sure anymore if 
what's attached is good or not. it at least works great here for me.
	I've let the setBold() etc functions in, you can remove them if you want.

	I hope to have more time to work on other things in koffice (and to have more 
time in a row, so i don't forget all that i was doing and do nonsense..).

	keep on the great work!

emmanuel.
-- 
"Give me a lever long enough and a place to stand, and I'll move the world."
	--Archimedes
["kotextobject.h.patch.3" (text/x-diff)]

Index: kotextobject.h
===================================================================
RCS file: /home/kde/koffice/lib/kotext/kotextobject.h,v
retrieving revision 1.20
diff -u -3 -p -r1.20 kotextobject.h
--- kotextobject.h	2001/12/14 22:14:11	1.20
+++ kotextobject.h	2002/01/21 20:24:12
@@ -41,46 +41,78 @@ class KoTextFormat;
  * unlike KWord), to implement "setBold", "setItalic" etc. only once, whether it \
                applies
  * to a text selection or to complete text objects.
  */
-class KoTextFormatInterface
+class KoTextFormatInterface: public QObject
 {
+Q_OBJECT
 public:
+	KoTextFormatInterface() {}
+	KoTextFormatInterface(QObject *parent, const char *name): QObject(parent, name) {}
     /** Interface for accessing the current format */
     virtual KoTextFormat * currentFormat() const = 0;
     /** Interface for setting the modified format */
-    virtual void setFormat( KoTextFormat * newFormat, int flags, bool zoomFont = \
false ) = 0; +    virtual KCommand *setFormatCommand( KoTextFormat * & currentFormat, \
KoTextFormat *format, int flags, bool zoomFont = false ) = 0;  
-    virtual const KoParagLayout * currentParagLayoutFormat() const =0;
+	virtual KCommand *setParagLayoutFormatCommand( KoParagLayout *newLayout,int flags, \
int marginIndex=-1)=0;  
-    virtual void setParagLayoutFormat( KoParagLayout *newLayout,int flags, int \
marginIndex=-1)=0; +    virtual const KoParagLayout * currentParagLayoutFormat() \
const = 0;  
-    void setBold(bool on);
-    void setItalic(bool on);
-    void setUnderline(bool on);
+	void setParagLayoutFormat( KoParagLayout *newLayout,int flags, int marginIndex=-1);
+	void setFormat( KoTextFormat * newFormat, int flags, bool zoomFont = false );
+
+	void setBold(bool on);
+    KCommand *setBoldCommand(bool on);
+	void setItalic(bool on);
+    KCommand *setItalicCommand(bool on);
+	void setUnderline(bool on);
+	KCommand *setUnderlineCommand(bool on);
     void setStrikeOut(bool on);
+	KCommand *setStrikeOutCommand(bool on);
     void setTextColor(const QColor &color);
+	KCommand *setTextColorCommand(const QColor &color);
     void setPointSize( int s );
+	KCommand *setPointSizeCommand( int s );
     void setFamily(const QString &font);
-    void setFont(const QFont &font, bool _subscript, bool _superscript, const QColor \
&col, const QColor &backGroundColor, int flags); +	KCommand *setFamilyCommand(const \
QString &font); +	void setFont(const QFont &font, bool _subscript, bool _superscript, \
const QColor &col, const QColor &backGroundColor, int flags); +	KCommand \
*setFontCommand(const QFont &font, bool _subscript, bool _superscript, const QColor \
&col, const QColor &backGroundColor, int flags);  void setTextSubScript(bool on);
-    void setTextSuperScript(bool on);
+	KCommand *setTextSubScriptCommand(bool on);
+	void setTextSuperScript(bool on);
+	KCommand *setTextSuperScriptCommand(bool on);
 
     void setDefaultFormat();
+	KCommand *setDefaultFormatCommand();
 
     void setTextBackgroundColor(const QColor &);
+	KCommand *setTextBackgroundColorCommand(const QColor &);
 
     void setAlign(int align);
+	KCommand *setAlignCommand(int align);
 
     void setMargin(QStyleSheetItem::Margin m, double margin);
+	KCommand *setMarginCommand(QStyleSheetItem::Margin m, double margin);
 
     void setTabList(const KoTabulatorList & tabList );
+	KCommand *setTabListCommand(const KoTabulatorList & tabList );
 
     void setCounter(const KoParagCounter & counter );
+	KCommand *setCounterCommand(const KoParagCounter & counter );
 
     QColor textColor() const;
     QFont textFont() const;
     QString textFontFamily()const;
 
     QColor textBackgroundColor()const;
+
+	void emitNewCommand(KCommand *cmd);
+
+signals:
+
+    /** Emitted when a new command has been created and should be added to
+     * the main list of commands (usually in the KoDocument).
+     * Make sure to connect to that one, otherwise the commands will just leak \
away... +     */
+	void newCommand(KCommand *cmd);
 };
 
 /**
@@ -89,7 +121,7 @@ public:
  * the undo/redo commands).
  * Editing the text isn't done by KoTextObject but by KoTextView (document/view \
                design).
  */
-class KoTextObject : public QObject, public KoTextFormatInterface
+class KoTextObject : public KoTextFormatInterface
 {
     Q_OBJECT
 public:
@@ -170,6 +202,9 @@ public:
     void highlightPortion( Qt3::QTextParag * parag, int index, int length );
     void removeHighlight();
 
+	/** Implementation of setFormatCommand from KoTextFormatInterface */
+	KCommand *setFormatCommand( KoTextFormat * & currentFormat, KoTextFormat *format, \
int flags, bool zoomFont = false ); +
     /** Set format changes on selection or current cursor.
         Returns a command if the format was applied to a selection */
     KCommand *setFormatCommand( QTextCursor * cursor, KoTextFormat * & \
currentFormat, KoTextFormat *format, int flags, bool zoomFont = false, int \
selectionId = QTextDocument::Standard ); @@ -199,10 +234,10 @@ public:
 
     KCommand * setShadowCommand( QTextCursor * cursor,double dist, short int \
direction, const QColor &col,int selectionId= QTextDocument::Standard  );  
-    void applyStyle( QTextCursor * cursor, const KoStyle * style,
+    KCommand *applyStyle( QTextCursor * cursor, const KoStyle * style,
                      int selectionId = QTextDocument::Standard,
                      int paragLayoutFlags = KoParagLayout::All, int formatFlags = \
                QTextFormat::Format,
-                     bool createUndoRedo = true, bool interactive = true );
+                     bool createUndoRedo = true, bool interactive = true, bool \
                applyIt = true );
     /** Update the paragraph that use the given style, after this style was changed.
      *  The flags tell which changes should be applied.
      *  @param paragLayoutChanged paragraph flags
@@ -229,7 +264,7 @@ public:
     /**
      * Support for changing the format in the whole textobject
      */
-    virtual void setParagLayoutFormat( KoParagLayout *newLayout,int flags, int \
marginIndex=-1); +    virtual KCommand *setParagLayoutFormatCommand( KoParagLayout \
*newLayout,int flags, int marginIndex=-1);  
     /**
      * Support for changing the format in the whole textobject
@@ -260,10 +295,8 @@ public:
 
     void selectionChangedNotify( bool enableActions = true );
 
-    void emitNewCommand(KCommand *cmd);
-
     void changeCaseOfText(QTextCursor *cursor,KoChangeCaseDia::TypeOfCase _type);
-    QString textChangedCase(const QString _text,KoChangeCaseDia::TypeOfCase _type);	
+    QString textChangedCase(const QString _text,KoChangeCaseDia::TypeOfCase _type);
     KCommand *changeCaseOfTextParag(int cursorPosStart, int \
cursorPosEnd,KoChangeCaseDia::TypeOfCase _type,QTextCursor *cursor, KoTextParag \
*parag);  
 #ifndef NDEBUG
@@ -279,12 +312,6 @@ signals:
      * KWord uses this signal to check for things like 'I need to create a new page'
      */
     void afterFormatting( int bottom, Qt3::QTextParag* m_lastFormatted, bool* abort \
                );
-
-    /** Emitted when a new command has been created and should be added to
-     * the main list of commands (usually in the KoDocument).
-     * Make sure to connect to that one, otherwise the commands will just leak \
                away...
-     */
-    void newCommand( KCommand *cmd );
 
     /** Tell the world that we'd like some repainting to happen */
     void repaintChanged( KoTextObject * );


["kwtextobject.cc" (text/x-c++src)]

/* This file is part of the KDE project
   Copyright (C) 2002 the Koffice team

   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., 59 Temple Place - Suite 330,
   Boston, MA 02111-1307, USA.
*/

#include "kwtextobject.h"
#include "kwtextframeset.h"
#include <kcommand.h>
#include <klocale.h>

KoTextFormat *KWTextFrameObject::currentFormat() const
{
 	KoTextObject *textObject = ((KWTextFrameSet*)m_frame->frameSet())->textObject();
	return textObject->currentFormat();
}

KCommand *KWTextFrameObject::setFormatCommand( KoTextFormat *&oldFormat, KoTextFormat \
* newFormat, int flags, bool zoomFont ) {
	KoTextObject *textObject = ((KWTextFrameSet*)m_frame->frameSet())->textObject();
	textObject->textDocument()->selectAll( QTextDocument::Temp );
	KCommand *cmd = textObject->setFormatCommand( 0L, oldFormat, newFormat, flags, \
zoomFont, QTextDocument::Temp );  textObject->textDocument()->removeSelection( \
QTextDocument::Temp );  return cmd;
}

const KoParagLayout * KWTextFrameObject::currentParagLayoutFormat() const
{
	KoTextObject *textObject = ((KWTextFrameSet*)m_frame->frameSet())->textObject();
	return textObject->currentParagLayoutFormat();
}

KCommand *KWTextFrameObject::setParagLayoutFormatCommand( KoParagLayout \
*newLayout,int flags, int marginIndex) {
	KoTextObject *textObject = ((KWTextFrameSet*)m_frame->frameSet())->textObject();
	return textObject->KoTextObject::setParagLayoutFormatCommand(newLayout, flags, \
marginIndex); }


["kwtextobject.h" (text/x-chdr)]

/* This file is part of the KDE project
   Copyright (C) 2002 the Koffice team

   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., 59 Temple Place - Suite 330,
   Boston, MA 02111-1307, USA.
*/

#ifndef KWTEXTOBJECT_H
#define KWTEXTOBJECT_H

#include <kotextobject.h>
#include "kwdoc.h"

/**
 * This class overrides KoTextFormat methods, allowing
 * to implement "setBold", "setItalic" etc. only once, whether it applies
 * to a text selection or to complete text objects.
 */
class KWTextFrameObject: public KoTextFormatInterface
{
public:

	KWTextFrameObject(KWFrame *frame, KWDocument* doc): m_frame(frame), m_doc(doc) {}

	/** Interface for accessing the current format */
    virtual KoTextFormat * currentFormat() const;

   /** Interface for setting the modified format */
    virtual KCommand *setFormatCommand( KoTextFormat *&oldFormat, KoTextFormat * \
newFormat, int flags, bool zoomFont = false );

	virtual const KoParagLayout * currentParagLayoutFormat() const;

    virtual KCommand *setParagLayoutFormatCommand( KoParagLayout *newLayout,int \
flags, int marginIndex=-1);

protected:
	KWFrame *m_frame;
	KWDocument *m_doc;

};

#endif


["kwview.cc.patch.3" (text/x-diff)]

Index: kwview.cc
===================================================================
RCS file: /home/kde/koffice/kword/kwview.cc,v
retrieving revision 1.464
diff -u -3 -p -r1.464 kwview.cc
--- kwview.cc	2002/01/05 12:35:31	1.464
+++ kwview.cc	2002/01/21 20:24:36
@@ -108,7 +108,7 @@ KWView::KWView( QWidget *_parent, const 
     m_searchEntry = 0L;
     m_replaceEntry = 0L;
     m_findReplace = 0L;
-    m_actionList.setAutoDelete( true );
+	m_actionList.setAutoDelete( true );
     // Default values.
     m_zoomViewModeNormal = m_doc->zoom();
     m_zoomViewModePreview = 33;
@@ -2754,87 +2754,180 @@ void KWView::tableDelete()
 
 void KWView::textStyleSelected( int index )
 {
-    if(m_gui->canvasWidget()->currentFrameSetEdit())
-    {
-        KWTextFrameSetEdit * edit = dynamic_cast<KWTextFrameSetEdit \
                *>(m_gui->canvasWidget()->currentFrameSetEdit()->currentTextEdit());
-        if ( edit )
-            edit->applyStyle( m_doc->styleAt( index ) );
-        m_gui->canvasWidget()->setFocus(); // the combo keeps focus...
-    }
+	if ( m_gui->canvasWidget()->currentFrameSetEdit() )
+	{
+		KWTextFrameSetEdit * edit = dynamic_cast<KWTextFrameSetEdit \
*>(m_gui->canvasWidget()->currentFrameSetEdit()->currentTextEdit()); +		if ( edit)
+           edit->applyStyle( m_doc->styleAt( index ) );
+	}
+	else
+	{ // it might be that a frame (or several frames) are selected
+		QPtrList <KWFrame> selectedFrames = m_doc->getSelectedFrames();
+		if (selectedFrames.count() <= 0)
+			return; // nope, no frames are selected.
+		// yes, indeed frames are selected.
+		QPtrListIterator<KWFrame> it( selectedFrames );
+		KMacroCommand *globalCmd = new KMacroCommand(i18n("change text style in frames"));
+		for ( ; it.current() ; ++it )
+		{
+			KWFrame *curFrame = it.current();
+			KWFrameSet *curFrameSet = curFrame->frameSet();
+			if (curFrameSet->type() == FT_TEXT)
+			{
+				KoTextObject *textObject = ((KWTextFrameSet*)curFrameSet)->textObject();
+				textObject->textDocument()->selectAll( QTextDocument::Temp );
+				KCommand *cmd = textObject->applyStyle( NULL, m_doc->styleAt( index ), \
QTextDocument::Temp, KoParagLayout::All, QTextFormat::Format, true, true ); \
+				textObject->textDocument()->removeSelection( QTextDocument::Temp ); +				if \
(cmd) +					globalCmd->addCommand( cmd );
+			}
+		}
+		m_doc->addCommand( globalCmd );
+	}
+	m_gui->canvasWidget()->setFocus(); // the combo keeps focus...*/
 }
 
 void KWView::textSizeSelected( int size )
 {
-    KWTextFrameSetEdit * edit = currentTextEdit();
-    if ( edit )
-        edit->setPointSize( size );
-    m_gui->canvasWidget()->setFocus(); // the combo keeps focus...
+	QPtrList<KoTextFormatInterface> lst = applicableTextInterfaces();
+    QPtrListIterator<KoTextFormatInterface> it( lst );
+    KMacroCommand *globalCmd = new KMacroCommand(i18n("change text size in \
frames")); +	for ( ; it.current() ; ++it )
+	{
+        KCommand *cmd = it.current()->setPointSizeCommand( size );
+		if (cmd)
+			globalCmd->addCommand(cmd);
+	}
+	m_doc->addCommand(globalCmd);
+	m_gui->canvasWidget()->setFocus(); // the combo keeps focus...
 }
 
 void KWView::textFontSelected( const QString & font )
 {
-    KWTextFrameSetEdit * edit = currentTextEdit();
-    if ( edit )
-        edit->setFamily( font );
+	QPtrList<KoTextFormatInterface> lst = applicableTextInterfaces();
+    QPtrListIterator<KoTextFormatInterface> it( lst );
+    KMacroCommand* macroCmd = new KMacroCommand( i18n("Change text font in \
frame(s)") ); +	for ( ; it.current() ; ++it )
+    {
+	    KCommand *cmd = it.current()->setFamilyCommand( font );
+		if (cmd)
+			macroCmd->addCommand( cmd );
+	}
+	m_doc->addCommand( macroCmd );
     m_gui->canvasWidget()->setFocus(); // the combo keeps focus...
 }
 
+QPtrList<KoTextFormatInterface> KWView::applicableTextInterfaces()
+{
+	QPtrList<KoTextFormatInterface> lst;
+	if (currentTextEdit())
+		// simply return the current textEdit :
+		lst.append( currentTextEdit() );
+	else
+	{	// it might be that a frame (or several frames) are selected
+		 QPtrList<KWFrame> selectedFrames = m_doc->getSelectedFrames();
+		 QPtrListIterator<KWFrame> it( selectedFrames );
+		 for ( ; it.current() ; ++it )
+		 {
+			if (it.current()->frameSet()->type() == FT_TEXT)
+				lst.append( new KWTextFrameObject( it.current(), m_doc ) );
+		 }
+	}
+	return lst;
+}
+
 void KWView::textBold()
 {
-    KWTextFrameSetEdit * edit = currentTextEdit();
-    if ( edit )
-        edit->setBold(actionFormatBold->isChecked());
+	QPtrList<KoTextFormatInterface> lst = applicableTextInterfaces();
+    QPtrListIterator<KoTextFormatInterface> it( lst );
+    KMacroCommand* macroCmd = new KMacroCommand( i18n("Make text in frame(s) bold") \
); +	for ( ; it.current() ; ++it )
+    {
+	    KCommand *cmd = it.current()->setBoldCommand( actionFormatBold->isChecked() );
+		if (cmd)
+			macroCmd->addCommand(cmd);
+	}
+	m_doc->addCommand(macroCmd);
 }
 
 void KWView::textItalic()
 {
-    KWTextFrameSetEdit * edit = currentTextEdit();
-    if ( edit )
-        edit->setItalic(actionFormatItalic->isChecked());
-
+	QPtrList<KoTextFormatInterface> lst = applicableTextInterfaces();
+    QPtrListIterator<KoTextFormatInterface> it( lst );
+	KMacroCommand* macroCmd = new KMacroCommand( i18n("Make text in frame(s) italic") \
); +    for ( ; it.current() ; ++it )
+    {
+	    KCommand *cmd = it.current()->setItalicCommand( actionFormatItalic->isChecked() \
); +		if (cmd)
+			macroCmd->addCommand( cmd );
+	}
+	m_doc->addCommand( macroCmd );
 }
 
 void KWView::textUnderline()
 {
-    KWTextFrameSetEdit * edit = currentTextEdit();
-    if ( edit )
-        edit->setUnderline(actionFormatUnderline->isChecked());
+	QPtrList<KoTextFormatInterface> lst = applicableTextInterfaces();
+	QPtrListIterator<KoTextFormatInterface> it( lst );
+	KMacroCommand* macroCmd = new KMacroCommand( i18n("underline text in frame(s)") );
+    for ( ; it.current() ; ++it )
+    {
+	    KCommand *cmd = it.current()->setUnderlineCommand( \
actionFormatUnderline->isChecked() ); +		if ( cmd )
+			macroCmd->addCommand( cmd );
+	}
+	m_doc->addCommand( macroCmd );
 }
 
 void KWView::textStrikeOut()
 {
-    KWTextFrameSetEdit * edit = currentTextEdit();
-    if ( edit )
-        edit->setStrikeOut(actionFormatStrikeOut->isChecked());
+	QPtrList<KoTextFormatInterface> lst = applicableTextInterfaces();
+    QPtrListIterator<KoTextFormatInterface> it( lst );
+	KMacroCommand* macroCmd = new KMacroCommand( i18n("strike out text in frame(s)") );
+    for ( ; it.current() ; ++it )
+	{
+        KCommand *cmd = it.current()->setStrikeOutCommand( \
actionFormatStrikeOut->isChecked() ); +		if ( cmd )
+			macroCmd->addCommand( cmd );
+	}
+	m_doc->addCommand( macroCmd );
 }
 
 void KWView::textColor()
 {
-    KWTextFrameSetEdit * edit = currentTextEdit();
-    if ( edit )
-    {
 /*        QColor color = edit->textColor();
         if ( KColorDialog::getColor( color ) ) {
             actionFormatColor->setColor( color );
             edit->setTextColor( color );
         }
 */
-        edit->setTextColor( actionFormatColor->color() );
-    }
+	QPtrList<KoTextFormatInterface> lst = applicableTextInterfaces();
+    QPtrListIterator<KoTextFormatInterface> it( lst );
+    KMacroCommand* macroCmd = new KMacroCommand( i18n("Color text in frame(s)") );
+	for ( ; it.current() ; ++it )
+	{
+        KCommand *cmd = it.current()->setTextColorCommand( \
actionFormatColor->color() ); +		if ( cmd )
+			macroCmd->addCommand( cmd );
+	}
+	m_doc->addCommand( macroCmd );
 }
 
 void KWView::textAlignLeft()
 {
     if ( actionFormatAlignLeft->isChecked() )
     {
-        KWTextFrameSetEdit * edit = currentTextEdit();
-        if ( edit )
-        {
-            KCommand *cmd=edit->setAlignCommand(Qt::AlignLeft);
-            if(cmd)
-                m_doc->addCommand(cmd);
-        }
-    } else
+		QPtrList<KoTextFormatInterface> lst = applicableTextInterfaces();
+		QPtrListIterator<KoTextFormatInterface> it( lst );
+		KMacroCommand* macroCmd = new KMacroCommand( i18n("Left-align text in frame(s)") \
); +		for ( ; it.current() ; ++it )
+		{
+			KCommand *cmd = it.current()->setAlignCommand( Qt::AlignLeft );
+			if (cmd)
+				macroCmd->addCommand( cmd );
+		}
+		m_doc->addCommand( macroCmd );
+    }
+	else
         actionFormatAlignLeft->setChecked( true );
 }
 
@@ -2842,14 +2935,18 @@ void KWView::textAlignCenter()
 {
     if ( actionFormatAlignCenter->isChecked() )
     {
-        KWTextFrameSetEdit * edit = currentTextEdit();
-        if ( edit )
-        {
-            KCommand *cmd=edit->setAlignCommand(Qt::AlignCenter);
-            if(cmd)
-                m_doc->addCommand(cmd);
-        }
-    } else
+		QPtrList<KoTextFormatInterface> lst = applicableTextInterfaces();
+		QPtrListIterator<KoTextFormatInterface> it( lst );
+		KMacroCommand* macroCmd = new KMacroCommand( i18n("Center text in frame(s)") );
+		for ( ; it.current() ; ++it )
+		{
+			KCommand *cmd = it.current()->setAlignCommand( Qt::AlignCenter );
+			if (cmd)
+				macroCmd->addCommand( cmd );
+		}
+		m_doc->addCommand( macroCmd );
+	}
+	else
         actionFormatAlignCenter->setChecked( true );
 }
 
@@ -2857,14 +2954,18 @@ void KWView::textAlignRight()
 {
     if ( actionFormatAlignRight->isChecked() )
     {
-        KWTextFrameSetEdit * edit = currentTextEdit();
-        if ( edit )
-        {
-            KCommand *cmd=edit->setAlignCommand(Qt::AlignRight);
-            if(cmd)
-                m_doc->addCommand(cmd);
-        }
-    } else
+		QPtrList<KoTextFormatInterface> lst = applicableTextInterfaces();
+		QPtrListIterator<KoTextFormatInterface> it( lst );
+		KMacroCommand* macroCmd = new KMacroCommand( i18n("Right-align text in frame(s)") \
); +		for ( ; it.current() ; ++it )
+		{
+			KCommand *cmd = it.current()->setAlignCommand( Qt::AlignRight );
+			if ( cmd )
+				macroCmd->addCommand( cmd );
+		}
+		m_doc->addCommand( macroCmd );
+    }
+	else
         actionFormatAlignRight->setChecked( true );
 }
 
@@ -2872,14 +2973,18 @@ void KWView::textAlignBlock()
 {
     if ( actionFormatAlignBlock->isChecked() )
     {
-        KWTextFrameSetEdit * edit = currentTextEdit();
-        if ( edit )
-        {
-            KCommand *cmd=edit->setAlignCommand(Qt::AlignJustify);
-            if(cmd)
-                m_doc->addCommand(cmd);
-        }
-    } else
+		QPtrList<KoTextFormatInterface> lst = applicableTextInterfaces();
+		QPtrListIterator<KoTextFormatInterface> it( lst );
+		KMacroCommand* macroCmd = new KMacroCommand( i18n("Justify text in frame(s)") );
+		for ( ; it.current() ; ++it )
+		{
+			KCommand *cmd = it.current()->setAlignCommand( Qt::AlignJustify );
+			if ( cmd )
+				macroCmd->addCommand( cmd );
+		}
+		m_doc->addCommand( macroCmd );
+    }
+	else
         actionFormatAlignBlock->setChecked( true );
 }
 
@@ -2944,9 +3049,9 @@ void KWView::editPersonalExpr()
 void KWView::textIncreaseIndent()
 {
     KWTextFrameSetEdit * edit = currentTextEdit();
-    if ( edit )
-    {
-        double leftMargin = \
edit->currentParagLayout().margins[QStyleSheetItem::MarginLeft]; +	if ( edit )
+	{
+       double leftMargin = \
edit->currentParagLayout().margins[QStyleSheetItem::MarginLeft];  double indent = \
m_doc->getIndentValue();  double newVal = leftMargin + indent;
         // Test commented out. This breaks with the DTP case... The user can put
@@ -2957,27 +3062,26 @@ void KWView::textIncreaseIndent()
             if(cmd)
                 m_doc->addCommand(cmd);
         }
-    }
+	}
 }
 
 void KWView::textDecreaseIndent()
 {
     KWTextFrameSetEdit * edit = currentTextEdit();
     if ( edit )
-    {
-        double leftMargin = \
                edit->currentParagLayout().margins[QStyleSheetItem::MarginLeft];
-        if ( leftMargin > 0 )
-        {
-            double indent = m_doc->getIndentValue();
-            double newVal = leftMargin - indent;
-            KCommand *cmd=edit->setMarginCommand( QStyleSheetItem::MarginLeft, QMAX( \
                newVal, 0 ) );
-            if(cmd)
-                m_doc->addCommand(cmd);
-        }
-    }
+	{
+		double leftMargin = \
edit->currentParagLayout().margins[QStyleSheetItem::MarginLeft]; +		if ( leftMargin > \
0 ) +		{
+			double indent = m_doc->getIndentValue();
+			double newVal = leftMargin - indent;
+			KCommand *cmd=edit->setMarginCommand( QStyleSheetItem::MarginLeft, QMAX( newVal, \
0 ) ); +			if(cmd)
+				m_doc->addCommand(cmd);
+		}
+	}
 }
 
-
 void KWView::textDefaultFormat()
 {
     KWTextFrameSetEdit * edit = currentTextEdit();
@@ -3520,19 +3624,19 @@ void KWView::slotFrameSetEditChanged()
     bool state = (edit != 0L) && rw;
     actionEditSelectAll->setEnabled(state);
     actionFormatDefault->setEnabled( state);
-    actionFormatFont->setEnabled(state);
-    actionFormatFontSize->setEnabled(state);
-    actionFormatFontFamily->setEnabled(state);
-    actionFormatStyle->setEnabled(state);
-    actionFormatBold->setEnabled(state);
-    actionFormatItalic->setEnabled(state);
-    actionFormatUnderline->setEnabled(state);
-    actionFormatStrikeOut->setEnabled(state);
-    actionFormatColor->setEnabled(state);
-    actionFormatAlignLeft->setEnabled(state);
-    actionFormatAlignCenter->setEnabled(state);
-    actionFormatAlignRight->setEnabled(state);
-    actionFormatAlignBlock->setEnabled(state);
+    actionFormatFont->setEnabled( rw );
+    actionFormatFontSize->setEnabled( rw );
+    actionFormatFontFamily->setEnabled( rw );
+    actionFormatStyle->setEnabled( rw );
+    actionFormatBold->setEnabled( rw );
+    actionFormatItalic->setEnabled( rw );
+    actionFormatUnderline->setEnabled( rw );
+    actionFormatStrikeOut->setEnabled( rw );
+    actionFormatColor->setEnabled( rw );
+    actionFormatAlignLeft->setEnabled( rw );
+    actionFormatAlignCenter->setEnabled( rw );
+    actionFormatAlignRight->setEnabled( rw );
+    actionFormatAlignBlock->setEnabled( rw );
     actionFormatIncreaseIndent->setEnabled(state);
     actionChangeCase->setEnabled( hasSelection && state);
     actionInsertLink->setEnabled(state);


["kotextobject.cc.patch.3" (text/x-diff)]

Index: kotextobject.cc
===================================================================
RCS file: /home/kde/koffice/lib/kotext/kotextobject.cc,v
retrieving revision 1.32
diff -u -3 -p -r1.32 kotextobject.cc
--- kotextobject.cc	2001/12/20 23:35:10	1.32
+++ kotextobject.cc	2002/01/21 20:41:01
@@ -41,7 +41,7 @@ struct KoTextObject::KoTextObjectPrivate
 
 KoTextObject::KoTextObject( KoZoomHandler *zh, const QFont& defaultFont, KoStyle* \
defaultStyle,  QObject* parent, const char *name )
-    : QObject( parent, name ), m_defaultStyle( defaultStyle ), undoRedoInfo( this )
+    : KoTextFormatInterface( parent, name ), m_defaultStyle( defaultStyle ), \
undoRedoInfo( this )  {
     textdoc = new KoTextDocument( zh, new KoTextFormatCollection( defaultFont ) );
     init();
@@ -49,7 +49,7 @@ KoTextObject::KoTextObject( KoZoomHandle
 
 KoTextObject::KoTextObject( KoTextDocument* _textdoc, KoStyle* defaultStyle,
                             QObject* parent, const char *name )
- : QObject( parent, name ), m_defaultStyle( defaultStyle ), undoRedoInfo( this )
+ : KoTextFormatInterface( parent, name ), m_defaultStyle( defaultStyle ), \
undoRedoInfo( this )  {
     textdoc = _textdoc;
     init();
@@ -566,10 +566,9 @@ void KoTextObject::pasteText( QTextCurso
 }
 
 
-void KoTextObject::applyStyle( QTextCursor * cursor, const KoStyle * newStyle,
+KCommand *KoTextObject::applyStyle( QTextCursor * cursor, const KoStyle * newStyle,
                                int selectionId,
-                               int paragLayoutFlags, int formatFlags,
-                               bool createUndoRedo, bool interactive )
+                               int paragLayoutFlags, int formatFlags, bool \
createUndoRedo, bool interactive, bool applyIt )  {
     QTextDocument * textdoc = textDocument();
     if ( interactive )
@@ -604,7 +603,7 @@ void KoTextObject::applyStyle( QTextCurs
             QTextCommand * cmd = new KoTextParagCommand( textdoc, undoRedoInfo.id, \
                undoRedoInfo.eid,
                                                          \
                undoRedoInfo.oldParagLayouts,
                                                          newStyle->paragLayout(), \
                paragLayoutFlags );
-            textdoc->addCommand( cmd );
+			textdoc->addCommand( cmd );
             macroCmd->addCommand( new KoTextCommand( this, /*cmd, */QString::null ) \
);  }
     }
@@ -651,13 +650,13 @@ void KoTextObject::applyStyle( QTextCurs
                                                          lastParag->paragId(), \
                c2.index(),
                                                          \
undoRedoInfo.text.rawData(), newFormat,  formatFlags );
-            textdoc->addCommand( cmd );
+			textdoc->addCommand( cmd );
             macroCmd->addCommand( new KoTextCommand( this, /*cmd, */QString::null ) \
);  
             // sub-command for '3' (paragFormat)
             cmd = new KoParagFormatCommand( textdoc, firstParag->paragId(), \
lastParag->paragId(),  lstFormats, newFormat );
-            textdoc->addCommand( cmd );
+			textdoc->addCommand( cmd );
             macroCmd->addCommand( new KoTextCommand( this, /*cmd, */QString::null ) \
);  }
 
@@ -685,12 +684,14 @@ void KoTextObject::applyStyle( QTextCurs
         formatMore();
         emit repaintChanged( this );
         emit updateUI( true );
-        if ( createUndoRedo )
-            emit newCommand( macroCmd );
+        if ( createUndoRedo && applyIt )
+			emit newCommand( macroCmd );
         emit showCursor();
     }
 
     undoRedoInfo.clear();
+
+	return macroCmd;
 }
 
 void KoTextObject::applyStyleChange( KoStyle * changedStyle, int paragLayoutChanged, \
int formatChanged ) @@ -770,6 +771,14 @@ void KoTextObject::applyStyleChange( KoS
     emit updateUI( true );
 }
 
+KCommand *KoTextObject::setFormatCommand( KoTextFormat * & currentFormat, \
KoTextFormat *format, int flags, bool zoomFont ) +{
+	textDocument()->selectAll( QTextDocument::Temp );
+	KCommand *cmd = setFormatCommand( NULL, currentFormat, format, flags, zoomFont, \
QTextDocument::Temp ); +	textDocument()->removeSelection( QTextDocument::Temp );
+	return cmd;
+}
+
 KCommand * KoTextObject::setFormatCommand( QTextCursor * cursor, KoTextFormat * & \
currentFormat, KoTextFormat *format, int flags, bool zoomFont, int selectionId )  {
     KCommand *ret = 0;
@@ -817,7 +826,7 @@ KCommand * KoTextObject::setFormatComman
         KoTextFormatCommand *cmd = new KoTextFormatCommand(
             textdoc, id, index, eid, eindex, undoRedoInfo.text.rawData(),
             format, flags );
-        textdoc->addCommand( cmd );
+		textdoc->addCommand( cmd );
         ret = new KoTextCommand( this, /*cmd, */i18n("Format text") );
         undoRedoInfo.clear();
         setLastFormattedParag( c1.parag() );
@@ -851,7 +860,7 @@ void KoTextObject::setFormat( QTextCurso
         emit newCommand( cmd );
 }
 
-void KoTextObject::emitNewCommand(KCommand *cmd)
+void KoTextFormatInterface::emitNewCommand(KCommand *cmd)
 {
     if(cmd)
         emit newCommand( cmd );
@@ -1640,7 +1649,7 @@ const KoParagLayout * KoTextObject::curr
     return &(parag->paragLayout());
 }
 
-void KoTextObject::setParagLayoutFormat( KoParagLayout *newLayout,int flags,int \
marginIndex) +KCommand *KoTextObject::setParagLayoutFormatCommand( KoParagLayout \
*newLayout,int flags,int marginIndex)  {
     QTextDocument *textdoc = textDocument();
     textdoc->selectAll( QTextDocument::Temp );
@@ -1669,8 +1678,7 @@ void KoTextObject::setParagLayoutFormat(
         break;
     }
     textdoc->removeSelection( QTextDocument::Temp );
-    if (cmd)
-        emit newCommand( cmd );
+	return cmd;
 }
 
 void KoTextObject::setFormat( KoTextFormat * newFormat, int flags, bool zoomFont )
@@ -1702,73 +1710,146 @@ void KoTextObject::printRTDebug(int info
         p->printRTDebug( info );
     }
     if ( info == 1 )
-        textdoc->formatCollection()->debug(); 
+        textdoc->formatCollection()->debug();
 }
 #endif
 
-void KoTextFormatInterface::setBold(bool on) {
-    KoTextFormat format( *currentFormat() );
-    format.setBold( on );
-    setFormat( &format, QTextFormat::Bold );
+void KoTextFormatInterface::setFormat( KoTextFormat * newFormat, int flags, bool \
zoomFont ) +{
+	KoTextFormat *format = currentFormat();
+	KCommand *cmd = setFormatCommand(format, newFormat, flags, zoomFont);
+	emitNewCommand( cmd );
 }
 
-void KoTextFormatInterface::setItalic( bool on ) {
-    KoTextFormat format( *currentFormat() );
+void KoTextFormatInterface::setBold(bool on)
+{
+	KCommand *cmd = setBoldCommand( on );
+	emitNewCommand( cmd );
+}
+
+KCommand *KoTextFormatInterface::setBoldCommand(bool on)
+{
+	KoTextFormat format( *currentFormat() );
+	format.setBold( on );
+	KoTextFormat *current = currentFormat();
+	return setFormatCommand( current, &format, QTextFormat::Bold );
+}
+
+void KoTextFormatInterface::setItalic( bool on )
+{
+	KCommand *cmd = setItalicCommand( on );
+	emitNewCommand( cmd );
+}
+
+KCommand *KoTextFormatInterface::setItalicCommand( bool on)
+{
+	KoTextFormat format( *currentFormat() );
     format.setItalic( on );
-    setFormat( &format, QTextFormat::Italic );
+	KoTextFormat *current = currentFormat();
+    return setFormatCommand( current, &format, QTextFormat::Italic );
 }
 
-void KoTextFormatInterface::setUnderline( bool on ) {
+void KoTextFormatInterface::setUnderline( bool on )
+{
+	KCommand *cmd = setUnderlineCommand( on );
+	emitNewCommand ( cmd );
+}
+
+KCommand *KoTextFormatInterface::setUnderlineCommand( bool on )
+{
     KoTextFormat format( *currentFormat() );
     format.setUnderline( on );
-    setFormat( &format, QTextFormat::Underline );
+    KoTextFormat *current = currentFormat();
+	return setFormatCommand( current, &format, QTextFormat::Underline );
+}
+
+void KoTextFormatInterface::setStrikeOut( bool on )
+{
+	KCommand *cmd = setStrikeOutCommand( on );
+	emitNewCommand( cmd );
 }
 
-void KoTextFormatInterface::setStrikeOut( bool on ) {
+KCommand *KoTextFormatInterface::setStrikeOutCommand( bool on )
+{
     KoTextFormat format( *currentFormat() );
     format.setStrikeOut( on );
-    setFormat( &format, KoTextFormat::StrikeOut );
+    KoTextFormat *current = currentFormat();
+	return setFormatCommand( current, &format, KoTextFormat::StrikeOut );
 }
 
-void KoTextFormatInterface::setTextBackgroundColor(const QColor & col) {
-    KoTextFormat format( *currentFormat() );
+void KoTextFormatInterface::setTextBackgroundColor(const QColor & col)
+{
+	KCommand *cmd = setTextBackgroundColorCommand( col );
+	emitNewCommand( cmd );
+}
+
+KCommand *KoTextFormatInterface::setTextBackgroundColorCommand(const QColor & col)
+{
+	KoTextFormat format( *currentFormat() );
     format.setTextBackgroundColor( col );
-    setFormat( &format, KoTextFormat::TextBackgroundColor );
+    KoTextFormat *current = currentFormat();
+	return setFormatCommand( current, &format, KoTextFormat::TextBackgroundColor );
 }
 
-QColor KoTextFormatInterface::textBackgroundColor() const {
+QColor KoTextFormatInterface::textBackgroundColor() const
+{
     return currentFormat()->textBackgroundColor();
 }
 
-QColor KoTextFormatInterface::textColor() const {
+QColor KoTextFormatInterface::textColor() const
+{
     return currentFormat()->color();
 }
 
-QFont KoTextFormatInterface::textFont() const {
-    QFont fn( currentFormat()->font() );
+QFont KoTextFormatInterface::textFont() const
+{
+    QFont fn( /***/currentFormat()->font() );
     // "unzoom" the font size
     fn.setPointSize( static_cast<int>( KoTextZoomHandler::layoutUnitToPt( \
fn.pointSize() ) ) );  return fn;
 }
 
-QString KoTextFormatInterface::textFontFamily()const {
+QString KoTextFormatInterface::textFontFamily()const
+{
     return currentFormat()->font().family();
 }
 
-void KoTextFormatInterface::setPointSize( int s ){
-    KoTextFormat format( *currentFormat() );
+void KoTextFormatInterface::setPointSize( int s )
+{
+	KCommand *cmd = setPointSizeCommand( s );
+	emitNewCommand( cmd );
+}
+
+KCommand *KoTextFormatInterface::setPointSizeCommand( int s )
+{
+	KoTextFormat format( *currentFormat() );
     format.setPointSize( s );
-    setFormat( &format, QTextFormat::Size, true /* zoom the font size */ );
+    KoTextFormat *current = currentFormat();
+	return setFormatCommand( current, &format, QTextFormat::Size, true /* zoom the font \
size */ ); +}
+
+void KoTextFormatInterface::setFamily(const QString &font)
+{
+	KCommand *cmd = setFamilyCommand( font );
+	emitNewCommand( cmd );
 }
 
-void KoTextFormatInterface::setFamily(const QString &font){
+KCommand *KoTextFormatInterface::setFamilyCommand(const QString &font)
+{
     KoTextFormat format( *currentFormat() );
     format.setFamily( font );
-    setFormat( &format, QTextFormat::Family );
+    KoTextFormat *current = currentFormat();
+	return setFormatCommand( current, &format, QTextFormat::Family );
 }
 
 void KoTextFormatInterface::setFont( const QFont &font, bool _subscript, bool \
_superscript, const QColor &col,const QColor &backGroundColor, int flags )  {
+	KCommand *cmd = setFontCommand( font, _subscript, _superscript, col, \
backGroundColor, flags ); +	emitNewCommand( cmd );
+}
+
+KCommand *KoTextFormatInterface::setFontCommand( const QFont &font, bool _subscript, \
bool _superscript, const QColor &col,const QColor &backGroundColor, int flags ) +{
     KoTextFormat format( *currentFormat() );
     format.setFont( font );
     format.setColor( col );
@@ -1782,74 +1863,138 @@ void KoTextFormatInterface::setFont( con
     }
     else
         format.setVAlign(QTextFormat::AlignSubScript);
+	KoTextFormat *current = currentFormat();
+    return setFormatCommand( current, &format, flags, true /* zoom the font size \
*/); +}
 
-    setFormat( &format, flags, true /* zoom the font size */);
+void KoTextFormatInterface::setTextColor(const QColor &color)
+{
+	KCommand *cmd = setTextColorCommand( color );
+	emitNewCommand( cmd );
 }
 
-void KoTextFormatInterface::setTextColor(const QColor &color) {
+KCommand *KoTextFormatInterface::setTextColorCommand(const QColor &color)
+{
     KoTextFormat format( *currentFormat() );
     format.setColor( color );
-    setFormat( &format, QTextFormat::Color );
+    KoTextFormat *current = currentFormat();
+	return setFormatCommand( current, &format, QTextFormat::Color );
 }
 
 void KoTextFormatInterface::setTextSubScript(bool on)
 {
+	KCommand *cmd = setTextSubScriptCommand( on );
+	emitNewCommand( cmd );
+}
+
+KCommand *KoTextFormatInterface::setTextSubScriptCommand(bool on)
+{
     KoTextFormat format( *currentFormat() );
     if(!on)
         format.setVAlign(QTextFormat::AlignNormal);
     else
         format.setVAlign(QTextFormat::AlignSubScript);
-    setFormat( &format, QTextFormat::VAlign );
+    KoTextFormat *current = currentFormat();
+	return setFormatCommand( current, &format, QTextFormat::VAlign );
 }
 
 void KoTextFormatInterface::setTextSuperScript(bool on)
 {
+	KCommand *cmd = setTextSuperScriptCommand( on );
+	emitNewCommand( cmd );
+}
+
+KCommand *KoTextFormatInterface::setTextSuperScriptCommand(bool on)
+{
     KoTextFormat format( *currentFormat() );
     if(!on)
         format.setVAlign(QTextFormat::AlignNormal);
     else
         format.setVAlign(QTextFormat::AlignSuperScript);
-    setFormat( &format, QTextFormat::VAlign );
+    KoTextFormat *current = currentFormat();
+	return setFormatCommand( current, &format, QTextFormat::VAlign );
 }
 
-void KoTextFormatInterface::setDefaultFormat() {
+void KoTextFormatInterface::setDefaultFormat()
+{
+	KCommand *cmd = setDefaultFormatCommand();
+	emitNewCommand( cmd );
+}
+
+KCommand *KoTextFormatInterface::setDefaultFormatCommand()
+{
     QTextFormatCollection * coll = currentFormat()->parent();
     Q_ASSERT(coll);
     if(coll)
     {
         KoTextFormat * format = static_cast<KoTextFormat *>(coll->defaultFormat());
-        setFormat( format, QTextFormat::Format );
+        KoTextFormat *current = currentFormat();
+		return setFormatCommand( current, format, QTextFormat::Format );
     }
+	return 0L;
 }
 
 void KoTextFormatInterface::setAlign(int align)
 {
+	KCommand *cmd = setAlignCommand( align );
+	emitNewCommand( cmd );
+}
+
+KCommand *KoTextFormatInterface::setAlignCommand(int align)
+{
     KoParagLayout format( *currentParagLayoutFormat() );
     format.alignment=align;
-    setParagLayoutFormat(&format,KoParagLayout::Alignment);
+    return setParagLayoutFormatCommand(&format,KoParagLayout::Alignment);
 }
 
 void KoTextFormatInterface::setMargin(QStyleSheetItem::Margin m, double margin)
 {
+	KCommand *cmd = setMarginCommand( m, margin );
+	emitNewCommand( cmd );
+}
+
+KCommand *KoTextFormatInterface::setMarginCommand(QStyleSheetItem::Margin m, double \
margin) +{
     KoParagLayout format( *currentParagLayoutFormat() );
     format.margins[m]=margin;
     setParagLayoutFormat(&format,KoParagLayout::Margins,(int)m);
+	return 0L;
 }
 
 void KoTextFormatInterface::setTabList(const KoTabulatorList & tabList )
 {
+	KCommand *cmd = setTabListCommand( tabList );
+	emitNewCommand( cmd );
+}
+
+KCommand *KoTextFormatInterface::setTabListCommand(const KoTabulatorList & tabList )
+{
     KoParagLayout format( *currentParagLayoutFormat() );
     format.setTabList(tabList);
     setParagLayoutFormat(&format,KoParagLayout::Tabulator);
+	return 0L;
 }
 
 void KoTextFormatInterface::setCounter(const KoParagCounter & counter )
 {
+	KCommand *cmd = setCounterCommand( counter );
+	emitNewCommand( cmd );
+}
+
+KCommand *KoTextFormatInterface::setCounterCommand(const KoParagCounter & counter )
+{
     KoParagLayout format( *currentParagLayoutFormat() );
     if(!format.counter)
         format.counter = new KoParagCounter;
     *format.counter= counter;
     setParagLayoutFormat(&format,KoParagLayout::BulletNumber);
+	return 0L;
+}
+
+void KoTextFormatInterface::setParagLayoutFormat( KoParagLayout *newLayout,int \
flags, int marginIndex) +{
+	KCommand *cmd = setParagLayoutFormatCommand(newLayout, flags, marginIndex);
+	emitNewCommand( cmd );
 }
 
 #include "kotextobject.moc"


_______________________________________________
koffice-devel mailing list
koffice-devel@mail.kde.org
http://mail.kde.org/mailman/listinfo/koffice-devel

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

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