split message into several paras and fix file extension markup
[kdepim.git] / knode / kncomposereditor.cpp
bloba52a7227c03c8ed0f42ee27154fe6fcc121d7cd6
1 /**
2 * kncomposereditor.cpp
4 * Copyright (C) 2008 Laurent Montel <montel@kde.org>
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19 * 02110-1301 USA
22 #include "kncomposereditor.h"
23 #include "kncomposereditor.moc"
24 #include "knglobals.h"
25 #include "utilities.h"
26 #include <KPIMTextEdit/EMailQuoteHighlighter>
27 #include <KConfigGroup>
28 #include <QApplication>
29 #include <messagecomposer/utils/util.h>
31 KNComposerEditor::KNComposerEditor( QWidget *parent)
32 :KMeditor(parent)
34 setSpellCheckingConfigFileName( KNGlobals::self()->config()->name() );
37 KNComposerEditor::~KNComposerEditor()
41 void KNComposerEditor::changeHighlighterColors(KPIMTextEdit::EMailQuoteHighlighter * highlighter )
43 KConfigGroup config( knGlobals.config(), "VISUAL_APPEARANCE" );
44 QColor defaultColor1( 0x00, 0x80, 0x00 ); // defaults from kmreaderwin.cpp
45 QColor defaultColor2( 0x00, 0x70, 0x00 );
46 QColor defaultColor3( 0x00, 0x60, 0x00 );
47 QColor defaultForeground( qApp->palette().color( QPalette::Text ) );
48 QColor col1 = config.readEntry( "ForegroundColor", defaultForeground );
49 QColor col2 = config.readEntry( "quote3Color", defaultColor3 );
50 QColor col3 = config.readEntry( "quote2Color", defaultColor2 );
51 QColor col4 = config.readEntry( "quote1Color", defaultColor1 );
53 highlighter->setQuoteColor(col1, col2, col3, col4);
56 void KNComposerEditor::slotRot13()
58 QTextCursor cursor = textCursor();
59 if ( cursor.hasSelection() )
60 insertPlainText( MessageComposer::Util::rot13( cursor.selectedText() ) );
61 //FIXME: breaks HTML formatting
65 void KNComposerEditor::slotRemoveBox()
67 //Laurent: fix me
68 #if 0
69 if (hasMarkedText()) {
70 QString s = QString::fromLatin1("\n") + markedText() + QString::fromLatin1("\n");
71 s.replace(QRegExp("\n,----[^\n]*\n"),"\n");
72 s.replace(QRegExp("\n| "),"\n");
73 s.replace(QRegExp("\n`----[^\n]*\n"),"\n");
74 s.remove(0,1);
75 s.truncate(s.length()-1);
76 insert(s);
77 } else {
78 int l = currentLine();
79 int c = currentColumn();
81 QString s = textLine(l); // test if we are in a box
82 if (!((s.left(2) == "| ")||(s.left(5)==",----")||(s.left(5)=="`----")))
83 return;
85 setAutoUpdate(false);
87 // find & remove box begin
88 int x = l;
89 while ((x>=0)&&(textLine(x).left(5)!=",----"))
90 x--;
91 if ((x>=0)&&(textLine(x).left(5)==",----")) {
92 removeLine(x);
93 l--;
94 for (int i=x;i<=l;++i) { // remove quotation
95 s = textLine(i);
96 if (s.left(2) == "| ") {
97 s.remove(0,2);
98 insertLine(s,i);
99 removeLine(i+1);
104 // find & remove box end
105 x = l;
106 while ((x<numLines())&&(textLine(x).left(5)!="`----"))
107 x++;
108 if ((x<numLines())&&(textLine(x).left(5)=="`----")) {
109 removeLine(x);
110 for (int i=l+1;i<x;++i) { // remove quotation
111 s = textLine(i);
112 if (s.left(2) == "| ") {
113 s.remove(0,2);
114 insertLine(s,i);
115 removeLine(i+1);
120 setCursorPosition(l,c-2);
122 setAutoUpdate(true);
123 repaint();
125 #endif
128 void KNComposerEditor::slotAddBox()
130 MessageComposer::Util::addTextBox(this);