more visual improvements
This commit is contained in:
parent
fccc91818d
commit
09d0e65d1d
4 changed files with 25 additions and 11 deletions
|
@ -6,7 +6,7 @@
|
|||
#include "chatview.h"
|
||||
|
||||
ChatView::ChatView(const QString &_ownName, bool _showTimestamps, QWidget *parent)
|
||||
: QTextBrowser(parent), evenNumber(false), ownName(_ownName), showTimestamps(_showTimestamps)
|
||||
: QTextBrowser(parent), evenNumber(true), ownName(_ownName), showTimestamps(_showTimestamps)
|
||||
{
|
||||
setReadOnly(true);
|
||||
setTextInteractionFlags(Qt::TextSelectableByMouse | Qt::LinksAccessibleByMouse);
|
||||
|
@ -14,16 +14,20 @@ ChatView::ChatView(const QString &_ownName, bool _showTimestamps, QWidget *paren
|
|||
connect(this, SIGNAL(anchorClicked(const QUrl &)), this, SLOT(openLink(const QUrl &)));
|
||||
}
|
||||
|
||||
QTextCursor ChatView::prepareBlock()
|
||||
QTextCursor ChatView::prepareBlock(bool same)
|
||||
{
|
||||
lastSender.clear();
|
||||
|
||||
QTextCursor cursor(document()->lastBlock());
|
||||
cursor.movePosition(QTextCursor::End);
|
||||
|
||||
QTextBlockFormat blockFormat;
|
||||
if ((evenNumber = !evenNumber))
|
||||
blockFormat.setBackground(palette().alternateBase());
|
||||
blockFormat.setBottomMargin(2);
|
||||
cursor.insertBlock(blockFormat);
|
||||
if (!same) {
|
||||
QTextBlockFormat blockFormat;
|
||||
if ((evenNumber = !evenNumber))
|
||||
blockFormat.setBackground(palette().alternateBase());
|
||||
blockFormat.setBottomMargin(2);
|
||||
cursor.insertBlock(blockFormat);
|
||||
} else
|
||||
cursor.insertHtml("<br>");
|
||||
|
||||
return cursor;
|
||||
}
|
||||
|
@ -36,11 +40,16 @@ void ChatView::appendHtml(const QString &html)
|
|||
|
||||
void ChatView::appendMessage(QString sender, QString message, QColor playerColor, bool playerBold)
|
||||
{
|
||||
QTextCursor cursor = prepareBlock();
|
||||
bool sameSender = (sender == lastSender) && !lastSender.isEmpty();
|
||||
QTextCursor cursor = prepareBlock(sameSender);
|
||||
lastSender = sender;
|
||||
|
||||
if (showTimestamps) {
|
||||
QTextCharFormat timeFormat;
|
||||
timeFormat.setForeground(Qt::black);
|
||||
if (sameSender)
|
||||
timeFormat.setForeground(Qt::transparent);
|
||||
else
|
||||
timeFormat.setForeground(Qt::black);
|
||||
cursor.setCharFormat(timeFormat);
|
||||
cursor.insertText(QDateTime::currentDateTime().toString("[hh:mm] "));
|
||||
}
|
||||
|
@ -57,6 +66,8 @@ void ChatView::appendMessage(QString sender, QString message, QColor playerColor
|
|||
if (playerBold)
|
||||
senderFormat.setFontWeight(QFont::Bold);
|
||||
}
|
||||
if (sameSender)
|
||||
senderFormat.setForeground(Qt::transparent);
|
||||
cursor.setCharFormat(senderFormat);
|
||||
if (!sender.isEmpty())
|
||||
sender.append(": ");
|
||||
|
|
|
@ -12,13 +12,14 @@ class QMouseEvent;
|
|||
class ChatView : public QTextBrowser {
|
||||
Q_OBJECT;
|
||||
private:
|
||||
QString lastSender;
|
||||
bool evenNumber;
|
||||
QString ownName;
|
||||
bool showTimestamps;
|
||||
QTextFragment getFragmentUnderMouse(const QPoint &pos) const;
|
||||
QString getCardNameUnderMouse(QTextFragment frag) const;
|
||||
QString getCardNameUnderMouse(const QPoint &pos) const;
|
||||
QTextCursor prepareBlock();
|
||||
QTextCursor prepareBlock(bool same = false);
|
||||
private slots:
|
||||
void openLink(const QUrl &link);
|
||||
public:
|
||||
|
|
|
@ -22,6 +22,7 @@ GameSelector::GameSelector(AbstractClient *_client, TabRoom *_room, const QMap<i
|
|||
gameListProxyModel->setSortCaseSensitivity(Qt::CaseInsensitive);
|
||||
gameListView->setModel(gameListProxyModel);
|
||||
gameListView->setSortingEnabled(true);
|
||||
gameListView->setAlternatingRowColors(true);
|
||||
if (_room)
|
||||
gameListView->header()->hideSection(0);
|
||||
gameListView->header()->setResizeMode(1, QHeaderView::ResizeToContents);
|
||||
|
|
|
@ -107,6 +107,7 @@ UserList::UserList(TabSupervisor *_tabSupervisor, AbstractClient *_client, UserL
|
|||
userTree->setRootIsDecorated(false);
|
||||
userTree->setIconSize(QSize(20, 12));
|
||||
userTree->setItemDelegate(itemDelegate);
|
||||
userTree->setAlternatingRowColors(true);
|
||||
connect(userTree, SIGNAL(itemActivated(QTreeWidgetItem *, int)), this, SLOT(userClicked(QTreeWidgetItem *, int)));
|
||||
|
||||
QVBoxLayout *vbox = new QVBoxLayout;
|
||||
|
|
Loading…
Reference in a new issue