mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-06-11 00:24:47 -07:00
chatview improvement
This commit is contained in:
parent
add47315d5
commit
fccc91818d
4 changed files with 76 additions and 76 deletions
|
|
@ -1,13 +1,12 @@
|
|||
#include <QTextEdit>
|
||||
#include <QDateTime>
|
||||
#include <QTextTable>
|
||||
#include <QScrollBar>
|
||||
#include <QMouseEvent>
|
||||
#include <QDesktopServices>
|
||||
#include "chatview.h"
|
||||
|
||||
ChatView::ChatView(const QString &_ownName, bool _showTimestamps, QWidget *parent)
|
||||
: QTextBrowser(parent), ownName(_ownName), showTimestamps(_showTimestamps)
|
||||
: QTextBrowser(parent), evenNumber(false), ownName(_ownName), showTimestamps(_showTimestamps)
|
||||
{
|
||||
setReadOnly(true);
|
||||
setTextInteractionFlags(Qt::TextSelectableByMouse | Qt::LinksAccessibleByMouse);
|
||||
|
|
@ -15,15 +14,30 @@ ChatView::ChatView(const QString &_ownName, bool _showTimestamps, QWidget *paren
|
|||
connect(this, SIGNAL(anchorClicked(const QUrl &)), this, SLOT(openLink(const QUrl &)));
|
||||
}
|
||||
|
||||
void ChatView::appendMessage(QString sender, QString message, QColor playerColor, bool playerBold)
|
||||
QTextCursor ChatView::prepareBlock()
|
||||
{
|
||||
QTextCursor cursor(document()->lastBlock());
|
||||
cursor.movePosition(QTextCursor::End);
|
||||
|
||||
QTextBlockFormat blockFormat;
|
||||
if ((evenNumber = !evenNumber))
|
||||
blockFormat.setBackground(palette().alternateBase());
|
||||
blockFormat.setBottomMargin(2);
|
||||
cursor.insertBlock(blockFormat);
|
||||
|
||||
return cursor;
|
||||
}
|
||||
|
||||
void ChatView::appendHtml(const QString &html)
|
||||
{
|
||||
prepareBlock().insertHtml(html);
|
||||
verticalScrollBar()->setValue(verticalScrollBar()->maximum());
|
||||
}
|
||||
|
||||
void ChatView::appendMessage(QString sender, QString message, QColor playerColor, bool playerBold)
|
||||
{
|
||||
QTextCursor cursor = prepareBlock();
|
||||
|
||||
if (showTimestamps) {
|
||||
QTextCharFormat timeFormat;
|
||||
timeFormat.setForeground(Qt::black);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue