diff options
author | Tomaz Canabrava <tomaz.canabrava@intel.com> | 2014-07-17 20:10:44 -0300 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2014-07-18 10:14:27 -0700 |
commit | 774a785a99c8ec2910c346de0ad40eb65f1948f6 (patch) | |
tree | 5fdd61a65151d872bfb2e3ab8c62ff3f3dd8bda8 /qt-ui/modeldelegates.cpp | |
parent | 345b01750a83229a331c91bdebb1cdf7730fdac1 (diff) | |
download | subsurface-774a785a99c8ec2910c346de0ad40eb65f1948f6.tar.gz |
Added a HTML Displayable Delegate
Added a HTML delegate to show rendered HTML on print.
Signed-off-by: Tomaz Canabrava <tomaz.canabrava@intel.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'qt-ui/modeldelegates.cpp')
-rw-r--r-- | qt-ui/modeldelegates.cpp | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/qt-ui/modeldelegates.cpp b/qt-ui/modeldelegates.cpp index 930f05501..c0b0f4dda 100644 --- a/qt-ui/modeldelegates.cpp +++ b/qt-ui/modeldelegates.cpp @@ -17,6 +17,7 @@ #include <QKeyEvent> #include <QAbstractItemView> #include <QApplication> +#include <QTextDocument> QSize DiveListDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const { @@ -399,3 +400,31 @@ QWidget *DoubleSpinBoxDelegate::createEditor(QWidget *parent, const QStyleOption w->setSingleStep(step); return w; } + +void HTMLDelegate::paint(QPainter* painter, const QStyleOptionViewItem & option, const QModelIndex &index) const +{ + QStyleOptionViewItemV4 options = option; + initStyleOption(&options, index); + painter->save(); + QTextDocument doc; + doc.setHtml(options.text); + doc.setTextWidth(options.rect.width()); + doc.setDefaultFont(options.font); + options.text.clear(); + options.widget->style()->drawControl(QStyle::CE_ItemViewItem, &options, painter); + painter->translate(options.rect.left(), options.rect.top()); + QRect clip(0, 0, options.rect.width(), options.rect.height()); + doc.drawContents(painter, clip); + painter->restore(); + ProfilePrintDelegate::paint(painter,option,index); +} + +QSize HTMLDelegate::sizeHint ( const QStyleOptionViewItem & option, const QModelIndex & index ) const +{ + QStyleOptionViewItemV4 options = option; + initStyleOption(&options, index); + QTextDocument doc; + doc.setHtml(options.text); + doc.setTextWidth(options.rect.width()); + return QSize(doc.idealWidth(), doc.size().height()); +}
\ No newline at end of file |