[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-15 21:43:40
[Download RAW message or body]
Hello!
>Thanks for the patch... but allow me to comment on it :
no problem, I actually asked for comments :O)
> I totally hate code
>duplication. It makes maintainance and debugging very difficult.
>
>Please use an approach similar to KPresenter's use of KoTextFormatInterface.
Yes, I understand, only it makes grouping the KCommand for the undo harder
(kpresenter does not group them). actually with the new patch the undo
actions are not grouped anymore (that is, if you select several cells in a
table, do an action, and undo it, you'll have to click undo the number of
selected cells, not just once).
the reason is that setBold() and such doesn't return a KCommand, so i would
need new methods like KoTextFormatInterface::startGrouping() and
endGrouping(), but that is not very adapted for the API i guess (and would
break a lot of code) so i don't know exactly how to solve that "nicely".
maybe you have a better idea?
note: the attached patch still has the issue of the previous patch: on undo
the toolbar buttons are not set back properly (center text on frame, press
undo, text is not centered anymore, but the center button is still on). i
don't know why is that.
hope you're happier with this new version anyway.
emmanuel.
--
"Give me a lever long enough and a place to stand, and I'll move the world."
--Archimedes
["kwview.cc.patch.2" (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/15 21:43:59
@@ -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,86 +2754,127 @@ 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 );
+ 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 );
+ textObject->applyStyle( NULL, m_doc->styleAt( index ), QTextDocument::Temp, \
KoParagLayout::All, QTextFormat::Format, true, true ); \
+ textObject->textDocument()->removeSelection( QTextDocument::Temp ); + }
+ }
+ }
+ 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 );
+ for ( ; it.current() ; ++it )
+ it.current()->setPointSize( size );
+ 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 );
+ for ( ; it.current() ; ++it )
+ it.current()->setFamily( font );
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 );
+ for ( ; it.current() ; ++it )
+ it.current()->setBold( actionFormatBold->isChecked() );
}
void KWView::textItalic()
{
- KWTextFrameSetEdit * edit = currentTextEdit();
- if ( edit )
- edit->setItalic(actionFormatItalic->isChecked());
-
+ QPtrList<KoTextFormatInterface> lst = applicableTextInterfaces();
+ QPtrListIterator<KoTextFormatInterface> it( lst );
+ for ( ; it.current() ; ++it )
+ it.current()->setItalic( actionFormatItalic->isChecked() );
}
void KWView::textUnderline()
{
- KWTextFrameSetEdit * edit = currentTextEdit();
- if ( edit )
- edit->setUnderline(actionFormatUnderline->isChecked());
+ QPtrList<KoTextFormatInterface> lst = applicableTextInterfaces();
+ QPtrListIterator<KoTextFormatInterface> it( lst );
+ for ( ; it.current() ; ++it )
+ it.current()->setUnderline( actionFormatUnderline->isChecked() );
}
void KWView::textStrikeOut()
{
- KWTextFrameSetEdit * edit = currentTextEdit();
- if ( edit )
- edit->setStrikeOut(actionFormatStrikeOut->isChecked());
+ QPtrList<KoTextFormatInterface> lst = applicableTextInterfaces();
+ QPtrListIterator<KoTextFormatInterface> it( lst );
+ for ( ; it.current() ; ++it )
+ it.current()->setStrikeOut( actionFormatStrikeOut->isChecked() );
}
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 );
+ for ( ; it.current() ; ++it )
+ it.current()->setTextColor( actionFormatColor->color() );
+
}
void KWView::textAlignLeft()
{
if ( actionFormatAlignLeft->isChecked() )
{
- KWTextFrameSetEdit * edit = currentTextEdit();
- if ( edit )
- {
- KCommand *cmd=edit->setAlignCommand(Qt::AlignLeft);
- if(cmd)
- m_doc->addCommand(cmd);
- }
+ QPtrList<KoTextFormatInterface> lst = applicableTextInterfaces();
+ QPtrListIterator<KoTextFormatInterface> it( lst );
+ for ( ; it.current() ; ++it )
+ it.current()->setAlign( Qt::AlignLeft );
} else
actionFormatAlignLeft->setChecked( true );
}
@@ -2842,14 +2883,11 @@ 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 );
+ for ( ; it.current() ; ++it )
+ it.current()->setAlign( Qt::AlignCenter );
+ } else
actionFormatAlignCenter->setChecked( true );
}
@@ -2857,13 +2895,10 @@ void KWView::textAlignRight()
{
if ( actionFormatAlignRight->isChecked() )
{
- KWTextFrameSetEdit * edit = currentTextEdit();
- if ( edit )
- {
- KCommand *cmd=edit->setAlignCommand(Qt::AlignRight);
- if(cmd)
- m_doc->addCommand(cmd);
- }
+ QPtrList<KoTextFormatInterface> lst = applicableTextInterfaces();
+ QPtrListIterator<KoTextFormatInterface> it( lst );
+ for ( ; it.current() ; ++it )
+ it.current()->setAlign( Qt::AlignRight );
} else
actionFormatAlignRight->setChecked( true );
}
@@ -2872,13 +2907,10 @@ void KWView::textAlignBlock()
{
if ( actionFormatAlignBlock->isChecked() )
{
- KWTextFrameSetEdit * edit = currentTextEdit();
- if ( edit )
- {
- KCommand *cmd=edit->setAlignCommand(Qt::AlignJustify);
- if(cmd)
- m_doc->addCommand(cmd);
- }
+ QPtrList<KoTextFormatInterface> lst = applicableTextInterfaces();
+ QPtrListIterator<KoTextFormatInterface> it( lst );
+ for ( ; it.current() ; ++it )
+ it.current()->setAlign( Qt::AlignJustify );
} else
actionFormatAlignBlock->setChecked( true );
}
@@ -2944,9 +2976,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 +2989,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 +3551,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);
_______________________________________________
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