1/*
2 Copyright (c) 2012 Montel Laurent <montel@kde.org>
3
4 This library is free software; you can redistribute it and/or modify it
5 under the terms of the GNU Library General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or (at your
7 option) any later version.
8
9 This library is distributed in the hope that it will be useful, but WITHOUT
10 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
12 License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to the
16 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17 02110-1301, USA.
18
19*/
20
21#include "inserthtmldialog.h"
22#include "htmlhighlighter.h"
23
24#include <KLocalizedString>
25#include <KTextEdit>
26
27#include <QVBoxLayout>
28#include <QLabel>
29
30namespace KPIMTextEdit {
31
32class InsertHtmlDialogPrivate
33{
34 public:
35 InsertHtmlDialogPrivate( InsertHtmlDialog *qq )
36 : q( qq )
37 {
38 q->setCaption( i18n( "Insert HTML" ) );
39 q->setButtons( KDialog::Ok|KDialog::Cancel );
40 q->setButtonText( KDialog::Ok, i18n( "Insert" ) );
41 QWidget *page = new QWidget( q );
42 q->setMainWidget( page );
43 QVBoxLayout *lay = new QVBoxLayout( page );
44 QLabel *label = new QLabel( i18n( "Insert HTML tags and texts:" ) );
45 lay->addWidget( label );
46 editor = new KTextEdit;
47 new HtmlHighlighter( editor->document() );
48 editor->setAcceptRichText( false );
49 editor->setFocus();
50 lay->addWidget( editor );
51 label = new QLabel( i18n( "Example: <i> Hello word </i>" ) );
52 QFont font = label->font();
53 font.setBold( true );
54 label->setFont( font );
55 label->setTextFormat( Qt::PlainText );
56 lay->addWidget( label );
57 q->connect( editor, SIGNAL(textChanged()),
58 q, SLOT(_k_slotTextChanged()) );
59 q->enableButtonOk( false );
60 q->resize( 640, 480 );
61 }
62
63 void _k_slotTextChanged();
64
65 KTextEdit *editor;
66 InsertHtmlDialog *q;
67};
68
69void InsertHtmlDialogPrivate::_k_slotTextChanged()
70{
71 q->enableButtonOk( !editor->toPlainText().isEmpty() );
72}
73
74InsertHtmlDialog::InsertHtmlDialog( QWidget *parent )
75 : KDialog( parent ), d( new InsertHtmlDialogPrivate( this ) )
76{
77}
78
79InsertHtmlDialog::~InsertHtmlDialog()
80{
81 delete d;
82}
83
84QString InsertHtmlDialog::html() const
85{
86 return d->editor->toPlainText();
87}
88
89}
90
91#include "moc_inserthtmldialog.cpp"
92