more visual improvements

This commit is contained in:
Max-Wilhelm Bruker 2011-07-05 22:40:03 +02:00
parent fccc91818d
commit 09d0e65d1d
4 changed files with 25 additions and 11 deletions

View file

@ -6,7 +6,7 @@
#include "chatview.h" #include "chatview.h"
ChatView::ChatView(const QString &_ownName, bool _showTimestamps, QWidget *parent) 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); setReadOnly(true);
setTextInteractionFlags(Qt::TextSelectableByMouse | Qt::LinksAccessibleByMouse); 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 &))); 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()); QTextCursor cursor(document()->lastBlock());
cursor.movePosition(QTextCursor::End); cursor.movePosition(QTextCursor::End);
if (!same) {
QTextBlockFormat blockFormat; QTextBlockFormat blockFormat;
if ((evenNumber = !evenNumber)) if ((evenNumber = !evenNumber))
blockFormat.setBackground(palette().alternateBase()); blockFormat.setBackground(palette().alternateBase());
blockFormat.setBottomMargin(2); blockFormat.setBottomMargin(2);
cursor.insertBlock(blockFormat); cursor.insertBlock(blockFormat);
} else
cursor.insertHtml("<br>");
return cursor; return cursor;
} }
@ -36,11 +40,16 @@ void ChatView::appendHtml(const QString &html)
void ChatView::appendMessage(QString sender, QString message, QColor playerColor, bool playerBold) 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) { if (showTimestamps) {
QTextCharFormat timeFormat; QTextCharFormat timeFormat;
timeFormat.setForeground(Qt::black); if (sameSender)
timeFormat.setForeground(Qt::transparent);
else
timeFormat.setForeground(Qt::black);
cursor.setCharFormat(timeFormat); cursor.setCharFormat(timeFormat);
cursor.insertText(QDateTime::currentDateTime().toString("[hh:mm] ")); cursor.insertText(QDateTime::currentDateTime().toString("[hh:mm] "));
} }
@ -57,6 +66,8 @@ void ChatView::appendMessage(QString sender, QString message, QColor playerColor
if (playerBold) if (playerBold)
senderFormat.setFontWeight(QFont::Bold); senderFormat.setFontWeight(QFont::Bold);
} }
if (sameSender)
senderFormat.setForeground(Qt::transparent);
cursor.setCharFormat(senderFormat); cursor.setCharFormat(senderFormat);
if (!sender.isEmpty()) if (!sender.isEmpty())
sender.append(": "); sender.append(": ");

View file

@ -12,13 +12,14 @@ class QMouseEvent;
class ChatView : public QTextBrowser { class ChatView : public QTextBrowser {
Q_OBJECT; Q_OBJECT;
private: private:
QString lastSender;
bool evenNumber; bool evenNumber;
QString ownName; QString ownName;
bool showTimestamps; bool showTimestamps;
QTextFragment getFragmentUnderMouse(const QPoint &pos) const; QTextFragment getFragmentUnderMouse(const QPoint &pos) const;
QString getCardNameUnderMouse(QTextFragment frag) const; QString getCardNameUnderMouse(QTextFragment frag) const;
QString getCardNameUnderMouse(const QPoint &pos) const; QString getCardNameUnderMouse(const QPoint &pos) const;
QTextCursor prepareBlock(); QTextCursor prepareBlock(bool same = false);
private slots: private slots:
void openLink(const QUrl &link); void openLink(const QUrl &link);
public: public:

View file

@ -22,6 +22,7 @@ GameSelector::GameSelector(AbstractClient *_client, TabRoom *_room, const QMap<i
gameListProxyModel->setSortCaseSensitivity(Qt::CaseInsensitive); gameListProxyModel->setSortCaseSensitivity(Qt::CaseInsensitive);
gameListView->setModel(gameListProxyModel); gameListView->setModel(gameListProxyModel);
gameListView->setSortingEnabled(true); gameListView->setSortingEnabled(true);
gameListView->setAlternatingRowColors(true);
if (_room) if (_room)
gameListView->header()->hideSection(0); gameListView->header()->hideSection(0);
gameListView->header()->setResizeMode(1, QHeaderView::ResizeToContents); gameListView->header()->setResizeMode(1, QHeaderView::ResizeToContents);

View file

@ -107,6 +107,7 @@ UserList::UserList(TabSupervisor *_tabSupervisor, AbstractClient *_client, UserL
userTree->setRootIsDecorated(false); userTree->setRootIsDecorated(false);
userTree->setIconSize(QSize(20, 12)); userTree->setIconSize(QSize(20, 12));
userTree->setItemDelegate(itemDelegate); userTree->setItemDelegate(itemDelegate);
userTree->setAlternatingRowColors(true);
connect(userTree, SIGNAL(itemActivated(QTreeWidgetItem *, int)), this, SLOT(userClicked(QTreeWidgetItem *, int))); connect(userTree, SIGNAL(itemActivated(QTreeWidgetItem *, int)), this, SLOT(userClicked(QTreeWidgetItem *, int)));
QVBoxLayout *vbox = new QVBoxLayout; QVBoxLayout *vbox = new QVBoxLayout;