mirror of
https://github.com/overte-org/overte.git
synced 2025-08-08 10:17:40 +02:00
Update chat window to use vertical layout
This commit is contained in:
parent
606a48d555
commit
c1fa6b41e4
2 changed files with 18 additions and 47 deletions
|
@ -44,9 +44,6 @@ ChatWindow::ChatWindow(QWidget* parent) :
|
||||||
FlowLayout* flowLayout = new FlowLayout(0, 4, 4);
|
FlowLayout* flowLayout = new FlowLayout(0, 4, 4);
|
||||||
ui->usersWidget->setLayout(flowLayout);
|
ui->usersWidget->setLayout(flowLayout);
|
||||||
|
|
||||||
ui->messagesGridLayout->setColumnStretch(0, 1);
|
|
||||||
ui->messagesGridLayout->setColumnStretch(1, 3);
|
|
||||||
|
|
||||||
ui->messagePlainTextEdit->installEventFilter(this);
|
ui->messagePlainTextEdit->installEventFilter(this);
|
||||||
ui->messagePlainTextEdit->setWordWrapMode(QTextOption::WrapAtWordBoundaryOrAnywhere);
|
ui->messagePlainTextEdit->setWordWrapMode(QTextOption::WrapAtWordBoundaryOrAnywhere);
|
||||||
|
|
||||||
|
@ -172,8 +169,8 @@ void ChatWindow::addTimeStamp() {
|
||||||
|
|
||||||
bool atBottom = isAtBottom();
|
bool atBottom = isAtBottom();
|
||||||
|
|
||||||
ui->messagesGridLayout->addWidget(timeLabel, ui->messagesGridLayout->rowCount(), 0, 1, 2);
|
ui->messagesVBoxLayout->addWidget(timeLabel);
|
||||||
ui->messagesGridLayout->parentWidget()->updateGeometry();
|
ui->messagesVBoxLayout->parentWidget()->updateGeometry();
|
||||||
|
|
||||||
Application::processEvents();
|
Application::processEvents();
|
||||||
numMessagesAfterLastTimeStamp = 0;
|
numMessagesAfterLastTimeStamp = 0;
|
||||||
|
@ -251,29 +248,8 @@ void ChatWindow::messageReceived(const QXmppMessage& message) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create username label
|
// Update background if this is a message from the current user
|
||||||
ChatMessageArea* userLabel = new ChatMessageArea(false);
|
bool fromSelf = getParticipantName(message.from()) == AccountManager::getInstance().getUsername();
|
||||||
userLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum);
|
|
||||||
userLabel->setWordWrapMode(QTextOption::NoWrap);
|
|
||||||
userLabel->setLineWrapMode(QTextEdit::NoWrap);
|
|
||||||
userLabel->setTextInteractionFlags(Qt::NoTextInteraction);
|
|
||||||
userLabel->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
|
||||||
userLabel->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
|
||||||
userLabel->setReadOnly(true);
|
|
||||||
userLabel->setSizeAdjustPolicy(QAbstractScrollArea::AdjustToContents);
|
|
||||||
|
|
||||||
userLabel->setStyleSheet("padding: 2px;"
|
|
||||||
"font-weight: bold;"
|
|
||||||
"background-color: rgba(0, 0, 0, 0%);"
|
|
||||||
"border: 0;");
|
|
||||||
|
|
||||||
QTextBlockFormat format;
|
|
||||||
format.setLineHeight(130, QTextBlockFormat::ProportionalHeight);
|
|
||||||
QTextCursor cursor = userLabel->textCursor();
|
|
||||||
cursor.setBlockFormat(format);
|
|
||||||
cursor.insertText(getParticipantName(message.from()));
|
|
||||||
|
|
||||||
userLabel->setAlignment(Qt::AlignRight);
|
|
||||||
|
|
||||||
// Create message area
|
// Create message area
|
||||||
ChatMessageArea* messageArea = new ChatMessageArea(true);
|
ChatMessageArea* messageArea = new ChatMessageArea(true);
|
||||||
|
@ -289,30 +265,27 @@ void ChatWindow::messageReceived(const QXmppMessage& message) {
|
||||||
"padding-left: 2px;"
|
"padding-left: 2px;"
|
||||||
"padding-top: 2px;"
|
"padding-top: 2px;"
|
||||||
"padding-right: 20px;"
|
"padding-right: 20px;"
|
||||||
|
"margin: 0px;"
|
||||||
|
"color: #333333;"
|
||||||
|
"font-size: 14pt;"
|
||||||
"background-color: rgba(0, 0, 0, 0%);"
|
"background-color: rgba(0, 0, 0, 0%);"
|
||||||
"border: 0;");
|
"border: 0;");
|
||||||
|
|
||||||
// Update background if this is a message from the current user
|
QString userLabel = getParticipantName(message.from());
|
||||||
bool fromSelf = getParticipantName(message.from()) == AccountManager::getInstance().getUsername();
|
|
||||||
if (fromSelf) {
|
if (fromSelf) {
|
||||||
userLabel->setStyleSheet(userLabel->styleSheet() + "background-color: #e1e8ea");
|
userLabel = "<b style=\"color: #4a6f91\">" + userLabel + ": </b>";
|
||||||
messageArea->setStyleSheet(messageArea->styleSheet() + "background-color: #e1e8ea");
|
messageArea->setStyleSheet(messageArea->styleSheet() + "background-color: #e1e8ea");
|
||||||
|
} else {
|
||||||
|
userLabel = "<b>" + userLabel + ": </b>";
|
||||||
}
|
}
|
||||||
|
|
||||||
messageArea->document()->setDefaultStyleSheet("a { text-decoration: none; font-weight: bold; color: #267077;}");
|
messageArea->document()->setDefaultStyleSheet("a { text-decoration: none; font-weight: bold; color: #267077;}");
|
||||||
messageArea->setHtml(message.body().replace(regexLinks, "<a href=\"\\1\">\\1</a>"));
|
messageArea->setHtml(userLabel + message.body().replace(regexLinks, "<a href=\"\\1\">\\1</a>"));
|
||||||
|
|
||||||
bool atBottom = isAtBottom();
|
bool atBottom = isAtBottom();
|
||||||
ui->messagesGridLayout->addWidget(userLabel, ui->messagesGridLayout->rowCount(), 0);
|
|
||||||
ui->messagesGridLayout->addWidget(messageArea, ui->messagesGridLayout->rowCount() - 1, 1);
|
|
||||||
|
|
||||||
// Force the height of the username area to match the height of the message area
|
ui->messagesVBoxLayout->addWidget(messageArea);
|
||||||
connect(messageArea, &ChatMessageArea::sizeChanged, userLabel, &ChatMessageArea::setSize);
|
ui->messagesVBoxLayout->parentWidget()->updateGeometry();
|
||||||
|
|
||||||
// Force initial height to match message area
|
|
||||||
userLabel->setFixedHeight(messageArea->size().height());
|
|
||||||
|
|
||||||
ui->messagesGridLayout->parentWidget()->updateGeometry();
|
|
||||||
Application::processEvents();
|
Application::processEvents();
|
||||||
|
|
||||||
if (atBottom || fromSelf) {
|
if (atBottom || fromSelf) {
|
||||||
|
|
|
@ -159,7 +159,10 @@ QPushButton:pressed {
|
||||||
<property name="styleSheet">
|
<property name="styleSheet">
|
||||||
<string notr="true">margin-top: 0px;</string>
|
<string notr="true">margin-top: 0px;</string>
|
||||||
</property>
|
</property>
|
||||||
<layout class="QGridLayout" name="messagesGridLayout">
|
<layout class="QVBoxLayout" name="messagesVBoxLayout">
|
||||||
|
<property name="spacing">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
<property name="leftMargin">
|
<property name="leftMargin">
|
||||||
<number>0</number>
|
<number>0</number>
|
||||||
</property>
|
</property>
|
||||||
|
@ -172,9 +175,6 @@ QPushButton:pressed {
|
||||||
<property name="bottomMargin">
|
<property name="bottomMargin">
|
||||||
<number>0</number>
|
<number>0</number>
|
||||||
</property>
|
</property>
|
||||||
<property name="spacing">
|
|
||||||
<number>0</number>
|
|
||||||
</property>
|
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
</widget>
|
</widget>
|
||||||
|
@ -213,8 +213,6 @@ QPushButton:pressed {
|
||||||
</layout>
|
</layout>
|
||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
<zorder>messagePlainTextEdit</zorder>
|
|
||||||
<zorder>dockWidgetContents</zorder>
|
|
||||||
</widget>
|
</widget>
|
||||||
<tabstops>
|
<tabstops>
|
||||||
<tabstop>messagePlainTextEdit</tabstop>
|
<tabstop>messagePlainTextEdit</tabstop>
|
||||||
|
|
Loading…
Reference in a new issue