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
Games
KMuddy
Commits
01ef118a
Commit
01ef118a
authored
Apr 20, 2020
by
Tomas Mecir
Browse files
redo the timestamp support so it doesn't cause crazy lags after a while
parent
f450d9b4
Changes
2
Hide whitespace changes
Inline
Side-by-side
libs/cconsole.cpp
View file @
01ef118a
...
...
@@ -115,6 +115,13 @@ protected:
int
_percentHeight
;
};
class
cConsoleTimestamp
:
public
QTextBlockUserData
{
public:
cConsoleTimestamp
(
QDateTime
s
)
{
stamp
=
s
;
}
virtual
~
cConsoleTimestamp
(){};
QDateTime
stamp
;
};
class
cConsoleScene
:
public
QGraphicsScene
{
protected:
...
...
@@ -164,21 +171,31 @@ class cConsoleScene : public QGraphicsScene {
return
;
// not a text item
}
// get the text format at the mouse position
// get the block at the mouse position
cConsoleTimestamp
*
stamp
=
nullptr
;
QPointF
coord
=
text
->
mapFromScene
(
helpEvent
->
scenePos
());
QTextFormat
format
=
text
->
document
()
->
documentLayout
()
->
formatAt
(
coord
);
if
(
!
format
.
isValid
())
{
QAbstractTextDocumentLayout
*
layout
=
text
->
document
()
->
documentLayout
();
QTextBlock
block
=
text
->
document
()
->
lastBlock
();
while
(
block
!=
text
->
document
()
->
firstBlock
())
{
if
(
layout
->
blockBoundingRect
(
block
).
contains
(
coord
))
{
// found it
stamp
=
dynamic_cast
<
cConsoleTimestamp
*>
(
block
.
userData
());
break
;
}
block
=
block
.
previous
();
}
if
(
!
stamp
)
{
QToolTip
::
hideText
();
return
;
// not in text
}
QDateTime
time
=
format
.
property
(
QTextFormat
::
UserProperty
+
1
).
toDateTime
();
QString
tip
=
formatTimeStamp
(
time
);
QString
tip
=
formatTimeStamp
(
stamp
->
stamp
);
QToolTip
::
showText
(
helpEvent
->
screenPos
(),
tip
);
}
};
class
cConsole
::
Private
{
cConsoleScene
scene
;
cTextOutputItem
*
mainText
,
*
scrollText
;
...
...
@@ -217,6 +234,7 @@ cConsole::cConsole(QWidget *parent) : QGraphicsView(parent) {
connect
(
verticalScrollBar
(),
SIGNAL
(
valueChanged
(
int
)),
this
,
SLOT
(
sliderChanged
(
int
)));
d
->
text
=
new
QTextDocument
;
d
->
text
->
setUndoRedoEnabled
(
false
);
// QString stylesheet = "* { white-space: pre-wrap; } a { color: " + QColor (Qt::blue).name() + "; } ";
// d->text->setDefaultStyleSheet (stylesheet);
QTextOption
opt
;
...
...
@@ -445,10 +463,15 @@ int cConsole::totalLines() {
void
cConsole
::
addNewText
(
cTextChunk
*
chunk
,
bool
endTheLine
)
{
QTextCursor
cursor
(
d
->
text
);
cursor
.
beginEditBlock
();
cursor
.
movePosition
(
QTextCursor
::
End
);
if
(
chunk
)
{
if
(
d
->
wantNewLine
)
{
cursor
.
insertBlock
();
cursor
.
block
().
layout
()
->
setCacheEnabled
(
true
);
cConsoleTimestamp
*
stamp
=
new
cConsoleTimestamp
(
chunk
->
getTimeStamp
());
cursor
.
block
().
setUserData
(
stamp
);
// this will delete the stamp
d
->
wantNewLine
=
false
;
QTextBlockFormat
bformat
=
cursor
.
blockFormat
();
bformat
.
setForeground
(
Qt
::
lightGray
);
...
...
@@ -457,13 +480,11 @@ void cConsole::addNewText (cTextChunk *chunk, bool endTheLine)
double
px
=
d
->
indentChars
*
d
->
charWidth
;
// 0 if no indentation is to happen
bformat
.
setLeftMargin
(
px
);
bformat
.
setTextIndent
(
-
1
*
px
);
bformat
.
setProperty
(
QTextFormat
::
UserProperty
+
1
,
chunk
->
getTimeStamp
());
cursor
.
setBlockFormat
(
bformat
);
}
chunk
->
insertToDocument
(
cursor
);
// cursor.insertHtml (chunk->toHTML());
}
cursor
.
endEditBlock
();
if
(
endTheLine
)
d
->
wantNewLine
=
true
;
while
(
totalLines
()
>
d
->
historySize
)
{
...
...
libs/ctextchunk.cpp
View file @
01ef118a
...
...
@@ -725,7 +725,6 @@ void cTextChunk::insertToDocument (QTextCursor &cursor)
chunkFg
::
setFormat
(
format
,
startattr
.
fg
);
chunkBg
::
setFormat
(
format
,
startattr
.
bg
);
chunkAttrib
::
setFormat
(
format
,
startattr
.
attrib
);
format
.
setProperty
(
QTextFormat
::
UserProperty
+
1
,
timestamp
);
/* I think this isn't needed anymore ...
if (startattr.startpos)
...
...
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