mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-07-02 11:33:55 -07:00
chat view performance regression fixed; minor user list fix; added russian translation stub
This commit is contained in:
parent
7200b5be0e
commit
c203d51f43
15 changed files with 3175 additions and 414 deletions
|
|
@ -8,35 +8,37 @@ ChatView::ChatView(const QString &_ownName, QWidget *parent)
|
|||
: QTextEdit(parent), ownName(_ownName)
|
||||
{
|
||||
setTextInteractionFlags(Qt::TextSelectableByMouse);
|
||||
|
||||
QTextTableFormat format;
|
||||
format.setBorderStyle(QTextFrameFormat::BorderStyle_None);
|
||||
table = textCursor().insertTable(1, 3, format);
|
||||
}
|
||||
|
||||
void ChatView::appendMessage(const QString &sender, const QString &message)
|
||||
{
|
||||
QTextCursor cellCursor = table->cellAt(table->rows() - 1, 0).lastCursorPosition();
|
||||
cellCursor.insertText(QDateTime::currentDateTime().toString("[hh:mm]"));
|
||||
QTextTableCell senderCell = table->cellAt(table->rows() - 1, 1);
|
||||
QTextCursor cursor(document()->lastBlock());
|
||||
cursor.movePosition(QTextCursor::End);
|
||||
|
||||
QTextBlockFormat blockFormat;
|
||||
blockFormat.setBottomMargin(3);
|
||||
cursor.insertBlock(blockFormat);
|
||||
|
||||
QTextCharFormat timeFormat;
|
||||
timeFormat.setForeground(Qt::black);
|
||||
cursor.setCharFormat(timeFormat);
|
||||
cursor.insertText(QDateTime::currentDateTime().toString("[hh:mm] "));
|
||||
|
||||
QTextCharFormat senderFormat;
|
||||
if (sender == ownName) {
|
||||
senderFormat.setFontWeight(QFont::Bold);
|
||||
senderFormat.setForeground(Qt::red);
|
||||
} else
|
||||
senderFormat.setForeground(Qt::blue);
|
||||
senderCell.setFormat(senderFormat);
|
||||
cellCursor = senderCell.lastCursorPosition();
|
||||
cellCursor.insertText(sender);
|
||||
QTextTableCell messageCell = table->cellAt(table->rows() - 1, 2);
|
||||
cursor.setCharFormat(senderFormat);
|
||||
cursor.insertText(sender + " ");
|
||||
|
||||
QTextCharFormat messageFormat;
|
||||
if (sender.isEmpty())
|
||||
messageFormat.setForeground(Qt::darkGreen);
|
||||
messageCell.setFormat(messageFormat);
|
||||
cellCursor = messageCell.lastCursorPosition();
|
||||
cellCursor.insertText(message);
|
||||
cursor.setCharFormat(messageFormat);
|
||||
cursor.insertText(message);
|
||||
|
||||
table->appendRows(1);
|
||||
|
||||
verticalScrollBar()->setValue(verticalScrollBar()->maximum());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -226,14 +226,12 @@ void TabRoom::processListGamesEvent(Event_ListGames *event)
|
|||
|
||||
void TabRoom::processJoinRoomEvent(Event_JoinRoom *event)
|
||||
{
|
||||
chatView->appendMessage(QString(), tr("%1 has joined the room.").arg(event->getUserInfo()->getName()));
|
||||
userList->processUserInfo(event->getUserInfo());
|
||||
userList->sortItems();
|
||||
}
|
||||
|
||||
void TabRoom::processLeaveRoomEvent(Event_LeaveRoom *event)
|
||||
{
|
||||
chatView->appendMessage(QString(), tr("%1 has left the room.").arg(event->getPlayerName()));
|
||||
userList->deleteUser(event->getPlayerName());
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@
|
|||
#include <QMenu>
|
||||
|
||||
UserListItemDelegate::UserListItemDelegate(QObject *const parent)
|
||||
: QItemDelegate(parent)
|
||||
: QStyledItemDelegate(parent)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
@ -21,7 +21,7 @@ bool UserListItemDelegate::editorEvent(QEvent *event, QAbstractItemModel *model,
|
|||
return true;
|
||||
}
|
||||
}
|
||||
return QItemDelegate::editorEvent(event, model, option, index);
|
||||
return QStyledItemDelegate::editorEvent(event, model, option, index);
|
||||
}
|
||||
|
||||
UserListTWI::UserListTWI()
|
||||
|
|
|
|||
|
|
@ -3,13 +3,13 @@
|
|||
|
||||
#include <QGroupBox>
|
||||
#include <QTreeWidgetItem>
|
||||
#include <QItemDelegate>
|
||||
#include <QStyledItemDelegate>
|
||||
|
||||
class QTreeWidget;
|
||||
class ServerInfo_User;
|
||||
class AbstractClient;
|
||||
|
||||
class UserListItemDelegate : public QItemDelegate {
|
||||
class UserListItemDelegate : public QStyledItemDelegate {
|
||||
public:
|
||||
UserListItemDelegate(QObject *const parent);
|
||||
bool editorEvent(QEvent *event, QAbstractItemModel *model, const QStyleOptionViewItem &option, const QModelIndex &index);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue