F:/KPlato/koffice/libs/kofficeui/KoDocumentSectionToolTip.cpp

Aller à la documentation de ce fichier.
00001 /*
00002   Copyright (c) 2006 Gábor Lehel <illissius@gmail.com>
00003 
00004   This library is free software; you can redistribute it and/or
00005   modify it under the terms of the GNU Library General Public
00006   License as published by the Free Software Foundation; either
00007   version 2 of the License, or (at your option) any later version.
00008 
00009   This library is distributed in the hope that it will be useful,
00010   but WITHOUT ANY WARRANTY; without even the implied warranty of
00011   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012   Library General Public License for more details.
00013 
00014   You should have received a copy of the GNU Library General Public License
00015   along with this library; see the file COPYING.LIB.  If not, write to
00016   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00017   Boston, MA 02110-1301, USA.
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"

Généré le Wed Nov 22 23:41:04 2006 pour KPlato par  doxygen 1.5.1-p1