Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Utilities
Kate
Commits
5caa244a
Commit
5caa244a
authored
Feb 26, 2021
by
Christoph Cullmann
🐮
Browse files
fixup rendering
parent
10e1a4e5
Changes
2
Hide whitespace changes
Inline
Side-by-side
kate/kateoutputview.cpp
View file @
5caa244a
...
...
@@ -8,9 +8,59 @@
#include <KLocalizedString>
#include <QPainter>
#include <QTextDocument>
#include <QTreeView>
#include <QVBoxLayout>
/**
* setup text document from data
*/
static
void
setupText
(
QTextDocument
&
doc
,
const
QModelIndex
&
index
)
{
/**
* fill in right variant of text
* we always trim spaces away, to avoid ugly empty line at the start/end
*/
const
auto
message
=
index
.
data
(
KateOutputMessageStyledDelegate
::
MessageRole
).
toMap
();
if
(
message
.
contains
(
QStringLiteral
(
"plainText"
)))
{
doc
.
setPlainText
(
message
.
value
(
QStringLiteral
(
"plainText"
)).
toString
().
trimmed
());
}
else
if
(
message
.
contains
(
QStringLiteral
(
"markDown"
)))
{
doc
.
setMarkdown
(
message
.
value
(
QStringLiteral
(
"markDown"
)).
toString
().
trimmed
());
}
else
if
(
message
.
contains
(
QStringLiteral
(
"html"
)))
{
doc
.
setHtml
(
message
.
value
(
QStringLiteral
(
"html"
)).
toString
().
trimmed
());
}
}
void
KateOutputMessageStyledDelegate
::
paint
(
QPainter
*
painter
,
const
QStyleOptionViewItem
&
option
,
const
QModelIndex
&
index
)
const
{
QStyleOptionViewItem
options
=
option
;
initStyleOption
(
&
options
,
index
);
// paint background
if
(
option
.
state
&
QStyle
::
State_Selected
)
{
painter
->
fillRect
(
option
.
rect
,
option
.
palette
.
highlight
());
}
else
{
painter
->
fillRect
(
option
.
rect
,
option
.
palette
.
base
());
}
options
.
text
=
QString
();
options
.
widget
->
style
()
->
drawControl
(
QStyle
::
CE_ItemViewItem
,
&
options
,
painter
,
options
.
widget
);
painter
->
translate
(
option
.
rect
.
x
(),
option
.
rect
.
y
());
QTextDocument
doc
;
setupText
(
doc
,
index
);
doc
.
drawContents
(
painter
);
}
QSize
KateOutputMessageStyledDelegate
::
sizeHint
(
const
QStyleOptionViewItem
&
,
const
QModelIndex
&
index
)
const
{
QTextDocument
doc
;
setupText
(
doc
,
index
);
return
doc
.
size
().
toSize
();
}
KateOutputView
::
KateOutputView
(
KateMainWindow
*
mainWindow
,
QWidget
*
parent
)
:
QWidget
(
parent
)
,
m_mainWindow
(
mainWindow
)
...
...
kate/kateoutputview.h
View file @
5caa244a
...
...
@@ -9,7 +9,6 @@
#include <QStandardItemModel>
#include <QStyledItemDelegate>
#include <QTextDocument>
#include <QWidget>
class
KateMainWindow
;
...
...
@@ -28,38 +27,12 @@ public:
*/
static
constexpr
int
MessageRole
=
Qt
::
UserRole
+
1
;
private:
/**
* setup text document from data
*/
static
void
setupText
(
QTextDocument
&
doc
,
const
QModelIndex
&
index
)
{
const
auto
message
=
index
.
data
(
KateOutputMessageStyledDelegate
::
MessageRole
).
toMap
();
if
(
message
.
contains
(
QStringLiteral
(
"plainText"
)))
{
doc
.
setPlainText
(
message
.
value
(
QStringLiteral
(
"plainText"
)).
toString
());
}
else
if
(
message
.
contains
(
QStringLiteral
(
"markDown"
)))
{
doc
.
setMarkdown
(
message
.
value
(
QStringLiteral
(
"markDown"
)).
toString
());
}
else
if
(
message
.
contains
(
QStringLiteral
(
"html"
)))
{
doc
.
setHtml
(
message
.
value
(
QStringLiteral
(
"html"
)).
toString
());
}
}
public:
KateOutputMessageStyledDelegate
()
=
default
;
void
paint
(
QPainter
*
painter
,
const
QStyleOptionViewItem
&
,
const
QModelIndex
&
index
)
const
override
{
QTextDocument
doc
;
setupText
(
doc
,
index
);
doc
.
drawContents
(
painter
);
}
QSize
sizeHint
(
const
QStyleOptionViewItem
&
,
const
QModelIndex
&
index
)
const
override
{
QTextDocument
doc
;
setupText
(
doc
,
index
);
return
doc
.
size
().
toSize
();
}
void
paint
(
QPainter
*
painter
,
const
QStyleOptionViewItem
&
option
,
const
QModelIndex
&
index
)
const
override
;
QSize
sizeHint
(
const
QStyleOptionViewItem
&
,
const
QModelIndex
&
index
)
const
override
;
};
/**
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment