Warning, file /office/calligra/libs/main/KoDocumentSectionToolTip.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 /*
0002   Copyright (c) 2006 Gábor Lehel <illissius@gmail.com>
0003 
0004   This library is free software; you can redistribute it and/or
0005   modify it under the terms of the GNU Library General Public
0006   License as published by the Free Software Foundation; either
0007   version 2 of the License, or (at your option) any later version.
0008 
0009   This library is distributed in the hope that it will be useful,
0010   but WITHOUT ANY WARRANTY; without even the implied warranty of
0011   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0012   Library General Public License for more details.
0013 
0014   You should have received a copy of the GNU Library General Public License
0015   along with this library; see the file COPYING.LIB.  If not, write to
0016   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0017   Boston, MA 02110-1301, USA.
0018 */
0019 #include "KoDocumentSectionToolTip.h"
0020 #include "KoDocumentSectionModel.h"
0021 
0022 #include <QImage>
0023 #include <QModelIndex>
0024 #include <QTextDocument>
0025 #include <QUrl>
0026 #include <klocalizedstring.h>
0027 
0028 KoDocumentSectionToolTip::KoDocumentSectionToolTip()
0029 {
0030 }
0031 
0032 KoDocumentSectionToolTip::~KoDocumentSectionToolTip()
0033 {
0034 }
0035 
0036 QTextDocument *KoDocumentSectionToolTip::createDocument(const QModelIndex &index)
0037 {
0038     QTextDocument *doc = new QTextDocument(this);
0039 
0040     QImage thumb = index.data(int(Model::BeginThumbnailRole) + 250).value<QImage>();
0041     doc->addResource(QTextDocument::ImageResource, QUrl("data:thumbnail"), thumb);
0042 
0043     QString name = index.data(Qt::DisplayRole).toString();
0044     Model::PropertyList properties = index.data(Model::PropertiesRole).value<Model::PropertyList>();
0045     QString rows;
0046     const QString row = QString("<tr><td align=\"right\">%1:</td><td align=\"left\">%2</td></tr>");
0047     QString value;
0048     for(int i = 0, n = properties.count(); i < n; ++i) {
0049         if (properties[i].isMutable)
0050             value = properties[i].state.toBool() ? i18n("Yes") : i18n("No");
0051         else
0052             value = properties[i].state.toString();
0053 
0054         rows.append(row.arg(properties[i].name).arg(value));
0055     }
0056 
0057     rows = QString("<table>%1</table>").arg(rows);
0058 
0059     const QString image = QString("<table border=\"1\"><tr><td><img src=\"data:thumbnail\"></td></tr></table>");
0060     const QString body = QString("<h3 align=\"center\">%1</h3>").arg(name)
0061                        + QString("<table><tr><td>%1</td><td>%2</td></tr></table>").arg(image).arg(rows);
0062     const QString html = QString("<html><body>%1</body></html>").arg(body);
0063 
0064     doc->setHtml(html);
0065     doc->setTextWidth(qMin(doc->size().width(), qreal(500.0)));
0066 
0067     return doc;
0068 }