set maxLen for Chatmessages
This commit is contained in:
@@ -6,8 +6,49 @@
|
||||
#include "../DataStore/DataStore.h"
|
||||
Chat::Chat() {}
|
||||
|
||||
void Chat::renderChatBox(Ui::MainWindow *ui, QListView *view)
|
||||
ChatMemoEdit::ChatMemoEdit(QWidget* parent) : QTextEdit(parent) {
|
||||
QObject::connect(this, &QTextEdit::textChanged, this, &ChatMemoEdit::updateDisplay);
|
||||
}
|
||||
|
||||
void ChatMemoEdit::updateDisplay() {
|
||||
QString txt = this->toPlainText();
|
||||
if (lenDisplayLabel)
|
||||
lenDisplayLabel->setText(QString::number(txt.toUtf8().size()) + "/" + QString::number(maxlen));
|
||||
|
||||
if (txt.toUtf8().size() <= maxlen) {
|
||||
// Everything is fine
|
||||
if (sendChatButton)
|
||||
sendChatButton->setEnabled(true);
|
||||
|
||||
if (lenDisplayLabel)
|
||||
lenDisplayLabel->setStyleSheet("");
|
||||
}
|
||||
else {
|
||||
// Overweight
|
||||
if (sendChatButton)
|
||||
sendChatButton->setEnabled(false);
|
||||
|
||||
if (lenDisplayLabel)
|
||||
lenDisplayLabel->setStyleSheet("color: red;");
|
||||
}
|
||||
}
|
||||
|
||||
void ChatMemoEdit::setMaxLen(int len) {
|
||||
this->maxlen = len;
|
||||
updateDisplay();
|
||||
}
|
||||
|
||||
void ChatMemoEdit::SetSendChatButton(QPushButton* button) {
|
||||
this->sendChatButton = button;
|
||||
}
|
||||
|
||||
void ChatMemoEdit::setLenDisplayLabel(QLabel* label) {
|
||||
this->lenDisplayLabel = label;
|
||||
}
|
||||
|
||||
void Chat::renderChatBox(Ui::MainWindow *ui, QListView *view, QLabel *label)
|
||||
{
|
||||
|
||||
QStandardItemModel *chat = new QStandardItemModel();
|
||||
// ui->lcdNumber->setStyleSheet("background-color: red");
|
||||
// ui->lcdNumber->setPalette(Qt::red);
|
||||
|
||||
Reference in New Issue
Block a user