message format change;
add functions fo chatdialog
This commit is contained in:
1 parent
eeff966b4b
commit
c71da77ac5
3 files changed
+70
-4
No files matched your search
+5
-4
@@ -1,13 +1,14 @@
|
||||
package SyncDemo;
|
||||
|
||||
message ChatMessage {
|
||||
required string msgData = 1;
|
||||
optional string msgData = 1;
|
||||
required string to = 2;
|
||||
required string from = 3;
|
||||
required int32 timestamp = 4;
|
||||
optional int32 timestamp = 4;
|
||||
enum ChatMessageType {
|
||||
CHAT = 0;
|
||||
OTHER = 1;
|
||||
HELLO = 1;
|
||||
OTHER = 2;
|
||||
}
|
||||
optional ChatMessageType type = 5;
|
||||
required ChatMessageType type = 5;
|
||||
}
|
||||
@@ -1,9 +1,61 @@
|
||||
#include <QtGui>
|
||||
#include "chatdialog.h"
|
||||
#include <ctime>
|
||||
|
||||
ChatDialog::ChatDialog(QWidget *parent)
|
||||
: QDialog(parent)
|
||||
{
|
||||
setupUi(this);
|
||||
lineEdit->setFocusPolicy(Qt::StrongFocus);
|
||||
|
||||
|
||||
connect(lineEdit, SIGNAL(returnPressed()), this, SLOT(returnPressed()));
|
||||
}
|
||||
|
||||
void
|
||||
ChatDialog::appendMessage(const SyncDemo::ChatMessage &msg)
|
||||
{
|
||||
if (msg.from().isEmpty || message.msgData().isEmpty())
|
||||
return;
|
||||
|
||||
QTextCursor cursor(textEdit->textCursor());
|
||||
cursor.movePosition(QTextCursor::End);
|
||||
QTextTableFormat tableFormat;
|
||||
tableFormat.setBorder(0);
|
||||
QTextTable *table = cursor.insertTable(1, 2, tableFormat);
|
||||
table->cellAt(0, 0).firstCursorPosition().insertText("<" + msg.from() + ">: ");
|
||||
table->cellAt(0, 1).firstCursorPosition().insertText(msg.msgData());
|
||||
QScrollBar *bar = textEdit->verticalScrollBar();
|
||||
bar->setValue(bar->maximum());
|
||||
}
|
||||
|
||||
void
|
||||
ChatDialog::updateTreeView()
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
ChatDialog::returnPressed()
|
||||
{
|
||||
QString text = lineEdit->text();
|
||||
if (text.isEmpty())
|
||||
return;
|
||||
|
||||
SyncDemo::ChatMessage msg;
|
||||
formChatMessage(text, msg);
|
||||
|
||||
// TODO:
|
||||
// send message
|
||||
appendMessage(msg);
|
||||
updateTreeView();
|
||||
|
||||
}
|
||||
|
||||
void
|
||||
ChatDialog::formChatMessage(const QString &text, SyncDemo::ChatMessage &msg) {
|
||||
msg.set_from(m_nick);
|
||||
msg.set_to(m_chatroom);
|
||||
msg.set_msgData(text);
|
||||
time_t seconds = time(NULL);
|
||||
msg.set_timestamp(seconds);
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
#ifndef CHATDIALOG_H
|
||||
#define CHATDIALOG_H
|
||||
#include "ui_chatdialog.h"
|
||||
#include "chatbuf.pb.h"
|
||||
|
||||
class ChatDialog : public QDialog, private Ui::ChatDialog
|
||||
{
|
||||
@@ -8,5 +9,17 @@ class ChatDialog : public QDialog, private Ui::ChatDialog
|
||||
|
||||
public:
|
||||
ChatDialog(QWidget *parent = 0);
|
||||
|
||||
public slots:
|
||||
void appendMessage(SyncDemo::ChatMessage &msg);
|
||||
void updateTreeView();
|
||||
|
||||
private slots:
|
||||
void returnPressed();
|
||||
void formChatMessage(const QString &text, SyncDemo::ChatMessage &msg);
|
||||
|
||||
private:
|
||||
QString m_nick;
|
||||
QString m_chatroom;
|
||||
};
|
||||
#endif
|
||||
Reference in new issue
Block a user