22 #include <QGraphicsSceneWheelEvent> 27 #include <kmimetype.h> 28 #include <ktextbrowser.h> 32 #include "private/style_p.h" 33 #include "private/themedwidgetinterface_p.h" 38 class TextBrowserPrivate :
public ThemedWidgetInterface<TextBrowser>
41 TextBrowserPrivate(TextBrowser *browser)
42 : ThemedWidgetInterface<TextBrowser>(browser),
43 savedMinimumHeight(0),
44 savedMaximumHeight(QWIDGETSIZE_MAX),
51 KTextBrowser *native = q->nativeWidget();
52 if (native->document() &&
53 q->sizePolicy().verticalPolicy() == QSizePolicy::Fixed &&
54 native->verticalScrollBarPolicy() == Qt::ScrollBarAlwaysOff) {
55 native->document()->setTextWidth(q->size().width());
56 QSize s = native->document()->size().toSize();
58 savedMinimumHeight = q->minimumHeight();
59 savedMaximumHeight = q->maximumHeight();
62 q->setMinimumHeight(s.height());
63 q->setMaximumHeight(s.height());
64 }
else if (!wasNotFixed) {
65 q->setMinimumHeight(savedMinimumHeight);
66 q->setMaximumHeight(savedMaximumHeight);
72 Plasma::Style::Ptr style;
73 int savedMinimumHeight;
74 int savedMaximumHeight;
80 d(new TextBrowserPrivate(this))
82 KTextBrowser *native =
new KTextBrowser;
83 native->setWindowFlags(native->windowFlags()|Qt::BypassGraphicsProxyWidget);
85 connect(native, SIGNAL(
textChanged()),
this, SLOT(setFixedHeight()));
86 native->setWindowIcon(QIcon());
89 native->setAttribute(Qt::WA_NoSystemBackground);
90 native->setFrameShape(QFrame::NoFrame);
91 native->setTextBackgroundColor(Qt::transparent);
92 native->viewport()->setAutoFillBackground(
false);
93 d->style = Plasma::Style::sharedStyle();
94 native->verticalScrollBar()->setStyle(d->style.data());
95 native->horizontalScrollBar()->setStyle(d->style.data());
102 Plasma::Style::doneWithSharedStyle();
107 static_cast<KTextBrowser*>(widget())->setText(
text);
112 return static_cast<KTextBrowser*>(widget())->toHtml();
127 widget()->setStyleSheet(stylesheet);
132 return widget()->styleSheet();
137 return static_cast<KTextBrowser*>(widget());
152 foreach (
const QVariant &v, data) {
153 if (v.canConvert(QVariant::String)) {
154 te->append(v.toString() +
'\n');
161 QMenu *popup =
nativeWidget()->createStandardContextMenu(event->screenPos());
163 popup->exec(event->screenPos());
171 QGraphicsProxyWidget::resizeEvent(event);
176 if (
nativeWidget()->verticalScrollBarPolicy() == Qt::ScrollBarAlwaysOff &&
177 nativeWidget()->horizontalScrollBarPolicy() == Qt::ScrollBarAlwaysOff) {
180 QGraphicsProxyWidget::wheelEvent(event);
186 d->changeEvent(event);
187 QGraphicsProxyWidget::changeEvent(event);
192 #include <textbrowser.moc> void setHorizontalScrollBarPolicy(Qt::ScrollBarPolicy policy)
Sets the policy used to show/hide the horizontal scrollbar.
TextBrowser(QGraphicsWidget *parent=0)
void dataUpdated(const QString &sourceName, const Plasma::DataEngine::Data &data)
void wheelEvent(QGraphicsSceneWheelEvent *event)
QHash< QString, QVariant > Data
Namespace for everything in libplasma.
void setVerticalScrollBarPolicy(Qt::ScrollBarPolicy policy)
Sets the policy used to show/hide the vertical scrollbar.
void append(const QString &text)
Allows appending text to the text browser.
KTextBrowser * nativeWidget() const
void contextMenuEvent(QGraphicsSceneContextMenuEvent *event)
void setText(const QString &text)
Sets the display text for this TextBrowser.
void setStyleSheet(const QString &stylesheet)
Sets the stylesheet used to control the visual display of this TextBrowser.
void resizeEvent(QGraphicsSceneResizeEvent *event)
void changeEvent(QEvent *event)