Changeset View
Changeset View
Standalone View
Standalone View
libs/ui/widgets/KisNewsWidget.cpp
Context not available. | |||||
19 | 19 | | |||
---|---|---|---|---|---|
20 | #include <QDesktopServices> | 20 | #include <QDesktopServices> | ||
21 | #include <QUrl> | 21 | #include <QUrl> | ||
22 | #include <QPainter> | ||||
23 | #include <QStyleOptionViewItem> | ||||
24 | #include <QModelIndex> | ||||
25 | #include <QTextDocument> | ||||
26 | #include <QAbstractTextDocumentLayout> | ||||
22 | 27 | | |||
23 | #include "kis_config.h" | 28 | #include "kis_config.h" | ||
24 | #include "KisMultiFeedRSSModel.h" | 29 | #include "KisMultiFeedRSSModel.h" | ||
25 | 30 | | |||
31 | | ||||
32 | KisNewsDelegate::KisNewsDelegate(QObject *parent) | ||||
33 | : QStyledItemDelegate(parent) | ||||
34 | { | ||||
35 | qDebug() << "Delegate created"; | ||||
36 | } | ||||
37 | | ||||
38 | void KisNewsDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const | ||||
39 | { | ||||
40 | painter->save(); | ||||
41 | | ||||
42 | QStyleOptionViewItem optionCopy = option; | ||||
43 | initStyleOption(&optionCopy, index); | ||||
44 | | ||||
45 | QStyle *style = optionCopy.widget? optionCopy.widget->style() : QApplication::style(); | ||||
46 | | ||||
47 | QTextDocument doc; | ||||
48 | doc.setHtml(optionCopy.text); | ||||
49 | | ||||
50 | /// Painting item without text | ||||
51 | optionCopy.text = QString(); | ||||
52 | style->drawControl(QStyle::CE_ItemViewItem, &optionCopy, painter); | ||||
53 | | ||||
54 | QAbstractTextDocumentLayout::PaintContext ctx; | ||||
55 | | ||||
56 | // Highlighting text if item is selected | ||||
57 | if (optionCopy.state & QStyle::State_Selected) { | ||||
58 | ctx.palette.setColor(QPalette::Text, optionCopy.palette.color(QPalette::Active, QPalette::HighlightedText)); | ||||
59 | } | ||||
60 | | ||||
61 | painter->translate(optionCopy.rect.left(), optionCopy.rect.top()); | ||||
62 | QRect clip(0, 0, optionCopy.rect.width(), optionCopy.rect.height()); | ||||
63 | doc.setPageSize(clip.size()); | ||||
64 | doc.drawContents(painter, clip); | ||||
65 | painter->restore(); | ||||
66 | } | ||||
67 | | ||||
68 | QSize KisNewsDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const | ||||
69 | { | ||||
70 | QStyleOptionViewItem optionCopy = option; | ||||
71 | initStyleOption(&optionCopy, index); | ||||
72 | | ||||
73 | QTextDocument doc; | ||||
74 | doc.setHtml(optionCopy.text); | ||||
75 | doc.setTextWidth(optionCopy.rect.width()); | ||||
76 | return QSize(doc.idealWidth(), doc.size().height()); | ||||
77 | } | ||||
78 | | ||||
26 | KisNewsWidget::KisNewsWidget(QWidget *parent) | 79 | KisNewsWidget::KisNewsWidget(QWidget *parent) | ||
27 | : QWidget(parent) | 80 | : QWidget(parent) | ||
28 | { | 81 | { | ||
Context not available. | |||||
39 | else { | 92 | else { | ||
40 | m_rssModel->removeFeed(QLatin1String("https://krita.org/en/feed/")); | 93 | m_rssModel->removeFeed(QLatin1String("https://krita.org/en/feed/")); | ||
41 | } | 94 | } | ||
95 | | ||||
42 | listNews->setModel(m_rssModel); | 96 | listNews->setModel(m_rssModel); | ||
97 | listNews->setItemDelegate(new KisNewsDelegate(listNews)); | ||||
43 | connect(listNews, SIGNAL(clicked(const QModelIndex&)), this, SLOT(itemSelected(const QModelIndex&))); | 98 | connect(listNews, SIGNAL(clicked(const QModelIndex&)), this, SLOT(itemSelected(const QModelIndex&))); | ||
44 | } | 99 | } | ||
45 | 100 | | |||
Context not available. |