1 /* This file is part of the KDE libraries
2 Copyright (C) 2000 Malte Starostik <malte@kde.org>
3 Copyright (C) 2006 Roberto Cappuccio <roberto.cappuccio@gmail.com>
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
21 #include "htmlcreator.h"
29 #include <kapplication.h>
30 #include <khtml_part.h>
34 KDE_EXPORT ThumbCreator
*new_creator()
36 return new HTMLCreator
;
40 HTMLCreator::HTMLCreator()
45 HTMLCreator::~HTMLCreator()
50 bool HTMLCreator::create(const QString
&path
, int width
, int height
, QImage
&img
)
54 m_html
= new KHTMLPart
;
55 connect(m_html
, SIGNAL(completed()), SLOT(slotCompleted()));
56 m_html
->setJScriptEnabled(false);
57 m_html
->setJavaEnabled(false);
58 m_html
->setPluginsEnabled(false);
59 m_html
->setMetaRefreshEnabled(false);
60 m_html
->setOnlyLocalReferences(true);
66 int t
= startTimer(5000);
68 m_eventLoop
.exec(QEventLoop::ExcludeUserInputEvents
);
72 // render the HTML page on a bigger pixmap and use smoothScale,
73 // looks better than directly scaling with the QPainter (malte)
75 if (width
> 400 || height
> 600)
77 if (height
* 3 > width
* 4)
78 pix
= QPixmap(width
, width
* 4 / 3);
80 pix
= QPixmap(height
* 3 / 4, height
);
83 pix
= QPixmap(400, 600);
85 // light-grey background, in case loadind the page failed
86 pix
.fill( QColor( 245, 245, 245 ) );
88 int borderX
= pix
.width() / width
,
89 borderY
= pix
.height() / height
;
90 QRect
rc(borderX
, borderY
, pix
.width() - borderX
* 2, pix
.height() - borderY
* 2);
94 m_html
->paint(&p
, rc
);
104 void HTMLCreator::timerEvent(QTimerEvent
*)
109 void HTMLCreator::slotCompleted()
114 ThumbCreator::Flags
HTMLCreator::flags() const
119 #include "htmlcreator.moc"