00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include <QImage>
00021 #include <QModelIndex>
00022 #include <QTextDocument>
00023 #include <QUrl>
00024 #include <klocale.h>
00025 #include "KoDocumentSectionModel.h"
00026 #include "KoDocumentSectionToolTip.h"
00027
00028 KoDocumentSectionToolTip::KoDocumentSectionToolTip()
00029 {
00030 }
00031
00032 KoDocumentSectionToolTip::~KoDocumentSectionToolTip()
00033 {
00034 }
00035
00036 QTextDocument *KoDocumentSectionToolTip::createDocument( const QModelIndex &index )
00037 {
00038 QTextDocument *doc = new QTextDocument( this );
00039
00040 QImage thumb = index.data( int( Model::BeginThumbnailRole ) + 250 ).value<QImage>();
00041 doc->addResource( QTextDocument::ImageResource, QUrl( "data:thumbnail" ), thumb );
00042
00043 QString name = index.data( Qt::DisplayRole ).toString();
00044 Model::PropertyList properties = index.data( Model::PropertiesRole ).value<Model::PropertyList>();
00045 QString rows;
00046 for( int i = 0, n = properties.count(); i < n; ++i )
00047 {
00048 const QString row = QString( "<tr><td align=\"right\">%1</td><td align=\"left\">%2</td></tr>" );
00049 const QString value = properties[i].isMutable
00050 ? ( properties[i].state.toBool() ? i18n( "Yes" ) : i18n( "No" ) )
00051 : properties[i].state.toString();
00052 rows.append( row.arg( i18n( "%1:", properties[i].name ) ).arg( value ) );
00053 }
00054
00055 rows = QString( "<table>%1</table>" ).arg( rows );
00056
00057 const QString image = QString( "<table border=\"1\"><tr><td><img src=\"data:thumbnail\"></td></tr></table>" );
00058 const QString body = QString( "<h3 align=\"center\">%1</h3>" ).arg( name )
00059 + QString( "<table><tr><td>%1</td><td>%2</td></tr></table>" ).arg( image ).arg( rows );
00060 const QString html = QString( "<html><body>%1</body></html>" ).arg( body );
00061
00062 doc->setHtml( html );
00063 doc->setTextWidth( qMin( doc->size().width(), 500.0 ) );
00064
00065 return doc;
00066 }
00067
00068 #include "KoDocumentSectionToolTip.moc"