41 #include <QDragEnterEvent>
43 #include <QRegularExpression>
45 #include <QToolButton>
46 #include <QPushButton>
50 const auto LABEL_PEER_TYPE_OUR = QVariant(QStringLiteral(
"our"));
51 const auto LABEL_PEER_TYPE_MUTED = QVariant(QStringLiteral(
"muted"));
52 const auto LABEL_PEER_PLAYING_AUDIO = QVariant(QStringLiteral(
"true"));
53 const auto LABEL_PEER_NOT_PLAYING_AUDIO = QVariant(QStringLiteral(
"false"));
54 const auto PEER_LABEL_STYLE_SHEET_PATH = QStringLiteral(
"chatArea/chatHead.css");
65 const int pos = name.indexOf(QRegularExpression(QStringLiteral(
"[\n\r]")));
70 QString result = name;
71 const int len = result.length();
72 result.chop(len - pos);
73 result.append(QStringLiteral(
"…"));
92 nusersLabel =
new QLabel();
96 fileButton->setEnabled(
false);
97 fileButton->setProperty(
"state",
"");
99 if (group->isAvGroupchat()) {
100 mode = ChatFormHeader::Mode::Audio;
103 headWidget->setMode(mode);
104 setName(group->getName());
107 nusersLabel->setObjectName(
"statusLabel");
110 const QSize&
size = headWidget->getAvatarSize();
113 msgEdit->setObjectName(
"group");
116 headWidget->addWidget(nusersLabel);
117 headWidget->addLayout(namesListLayout);
118 headWidget->addStretch();
121 nusersLabel->setMinimumHeight(12);
134 settings.connectTo_blackListChanged(
this, [
this](QStringList
const&) { this->updateUserNames(); });
137 setAcceptDrops(
true);
148 if (author.isEmpty()) {
152 const QDateTime curTime = QDateTime::currentDateTime();
173 child->widget()->hide();
174 delete child->widget();
182 if (peers.isEmpty()) {
190 for (
const auto& peerPk : peers.keys()) {
191 const QString peerName = peers.value(peerPk);
192 const QString editedName =
editName(peerName);
193 QLabel*
const label =
new QLabel(editedName + QLatin1String(
", "));
194 if (editedName != peerName) {
195 label->setToolTip(peerName +
" (" + peerPk.toString() +
")");
196 }
else if (peerName != peerPk.toString()) {
197 label->setToolTip(peerPk.toString());
199 label->setTextFormat(Qt::PlainText);
200 label->setContextMenuPolicy(Qt::CustomContextMenu);
204 if (peerPk == selfPk) {
205 label->setProperty(
"peerType", LABEL_PEER_TYPE_OUR);
207 label->setProperty(
"peerType", LABEL_PEER_TYPE_MUTED);
217 std::sort(nickLabelList.begin(), nickLabelList.end(), [](
const QLabel* a,
const QLabel* b)
219 return a->text().toLower() < b->text().toLower();
223 QLabel*
const lastLabel = nickLabelList.last();
224 QString labelText = lastLabel->text();
226 lastLabel->setText(labelText);
227 for (QLabel* l : nickLabelList) {
257 peerLabels[peerPk]->setProperty(
"playingAudio", LABEL_PEER_PLAYING_AUDIO);
267 peerLabels[peerPk]->setProperty(
"playingAudio", LABEL_PEER_NOT_PLAYING_AUDIO);
268 peerLabels[peerPk]->style()->unpolish(peerLabels[peerPk]);
269 peerLabels[peerPk]->style()->polish(peerLabels[peerPk]);
282 if (!ev->mimeData()->hasFormat(
"toxPk")) {
285 ToxPk toxPk{ev->mimeData()->data(
"toxPk")};
288 ev->acceptProposedAction();
293 if (!ev->mimeData()->hasFormat(
"toxPk")) {
296 ToxPk toxPk{ev->mimeData()->data(
"toxPk")};
301 int friendId = frnd->
getId();
313 const bool newMute = !oldMuteState;
324 const bool newMute = !oldMuteState;
352 if (ev->key() == Qt::Key_P && (ev->modifiers() & Qt::ControlModifier) &&
inCall) {
363 if (ev->key() == Qt::Key_P && (ev->modifiers() & Qt::ControlModifier) &&
inCall) {
376 nusersLabel->setText(tr(
"%n user(s) in chat",
"Number of users in chat", numPeers));
387 QLabel* label =
static_cast<QLabel*
>(QObject::sender());
389 if (label ==
nullptr) {
393 const QPoint pos = label->mapToGlobal(localPos);
394 const QString muteString = tr(
"mute");
395 const QString unmuteString = tr(
"unmute");
397 QMenu*
const contextMenu =
new QMenu(
this);
402 connect(contextMenu, &QMenu::aboutToHide, contextMenu, &QObject::deleteLater);
405 if (peerPk.
isEmpty() || peerPk == selfPk) {
409 const bool isPeerBlocked = blackList.contains(peerPk.
toString());
410 QString menuTitle = label->text();
411 if (menuTitle.endsWith(QLatin1String(
", "))) {
414 QAction* menuTitleAction = contextMenu->addAction(menuTitle);
415 menuTitleAction->setEnabled(
false);
416 contextMenu->addSeparator();
418 const QAction* toggleMuteAction;
420 toggleMuteAction = contextMenu->addAction(unmuteString);
422 toggleMuteAction = contextMenu->addAction(muteString);
426 const QAction* selectedItem = contextMenu->exec(pos);
427 if (selectedItem == toggleMuteAction) {
429 const int index = blackList.indexOf(peerPk.
toString());
431 blackList.removeAt(index);