From b71581501165ccb48c29799ddb857489c28a2736 Mon Sep 17 00:00:00 2001 From: Mick Sayson Date: Thu, 14 Nov 2019 19:08:40 -0800 Subject: [PATCH] feat(extensions): UI updates for extension support Added a UI element to indicate extension support of the chatroom. For all groups it will always be red since we do not support extensions in groups. In a 1-1 chat the indicator will either be green/yellow/red depending on if the friend has support for all/some/none of qTox's desired extension set. --- CMakeLists.txt | 2 + img/status/extensions_available.svg | 1 + img/status/extensions_partial.svg | 1 + img/status/extensions_unavailable.svg | 1 + res.qrc | 3 ++ src/widget/chatformheader.cpp | 18 ++++++++- src/widget/chatformheader.h | 8 ++++ src/widget/extensionstatus.cpp | 54 +++++++++++++++++++++++++++ src/widget/extensionstatus.h | 34 +++++++++++++++++ src/widget/form/chatform.cpp | 7 ++++ src/widget/form/chatform.h | 1 + 11 files changed, 129 insertions(+), 1 deletion(-) create mode 100644 img/status/extensions_available.svg create mode 100644 img/status/extensions_partial.svg create mode 100644 img/status/extensions_unavailable.svg create mode 100644 src/widget/extensionstatus.cpp create mode 100644 src/widget/extensionstatus.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 152a3e36a..7f5434c1d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -362,6 +362,8 @@ set(${PROJECT_NAME}_SOURCES src/widget/contentlayout.h src/widget/emoticonswidget.cpp src/widget/emoticonswidget.h + src/widget/extensionstatus.cpp + src/widget/extensionstatus.h src/widget/flowlayout.cpp src/widget/flowlayout.h src/widget/searchform.cpp diff --git a/img/status/extensions_available.svg b/img/status/extensions_available.svg new file mode 100644 index 000000000..e5025ae68 --- /dev/null +++ b/img/status/extensions_available.svg @@ -0,0 +1 @@ + diff --git a/img/status/extensions_partial.svg b/img/status/extensions_partial.svg new file mode 100644 index 000000000..14f86fdae --- /dev/null +++ b/img/status/extensions_partial.svg @@ -0,0 +1 @@ + diff --git a/img/status/extensions_unavailable.svg b/img/status/extensions_unavailable.svg new file mode 100644 index 000000000..7734fdecd --- /dev/null +++ b/img/status/extensions_unavailable.svg @@ -0,0 +1 @@ + diff --git a/res.qrc b/res.qrc index 9d200bef1..bb20bf79f 100644 --- a/res.qrc +++ b/res.qrc @@ -28,6 +28,9 @@ img/status/offline_notification.svg img/status/online.svg img/status/online_notification.svg + img/status/extensions_available.svg + img/status/extensions_partial.svg + img/status/extensions_unavailable.svg img/taskbar/dark/taskbar_online.svg img/taskbar/dark/taskbar_online_event.svg img/taskbar/dark/taskbar_away.svg diff --git a/src/widget/chatformheader.cpp b/src/widget/chatformheader.cpp index 6cd708054..b0f770e59 100644 --- a/src/widget/chatformheader.cpp +++ b/src/widget/chatformheader.cpp @@ -18,6 +18,9 @@ */ #include "chatformheader.h" +#include "extensionstatus.h" + +#include "src/model/status.h" #include "src/widget/gui.h" #include "src/widget/maskablepixmapwidget.h" @@ -117,6 +120,11 @@ ChatFormHeader::ChatFormHeader(QWidget* parent) avatar = new MaskablePixmapWidget(this, AVATAR_SIZE, ":/img/avatar_mask.svg"); avatar->setObjectName("avatar"); + nameLine = new QHBoxLayout(); + nameLine->setSpacing(3); + + extensionStatus = new ExtensionStatus(); + nameLabel = new CroppingLabel(); nameLabel->setObjectName("nameLabel"); nameLabel->setMinimumHeight(Style::getFont(Style::Medium).pixelSize()); @@ -124,9 +132,12 @@ ChatFormHeader::ChatFormHeader(QWidget* parent) nameLabel->setTextFormat(Qt::PlainText); connect(nameLabel, &CroppingLabel::editFinished, this, &ChatFormHeader::nameChanged); + nameLine->addWidget(extensionStatus); + nameLine->addWidget(nameLabel); + headTextLayout = new QVBoxLayout(); headTextLayout->addStretch(); - headTextLayout->addWidget(nameLabel); + headTextLayout->addLayout(nameLine); headTextLayout->addStretch(); micButton = createButton("micButton", this, &ChatFormHeader::micMuteToggle); @@ -223,6 +234,11 @@ void ChatFormHeader::removeCallConfirm() callConfirm.reset(nullptr); } +void ChatFormHeader::updateExtensionSupport(ExtensionSet extensions) +{ + extensionStatus->onExtensionSetUpdate(extensions); +} + void ChatFormHeader::updateCallButtons(bool online, bool audio, bool video) { const bool audioAvaliable = online && (mode & Mode::Audio); diff --git a/src/widget/chatformheader.h b/src/widget/chatformheader.h index 7e39a8f23..aac2477d9 100644 --- a/src/widget/chatformheader.h +++ b/src/widget/chatformheader.h @@ -21,14 +21,19 @@ #include +#include "src/core/extension.h" + #include class MaskablePixmapWidget; class QVBoxLayout; +class QHBoxLayout; class CroppingLabel; class QPushButton; class QToolButton; class CallConfirmWidget; +class QLabel; +class ExtensionStatus; class ChatFormHeader : public QWidget { @@ -64,6 +69,7 @@ public: void showCallConfirm(); void removeCallConfirm(); + void updateExtensionSupport(ExtensionSet extensions); void updateCallButtons(bool online, bool audio, bool video = false); void updateMuteMicButton(bool active, bool inputMuted); void updateMuteVolButton(bool active, bool outputMuted); @@ -98,6 +104,8 @@ private: Mode mode; MaskablePixmapWidget* avatar; QVBoxLayout* headTextLayout; + QHBoxLayout* nameLine; + ExtensionStatus* extensionStatus; CroppingLabel* nameLabel; QPushButton* callButton; diff --git a/src/widget/extensionstatus.cpp b/src/widget/extensionstatus.cpp new file mode 100644 index 000000000..d81784623 --- /dev/null +++ b/src/widget/extensionstatus.cpp @@ -0,0 +1,54 @@ +/* + Copyright © 2019-2020 by The qTox Project Contributors + + This file is part of qTox, a Qt-based graphical interface for Tox. + + qTox is libre software: you can redistribute it and/or modify + 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. + + qTox is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with qTox. If not, see . +*/ + +#include "extensionstatus.h" + +#include + +ExtensionStatus::ExtensionStatus(QWidget* parent) + : QLabel(parent) +{ + // Initialize with 0 extensions + onExtensionSetUpdate(ExtensionSet()); +} + +void ExtensionStatus::onExtensionSetUpdate(ExtensionSet extensionSet) +{ + QString iconName; + QString hoverText; + if (extensionSet.all()) { + iconName = ":/img/status/extensions_available.svg"; + hoverText = tr("All extensions supported"); + } else if (extensionSet.none()) { + iconName = ":/img/status/extensions_unavailable.svg"; + hoverText = tr("No extensions supported"); + } else { + iconName = ":/img/status/extensions_partial.svg"; + hoverText = tr("Not all extensions supported"); + } + + hoverText += "\n"; + hoverText += tr("Multipart Messages: "); + hoverText += extensionSet[ExtensionType::messages] ? "✔" : "❌"; + + auto pixmap = QIcon(iconName).pixmap(QSize(16, 16)); + + setPixmap(pixmap); + setToolTip(hoverText); +} diff --git a/src/widget/extensionstatus.h b/src/widget/extensionstatus.h new file mode 100644 index 000000000..759f14c3c --- /dev/null +++ b/src/widget/extensionstatus.h @@ -0,0 +1,34 @@ +/* + Copyright © 2019-2020 by The qTox Project Contributors + + This file is part of qTox, a Qt-based graphical interface for Tox. + + qTox is libre software: you can redistribute it and/or modify + 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. + + qTox is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with qTox. If not, see . +*/ + +#pragma once + +#include "src/core/extension.h" + +#include + +class ExtensionStatus : public QLabel +{ + Q_OBJECT +public: + ExtensionStatus(QWidget* parent = nullptr); + +public slots: + void onExtensionSetUpdate(ExtensionSet extensionSet); +}; diff --git a/src/widget/form/chatform.cpp b/src/widget/form/chatform.cpp index 8c05b33bb..fb9a83048 100644 --- a/src/widget/form/chatform.cpp +++ b/src/widget/form/chatform.cpp @@ -181,6 +181,8 @@ ChatForm::ChatForm(Profile& profile, Friend* chatFriend, IChatLog& chatLog, IMes connect(bodySplitter, &QSplitter::splitterMoved, this, &ChatForm::onSplitterMoved); + connect(f, &Friend::extensionSupportChanged, this, &ChatForm::onExtensionSupportChanged); + updateCallButtons(); setAcceptDrops(true); @@ -224,6 +226,11 @@ void ChatForm::onFileNameChanged(const ToxPk& friendPk) "so you can save the file on Windows.")); } +void ChatForm::onExtensionSupportChanged(ExtensionSet extensions) +{ + headWidget->updateExtensionSupport(extensions); +} + void ChatForm::onTextEditChanged() { if (!Settings::getInstance().getTypingNotification()) { diff --git a/src/widget/form/chatform.h b/src/widget/form/chatform.h index f7cc09135..bb940e5ad 100644 --- a/src/widget/form/chatform.h +++ b/src/widget/form/chatform.h @@ -72,6 +72,7 @@ public slots: void onAvEnd(uint32_t friendId, bool error); void onAvatarChanged(const ToxPk& friendPk, const QPixmap& pic); void onFileNameChanged(const ToxPk& friendPk); + void onExtensionSupportChanged(ExtensionSet extensions); void clearChatArea(); void onShowMessagesClicked(); void onSplitterMoved(int pos, int index);