1/*
2 This file is part of libkdepim.
3
4 Copyright (c) 2004 Tobias Koenig <tokoe@kde.org>
5
6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Library General Public
8 License as published by the Free Software Foundation; either
9 version 2 of the License, or (at your option) any later version.
10
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 Library General Public License for more details.
15
16 You should have received a copy of the GNU Library General Public License
17 along with this library; see the file COPYING.LIB. If not, write to
18 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 Boston, MA 02110-1301, USA.
20*/
21
22#include "htmldiffalgodisplay.h"
23#include <KColorScheme>
24#include <QTextDocument>
25
26using namespace KPIM;
27
28static QString textToHTML( const QString &text )
29{
30 return Qt::convertFromPlainText( text );
31}
32
33HTMLDiffAlgoDisplay::HTMLDiffAlgoDisplay( QWidget *parent )
34 : KTextBrowser( parent )
35{
36 setWordWrapMode( QTextOption::WrapAtWordBoundaryOrAnywhere );
37 setHorizontalScrollBarPolicy ( Qt::ScrollBarAlwaysOff );
38 setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff );
39}
40
41void HTMLDiffAlgoDisplay::begin()
42{
43 clear();
44 mText.clear();
45
46 mText.append( QLatin1String("<html>") );
47 mText.append( QString::fromLatin1( "<body text=\"%1\" bgcolor=\"%2\">" )
48 .arg( KColorScheme( QPalette::Active, KColorScheme::View ).foreground().color().name() )
49 .arg( KColorScheme( QPalette::Active, KColorScheme::View ).background().color().name() ) );
50
51 mText.append( QLatin1String("<center><table>") );
52 mText.append( QString::fromLatin1( "<tr><th></th><th align=\"center\">%1</th><td> </td><th align=\"center\">%2</th></tr>" )
53 .arg( mLeftTitle )
54 .arg( mRightTitle ) );
55}
56
57void HTMLDiffAlgoDisplay::end()
58{
59 mText.append( QLatin1String("</table></center>"
60 "</body>"
61 "</html>") );
62
63 setHtml( mText );
64}
65
66void HTMLDiffAlgoDisplay::setLeftSourceTitle( const QString &title )
67{
68 mLeftTitle = title;
69}
70
71void HTMLDiffAlgoDisplay::setRightSourceTitle( const QString &title )
72{
73 mRightTitle = title;
74}
75
76void HTMLDiffAlgoDisplay::additionalLeftField( const QString &id, const QString &value )
77{
78 mText.append( QString::fromLatin1( "<tr><td align=\"right\"><b>%1:</b></td><td bgcolor=\"#9cff83\">%2</td><td></td><td></td></tr>" )
79 .arg( id )
80 .arg( textToHTML( value ) ) );
81}
82
83void HTMLDiffAlgoDisplay::additionalRightField( const QString &id, const QString &value )
84{
85 mText.append( QString::fromLatin1( "<tr><td align=\"right\"><b>%1:</b></td><td></td><td></td><td bgcolor=\"#9cff83\">%2</td></tr>" )
86 .arg( id )
87 .arg( textToHTML( value ) ) );
88}
89
90void HTMLDiffAlgoDisplay::conflictField( const QString &id, const QString &leftValue,
91 const QString &rightValue )
92{
93 mText.append( QString::fromLatin1( "<tr><td align=\"right\"><b>%1:</b></td><td bgcolor=\"#ff8686\">%2</td><td></td><td bgcolor=\"#ff8686\">%3</td></tr>" )
94 .arg( id )
95 .arg( textToHTML( leftValue ) )
96 .arg( textToHTML( rightValue ) ) );
97}
98