2014-07-07 00:19:45 +08:00
|
|
|
/*
|
2016-11-28 21:33:38 +08:00
|
|
|
Copyright © 2014-2015 by The qTox Project Contributors
|
2015-06-06 09:40:08 +08:00
|
|
|
|
2014-07-07 00:19:45 +08:00
|
|
|
This file is part of qTox, a Qt-based graphical interface for Tox.
|
|
|
|
|
2015-06-06 09:40:08 +08:00
|
|
|
qTox is libre software: you can redistribute it and/or modify
|
2014-07-07 00:19:45 +08:00
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
2015-06-06 09:40:08 +08:00
|
|
|
|
|
|
|
qTox is distributed in the hope that it will be useful,
|
2014-07-07 00:19:45 +08:00
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2015-06-06 09:40:08 +08:00
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
2014-07-07 00:19:45 +08:00
|
|
|
|
2015-06-06 09:40:08 +08:00
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with qTox. If not, see <http://www.gnu.org/licenses/>.
|
2014-07-07 00:19:45 +08:00
|
|
|
*/
|
|
|
|
|
2014-06-25 04:11:11 +08:00
|
|
|
#include "groupchatform.h"
|
2016-08-07 03:28:40 +08:00
|
|
|
|
|
|
|
#include <QDragEnterEvent>
|
|
|
|
#include <QMimeData>
|
|
|
|
#include <QTimer>
|
2016-12-25 18:55:23 +08:00
|
|
|
#include <QToolButton>
|
2016-08-07 03:28:40 +08:00
|
|
|
|
2014-10-20 18:01:22 +08:00
|
|
|
#include "tabcompleter.h"
|
2017-02-26 19:52:45 +08:00
|
|
|
#include "src/core/core.h"
|
|
|
|
#include "src/core/coreav.h"
|
2016-12-19 10:26:26 +08:00
|
|
|
#include "src/friend.h"
|
|
|
|
#include "src/friendlist.h"
|
2017-02-26 19:52:45 +08:00
|
|
|
#include "src/group.h"
|
|
|
|
#include "src/video/groupnetcamview.h"
|
|
|
|
#include "src/widget/flowlayout.h"
|
|
|
|
#include "src/widget/form/chatform.h"
|
2016-12-19 10:26:26 +08:00
|
|
|
#include "src/widget/groupwidget.h"
|
|
|
|
#include "src/widget/maskablepixmapwidget.h"
|
|
|
|
#include "src/widget/style.h"
|
2017-02-26 19:52:45 +08:00
|
|
|
#include "src/widget/tool/croppinglabel.h"
|
2016-12-19 10:26:26 +08:00
|
|
|
#include "src/widget/translator.h"
|
2014-06-25 04:11:11 +08:00
|
|
|
|
2016-07-27 06:20:39 +08:00
|
|
|
/**
|
2016-08-01 16:21:23 +08:00
|
|
|
* @var QList<QLabel*> GroupChatForm::peerLabels
|
|
|
|
* @brief Maps peernumbers to the QLabels in namesListLayout.
|
|
|
|
*
|
|
|
|
* @var QMap<int, QTimer*> GroupChatForm::peerAudioTimers
|
|
|
|
* @brief Timeout = peer stopped sending audio.
|
|
|
|
*/
|
2016-07-27 06:20:39 +08:00
|
|
|
|
2014-06-25 04:11:11 +08:00
|
|
|
GroupChatForm::GroupChatForm(Group* chatGroup)
|
2016-08-29 15:07:23 +08:00
|
|
|
: audioInputFlag(false)
|
|
|
|
, audioOutputFlag(false)
|
|
|
|
, group(chatGroup)
|
|
|
|
, inCall(false)
|
2014-06-25 04:11:11 +08:00
|
|
|
{
|
2014-09-05 23:29:14 +08:00
|
|
|
nusersLabel = new QLabel();
|
2014-09-05 02:09:55 +08:00
|
|
|
|
2014-10-20 18:01:22 +08:00
|
|
|
tabber = new TabCompleter(msgEdit, group);
|
2014-09-05 02:09:55 +08:00
|
|
|
|
|
|
|
fileButton->setEnabled(false);
|
2017-02-26 19:52:45 +08:00
|
|
|
if (group->isAvGroupchat()) {
|
2014-11-13 20:11:23 +08:00
|
|
|
videoButton->setEnabled(false);
|
|
|
|
videoButton->setObjectName("grey");
|
2017-02-26 19:52:45 +08:00
|
|
|
} else {
|
2014-11-13 20:11:23 +08:00
|
|
|
videoButton->setVisible(false);
|
|
|
|
callButton->setVisible(false);
|
|
|
|
volButton->setVisible(false);
|
|
|
|
micButton->setVisible(false);
|
|
|
|
}
|
2014-09-05 02:09:55 +08:00
|
|
|
|
2014-11-23 23:22:29 +08:00
|
|
|
nameLabel->setText(group->getGroupWidget()->getName());
|
2014-10-01 02:10:42 +08:00
|
|
|
|
|
|
|
nusersLabel->setFont(Style::getFont(Style::Medium));
|
2014-10-10 03:20:06 +08:00
|
|
|
nusersLabel->setObjectName("statusLabel");
|
2015-06-06 03:37:01 +08:00
|
|
|
retranslateUi();
|
2014-10-01 02:10:42 +08:00
|
|
|
|
2016-01-21 11:47:26 +08:00
|
|
|
avatar->setPixmap(Style::scaleSvgImage(":/img/group_dark.svg", avatar->width(), avatar->height()));
|
2014-09-05 02:09:55 +08:00
|
|
|
|
2014-06-29 05:59:11 +08:00
|
|
|
msgEdit->setObjectName("group");
|
|
|
|
|
2017-02-26 19:52:45 +08:00
|
|
|
namesListLayout = new FlowLayout(0, 5, 0);
|
2014-11-23 23:22:29 +08:00
|
|
|
QStringList names(group->getPeerList());
|
2015-06-06 09:40:08 +08:00
|
|
|
|
2017-02-26 19:52:45 +08:00
|
|
|
for (QString& name : names) {
|
|
|
|
QLabel* l = new QLabel();
|
2015-06-08 07:27:28 +08:00
|
|
|
QString tooltip = correctNames(name);
|
2017-02-26 19:52:45 +08:00
|
|
|
if (tooltip.isNull()) {
|
2015-06-08 07:27:28 +08:00
|
|
|
l->setToolTip(tooltip);
|
|
|
|
}
|
|
|
|
l->setText(name);
|
2015-02-27 22:05:03 +08:00
|
|
|
l->setTextFormat(Qt::PlainText);
|
|
|
|
namesListLayout->addWidget(l);
|
|
|
|
}
|
2015-06-06 09:40:08 +08:00
|
|
|
|
2014-09-05 23:29:14 +08:00
|
|
|
headTextLayout->addWidget(nusersLabel);
|
2014-11-02 17:41:58 +08:00
|
|
|
headTextLayout->addLayout(namesListLayout);
|
2014-06-25 04:11:11 +08:00
|
|
|
headTextLayout->addStretch();
|
|
|
|
|
2014-10-24 06:18:48 +08:00
|
|
|
nameLabel->setMinimumHeight(12);
|
|
|
|
nusersLabel->setMinimumHeight(12);
|
|
|
|
|
2014-06-25 04:11:11 +08:00
|
|
|
connect(sendButton, SIGNAL(clicked()), this, SLOT(onSendTriggered()));
|
|
|
|
connect(msgEdit, SIGNAL(enterPressed()), this, SLOT(onSendTriggered()));
|
2014-10-20 18:01:22 +08:00
|
|
|
connect(msgEdit, &ChatTextEdit::tabPressed, tabber, &TabCompleter::complete);
|
|
|
|
connect(msgEdit, &ChatTextEdit::keyPressed, tabber, &TabCompleter::reset);
|
2014-11-13 20:11:23 +08:00
|
|
|
connect(callButton, &QPushButton::clicked, this, &GroupChatForm::onCallClicked);
|
|
|
|
connect(micButton, SIGNAL(clicked()), this, SLOT(onMicMuteToggle()));
|
|
|
|
connect(volButton, SIGNAL(clicked()), this, SLOT(onVolMuteToggle()));
|
2017-02-26 19:52:45 +08:00
|
|
|
connect(nameLabel, &CroppingLabel::editFinished, this, [=](const QString& newName) {
|
|
|
|
if (!newName.isEmpty()) {
|
2015-06-08 02:25:05 +08:00
|
|
|
nameLabel->setText(newName);
|
|
|
|
emit groupTitleChanged(group->getGroupId(), newName.left(128));
|
|
|
|
}
|
|
|
|
});
|
2014-06-25 04:11:11 +08:00
|
|
|
|
2014-09-26 00:03:25 +08:00
|
|
|
setAcceptDrops(true);
|
2015-06-06 03:37:01 +08:00
|
|
|
Translator::registerHandler(std::bind(&GroupChatForm::retranslateUi, this), this);
|
|
|
|
}
|
|
|
|
|
2015-06-08 07:27:28 +08:00
|
|
|
// Correct names with "\n" in NamesListLayout widget
|
|
|
|
QString GroupChatForm::correctNames(QString& name)
|
|
|
|
{
|
|
|
|
int pos = name.indexOf(QRegExp("\n|\r\n|\r"));
|
|
|
|
int len = name.length();
|
2017-02-26 19:52:45 +08:00
|
|
|
if ((pos < len) && (pos != -1)) {
|
2015-06-08 07:27:28 +08:00
|
|
|
QString tooltip = name;
|
2017-02-26 19:52:45 +08:00
|
|
|
name.remove(pos, len - pos);
|
2015-06-08 07:27:28 +08:00
|
|
|
name.append("...");
|
|
|
|
return tooltip;
|
2017-02-26 19:52:45 +08:00
|
|
|
} else {
|
2015-06-08 07:27:28 +08:00
|
|
|
return QString();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-06 03:37:01 +08:00
|
|
|
GroupChatForm::~GroupChatForm()
|
|
|
|
{
|
|
|
|
Translator::unregister(this);
|
2014-06-25 04:11:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void GroupChatForm::onSendTriggered()
|
|
|
|
{
|
|
|
|
QString msg = msgEdit->toPlainText();
|
|
|
|
if (msg.isEmpty())
|
|
|
|
return;
|
2014-11-01 21:00:43 +08:00
|
|
|
|
2015-03-09 01:00:57 +08:00
|
|
|
msgEdit->setLastMessage(msg);
|
2014-06-25 04:11:11 +08:00
|
|
|
msgEdit->clear();
|
2014-11-01 21:00:43 +08:00
|
|
|
|
2017-02-26 19:52:45 +08:00
|
|
|
if (group->getPeersCount() != 1) {
|
|
|
|
if (msg.startsWith(ChatForm::ACTION_PREFIX, Qt::CaseInsensitive)) {
|
2016-07-31 22:17:11 +08:00
|
|
|
msg.remove(0, ChatForm::ACTION_PREFIX.length());
|
2015-03-11 10:20:36 +08:00
|
|
|
emit sendAction(group->getGroupId(), msg);
|
2017-02-26 19:52:45 +08:00
|
|
|
} else {
|
2015-03-11 10:20:36 +08:00
|
|
|
emit sendMessage(group->getGroupId(), msg);
|
2015-04-24 19:01:50 +08:00
|
|
|
}
|
2017-02-26 19:52:45 +08:00
|
|
|
} else {
|
2016-07-31 22:17:11 +08:00
|
|
|
if (msg.startsWith(ChatForm::ACTION_PREFIX, Qt::CaseInsensitive))
|
2017-02-26 19:52:45 +08:00
|
|
|
addSelfMessage(msg.mid(ChatForm::ACTION_PREFIX.length()), true,
|
|
|
|
QDateTime::currentDateTime(), true);
|
2015-03-29 22:36:43 +08:00
|
|
|
else
|
|
|
|
addSelfMessage(msg, false, QDateTime::currentDateTime(), true);
|
2015-04-24 19:01:50 +08:00
|
|
|
}
|
2014-06-25 04:11:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void GroupChatForm::onUserListChanged()
|
|
|
|
{
|
2015-09-27 01:37:17 +08:00
|
|
|
int peersCount = group->getPeersCount();
|
|
|
|
if (peersCount == 1)
|
|
|
|
nusersLabel->setText(tr("1 user in chat", "Number of users in chat"));
|
|
|
|
else
|
|
|
|
nusersLabel->setText(tr("%1 users in chat", "Number of users in chat").arg(peersCount));
|
2014-11-02 17:41:58 +08:00
|
|
|
|
2017-02-26 19:52:45 +08:00
|
|
|
QLayoutItem* child;
|
|
|
|
while ((child = namesListLayout->takeAt(0))) {
|
2014-11-02 17:41:58 +08:00
|
|
|
child->widget()->hide();
|
|
|
|
delete child->widget();
|
|
|
|
delete child;
|
|
|
|
}
|
2015-03-13 14:00:12 +08:00
|
|
|
peerLabels.clear();
|
2014-11-02 17:41:58 +08:00
|
|
|
|
2015-03-13 14:00:12 +08:00
|
|
|
// the list needs peers in peernumber order, nameLayout needs alphabetical
|
2016-01-23 01:37:03 +08:00
|
|
|
QList<QLabel*> nickLabelList;
|
2015-03-13 14:00:12 +08:00
|
|
|
|
|
|
|
// first traverse in peer number order, storing the QLabels as necessary
|
|
|
|
QStringList names = group->getPeerList();
|
2014-11-02 20:38:00 +08:00
|
|
|
unsigned nNames = names.size();
|
2017-02-26 19:52:45 +08:00
|
|
|
for (unsigned i = 0; i < nNames; ++i) {
|
2015-06-08 07:27:28 +08:00
|
|
|
QString tooltip = correctNames(names[i]);
|
2015-03-13 14:00:12 +08:00
|
|
|
peerLabels.append(new QLabel(names[i]));
|
2015-06-08 07:27:28 +08:00
|
|
|
if (!tooltip.isEmpty())
|
|
|
|
peerLabels[i]->setToolTip(tooltip);
|
2015-03-13 14:00:12 +08:00
|
|
|
peerLabels[i]->setTextFormat(Qt::PlainText);
|
2016-01-23 01:37:03 +08:00
|
|
|
nickLabelList.append(peerLabels[i]);
|
2015-03-13 14:00:12 +08:00
|
|
|
if (group->isSelfPeerNumber(i))
|
|
|
|
peerLabels[i]->setStyleSheet("QLabel {color : green;}");
|
2015-08-19 01:40:11 +08:00
|
|
|
|
|
|
|
if (netcam && !group->isSelfPeerNumber(i))
|
|
|
|
static_cast<GroupNetCamView*>(netcam)->addPeer(i, names[i]);
|
2015-03-13 14:00:12 +08:00
|
|
|
}
|
2015-08-19 01:40:11 +08:00
|
|
|
|
|
|
|
if (netcam)
|
|
|
|
static_cast<GroupNetCamView*>(netcam)->clearPeers();
|
|
|
|
|
2015-03-13 14:00:12 +08:00
|
|
|
// now alphabetize and add to layout
|
2017-02-26 19:52:45 +08:00
|
|
|
qSort(nickLabelList.begin(), nickLabelList.end(),
|
|
|
|
[](QLabel* a, QLabel* b) { return a->text().toLower() < b->text().toLower(); });
|
|
|
|
for (unsigned i = 0; i < nNames; ++i) {
|
|
|
|
QLabel* label = nickLabelList.at(i);
|
2015-03-13 14:00:12 +08:00
|
|
|
if (i != nNames - 1)
|
|
|
|
label->setText(label->text() + ", ");
|
2015-04-24 19:01:50 +08:00
|
|
|
|
2015-03-13 14:00:12 +08:00
|
|
|
namesListLayout->addWidget(label);
|
|
|
|
}
|
2015-03-15 00:04:06 +08:00
|
|
|
|
|
|
|
// Enable or disable call button
|
2017-02-26 19:52:45 +08:00
|
|
|
if (peersCount > 1 && group->isAvGroupchat()) {
|
2016-04-24 19:12:02 +08:00
|
|
|
// don't set button to green if call running
|
2017-02-26 19:52:45 +08:00
|
|
|
if (!inCall) {
|
2016-04-24 19:12:02 +08:00
|
|
|
callButton->setEnabled(true);
|
|
|
|
callButton->setObjectName("green");
|
|
|
|
callButton->style()->polish(callButton);
|
|
|
|
callButton->setToolTip(tr("Start audio call"));
|
|
|
|
}
|
2017-02-26 19:52:45 +08:00
|
|
|
} else {
|
2015-03-15 00:04:06 +08:00
|
|
|
callButton->setEnabled(false);
|
|
|
|
callButton->setObjectName("grey");
|
|
|
|
callButton->style()->polish(callButton);
|
|
|
|
callButton->setToolTip("");
|
2016-03-31 21:14:49 +08:00
|
|
|
Core::getInstance()->getAv()->leaveGroupCall(group->getGroupId());
|
2016-03-31 20:12:11 +08:00
|
|
|
hideNetcam();
|
2015-03-15 00:04:06 +08:00
|
|
|
}
|
2015-03-13 14:00:12 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void GroupChatForm::peerAudioPlaying(int peer)
|
|
|
|
{
|
|
|
|
peerLabels[peer]->setStyleSheet("QLabel {color : red;}");
|
2017-02-26 19:52:45 +08:00
|
|
|
if (!peerAudioTimers[peer]) {
|
2015-03-13 14:00:12 +08:00
|
|
|
peerAudioTimers[peer] = new QTimer(this);
|
|
|
|
peerAudioTimers[peer]->setSingleShot(true);
|
2017-02-26 19:52:45 +08:00
|
|
|
connect(peerAudioTimers[peer], &QTimer::timeout, [this, peer] {
|
2015-08-19 01:40:11 +08:00
|
|
|
if (netcam)
|
|
|
|
static_cast<GroupNetCamView*>(netcam)->removePeer(peer);
|
|
|
|
|
|
|
|
if (peer >= peerLabels.size())
|
|
|
|
return;
|
|
|
|
|
|
|
|
peerLabels[peer]->setStyleSheet("");
|
|
|
|
delete peerAudioTimers[peer];
|
|
|
|
peerAudioTimers[peer] = nullptr;
|
|
|
|
});
|
|
|
|
|
2017-02-26 19:52:45 +08:00
|
|
|
if (netcam) {
|
2015-08-19 01:40:11 +08:00
|
|
|
static_cast<GroupNetCamView*>(netcam)->removePeer(peer);
|
|
|
|
static_cast<GroupNetCamView*>(netcam)->addPeer(peer, group->getPeerList()[peer]);
|
|
|
|
}
|
2014-11-02 17:41:58 +08:00
|
|
|
}
|
2015-03-13 14:00:12 +08:00
|
|
|
peerAudioTimers[peer]->start(500);
|
2014-06-25 04:11:11 +08:00
|
|
|
}
|
2014-09-26 00:03:25 +08:00
|
|
|
|
2017-02-26 19:52:45 +08:00
|
|
|
void GroupChatForm::dragEnterEvent(QDragEnterEvent* ev)
|
2014-09-26 00:03:25 +08:00
|
|
|
{
|
2016-08-07 03:28:40 +08:00
|
|
|
ToxId toxId = ToxId(ev->mimeData()->text());
|
2017-01-06 19:02:54 +08:00
|
|
|
Friend* frnd = FriendList::findFriend(toxId.getPublicKey());
|
2016-08-07 03:28:40 +08:00
|
|
|
if (frnd)
|
2014-09-26 00:03:25 +08:00
|
|
|
ev->acceptProposedAction();
|
|
|
|
}
|
|
|
|
|
2017-02-26 19:52:45 +08:00
|
|
|
void GroupChatForm::dropEvent(QDropEvent* ev)
|
2014-09-26 00:03:25 +08:00
|
|
|
{
|
2016-08-07 03:28:40 +08:00
|
|
|
ToxId toxId = ToxId(ev->mimeData()->text());
|
2017-01-06 19:02:54 +08:00
|
|
|
Friend* frnd = FriendList::findFriend(toxId.getPublicKey());
|
2016-08-07 03:28:40 +08:00
|
|
|
if (!frnd)
|
|
|
|
return;
|
|
|
|
|
2016-08-22 05:30:07 +08:00
|
|
|
int friendId = frnd->getFriendId();
|
2016-08-07 03:28:40 +08:00
|
|
|
int groupId = group->getGroupId();
|
2017-02-02 06:47:45 +08:00
|
|
|
if (frnd->getStatus() != Status::Offline) {
|
|
|
|
Core::getInstance()->groupInviteFriend(friendId, groupId);
|
|
|
|
}
|
2014-09-26 00:03:25 +08:00
|
|
|
}
|
|
|
|
|
2014-11-13 20:11:23 +08:00
|
|
|
void GroupChatForm::onMicMuteToggle()
|
|
|
|
{
|
2017-02-26 19:52:45 +08:00
|
|
|
if (audioInputFlag) {
|
2016-08-29 15:07:23 +08:00
|
|
|
CoreAV* av = Core::getInstance()->getAv();
|
2017-02-26 19:52:45 +08:00
|
|
|
if (micButton->objectName() == "red") {
|
2016-08-29 15:07:23 +08:00
|
|
|
av->muteCallInput(group, false);
|
2014-11-13 20:11:23 +08:00
|
|
|
micButton->setObjectName("green");
|
2015-02-23 03:37:00 +08:00
|
|
|
micButton->setToolTip(tr("Mute microphone"));
|
2017-02-26 19:52:45 +08:00
|
|
|
} else {
|
2016-08-29 15:07:23 +08:00
|
|
|
av->muteCallInput(group, true);
|
2014-11-13 20:11:23 +08:00
|
|
|
micButton->setObjectName("red");
|
2015-02-23 03:37:00 +08:00
|
|
|
micButton->setToolTip(tr("Unmute microphone"));
|
2014-11-13 20:11:23 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
Style::repolish(micButton);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void GroupChatForm::onVolMuteToggle()
|
|
|
|
{
|
2017-02-26 19:52:45 +08:00
|
|
|
if (audioOutputFlag) {
|
2016-08-29 15:07:23 +08:00
|
|
|
CoreAV* av = Core::getInstance()->getAv();
|
2017-02-26 19:52:45 +08:00
|
|
|
if (volButton->objectName() == "red") {
|
2016-08-29 15:07:23 +08:00
|
|
|
av->muteCallOutput(group, false);
|
2014-11-13 20:11:23 +08:00
|
|
|
volButton->setObjectName("green");
|
2015-02-23 03:37:00 +08:00
|
|
|
volButton->setToolTip(tr("Mute call"));
|
2017-02-26 19:52:45 +08:00
|
|
|
} else {
|
2016-08-29 15:07:23 +08:00
|
|
|
av->muteCallOutput(group, true);
|
2014-11-13 20:11:23 +08:00
|
|
|
volButton->setObjectName("red");
|
2015-02-23 03:37:00 +08:00
|
|
|
volButton->setToolTip(tr("Unmute call"));
|
2014-11-13 20:11:23 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
Style::repolish(volButton);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void GroupChatForm::onCallClicked()
|
|
|
|
{
|
2017-02-26 19:52:45 +08:00
|
|
|
if (!inCall) {
|
2015-09-28 01:59:26 +08:00
|
|
|
Core::getInstance()->getAv()->joinGroupCall(group->getGroupId());
|
2014-11-13 20:11:23 +08:00
|
|
|
audioInputFlag = true;
|
|
|
|
audioOutputFlag = true;
|
|
|
|
callButton->setObjectName("red");
|
|
|
|
callButton->style()->polish(callButton);
|
2015-02-23 03:37:00 +08:00
|
|
|
callButton->setToolTip(tr("End audio call"));
|
|
|
|
micButton->setObjectName("green");
|
|
|
|
micButton->style()->polish(micButton);
|
|
|
|
micButton->setToolTip(tr("Mute microphone"));
|
|
|
|
volButton->setObjectName("green");
|
|
|
|
volButton->style()->polish(volButton);
|
|
|
|
volButton->setToolTip(tr("Mute call"));
|
2014-11-13 20:11:23 +08:00
|
|
|
inCall = true;
|
2015-08-19 01:40:11 +08:00
|
|
|
showNetcam();
|
2017-02-26 19:52:45 +08:00
|
|
|
} else {
|
2015-09-28 01:59:26 +08:00
|
|
|
Core::getInstance()->getAv()->leaveGroupCall(group->getGroupId());
|
2014-11-13 20:11:23 +08:00
|
|
|
audioInputFlag = false;
|
|
|
|
audioOutputFlag = false;
|
|
|
|
callButton->setObjectName("green");
|
|
|
|
callButton->style()->polish(callButton);
|
2015-02-23 03:37:00 +08:00
|
|
|
callButton->setToolTip(tr("Start audio call"));
|
|
|
|
micButton->setObjectName("grey");
|
|
|
|
micButton->style()->polish(micButton);
|
|
|
|
micButton->setToolTip("");
|
|
|
|
volButton->setObjectName("grey");
|
|
|
|
volButton->style()->polish(volButton);
|
|
|
|
volButton->setToolTip("");
|
2014-11-13 20:11:23 +08:00
|
|
|
inCall = false;
|
2015-08-19 01:40:11 +08:00
|
|
|
hideNetcam();
|
2014-11-13 20:11:23 +08:00
|
|
|
}
|
|
|
|
}
|
2014-11-14 02:20:06 +08:00
|
|
|
|
2017-02-26 19:52:45 +08:00
|
|
|
GenericNetCamView* GroupChatForm::createNetcam()
|
2015-08-19 01:40:11 +08:00
|
|
|
{
|
|
|
|
GroupNetCamView* view = new GroupNetCamView(group->getGroupId(), this);
|
|
|
|
|
|
|
|
QStringList names = group->getPeerList();
|
2017-02-26 19:52:45 +08:00
|
|
|
for (int i = 0; i < names.size(); ++i) {
|
2015-08-19 01:40:11 +08:00
|
|
|
if (!group->isSelfPeerNumber(i))
|
|
|
|
static_cast<GroupNetCamView*>(view)->addPeer(i, names[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
return view;
|
|
|
|
}
|
|
|
|
|
2014-11-14 02:20:06 +08:00
|
|
|
void GroupChatForm::keyPressEvent(QKeyEvent* ev)
|
|
|
|
{
|
2014-12-06 20:49:04 +08:00
|
|
|
// Push to talk (CTRL+P)
|
2017-02-26 19:52:45 +08:00
|
|
|
if (ev->key() == Qt::Key_P && (ev->modifiers() & Qt::ControlModifier) && inCall) {
|
2016-08-29 15:07:23 +08:00
|
|
|
CoreAV* av = Core::getInstance()->getAv();
|
2017-02-26 19:52:45 +08:00
|
|
|
if (!av->isGroupCallInputMuted(group)) {
|
2016-08-29 15:07:23 +08:00
|
|
|
av->muteCallInput(group, false);
|
2014-11-14 02:20:06 +08:00
|
|
|
micButton->setObjectName("green");
|
|
|
|
micButton->style()->polish(micButton);
|
|
|
|
Style::repolish(micButton);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-14 03:32:09 +08:00
|
|
|
if (msgEdit->hasFocus())
|
|
|
|
return;
|
2014-12-06 20:59:19 +08:00
|
|
|
}
|
2014-11-14 03:32:09 +08:00
|
|
|
|
2014-12-06 20:59:19 +08:00
|
|
|
void GroupChatForm::keyReleaseEvent(QKeyEvent* ev)
|
|
|
|
{
|
2014-12-06 20:59:34 +08:00
|
|
|
// Push to talk (CTRL+P)
|
2017-02-26 19:52:45 +08:00
|
|
|
if (ev->key() == Qt::Key_P && (ev->modifiers() & Qt::ControlModifier) && inCall) {
|
2016-08-29 15:07:23 +08:00
|
|
|
CoreAV* av = Core::getInstance()->getAv();
|
2017-02-26 19:52:45 +08:00
|
|
|
if (av->isGroupCallInputMuted(group)) {
|
2016-08-29 15:07:23 +08:00
|
|
|
av->muteCallInput(group, true);
|
2014-11-14 02:20:06 +08:00
|
|
|
micButton->setObjectName("red");
|
|
|
|
micButton->style()->polish(micButton);
|
|
|
|
Style::repolish(micButton);
|
|
|
|
}
|
|
|
|
}
|
2014-12-06 20:59:19 +08:00
|
|
|
|
|
|
|
if (msgEdit->hasFocus())
|
|
|
|
return;
|
2014-11-14 02:20:06 +08:00
|
|
|
}
|
2015-06-06 03:37:01 +08:00
|
|
|
|
|
|
|
void GroupChatForm::retranslateUi()
|
|
|
|
{
|
2015-09-27 01:37:17 +08:00
|
|
|
int peersCount = group->getPeersCount();
|
|
|
|
if (peersCount == 1)
|
|
|
|
nusersLabel->setText(tr("1 user in chat", "Number of users in chat"));
|
|
|
|
else
|
|
|
|
nusersLabel->setText(tr("%1 users in chat", "Number of users in chat").arg(peersCount));
|
2015-06-06 03:37:01 +08:00
|
|
|
}
|