Dear visitor, welcome to KDE-Forum.org. If this is your first visit here, please read the Help. It explains in detail how this page works. To use all features of this page, you should consider registering. Please use the registration form, to register here or read more information about the registration process. If you are already registered, please login here.
Source code |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 |
/*************************************************************************** * Copyright (C) 2007 by Lawrence Lee * * valheru@facticius.net * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ #include <kstandarddirs.h> #include <kapplication.h> #include <kmimetype.h> #include <time.h> #include <qpixmap.h> #include <qimage.h> #include <qpainter.h> #include <khtml_part.h> #include <qfile.h> #include <qimage.h> #include <qtextstream.h> #include "knfoviewerthumbnail.h" #include "cp437codec.h" extern "C" { ThumbCreator *new_creator() { return new KNfoViewerThumbnail(); } } /* * This code is taken nearly verbatim from htmlcreator.cpp * in kdebase/kioslave/thumbnail/ with minor changes to * ensure the correct rendering of CP437 encoded characters. */ KNfoViewerThumbnail::KNfoViewerThumbnail() : m_html( 0 ) { } KNfoViewerThumbnail::~KNfoViewerThumbnail() { delete m_html; } bool KNfoViewerThumbnail::create( const QString &path, int width, int height, QImage &img ) { if (!m_html) { m_html = new KHTMLPart; connect(m_html, SIGNAL(completed()), SLOT(slotCompleted())); m_html->setJScriptEnabled(false); m_html->setJavaEnabled(false); m_html->setPluginsEnabled(false); m_html->setMetaRefreshEnabled(false); m_html->setOnlyLocalReferences(true); } KURL url; url.setPath( path ); // QFile file( url.url() ); // if( !file.open( IO_ReadOnly ) ) // return false; // QString text; // QTextStream stream( &file ); // CP437Codec codec; // stream.setCodec( &codec ); // // while( !stream.atEnd() ){ // text += stream.readLine() + "\n"; // } // m_html->begin(); // m_html->write( htmlCode( text ) ); // m_html->end(); m_html->openURL(url); int t = startTimer(5000); qApp->enter_loop(); killTimer(t); // render the HTML page on a bigger pixmap and use smoothScale, // looks better than directly scaling with the QPainter (malte) QPixmap pix; if (width > 400 || height > 600) { if (height * 3 > width * 4) pix.resize(width, width * 4 / 3); else pix.resize(height * 3 / 4, height); } else pix.resize(400, 600); // light-grey background, in case loadind the page failed pix.fill( QColor( 245, 245, 245 ) ); int borderX = pix.width() / width, borderY = pix.height() / height; QRect rc(borderX, borderY, pix.width() - borderX * 2, pix.height() - borderY * 2); QPainter p; p.begin(&pix); m_html->paint(&p, rc); p.end(); img = pix.convertToImage(); m_html->closeURL(); return true; } const QString KNfoViewerThumbnail::htmlCode( const QString &text ) { QString code = "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">\n\ <html>\n\ <head>\n\ <meta http-equiv=\"Content-Type\" content=\"text/html; charset=ISO-8859-1\" />\n\ <style type=\"text/css\" media=\"screen\"><!--\n\ body {\n \ color : #000000;\n\ background-color: #ffffff;\n\ margin: 0px;\n\ }\n\ #nfo {\n\ color: #000000;\n\ background-color: transparent;\n\ text-align: center;\n\ position: absolute;\n\ top: 0px;\n\ left: 0px;\n\ width: 100%;\n\ height: 100%;\n\ overflow: visible;\n\ visibility: visible;\n\ display: block\n\ }\n\ #data {\n\ font-size: 11px;\n\ font-family: \"Andale Mono\";\n\ line-height: 11px;\n\ background-color: #ffffff;\n\ color: #000000;\n\ position: relative;\n\ white-space: pre;\n\ visibility : visible;\n\ }\n\ a {\n\ color: #000000;\n\ text-decoration: none;\n\ }\n\ a:hover {\n\ color: #000000;\n\ text-decoration: none;\n\ }\n\ --></style>\n\ </head>\n\ <body>\n\ <div id\"nfo\">\n\ <div id=\"data\">\n"; code += text; code += "<br></div></div><br/></body></html>"; return code; } void KNfoViewerThumbnail::timerEvent(QTimerEvent *) { qApp->exit_loop(); } void KNfoViewerThumbnail::slotCompleted() { qApp->exit_loop(); } ThumbCreator::Flags KNfoViewerThumbnail::flags() const { return DrawFrame; } #include "knfoviewerthumbnail.moc" |
Source code |
|
1 2 3 4 |
QFile file( url.url() ); if( !file.open( IO_ReadOnly ) ) return false; |
Forum Software: Burning Board®, developed by WoltLab® GmbH
Linux Computer - Linux Forum -
Linux Computer und Notebooks - Lastminute - Wasserbetten & Whirlpools