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 "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
)
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()
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");
75 s
.truncate(s
.length()-1);
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)=="`----")))
87 // find & remove box begin
89 while ((x
>=0)&&(textLine(x
).left(5)!=",----"))
91 if ((x
>=0)&&(textLine(x
).left(5)==",----")) {
94 for (int i
=x
;i
<=l
;++i
) { // remove quotation
96 if (s
.left(2) == "| ") {
104 // find & remove box end
106 while ((x
<numLines())&&(textLine(x
).left(5)!="`----"))
108 if ((x
<numLines())&&(textLine(x
).left(5)=="`----")) {
110 for (int i
=l
+1;i
<x
;++i
) { // remove quotation
112 if (s
.left(2) == "| ") {
120 setCursorPosition(l
,c
-2);
128 void KNComposerEditor::slotAddBox()
130 MessageComposer::Util::addTextBox(this);