mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
parent
e2d67e4250
commit
885b874ef3
|
@ -7,6 +7,7 @@
|
|||
#include <QTime>
|
||||
#include <QScrollBar>
|
||||
#include <QFileDialog>
|
||||
#include <QMenu>
|
||||
|
||||
ChatForm::ChatForm(Friend* chatFriend)
|
||||
: f(chatFriend), curRow{0}, lockSliderToBottom{true}
|
||||
|
@ -30,6 +31,7 @@ ChatForm::ChatForm(Friend* chatFriend)
|
|||
chatAreaWidget->setLayout(mainChatLayout);
|
||||
chatArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded);
|
||||
chatArea->setWidgetResizable(true);
|
||||
chatArea->setContextMenuPolicy(Qt::CustomContextMenu);
|
||||
mainChatLayout->setColumnStretch(1,1);
|
||||
mainChatLayout->setSpacing(10);
|
||||
|
||||
|
@ -96,6 +98,7 @@ ChatForm::ChatForm(Friend* chatFriend)
|
|||
connect(callButton, SIGNAL(clicked()), this, SLOT(onCallTriggered()));
|
||||
connect(msgEdit, SIGNAL(enterPressed()), this, SLOT(onSendTriggered()));
|
||||
connect(chatArea->verticalScrollBar(), SIGNAL(rangeChanged(int,int)), this, SLOT(onSliderRangeChanged()));
|
||||
connect(chatArea, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(onChatContextMenuRequested(QPoint)));
|
||||
}
|
||||
|
||||
ChatForm::~ChatForm()
|
||||
|
@ -169,16 +172,24 @@ void ChatForm::addMessage(QLabel* author, QLabel* message, QLabel* date)
|
|||
{
|
||||
mainChatLayout->setRowStretch(curRow, 0);
|
||||
mainChatLayout->addItem(new QSpacerItem(0,AUTHOR_CHANGE_SPACING),curRow,0,1,3);
|
||||
curRow++;
|
||||
}
|
||||
mainChatLayout->addWidget(author, curRow, 0);
|
||||
}
|
||||
previousName = author->text();
|
||||
curRow++;
|
||||
}
|
||||
else if (curRow)// onSaveLogClicked expects 0 or 3 QLabel per line
|
||||
author->setText("");
|
||||
mainChatLayout->addWidget(author, curRow, 0);
|
||||
mainChatLayout->addWidget(message, curRow, 1);
|
||||
mainChatLayout->addWidget(date, curRow, 3);
|
||||
mainChatLayout->setRowStretch(curRow+1, 1);
|
||||
mainChatLayout->setRowStretch(curRow, 0);
|
||||
curRow++;
|
||||
author->setContextMenuPolicy(Qt::CustomContextMenu);
|
||||
message->setContextMenuPolicy(Qt::CustomContextMenu);
|
||||
date->setContextMenuPolicy(Qt::CustomContextMenu);
|
||||
connect(author, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(onChatContextMenuRequested(QPoint)));
|
||||
connect(message, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(onChatContextMenuRequested(QPoint)));
|
||||
connect(date, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(onChatContextMenuRequested(QPoint)));
|
||||
}
|
||||
|
||||
void ChatForm::onAttachClicked()
|
||||
|
@ -400,3 +411,44 @@ void ChatForm::onCancelCallTriggered()
|
|||
connect(callButton, SIGNAL(clicked()), this, SLOT(onCallTriggered()));
|
||||
emit cancelCall(callId, f->friendId);
|
||||
}
|
||||
|
||||
void ChatForm::onChatContextMenuRequested(QPoint pos)
|
||||
{
|
||||
QWidget* sender = (QWidget*)QObject::sender();
|
||||
pos = sender->mapToGlobal(pos);
|
||||
QMenu menu;
|
||||
menu.addAction("Save chat log", this, SLOT(onSaveLogClicked()));
|
||||
menu.exec(pos);
|
||||
}
|
||||
|
||||
void ChatForm::onSaveLogClicked()
|
||||
{
|
||||
QString path = QFileDialog::getSaveFileName(0,"Save chat log");
|
||||
if (path.isEmpty())
|
||||
return;
|
||||
|
||||
QFile file(path);
|
||||
if (!file.open(QIODevice::WriteOnly | QIODevice::Text))
|
||||
return;
|
||||
|
||||
QString log;
|
||||
QList<QLabel*> labels = chatAreaWidget->findChildren<QLabel*>();
|
||||
int i=0;
|
||||
for (QLabel* label : labels)
|
||||
{
|
||||
log += label->text();
|
||||
if (i==2)
|
||||
{
|
||||
i=0;
|
||||
log += '\n';
|
||||
}
|
||||
else
|
||||
{
|
||||
log += '\t';
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
file.write(log.toUtf8());
|
||||
file.close();
|
||||
}
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
#include <QTextEdit>
|
||||
#include <QScrollArea>
|
||||
#include <QTime>
|
||||
#include <QPoint>
|
||||
|
||||
#include "widget/tool/chattextedit.h"
|
||||
#include "ui_widget.h"
|
||||
|
@ -61,6 +62,8 @@ private slots:
|
|||
void onAnswerCallTriggered();
|
||||
void onHangupCallTriggered();
|
||||
void onCancelCallTriggered();
|
||||
void onChatContextMenuRequested(QPoint pos);
|
||||
void onSaveLogClicked();
|
||||
|
||||
private:
|
||||
Friend* f;
|
||||
|
|
|
@ -7,6 +7,9 @@
|
|||
#include <QFont>
|
||||
#include <QTime>
|
||||
#include <QScrollBar>
|
||||
#include <QMenu>
|
||||
#include <QFile>
|
||||
#include <QFileDialog>
|
||||
|
||||
GroupChatForm::GroupChatForm(Group* chatGroup)
|
||||
: group(chatGroup), curRow{0}, lockSliderToBottom{true}
|
||||
|
@ -38,6 +41,7 @@ GroupChatForm::GroupChatForm(Group* chatGroup)
|
|||
chatAreaWidget->setLayout(mainChatLayout);
|
||||
chatArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded);
|
||||
chatArea->setWidgetResizable(true);
|
||||
chatArea->setContextMenuPolicy(Qt::CustomContextMenu);
|
||||
mainChatLayout->setColumnStretch(1,1);
|
||||
mainChatLayout->setHorizontalSpacing(10);
|
||||
|
||||
|
@ -78,6 +82,7 @@ GroupChatForm::GroupChatForm(Group* chatGroup)
|
|||
connect(sendButton, SIGNAL(clicked()), this, SLOT(onSendTriggered()));
|
||||
connect(msgEdit, SIGNAL(enterPressed()), this, SLOT(onSendTriggered()));
|
||||
connect(chatArea->verticalScrollBar(), SIGNAL(rangeChanged(int,int)), this, SLOT(onSliderRangeChanged()));
|
||||
connect(chatArea, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(onChatContextMenuRequested(QPoint)));
|
||||
}
|
||||
|
||||
GroupChatForm::~GroupChatForm()
|
||||
|
@ -149,16 +154,24 @@ void GroupChatForm::addMessage(QLabel* author, QLabel* message, QLabel* date)
|
|||
{
|
||||
mainChatLayout->setRowStretch(curRow, 0);
|
||||
mainChatLayout->addItem(new QSpacerItem(0,AUTHOR_CHANGE_SPACING),curRow,0,1,3);
|
||||
curRow++;
|
||||
}
|
||||
mainChatLayout->addWidget(author, curRow, 0);
|
||||
}
|
||||
previousName = author->text();
|
||||
curRow++;
|
||||
}
|
||||
else if (curRow)// onSaveLogClicked expects 0 or 3 QLabel per line
|
||||
author->setText("");
|
||||
mainChatLayout->addWidget(author, curRow, 0);
|
||||
mainChatLayout->addWidget(message, curRow, 1);
|
||||
mainChatLayout->addWidget(date, curRow, 3);
|
||||
mainChatLayout->setRowStretch(curRow+1, 1);
|
||||
mainChatLayout->setRowStretch(curRow, 0);
|
||||
curRow++;
|
||||
author->setContextMenuPolicy(Qt::CustomContextMenu);
|
||||
message->setContextMenuPolicy(Qt::CustomContextMenu);
|
||||
date->setContextMenuPolicy(Qt::CustomContextMenu);
|
||||
connect(author, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(onChatContextMenuRequested(QPoint)));
|
||||
connect(message, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(onChatContextMenuRequested(QPoint)));
|
||||
connect(date, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(onChatContextMenuRequested(QPoint)));
|
||||
}
|
||||
|
||||
void GroupChatForm::onSliderRangeChanged()
|
||||
|
@ -177,3 +190,44 @@ void GroupChatForm::onUserListChanged()
|
|||
names.chop(2);
|
||||
namesList->setText(names);
|
||||
}
|
||||
|
||||
void GroupChatForm::onChatContextMenuRequested(QPoint pos)
|
||||
{
|
||||
QWidget* sender = (QWidget*)QObject::sender();
|
||||
pos = sender->mapToGlobal(pos);
|
||||
QMenu menu;
|
||||
menu.addAction("Save chat log", this, SLOT(onSaveLogClicked()));
|
||||
menu.exec(pos);
|
||||
}
|
||||
|
||||
void GroupChatForm::onSaveLogClicked()
|
||||
{
|
||||
QString path = QFileDialog::getSaveFileName(0,"Save chat log");
|
||||
if (path.isEmpty())
|
||||
return;
|
||||
|
||||
QFile file(path);
|
||||
if (!file.open(QIODevice::WriteOnly | QIODevice::Text))
|
||||
return;
|
||||
|
||||
QString log;
|
||||
QList<QLabel*> labels = chatAreaWidget->findChildren<QLabel*>();
|
||||
int i=0;
|
||||
for (QLabel* label : labels)
|
||||
{
|
||||
log += label->text();
|
||||
if (i==2)
|
||||
{
|
||||
i=0;
|
||||
log += '\n';
|
||||
}
|
||||
else
|
||||
{
|
||||
log += '\t';
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
file.write(log.toUtf8());
|
||||
file.close();
|
||||
}
|
||||
|
|
|
@ -37,6 +37,8 @@ signals:
|
|||
private slots:
|
||||
void onSendTriggered();
|
||||
void onSliderRangeChanged();
|
||||
void onChatContextMenuRequested(QPoint pos);
|
||||
void onSaveLogClicked();
|
||||
|
||||
private:
|
||||
Group* group;
|
||||
|
|
|
@ -405,7 +405,7 @@ void Widget::removeFriend(int friendId)
|
|||
onAddClicked();
|
||||
}
|
||||
|
||||
void Widget::onGroupInviteReceived(int friendId, uint8_t* publicKey)
|
||||
void Widget::onGroupInviteReceived(int32_t friendId, uint8_t* publicKey)
|
||||
{
|
||||
int groupId = core->joinGroupchat(friendId, publicKey);
|
||||
if (groupId == -1)
|
||||
|
@ -413,7 +413,6 @@ void Widget::onGroupInviteReceived(int friendId, uint8_t* publicKey)
|
|||
qWarning() << "Widget::onGroupInviteReceived: Unable to accept invitation";
|
||||
return;
|
||||
}
|
||||
//createGroup(groupId);
|
||||
}
|
||||
|
||||
void Widget::onGroupMessageReceived(int groupnumber, int friendgroupnumber, const QString& message)
|
||||
|
|
|
@ -62,7 +62,7 @@ private slots:
|
|||
void onFriendWidgetClicked(FriendWidget* widget);
|
||||
void onFriendMessageReceived(int friendId, const QString& message);
|
||||
void onFriendRequestReceived(const QString& userId, const QString& message);
|
||||
void onGroupInviteReceived(int friendId, uint8_t *publicKey);
|
||||
void onGroupInviteReceived(int32_t friendId, uint8_t *publicKey);
|
||||
void onGroupMessageReceived(int groupnumber, int friendgroupnumber, const QString& message);
|
||||
void onGroupNamelistChanged(int groupnumber, int peernumber, uint8_t change);
|
||||
void onGroupWidgetClicked(GroupWidget* widget);
|
||||
|
|
Loading…
Reference in New Issue
Block a user