forked from mirror/nheko
commit
99ba1f17d3
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,111 @@ |
||||
import QtQuick 2.9 |
||||
import QtQuick.Controls 2.3 |
||||
import QtQuick.Layouts 1.2 |
||||
|
||||
import im.nheko 1.0 |
||||
|
||||
Rectangle { |
||||
id: activeCallBar |
||||
visible: TimelineManager.callState != WebRTCState.DISCONNECTED |
||||
color: "#2ECC71" |
||||
implicitHeight: rowLayout.height + 8 |
||||
|
||||
RowLayout { |
||||
id: rowLayout |
||||
anchors.left: parent.left |
||||
anchors.right: parent.right |
||||
anchors.verticalCenter: parent.verticalCenter |
||||
anchors.leftMargin: 8 |
||||
|
||||
Avatar { |
||||
width: avatarSize |
||||
height: avatarSize |
||||
|
||||
url: TimelineManager.callPartyAvatarUrl.replace("mxc://", "image://MxcImage/") |
||||
displayName: TimelineManager.callPartyName |
||||
} |
||||
|
||||
Label { |
||||
font.pointSize: fontMetrics.font.pointSize * 1.1 |
||||
text: " " + TimelineManager.callPartyName + " " |
||||
} |
||||
|
||||
Image { |
||||
Layout.preferredWidth: 24 |
||||
Layout.preferredHeight: 24 |
||||
source: "qrc:/icons/icons/ui/place-call.png" |
||||
} |
||||
|
||||
Label { |
||||
id: callStateLabel |
||||
font.pointSize: fontMetrics.font.pointSize * 1.1 |
||||
} |
||||
|
||||
Connections { |
||||
target: TimelineManager |
||||
function onCallStateChanged(state) { |
||||
switch (state) { |
||||
case WebRTCState.INITIATING: |
||||
callStateLabel.text = qsTr("Initiating...") |
||||
break; |
||||
case WebRTCState.OFFERSENT: |
||||
callStateLabel.text = qsTr("Calling...") |
||||
break; |
||||
case WebRTCState.CONNECTING: |
||||
callStateLabel.text = qsTr("Connecting...") |
||||
break; |
||||
case WebRTCState.CONNECTED: |
||||
callStateLabel.text = "00:00" |
||||
var d = new Date() |
||||
callTimer.startTime = Math.floor(d.getTime() / 1000) |
||||
break; |
||||
case WebRTCState.DISCONNECTED: |
||||
callStateLabel.text = "" |
||||
} |
||||
} |
||||
} |
||||
|
||||
Timer { |
||||
id: callTimer |
||||
property int startTime |
||||
interval: 1000 |
||||
running: TimelineManager.callState == WebRTCState.CONNECTED |
||||
repeat: true |
||||
onTriggered: { |
||||
var d = new Date() |
||||
let seconds = Math.floor(d.getTime() / 1000 - startTime) |
||||
let s = Math.floor(seconds % 60) |
||||
let m = Math.floor(seconds / 60) % 60 |
||||
let h = Math.floor(seconds / 3600) |
||||
callStateLabel.text = (h ? (pad(h) + ":") : "") + pad(m) + ":" + pad(s) |
||||
} |
||||
|
||||
function pad(n) { |
||||
return (n < 10) ? ("0" + n) : n |
||||
} |
||||
} |
||||
|
||||
Item { |
||||
Layout.fillWidth: true |
||||
} |
||||
|
||||
ImageButton { |
||||
width: 24 |
||||
height: 24 |
||||
buttonTextColor: "#000000" |
||||
image: TimelineManager.isMicMuted ? |
||||
":/icons/icons/ui/microphone-unmute.png" : |
||||
":/icons/icons/ui/microphone-mute.png" |
||||
|
||||
hoverEnabled: true |
||||
ToolTip.visible: hovered |
||||
ToolTip.text: TimelineManager.isMicMuted ? qsTr("Unmute Mic") : qsTr("Mute Mic") |
||||
|
||||
onClicked: TimelineManager.toggleMicMute() |
||||
} |
||||
|
||||
Item { |
||||
implicitWidth: 16 |
||||
} |
||||
} |
||||
} |
@ -1,160 +0,0 @@ |
||||
#include <cstdio> |
||||
|
||||
#include <QDateTime> |
||||
#include <QHBoxLayout> |
||||
#include <QIcon> |
||||
#include <QLabel> |
||||
#include <QString> |
||||
#include <QTimer> |
||||
|
||||
#include "ActiveCallBar.h" |
||||
#include "ChatPage.h" |
||||
#include "Utils.h" |
||||
#include "WebRTCSession.h" |
||||
#include "ui/Avatar.h" |
||||
#include "ui/FlatButton.h" |
||||
|
||||
ActiveCallBar::ActiveCallBar(QWidget *parent) |
||||
: QWidget(parent) |
||||
{ |
||||
setAutoFillBackground(true); |
||||
auto p = palette(); |
||||
p.setColor(backgroundRole(), QColor(46, 204, 113)); |
||||
setPalette(p); |
||||
|
||||
QFont f; |
||||
f.setPointSizeF(f.pointSizeF()); |
||||
|
||||
const int fontHeight = QFontMetrics(f).height(); |
||||
const int widgetMargin = fontHeight / 3; |
||||
const int contentHeight = fontHeight * 3; |
||||
|
||||
setFixedHeight(contentHeight + widgetMargin); |
||||
|
||||
layout_ = new QHBoxLayout(this); |
||||
layout_->setSpacing(widgetMargin); |
||||
layout_->setContentsMargins(2 * widgetMargin, widgetMargin, 2 * widgetMargin, widgetMargin); |
||||
|
||||
QFont labelFont; |
||||
labelFont.setPointSizeF(labelFont.pointSizeF() * 1.1); |
||||
labelFont.setWeight(QFont::Medium); |
||||
|
||||
avatar_ = new Avatar(this, QFontMetrics(f).height() * 2.5); |
||||
|
||||
callPartyLabel_ = new QLabel(this); |
||||
callPartyLabel_->setFont(labelFont); |
||||
|
||||
stateLabel_ = new QLabel(this); |
||||
stateLabel_->setFont(labelFont); |
||||
|
||||
durationLabel_ = new QLabel(this); |
||||
durationLabel_->setFont(labelFont); |
||||
durationLabel_->hide(); |
||||
|
||||
muteBtn_ = new FlatButton(this); |
||||
setMuteIcon(false); |
||||
muteBtn_->setFixedSize(buttonSize_, buttonSize_); |
||||
muteBtn_->setCornerRadius(buttonSize_ / 2); |
||||
connect(muteBtn_, &FlatButton::clicked, this, [this]() { |
||||
if (WebRTCSession::instance().toggleMuteAudioSrc(muted_)) |
||||
setMuteIcon(muted_); |
||||
}); |
||||
|
||||
layout_->addWidget(avatar_, 0, Qt::AlignLeft); |
||||
layout_->addWidget(callPartyLabel_, 0, Qt::AlignLeft); |
||||
layout_->addWidget(stateLabel_, 0, Qt::AlignLeft); |
||||
layout_->addWidget(durationLabel_, 0, Qt::AlignLeft); |
||||
layout_->addStretch(); |
||||
layout_->addWidget(muteBtn_, 0, Qt::AlignCenter); |
||||
layout_->addSpacing(18); |
||||
|
||||
timer_ = new QTimer(this); |
||||
connect(timer_, &QTimer::timeout, this, [this]() { |
||||
auto seconds = QDateTime::currentSecsSinceEpoch() - callStartTime_; |
||||
int s = seconds % 60; |
||||
int m = (seconds / 60) % 60; |
||||
int h = seconds / 3600; |
||||
char buf[12]; |
||||
if (h) |
||||
snprintf(buf, sizeof(buf), "%.2d:%.2d:%.2d", h, m, s); |
||||
else |
||||
snprintf(buf, sizeof(buf), "%.2d:%.2d", m, s); |
||||
durationLabel_->setText(buf); |
||||
}); |
||||
|
||||
connect( |
||||
&WebRTCSession::instance(), &WebRTCSession::stateChanged, this, &ActiveCallBar::update); |
||||
} |
||||
|
||||
void |
||||
ActiveCallBar::setMuteIcon(bool muted) |
||||
{ |
||||
QIcon icon; |
||||
if (muted) { |
||||
muteBtn_->setToolTip("Unmute Mic"); |
||||
icon.addFile(":/icons/icons/ui/microphone-unmute.png"); |
||||
} else { |
||||
muteBtn_->setToolTip("Mute Mic"); |
||||
icon.addFile(":/icons/icons/ui/microphone-mute.png"); |
||||
} |
||||
muteBtn_->setIcon(icon); |
||||
muteBtn_->setIconSize(QSize(buttonSize_, buttonSize_)); |
||||
} |
||||
|
||||
void |
||||
ActiveCallBar::setCallParty(const QString &userid, |
||||
const QString &displayName, |
||||
const QString &roomName, |
||||
const QString &avatarUrl) |
||||
{ |
||||
callPartyLabel_->setText(" " + (displayName.isEmpty() ? userid : displayName) + " "); |
||||
|
||||
if (!avatarUrl.isEmpty()) |
||||
avatar_->setImage(avatarUrl); |
||||
else |
||||
avatar_->setLetter(utils::firstChar(roomName)); |
||||
} |
||||
|
||||
void |
||||
ActiveCallBar::update(WebRTCSession::State state) |
||||
{ |
||||
switch (state) { |
||||
case WebRTCSession::State::INITIATING: |
||||
show(); |
||||
stateLabel_->setText("Initiating call..."); |
||||
break; |
||||
case WebRTCSession::State::INITIATED: |
||||
show(); |
||||
stateLabel_->setText("Call initiated..."); |
||||
break; |
||||
case WebRTCSession::State::OFFERSENT: |
||||
show(); |
||||
stateLabel_->setText("Calling..."); |
||||
break; |
||||
case WebRTCSession::State::CONNECTING: |
||||
show(); |
||||
stateLabel_->setText("Connecting..."); |
||||
break; |
||||
case WebRTCSession::State::CONNECTED: |
||||
show(); |
||||
callStartTime_ = QDateTime::currentSecsSinceEpoch(); |
||||
timer_->start(1000); |
||||
stateLabel_->setPixmap( |
||||
QIcon(":/icons/icons/ui/place-call.png").pixmap(QSize(buttonSize_, buttonSize_))); |
||||
durationLabel_->setText("00:00"); |
||||
durationLabel_->show(); |
||||
break; |
||||
case WebRTCSession::State::ICEFAILED: |
||||
case WebRTCSession::State::DISCONNECTED: |
||||
hide(); |
||||
timer_->stop(); |
||||
callPartyLabel_->setText(QString()); |
||||
stateLabel_->setText(QString()); |
||||
durationLabel_->setText(QString()); |
||||
durationLabel_->hide(); |
||||
setMuteIcon(false); |
||||
break; |
||||
default: |
||||
break; |
||||
} |
||||
} |
@ -1,40 +0,0 @@ |
||||
#pragma once |
||||
|
||||
#include <QWidget> |
||||
|
||||
#include "WebRTCSession.h" |
||||
|
||||
class QHBoxLayout; |
||||
class QLabel; |
||||
class QTimer; |
||||
class Avatar; |
||||
class FlatButton; |
||||
|
||||
class ActiveCallBar : public QWidget |
||||
{ |
||||
Q_OBJECT |
||||
|
||||
public: |
||||
ActiveCallBar(QWidget *parent = nullptr); |
||||
|
||||
public slots: |
||||
void update(WebRTCSession::State); |
||||
void setCallParty(const QString &userid, |
||||
const QString &displayName, |
||||
const QString &roomName, |
||||
const QString &avatarUrl); |
||||
|
||||
private: |
||||
QHBoxLayout *layout_ = nullptr; |
||||
Avatar *avatar_ = nullptr; |
||||
QLabel *callPartyLabel_ = nullptr; |
||||
QLabel *stateLabel_ = nullptr; |
||||
QLabel *durationLabel_ = nullptr; |
||||
FlatButton *muteBtn_ = nullptr; |
||||
int buttonSize_ = 22; |
||||
bool muted_ = false; |
||||
qint64 callStartTime_ = 0; |
||||
QTimer *timer_ = nullptr; |
||||
|
||||
void setMuteIcon(bool muted); |
||||
}; |
Loading…
Reference in new issue