tools/chatgui: Qt5 GUI chat app stub with tray, channel list, message bubbles

This commit is contained in:
Evgeny committed 2026-06-22 22:48:27 +03:00
1 parent 6717c863e7
commit b667d6f352
20 files changed
+1089

No files matched your search

+82
View File
@@ -0,0 +1,82 @@
#include "channellist.h"
#include "channeldelegate.h"
#include <QVBoxLayout>
#include <QLabel>
#include <QPainter>
#include <QPixmap>
static QIcon makeChannelIcon(const QColor &color, const QString &letter) {
QPixmap pix(32, 32);
pix.fill(Qt::transparent);
QPainter p(&pix);
p.setRenderHint(QPainter::Antialiasing);
p.setBrush(color);
p.setPen(Qt::NoPen);
p.drawRoundedRect(0, 0, 32, 32, 8, 8);
p.setPen(Qt::white);
QFont f = p.font();
f.setBold(true);
f.setPointSize(14);
p.setFont(f);
p.drawText(QRect(0, 0, 32, 32), Qt::AlignCenter, letter);
p.end();
return QIcon(pix);
}
ChannelList::ChannelList(QWidget *parent)
: QWidget(parent)
, m_listView(new QListView(this))
, m_model(new QStandardItemModel(this))
{
auto *layout = new QVBoxLayout(this);
layout->setContentsMargins(0, 0, 0, 0);
layout->setSpacing(0);
auto *header = new QLabel("Channels", this);
header->setAlignment(Qt::AlignCenter);
header->setStyleSheet("font-weight: bold; padding: 8px; background: palette(window);");
layout->addWidget(header);
m_listView->setModel(m_model);
m_listView->setItemDelegate(new ChannelDelegate(this));
m_listView->setEditTriggers(QAbstractItemView::NoEditTriggers);
m_listView->setSelectionMode(QAbstractItemView::SingleSelection);
m_listView->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
m_listView->setVerticalScrollMode(QAbstractItemView::ScrollPerPixel);
layout->addWidget(m_listView);
connect(m_listView->selectionModel(), &QItemSelectionModel::currentChanged,
this, [this](const QModelIndex &current, const QModelIndex &) {
if (current.isValid()) {
emit channelSelected(current.row());
}
});
populateStubData();
}
void ChannelList::populateStubData() {
struct {
const char *name;
const char *lastMsg;
QColor color;
const char *letter;
} channels[] = {
{"#general", "Alice: Sounds good, let's deploy tomorrow morning.", QColor(74, 144, 226), "G"},
{"#random", "Bob: Anyone seen the latest episode? It was amazing!", QColor(126, 211, 33), "R"},
{"#dev-team", "Carol: I've pushed the fix for ETCP-42 to staging.", QColor(245, 166, 35), "D"},
{"#announcements","Admin: Maintenance scheduled for Sunday 02:00 UTC.", QColor(208, 2, 27), "A"},
{"#support", "Dave: Can someone help me configure the routing table? The BGP session keeps dropping after the handshake completes. I've checked the logs.", QColor(144, 19, 254), "S"},
{"#offtopic", "Eve: Check out this new keyboard — Cherry MX Blue, 60%.", QColor(0, 184, 148), "O"},
};
for (const auto &ch : channels) {
auto *item = new QStandardItem();
item->setData(ch.name, ChannelNameRole);
item->setData(QString::fromUtf8(ch.lastMsg), ChannelLastMessageRole);
item->setData(makeChannelIcon(ch.color, ch.letter), ChannelIconRole);
m_model->appendRow(item);
}
m_listView->setCurrentIndex(m_model->index(0, 0));
}