tools/chatgui: Qt5 GUI chat app stub with tray, channel list, message bubbles
This commit is contained in:
1 parent
6717c863e7
commit
b667d6f352
20 files changed
+1089
No files matched your search
@@ -0,0 +1,74 @@
|
||||
#include "channeldelegate.h"
|
||||
#include <QPainter>
|
||||
#include <QApplication>
|
||||
|
||||
ChannelDelegate::ChannelDelegate(QObject *parent)
|
||||
: QStyledItemDelegate(parent) {}
|
||||
|
||||
void ChannelDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option,
|
||||
const QModelIndex &index) const {
|
||||
painter->save();
|
||||
|
||||
if (option.state & QStyle::State_Selected) {
|
||||
painter->fillRect(option.rect, option.palette.highlight());
|
||||
} else if (option.state & QStyle::State_MouseOver) {
|
||||
painter->fillRect(option.rect, option.palette.light());
|
||||
}
|
||||
|
||||
const int margin = 8;
|
||||
const int iconSize = 32;
|
||||
QRect iconRect(option.rect.left() + margin,
|
||||
option.rect.top() + (option.rect.height() - iconSize) / 2,
|
||||
iconSize, iconSize);
|
||||
|
||||
QIcon icon = qvariant_cast<QIcon>(index.data(ChannelIconRole));
|
||||
if (!icon.isNull()) {
|
||||
icon.paint(painter, iconRect);
|
||||
}
|
||||
|
||||
QRect textRect(iconRect.right() + margin, option.rect.top() + margin,
|
||||
option.rect.right() - iconRect.right() - 2 * margin,
|
||||
option.rect.height() - 2 * margin);
|
||||
|
||||
QString name = index.data(ChannelNameRole).toString();
|
||||
QFont nameFont = option.font;
|
||||
nameFont.setBold(true);
|
||||
nameFont.setPointSize(nameFont.pointSize() + 1);
|
||||
painter->setFont(nameFont);
|
||||
|
||||
QColor textColor = (option.state & QStyle::State_Selected)
|
||||
? option.palette.highlightedText().color()
|
||||
: option.palette.text().color();
|
||||
painter->setPen(textColor);
|
||||
|
||||
QRect nameRect = textRect;
|
||||
nameRect.setHeight(QFontMetrics(nameFont).height());
|
||||
painter->drawText(nameRect, Qt::AlignLeft | Qt::AlignTop,
|
||||
painter->fontMetrics().elidedText(name, Qt::ElideRight, nameRect.width()));
|
||||
|
||||
QString lastMsg = index.data(ChannelLastMessageRole).toString();
|
||||
if (!lastMsg.isEmpty()) {
|
||||
QFont msgFont = option.font;
|
||||
msgFont.setPointSize(msgFont.pointSize() - 1);
|
||||
painter->setFont(msgFont);
|
||||
|
||||
QColor msgColor = (option.state & QStyle::State_Selected)
|
||||
? option.palette.highlightedText().color().darker(120)
|
||||
: QColor(128, 128, 128);
|
||||
painter->setPen(msgColor);
|
||||
|
||||
QRect msgRect(textRect.left(), nameRect.bottom() + 4,
|
||||
textRect.width(), option.rect.bottom() - nameRect.bottom() - margin);
|
||||
QString elidedMsg = painter->fontMetrics().elidedText(lastMsg, Qt::ElideRight, msgRect.width());
|
||||
painter->drawText(msgRect, Qt::AlignLeft | Qt::AlignTop | Qt::TextWordWrap, elidedMsg);
|
||||
}
|
||||
|
||||
painter->restore();
|
||||
}
|
||||
|
||||
QSize ChannelDelegate::sizeHint(const QStyleOptionViewItem &option,
|
||||
const QModelIndex &index) const {
|
||||
Q_UNUSED(option);
|
||||
Q_UNUSED(index);
|
||||
return QSize(200, 56);
|
||||
}
|
||||
Reference in new issue
Block a user