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
22 #include "kncomposereditor.h"
23 #include "knglobals.h"
24 #include "utilities.h"
25 #include <KPIMTextEdit/EMailQuoteHighlighter>
26 #include <KConfigGroup>
27 #include <QApplication>
28 #include <messagecomposer/utils/util.h>
30 KNComposerEditor::KNComposerEditor( QWidget
*parent
)
33 setSpellCheckingConfigFileName( KNGlobals::self()->config()->name() );
36 KNComposerEditor::~KNComposerEditor()
40 void KNComposerEditor::changeHighlighterColors(KPIMTextEdit::EMailQuoteHighlighter
* highlighter
)
42 KConfigGroup
config( knGlobals
.config(), "VISUAL_APPEARANCE" );
43 QColor
defaultColor1( 0x00, 0x80, 0x00 ); // defaults from kmreaderwin.cpp
44 QColor
defaultColor2( 0x00, 0x70, 0x00 );
45 QColor
defaultColor3( 0x00, 0x60, 0x00 );
46 QColor
defaultForeground( qApp
->palette().color( QPalette::Text
) );
47 QColor col1
= config
.readEntry( "ForegroundColor", defaultForeground
);
48 QColor col2
= config
.readEntry( "quote3Color", defaultColor3
);
49 QColor col3
= config
.readEntry( "quote2Color", defaultColor2
);
50 QColor col4
= config
.readEntry( "quote1Color", defaultColor1
);
52 highlighter
->setQuoteColor(col1
, col2
, col3
, col4
);
55 void KNComposerEditor::slotRot13()
57 QTextCursor cursor
= textCursor();
58 if ( cursor
.hasSelection() )
59 insertPlainText( MessageComposer::Util::rot13( cursor
.selectedText() ) );
60 //FIXME: breaks HTML formatting
64 void KNComposerEditor::slotRemoveBox()
68 if (hasMarkedText()) {
69 QString s
= QString::fromLatin1("\n") + markedText() + QString::fromLatin1("\n");
70 s
.replace(QRegExp("\n,----[^\n]*\n"),"\n");
71 s
.replace(QRegExp("\n| "),"\n");
72 s
.replace(QRegExp("\n`----[^\n]*\n"),"\n");
74 s
.truncate(s
.length()-1);
77 int l
= currentLine();
78 int c
= currentColumn();
80 QString s
= textLine(l
); // test if we are in a box
81 if (!((s
.left(2) == "| ")||(s
.left(5)==",----")||(s
.left(5)=="`----")))
86 // find & remove box begin
88 while ((x
>=0)&&(textLine(x
).left(5)!=",----"))
90 if ((x
>=0)&&(textLine(x
).left(5)==",----")) {
93 for (int i
=x
;i
<=l
;++i
) { // remove quotation
95 if (s
.left(2) == "| ") {
103 // find & remove box end
105 while ((x
<numLines())&&(textLine(x
).left(5)!="`----"))
107 if ((x
<numLines())&&(textLine(x
).left(5)=="`----")) {
109 for (int i
=l
+1;i
<x
;++i
) { // remove quotation
111 if (s
.left(2) == "| ") {
119 setCursorPosition(l
,c
-2);
127 void KNComposerEditor::slotAddBox()
129 MessageComposer::Util::addTextBox(this);