(*** This bug was imported into bugs.kde.org ***) Package: kspread Version: pre-Beta1 (checked out from CVS 2000-08-30) Severity: wishlist Description: It would be useful to be able to manually control linebreaks within a multi-row cell. A suggestion if this is implemented is that the linebreak is inserted via "some key e.g. Crtl or Alt" + "Enter" (pressed simultaneously). /Lasse
*** Bug 38463 has been marked as a duplicate of this bug. ***
Replaced lasse.jansson@telia.com with rupert.kolb@med.uni-tuebingen.de due to bounces by reporter
*** Bug 115324 has been marked as a duplicate of this bug. ***
SVN commit 486743 by raphael: BUG: 9881 Allow manual line breaks. Updated cell rendering to honor manual line breaks. A line break can be inserted with Shift+Return while editing a cell in-place (NOT the formula editor at the top) The line break will ONLY be visible if text wrap itself is turned on (Cell Format -> Position -> Wrap text). Please note that the Shift+Return key combination is already present in the KTextEdit class that is used for in-place editing of cells, so there is no extra code for key handling required. M +2 -0 CHANGES M +52 -26 kspread_cell.cc M +1 -48 kspread_editors.cc --- trunk/koffice/kspread/CHANGES #486742:486743 @@ -12,6 +12,8 @@ - Fix date (and time) increment for autofill (#117252) - Always allow date input in ISO 8601 format, regardless of local settings (#50192) - Fix cell protection (#116444) +- Fix freeze with certain spreadsheet content (#116702) +- Implement manual line wrap (#9881) Some important developer visible changes: - Decouple KSpread::Cell and KSpread::Format (association instead of inheritance) --- trunk/koffice/kspread/kspread_cell.cc #486742:486743 @@ -140,7 +140,7 @@ Conditions *conditions; Validity *validity; - // Store the number of line when you multirow is used (default is 0) + // Store the number of line when multirow is used (default is 0) int nbLines; private: @@ -1301,12 +1301,16 @@ && format()->multiRow( _col, _row ) ) { // Copy of d->strOutText but without the newlines. - QString o = d->strOutText.replace( QChar('\n'), " " ); +// QString o = d->strOutText.replace( QChar('\n'), " " ); + // don't remove the existing LF, these are intended line wraps (whishlist #9881) + QString o = d->strOutText; + // Break the line at appropriate places, i.e. spaces, if // necessary. This means to change the spaces where breaks occur // into newlines. - if ( o.find(' ') != -1 ) { + if ( o.find(' ') != -1 ) + { d->strOutText = ""; // Make sure that we have a space at the end. @@ -1320,35 +1324,57 @@ - format()->rightBorderWidth( _col, _row ) ); do { - breakpos = o.find( ' ', breakpos ); - double lineWidth = format()->sheet()->doc() - ->unzoomItX( fm.width( d->strOutText.mid( start, (pos1 - start) ) - + o.mid( pos1, breakpos - pos1 ) ) ); - if ( lineWidth <= availableWidth ) { - // We have room for the rest of the line. End it here. - d->strOutText += o.mid( pos1, breakpos - pos1 ); - pos1 = breakpos; - } - else { - // Still not enough room. Try to split further. - if ( o.at( pos1 ) == ' ' ) - pos1++; + breakpos = o.find( ' ', breakpos ); + int linefeed = o.find( '\n', pos1 ); - if ( pos1 != 0 && breakpos != -1 ) { - d->strOutText += "\n" + o.mid( pos1, breakpos - pos1 ); - lines++; - } - else - d->strOutText += o.mid( pos1, breakpos - pos1 ); +// kdDebug() << "start: " << start << "; breakpos: " << breakpos << "; pos1: " << pos1 << "; linefeed: " << linefeed << endl; - start = pos1; - pos1 = breakpos; - } + //don't miss LF as a position to calculate current lineWidth + int work_breakpos = breakpos; + if (pos1 < linefeed && linefeed < breakpos) + work_breakpos = linefeed; - breakpos++; + double lineWidth = format()->sheet()->doc() + ->unzoomItX( fm.width( d->strOutText.mid( start, (pos1 - start) ) + + o.mid( pos1, work_breakpos - pos1 ) ) ); + + //linefeed could be -1 when no linefeed is found! + if (breakpos > linefeed && linefeed > 0) + { +// kdDebug() << "applying linefeed to start;" << endl; + start = linefeed; + lines++; + } + + if ( lineWidth <= availableWidth ) { + // We have room for the rest of the line. End it here. + d->strOutText += o.mid( pos1, breakpos - pos1 ); + pos1 = breakpos; + } + else { + // Still not enough room. Try to split further. + if ( o.at( pos1 ) == ' ' ) + pos1++; + + if ( pos1 != 0 && breakpos != -1 ) { + d->strOutText += "\n" + o.mid( pos1, breakpos - pos1 ); + lines++; + } + else + d->strOutText += o.mid( pos1, breakpos - pos1 ); + + start = pos1; + pos1 = breakpos; + } + + breakpos++; } while( o.find( ' ', breakpos ) != -1 ); } + else + { + lines = o.contains('\n'); + } d->textHeight *= lines; if (lines > 1) --- trunk/koffice/kspread/kspread_editors.cc #486742:486743 @@ -768,60 +768,13 @@ void TextEditor::handleKeyPressEvent( QKeyEvent * _ev ) { - /* Qt 4 code: - if (_ev->key() == Qt::Key_Enter && _ev->modifiers() == Qt::ShiftModifier) + if (_ev->key() == Qt::Key_F4) { if (m_pEdit == 0) { QApplication::sendEvent( m_pEdit, _ev ); return; } - - int cursor_pos = m_pEdit->cursorPosition(); - QString left = m_pEdit->text().left(cursor_pos); - QString right = m_pEdit->text().right(cursor_pos+1); - - if (!right.isEmpty()) - { - m_pEdit->setText(left + "\n" + right); - m_pEdit->setCursorPosition(cursor_pos+1); - } - - return; - } - */ - - if (_ev->key() == Qt::Key_Enter && _ev->state() & ShiftButton == ShiftButton) - { - kdDebug() << "Detected desire for a manual LF character" << endl; - if (m_pEdit == 0) - { - QApplication::sendEvent( m_pEdit, _ev ); - return; - } - - int para, cur; - m_pEdit->getCursorPosition(¶,&cur); - QString left = m_pEdit->text().left(cur); - QString right = m_pEdit->text().right(cur+1); - - if (!right.isEmpty()) - { - kdDebug() << "Inserting a LF character at paragraph " << para << " and index " << cur << endl; - m_pEdit->setText(left + "\n" + right); - m_pEdit->setCursorPosition(para+1,0); - } - - return; - } - - else if (_ev->key() == Qt::Key_F4) - { - if (m_pEdit == 0) - { - QApplication::sendEvent( m_pEdit, _ev ); - return; - } QRegExp exp("(\\$?)([a-zA-Z]+)(\\$?)([0-9]+)$");