[prev in list] [next in list] [prev in thread] [next in thread]
List: koffice-devel
Subject: shift+enter in kword
From: Krister Wicksell Eriksson <krister.wicksell () spray ! se>
Date: 2002-02-27 18:29:20
[Download RAW message or body]
Hi
Wanted to learn some of the kword code so I have started trying to implement
line break (shift+enter) cause that is a thing I really miss in kword.
Have attached a patch that I be happy if someone could take a look at and
give some feedback.
Thanks
Krister
--
krister.wicksell@spray.se
http://hem.spray.se/krister.wicksell/
["koffice-20020227.patch" (text/x-diff)]
Index: kword/kwtextparag.cc
===================================================================
RCS file: /home/kde/koffice/kword/kwtextparag.cc,v
retrieving revision 1.189
diff -u -3 -p -u -r1.189 kwtextparag.cc
--- kword/kwtextparag.cc 2002/02/20 13:58:15 1.189
+++ kword/kwtextparag.cc 2002/02/27 18:15:03
@@ -81,17 +81,16 @@ void KWTextParag::drawFormattingChars( Q
KoTextFormat* format = static_cast<KoTextFormat *>( at( length() \
- 1 )->format() );
int w = format->screenFontMetrics(zh).width('x'); // see \
KWTextFrameSet::formatVertically int size = QMIN( w, h_pix * 3 / 4 );
- int arrowsize = zh->zoomItY( 2 );
- // x,y is the bottom right corner of the reversed L
+ // x,y is the bottom right corner of the ¶
//kdDebug() << "startX=" << startX << " bw=" << bw << " w=" << w \
<< endl; int x = ( startX_pix + bw ) + w - 1;
- int y = lastY_pix + baseLine_pix - arrowsize;
+ int y = lastY_pix + baseLine_pix;
//kdDebug() << "KWTextParag::drawFormattingChars drawing CR at " \
<< x << "," << y << endl;
- painter.drawLine( x, y - size, x, y );
- painter.drawLine( x, y, x - size, y );
- // Now the arrow
- painter.drawLine( x - size, y, x - size + arrowsize, y - \
arrowsize );
- painter.drawLine( x - size, y, x - size + arrowsize, y + \
arrowsize ); + painter.drawLine( (int)(x - size * 0.2), y - size, \
(int)(x - size * 0.2), y ); + painter.drawLine( (int)(x - size * \
0.5), y - size, (int)(x - size * 0.5), y ); + painter.drawLine( x, \
y, (int)(x - size * 0.7), y ); + painter.drawLine( x, y - size, \
(int)(x - size * 0.5), y - size); + painter.drawArc( x - size, y - \
size, size, (int)(size / 2), -90*16, -180*16 ); }
}
// Now draw spaces and tabs
@@ -129,6 +128,23 @@ void KWTextParag::drawFormattingChars( Q
painter.drawLine( x + size, y, x - size, y );
painter.drawLine( x + size, y, x + size - arrowsize, y - \
arrowsize );
painter.drawLine( x + size, y, x + size - arrowsize, y + \
arrowsize ); + }
+ else if ( ch.c == 0x0b )
+ {
+ // drawing the end of line
+ int w = zh->layoutUnitToPixelX( string()->width(i) );
+ int size = QMIN( w, h_pix * 3 / 4 );
+ int arrowsize = zh->zoomItY( 2 );
+ // x,y is the bottom right corner of the reversed L
+ //kdDebug() << "startX=" << startX << " bw=" << bw << " w=" << w \
<< endl; + int x = zh->layoutUnitToPixelX( ch.x ) + ch.pixelxadj + \
ch.pixelwidth - 1; + int y = lastY_pix + baseLine_pix - arrowsize;
+ //kdDebug() << "KWTextParag::drawFormattingChars drawing Line \
Break at " << x << "," << y << endl; + painter.drawLine( x, y - \
size, x, y ); + painter.drawLine( x, y, (int)(x - size * 0.7), y \
); + // Now the arrow
+ painter.drawLine( (int)(x - size * 0.7), y, (int)(x - size * 0.7 \
+ arrowsize), y - arrowsize ); + painter.drawLine( (int)(x - size \
* 0.7), y, (int)(x - size * 0.7 + arrowsize), y + arrowsize ); }
}
painter.restore();
Index: kword/kwview.cc
===================================================================
RCS file: /home/kde/koffice/kword/kwview.cc,v
retrieving revision 1.496
diff -u -3 -p -u -r1.496 kwview.cc
--- kword/kwview.cc 2002/02/27 16:42:39 1.496
+++ kword/kwview.cc 2002/02/27 18:15:03
@@ -815,11 +815,14 @@ void KWView::setupActions()
this, SLOT( slotNonbreakingSpace() ), actionCollection(), \
"nonbreaking_space" );
KAction* actSoftHyphen = new KAction( i18n( "Insert soft hyphen" ), \
CTRL+Key_Minus,
this, SLOT( slotSoftHyphen() ), actionCollection(), \
"soft_hyphen" ); + KAction* actLineBreak = new KAction( i18n( "Line break" ), \
SHIFT+Key_Return, + this, SLOT( slotLineBreak() ), \
actionCollection(), "line_break" ); // Necessary for the actions that are not \
plugged anywhere KAccel * accel = new KAccel( this );
actNbsp ->plugAccel( accel );
accel = new KAccel( this ); // needed ?
actSoftHyphen->plugAccel( accel );
+ actLineBreak->plugAccel( accel );
}
void KWView::refreshMenuExpression()
@@ -4190,6 +4193,13 @@ void KWView::showDocStructure()
m_doc->reorganizeGUI();
}
+void KWView::slotSoftHyphen()
+{
+ KWTextFrameSetEdit * edit = currentTextEdit();
+ if ( edit )
+ edit->insertSoftHyphen();
+}
+
void KWView::slotNonbreakingSpace()
{
KWTextFrameSetEdit * edit = currentTextEdit();
@@ -4197,11 +4207,11 @@ void KWView::slotNonbreakingSpace()
edit->insertNonbreakingSpace();
}
-void KWView::slotSoftHyphen()
+void KWView::slotLineBreak()
{
KWTextFrameSetEdit * edit = currentTextEdit();
if ( edit )
- edit->insertSoftHyphen();
+ edit->insertLineBreak();
}
void KWView::refreshAllVariable()
Index: kword/kwview.h
===================================================================
RCS file: /home/kde/koffice/kword/kwview.h,v
retrieving revision 1.138
diff -u -3 -p -u -r1.138 kwview.h
--- kword/kwview.h 2002/02/27 01:12:03 1.138
+++ kword/kwview.h 2002/02/27 18:15:03
@@ -312,6 +312,7 @@ public slots:
void showDocStructure();
void slotSoftHyphen();
+ void slotLineBreak();
void slotNonbreakingSpace();
void refreshAllVariable();
Index: lib/kotext/kotextformatter.cc
===================================================================
RCS file: /home/kde/koffice/lib/kotext/kotextformatter.cc,v
retrieving revision 1.17
diff -u -3 -p -u -r1.17 kotextformatter.cc
--- lib/kotext/kotextformatter.cc 2002/02/18 14:31:24 1.17
+++ lib/kotext/kotextformatter.cc 2002/02/27 18:15:03
@@ -197,8 +197,54 @@ int KoTextFormatter::format( Qt3::QTextD
#ifdef DEBUG_FORMATTER
qDebug("c='%c' i=%d/%d x=%d ww=%d w=%d (test is x+ww>w) lastBreak=%d \
isBreakable=%d",c->c.latin1(),i,len,x,ww,w,lastBreak,isBreakable(string,i)); #endif
- // Wrapping at end of line
- if ( wrapEnabled
+ // Line break found
+ if ( lastChr == 0x0b ) {
+ int belowBaseLine = QMAX( h - lineStart->baseLine, tmph - tmpBaseLine );
+ lineStart->baseLine = QMAX( lineStart->baseLine, tmpBaseLine );
+ h = lineStart->baseLine + belowBaseLine;
+ lineStart->h = h;
+
+ KoTextStringChar *lc = &string->at( i-1 );
+ QTextParagLineStart *lineStart2 = formatLineKo( zh, parag, string, lineStart, \
firstChar, c-1, align, w - x + lc->width); + lineStart->h += doc ? \
parag->lineSpacing( linenr++ ) : 0; + y += lineStart->h;
+#ifdef DEBUG_FORMATTER
+ qDebug( "BREAKING" );
+ qDebug( "line break found and new line created, linenr now %d", linenr );
+#endif
+ lineStart = lineStart2;
+ tmph = c->height();
+ h = 0;
+ x = doc ? doc->flow()->adjustLMargin( y + parag->rect().y(), tmph, left, 4 ) : \
left; + pixelx = zh->layoutUnitToPixelX( x );
+ initialHeight = tmph;
+ initialLMargin = x;
+ initialRMargin = ( doc ? doc->flow()->adjustRMargin( y + parag->rect().y(), tmph, \
rm, 4 ) : 0 ); + w = dw - initialRMargin;
+ if ( c->c == '\t' ) {
+ int nx = parag->nextTab( i, x );
+ if ( nx < x )
+ ww = w - x;
+ else
+ ww = nx - x + 1;
+ pixelww = zh->layoutUnitToPixelX( ww );
+ c->width = ww;
+ }
+ if ( x != left || w != dw )
+ fullWidth = FALSE;
+ pixelx = zh->layoutUnitToPixelX( x );
+ curLeft = x;
+ lineStart->y = y;
+ insertLineStart( parag, i, lineStart );
+ lineStart->baseLine = c->ascent();
+ lineStart->h = c->height();
+ c->lineStart = 1;
+ firstChar = c;
+ tmpBaseLine = lineStart->baseLine;
+ lastBreak = -1;
+ col = 0;
+ tminw = marg;
+ } else if ( wrapEnabled // Wrapping at end of line
// Allow ' ' but not more
&& ( !isBreakable( string, i ) || ( i > 1 && lastBreak == i-1 && isBreakable( \
string, i-2 ) ) || lastBreak == -2 )
Index: lib/kotext/kotextparag.cc
===================================================================
RCS file: /home/kde/koffice/lib/kotext/kotextparag.cc,v
retrieving revision 1.38
diff -u -3 -p -u -r1.38 kotextparag.cc
--- lib/kotext/kotextparag.cc 2002/02/21 21:30:31 1.38
+++ lib/kotext/kotextparag.cc 2002/02/27 18:15:03
@@ -522,6 +522,9 @@ void KoTextParag::drawParagStringInterna
if ( dir != QPainter::RTL && start + len == length() ) // don't draw the last \
character (trailing space) len--;
+ if ( str[ start + len - 1 ] == 0x0b ) // don't draw line break
+ len--;
+
if ( str[ start ] != '\t' && str[ start ].unicode() != 0xad ) {
if ( lastFormat->vAlign() == QTextFormat::AlignNormal ) {
painter.drawText( startX, lastY + baseLine, str, start, len, dir );
Index: lib/kotext/kotextview.cc
===================================================================
RCS file: /home/kde/koffice/lib/kotext/kotextview.cc,v
retrieving revision 1.40
diff -u -3 -p -u -r1.40 kotextview.cc
--- lib/kotext/kotextview.cc 2002/02/27 01:10:45 1.40
+++ lib/kotext/kotextview.cc 2002/02/27 18:15:03
@@ -939,6 +939,12 @@ void KoTextView::insertSoftHyphen()
false /* no newline */, true, i18n("Insert Soft Hyphen") \
); }
+void KoTextView::insertLineBreak()
+{
+ textObject()->insert( cursor(), currentFormat(), QChar(0x0b),
+ false /* no newline */, true, i18n("Insert Line Break") );
+}
+
void KoTextView::insertNonbreakingSpace()
{
textObject()->insert( cursor(), currentFormat(), QChar(0xa0) /* see QRichText \
*/,
Index: lib/kotext/kotextview.h
===================================================================
RCS file: /home/kde/koffice/lib/kotext/kotextview.h,v
retrieving revision 1.31
diff -u -3 -p -u -r1.31 kotextview.h
--- lib/kotext/kotextview.h 2002/02/27 01:10:45 1.31
+++ lib/kotext/kotextview.h 2002/02/27 18:15:03
@@ -120,6 +120,7 @@ public:
void insertSoftHyphen();
+ void insertLineBreak();
void insertNonbreakingSpace();
void insertSpecialChar(QChar _c);
void changeCaseOfText(KoChangeCaseDia::TypeOfCase _type);
_______________________________________________
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