From 0c393e717ac59b2dec68fc6cf7cba515c39ed2b8 Mon Sep 17 00:00:00 2001 From: "Tux3 / Mlkj / !Lev.uXFMLA" Date: Thu, 13 Nov 2014 19:20:06 +0100 Subject: [PATCH] Add simple push to talk with P Fixes #734 --- src/core.h | 2 ++ src/coreav.cpp | 10 +++++++++ src/widget/form/groupchatform.cpp | 37 +++++++++++++++++++++++++++++++ src/widget/form/groupchatform.h | 2 ++ 4 files changed, 51 insertions(+) diff --git a/src/core.h b/src/core.h index 2bdb97c4d..e65710c26 100644 --- a/src/core.h +++ b/src/core.h @@ -123,6 +123,8 @@ public slots: static void disableGroupCallVol(int groupId); static void enableGroupCallMic(int groupId); static void enableGroupCallVol(int groupId); + static bool isGroupCallMicEnabled(int groupId); + static bool isGroupCallVolEnabled(int groupId); void setPassword(QString& password, PasswordType passtype, uint8_t* salt = nullptr); void clearPassword(PasswordType passtype); diff --git a/src/coreav.cpp b/src/coreav.cpp index 95560315b..89a9ae1da 100644 --- a/src/coreav.cpp +++ b/src/coreav.cpp @@ -690,3 +690,13 @@ void Core::enableGroupCallVol(int groupId) { groupCalls[groupId].muteVol = false; } + +bool Core::isGroupCallMicEnabled(int groupId) +{ + return !groupCalls[groupId].muteMic; +} + +bool Core::isGroupCallVolEnabled(int groupId) +{ + return !groupCalls[groupId].muteVol; +} diff --git a/src/widget/form/groupchatform.cpp b/src/widget/form/groupchatform.cpp index fb8a4faef..2047f8e47 100644 --- a/src/widget/form/groupchatform.cpp +++ b/src/widget/form/groupchatform.cpp @@ -28,6 +28,7 @@ #include #include "src/historykeeper.h" #include "src/misc/flowlayout.h" +#include GroupChatForm::GroupChatForm(Group* chatGroup) : group(chatGroup), inCall{false} @@ -203,3 +204,39 @@ void GroupChatForm::onCallClicked() inCall = false; } } + +void GroupChatForm::keyPressEvent(QKeyEvent* ev) +{ + qDebug() << "Press:"<key(); + // Push to talk + if (ev->key() == Qt::Key_P && inCall) + { + qDebug() << "Press:"<key(); + Core* core = Core::getInstance(); + if (!core->isGroupCallMicEnabled(group->groupId)) + { + qDebug() << "Press:"<key(); + core->enableGroupCallMic(group->groupId); + micButton->setObjectName("green"); + micButton->style()->polish(micButton); + Style::repolish(micButton); + } + } +} + +void GroupChatForm::keyReleaseEvent(QKeyEvent* ev) +{ + qDebug() << "Release:"<key(); + // Push to talk + if (ev->key() == Qt::Key_P && inCall) + { + Core* core = Core::getInstance(); + if (core->isGroupCallMicEnabled(group->groupId)) + { + core->disableGroupCallMic(group->groupId); + micButton->setObjectName("red"); + micButton->style()->polish(micButton); + Style::repolish(micButton); + } + } +} diff --git a/src/widget/form/groupchatform.h b/src/widget/form/groupchatform.h index 70399be80..8b7d07339 100644 --- a/src/widget/form/groupchatform.h +++ b/src/widget/form/groupchatform.h @@ -42,6 +42,8 @@ protected: // drag & drop void dragEnterEvent(QDragEnterEvent* ev); void dropEvent(QDropEvent* ev); + void keyPressEvent(QKeyEvent* ev); + void keyReleaseEvent(QKeyEvent* ev); private: Group* group;