Warning, file /office/calligra/libs/widgets/KoItemToolTip.h 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 
0020 #ifndef KO_ITEM_TOOLTIP_H
0021 #define KO_ITEM_TOOLTIP_H
0022 
0023 #include <QFrame>
0024 #include "kowidgets_export.h"
0025 
0026 class QStyleOptionViewItem;
0027 class QModelIndex;
0028 class QTextDocument;
0029 
0030 /**
0031  * Base class for tooltips that can show extensive information about
0032  * the contents of the data pointed to by something that contains a
0033  * QModelIndex. Subclasses need to use this data to create a
0034  * QTextDocument that is formatted to provide the complete tooltip.
0035  *
0036  * (KoItemToolTip is currently used in kopainter/KoResourceChooser)
0037  */
0038 class KOWIDGETS_EXPORT KoItemToolTip : public QFrame
0039 {
0040     Q_OBJECT
0041 public:
0042     KoItemToolTip();
0043     ~KoItemToolTip() override;
0044     void showTip(QWidget *widget, const QPoint &pos, const QStyleOptionViewItem &option, const QModelIndex &index);
0045 
0046 protected:
0047 
0048     /**
0049      * Re-implement this to provide the actual tooltip contents.
0050      * For instance:
0051      * @code
0052      *    QTextDocument *doc = new QTextDocument(this);
0053      *
0054      *     QImage thumb = index.data(KoResourceModel::LargeThumbnailRole).value<QImage>();
0055      *     doc->addResource(QTextDocument::ImageResource, QUrl("data:thumbnail"), thumb);
0056      *
0057      *     QString name = index.data(Qt::DisplayRole).toString();
0058      *
0059      *     const QString image = QString("<img src=\"data:thumbnail\">");
0060      *     const QString body = QString("<h3 align=\"center\">%1</h3>").arg(name) + image;
0061      *     const QString html = QString("<html><body>%1</body></html>").arg(body);
0062      *
0063      *     doc->setHtml(html);
0064      *     doc->setTextWidth(qMin(doc->size().width(), 500.0));
0065      *
0066      *     return doc;
0067      * @endcode
0068      */
0069     virtual QTextDocument *createDocument(const QModelIndex &index) = 0;
0070 
0071 private:
0072     class Private;
0073     Private* const d;
0074 
0075     void updatePosition(QWidget *widget, const QPoint &pos, const QStyleOptionViewItem &option);
0076 
0077 public:
0078     QSize sizeHint() const override;
0079 
0080 protected:
0081     void paintEvent(QPaintEvent *e) override;
0082     void timerEvent(QTimerEvent *e) override;
0083     bool eventFilter(QObject *object, QEvent *event) override;
0084 };
0085 
0086 #endif