Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Games
KMuddy
Commits
d48436bb
Commit
d48436bb
authored
May 11, 2019
by
Tomas Mecir
Browse files
Speed optimisations for the main output, should no longer be so slow
parent
8d9b8424
Changes
3
Hide whitespace changes
Inline
Side-by-side
libs/cconsole.cpp
View file @
d48436bb
...
...
@@ -66,7 +66,9 @@ public:
void
updateSize
()
{
QRectF
rect
=
scene
()
->
sceneRect
();
setTextWidth
(
rect
.
width
());
double
w
=
rect
.
width
();
if
(
textWidth
()
==
w
)
return
;
// don't update the width if it already is fine - it's an expensive operation
setTextWidth
(
w
);
prepareGeometryChange
();
}
...
...
@@ -148,8 +150,8 @@ cConsole::cConsole(QWidget *parent) : QGraphicsView(parent) {
connect
(
verticalScrollBar
(),
SIGNAL
(
valueChanged
(
int
)),
this
,
SLOT
(
sliderChanged
(
int
)));
d
->
text
=
new
QTextDocument
;
QString
stylesheet
=
"* {
color: "
+
QColor
(
Qt
::
lightGray
).
name
()
+
";
white-space: pre-wrap; } a { color: "
+
QColor
(
Qt
::
blue
).
name
()
+
"; }
p,div { padding: 1px; line-spacing: 1.3 }
"
;
d
->
text
->
setDefaultStyleSheet
(
stylesheet
);
//
QString stylesheet = "* { white-space: pre-wrap; } a { color: " + QColor (Qt::blue).name() + "; } ";
//
d->text->setDefaultStyleSheet (stylesheet);
QTextOption
opt
;
opt
.
setWrapMode
(
QTextOption
::
WrapAtWordBoundaryOrAnywhere
);
d
->
text
->
setDefaultTextOption
(
opt
);
...
...
@@ -382,6 +384,8 @@ void cConsole::addNewText (cTextChunk *chunk, bool endTheLine)
cursor
.
insertBlock
();
d
->
wantNewLine
=
false
;
QTextBlockFormat
bformat
=
cursor
.
blockFormat
();
bformat
.
setForeground
(
Qt
::
lightGray
);
bformat
.
setProperty
(
QTextFormat
::
FramePadding
,
1
);
bformat
.
setLineHeight
(
2
,
QTextBlockFormat
::
LineDistanceHeight
);
double
px
=
d
->
indentChars
*
d
->
charWidth
;
// 0 if no indentation is to happen
bformat
.
setLeftMargin
(
px
);
...
...
@@ -389,7 +393,8 @@ void cConsole::addNewText (cTextChunk *chunk, bool endTheLine)
cursor
.
setBlockFormat
(
bformat
);
}
cursor
.
insertHtml
(
chunk
->
toHTML
());
chunk
->
insertToDocument
(
cursor
);
// cursor.insertHtml (chunk->toHTML());
}
if
(
endTheLine
)
d
->
wantNewLine
=
true
;
...
...
libs/ctextchunk.cpp
View file @
d48436bb
...
...
@@ -96,6 +96,7 @@ void cTextChunk::appendEntry (chunkItem *entry)
_entries
.
push_back
(
entry
);
//update starting position
entry
->
setStartPos
(
basepos
);
entry
->
_chunk
=
this
;
//update the timestamp
timestamp
=
QDateTime
::
currentDateTime
();
}
...
...
@@ -720,6 +721,27 @@ QString cTextChunk::toHTML ()
return
"<p>"
+
s
+
"</p>"
;
}
void
cTextChunk
::
insertToDocument
(
QTextCursor
&
cursor
)
{
QTextCharFormat
format
;
chunkFg
::
setFormat
(
format
,
startattr
.
fg
);
chunkBg
::
setFormat
(
format
,
startattr
.
bg
);
chunkAttrib
::
setFormat
(
format
,
startattr
.
attrib
);
/* I think this isn't needed anymore ...
if (startattr.startpos)
{
QString s;
s.fill (' ', startattr.startpos);
cursor.insertText (s, format);
}
*/
for
(
chunkItem
*
item
:
_entries
)
item
->
insertToDocument
(
cursor
,
format
);
}
cTextChunk
*
cTextChunk
::
makeLine
(
const
QString
&
text
,
QColor
fg
,
QColor
bg
,
cConsole
*
console
)
{
cTextChunk
*
chunk
=
new
cTextChunk
(
console
);
...
...
@@ -1289,3 +1311,32 @@ QString chunkLink::toHTML (QString &)
return
"<a rel=
\"
"
+
rel
+
"
\"
href=
\"
"
+
href
+
"
\"
>"
+
_text
+
"</a>"
;
}
void
chunkLink
::
insertToDocument
(
QTextCursor
&
cursor
,
QTextCharFormat
&
format
)
{
QTextCharFormat
linkformat
=
format
;
linkformat
.
setAnchor
(
true
);
linkformat
.
setAnchorHref
(
_target
);
if
(
linkformat
.
foreground
().
color
()
==
_chunk
->
startAttr
().
fg
)
linkformat
.
setForeground
(
linkColor
);
cursor
.
insertText
(
_text
,
linkformat
);
}
void
chunkFg
::
setFormat
(
QTextCharFormat
&
format
,
QColor
color
)
{
format
.
setForeground
(
color
);
}
void
chunkBg
::
setFormat
(
QTextCharFormat
&
format
,
QColor
color
)
{
format
.
setBackground
(
color
);
}
void
chunkAttrib
::
setFormat
(
QTextCharFormat
&
format
,
int
attrib
)
{
format
.
setFontWeight
((
attrib
&
ATTRIB_BOLD
)
?
QFont
::
Bold
:
QFont
::
Normal
);
format
.
setFontItalic
(
attrib
&
ATTRIB_ITALIC
);
format
.
setFontUnderline
(
attrib
&
ATTRIB_UNDERLINE
);
format
.
setFontStrikeOut
(
attrib
&
ATTRIB_STRIKEOUT
);
// blink, negative, and invisible are currently not supported
}
libs/ctextchunk.h
View file @
d48436bb
...
...
@@ -27,6 +27,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include
<QDateTime>
#include
<QFont>
#include
<QString>
#include
<QTextCharFormat>
#include
<QTextCursor>
#include
<list>
#include
<kmuddy_export.h>
...
...
@@ -35,6 +37,7 @@ using namespace std;
class
cANSIParser
;
class
cConsole
;
class
cTextChunk
;
class
QPainter
;
...
...
@@ -44,6 +47,7 @@ class QPainter;
class
KMUDDY_EXPORT
chunkItem
{
public:
chunkItem
()
:
startpos
(
0
),
_chunk
(
nullptr
)
{}
virtual
~
chunkItem
()
{};
virtual
int
type
()
=
0
;
int
startPos
()
{
return
startpos
;
}
...
...
@@ -65,9 +69,14 @@ class KMUDDY_EXPORT chunkItem {
virtual
QString
toAnsi
(
cANSIParser
*
)
{
return
QString
();
};
/** output to HTML, suffix can be used to provide closing tags if needed */
virtual
QString
toHTML
(
QString
&
)
{
return
QString
();
};
/** Insert self into a text document at the QTextCursor's position */
virtual
void
insertToDocument
(
QTextCursor
&
,
QTextCharFormat
&
)
=
0
;
protected:
// void paintText (const QString &text, QPainter *painter, QFont font, QColor fg, QColor bg, paintStatus *ps);
int
startpos
;
cTextChunk
*
_chunk
;
friend
class
cTextChunk
;
};
/** one color change made by color triggers */
...
...
@@ -156,6 +165,7 @@ public:
/** output to HTML */
QString
toHTML
();
void
insertToDocument
(
QTextCursor
&
cursor
);
//get timestamp in a textual form
QString
getTimeStamp
();
...
...
@@ -169,7 +179,7 @@ protected:
/** starting attributes... */
chunkStart
startattr
;
/** cConsole object, used when needed */
cConsole
*
console
;
...
...
@@ -197,6 +207,8 @@ class KMUDDY_EXPORT chunkText : public chunkItem {
virtual
void
trimLeft
()
override
;
virtual
void
replace
(
int
pos
,
int
len
,
const
QString
&
newtext
)
override
;
virtual
void
insertToDocument
(
QTextCursor
&
cursor
,
QTextCharFormat
&
format
)
override
{
cursor
.
insertText
(
_text
,
format
);
};
//painting
// virtual void paint (QPainter *painter, paintStatus *ps) override;
...
...
@@ -224,12 +236,15 @@ class KMUDDY_EXPORT chunkFg : public chunkItem {
//painting
// virtual void paint (QPainter *painter, paintStatus *ps) override;
virtual
void
insertToDocument
(
QTextCursor
&
,
QTextCharFormat
&
format
)
override
{
setFormat
(
format
,
_fg
);
};
//output to transcript...
/** output to plain-text with ANSI sequences */
virtual
QString
toAnsi
(
cANSIParser
*
ap
)
override
;
/** output to HTML, suffix can be used to provide closing tags if needed */
virtual
QString
toHTML
(
QString
&
suffix
)
override
;
static
void
setFormat
(
QTextCharFormat
&
format
,
QColor
color
);
static
QString
constructAnsi
(
QColor
color
,
cANSIParser
*
ap
);
static
QString
constructHTML
(
QColor
color
,
QString
&
suffix
);
protected:
...
...
@@ -246,6 +261,8 @@ class KMUDDY_EXPORT chunkBg : public chunkItem {
virtual
int
length
()
override
{
return
0
;
}
virtual
chunkItem
*
duplicate
()
override
;
virtual
void
insertToDocument
(
QTextCursor
&
,
QTextCharFormat
&
format
)
override
{
setFormat
(
format
,
_bg
);
};
//painting
// virtual void paint (QPainter *painter, paintStatus *ps) override;
...
...
@@ -255,6 +272,7 @@ class KMUDDY_EXPORT chunkBg : public chunkItem {
/** output to HTML, suffix can be used to provide closing tags if needed */
virtual
QString
toHTML
(
QString
&
suffix
)
override
;
static
void
setFormat
(
QTextCharFormat
&
format
,
QColor
color
);
static
QString
constructAnsi
(
QColor
color
,
cANSIParser
*
ap
);
static
QString
constructHTML
(
QColor
color
,
QString
&
suffix
);
protected:
...
...
@@ -282,13 +300,16 @@ class KMUDDY_EXPORT chunkAttrib : public chunkItem {
//painting
// virtual void paint (QPainter *painter, paintStatus *ps) override;
virtual
void
insertToDocument
(
QTextCursor
&
,
QTextCharFormat
&
format
)
override
{
setFormat
(
format
,
_attrib
);
};
//output to transcript...
/** output to plain-text with ANSI sequences */
virtual
QString
toAnsi
(
cANSIParser
*
)
override
;
//no HTML output here - we cannot handle closing tags properly without too much hassle
static
void
setFormat
(
QTextCharFormat
&
format
,
int
attrib
);
static
QString
constructAnsi
(
unsigned
char
attrib
);
protected:
int
_attrib
;
...
...
@@ -332,7 +353,9 @@ class KMUDDY_EXPORT chunkLink : public chunkItem {
const
list
<
menuItem
>
&
menu
()
{
return
_menu
;
};
//painting
// virtual void paint (QPainter *painter, paintStatus *ps) override;
virtual
void
insertToDocument
(
QTextCursor
&
cursor
,
QTextCharFormat
&
format
)
override
;
//output to transcript...
/** output to plain-text with ANSI sequences */
virtual
QString
toAnsi
(
cANSIParser
*
ap
)
override
;
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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