From 0aba5d1ec2856487f8608fee32754fbc61af6de4 Mon Sep 17 00:00:00 2001 From: Thomas Zander Date: Wed, 8 Jun 2005 14:08:58 +0000 Subject: [PATCH] Implement a smarter quoting for 'paste as quotation' and 'add quotation marks'. This method adds a quoteation mark on each line and takes into account the max-column size of the email composer to avoid words getting wrapped later and being printed without any quotation marks. BUG:70161 svn path=/trunk/KDE/kdepim/; revision=423473 --- kmcomposewin.cpp | 53 ++++++++++++++++++++++++++++++++++-------------- kmcomposewin.h | 2 ++ 2 files changed, 40 insertions(+), 15 deletions(-) diff --git a/kmcomposewin.cpp b/kmcomposewin.cpp index fa590d838..68cb4ccbf 100644 --- a/kmcomposewin.cpp +++ b/kmcomposewin.cpp @@ -3240,17 +3240,9 @@ void KMComposeWin::slotPasteAsQuotation() { if( mEditor->hasFocus() && msg() ) { - QString quotePrefix = quotePrefixName(); QString s = QApplication::clipboard()->text(); - if (!s.isEmpty()) { - for (int i=0; (uint)iinsert(s); - } + if (!s.isEmpty()) + mEditor->insert(addQuotesToText(s)); } } @@ -3284,11 +3276,9 @@ void KMComposeWin::slotAddQuotes() if( mEditor->hasFocus() && msg() ) { if ( mEditor->hasMarkedText()) { - QString s = mEditor->markedText(); - QString quotePrefix = quotePrefixName(); - s.prepend(quotePrefix); - s.replace("\n", "\n"+quotePrefix); - mEditor->insert(s); + QString s = mEditor->markedText(); + if(!s.isEmpty()) + mEditor->insert(addQuotesToText(s)); } else { int l = mEditor->currentLine(); int c = mEditor->currentColumn(); @@ -3301,6 +3291,39 @@ void KMComposeWin::slotAddQuotes() } } +QString KMComposeWin::addQuotesToText(const QString &inputText) +{ + QString answer = QString(quotePrefixName()); + int sentenceLength = 0; + for (unsigned int i=0; (uint)i 0 && inputText[i-1] == ' ') + continue; + sentenceLength = 1; + answer.append('\n'); + if(i < inputText.length()) + answer.append(quotePrefixName()); + continue; + } + else if(sentenceLength > GlobalSettings::lineWrapWidth()) { + unsigned int back = answer.length(); + while(answer[back] != ' ' && back > 0) + back--; + if(back != 0) { + answer.insert(back+1, quotePrefixName()); + answer.insert(back+1, "\n"); + } + sentenceLength = 0; + } + + if ( inputText[i] < ' ' && inputText[i] != '\t' ) + answer.append(' '); + else + answer.append(inputText[i]); + sentenceLength++; + } + return answer; +} void KMComposeWin::slotRemoveQuotes() { diff --git a/kmcomposewin.h b/kmcomposewin.h index 51733c11c..84af1bb48 100644 --- a/kmcomposewin.h +++ b/kmcomposewin.h @@ -905,6 +905,8 @@ private: bool mSubjectTextWasSpellChecked; + QString addQuotesToText(const QString &inputText); + private slots: void slotCompletionModeChanged( KGlobalSettings::Completion ); void slotConfigChanged();