diff options
| author | Anton <anton@picapica.im> | 2026-08-12 00:15:06 +0400 |
|---|---|---|
| committer | Anton <anton@picapica.im> | 2026-08-12 00:15:06 +0400 |
| commit | 5ae6a1ff696f70b8eb1eac042a2cc278d4e7ceed (patch) | |
| tree | 9c4baf3df4fa704fdf0ef93c4bea8c605fe9976c /pica-client | |
| parent | 27693e8f033b5a5bb857190d203f17a39d04c378 (diff) | |
| download | pica-pica-5ae6a1ff696f70b8eb1eac042a2cc278d4e7ceed.tar.gz pica-pica-5ae6a1ff696f70b8eb1eac042a2cc278d4e7ceed.zip | |
pica-client: add call timer
Diffstat (limited to 'pica-client')
| -rw-r--r-- | pica-client/callwindow.cpp | 55 | ||||
| -rw-r--r-- | pica-client/callwindow.h | 8 |
2 files changed, 60 insertions, 3 deletions
diff --git a/pica-client/callwindow.cpp b/pica-client/callwindow.cpp index a987b79..21bbcb0 100644 --- a/pica-client/callwindow.cpp +++ b/pica-client/callwindow.cpp @@ -25,22 +25,30 @@ CallWindow::CallWindow(QByteArray peer_id, bool incoming) { setAttribute(Qt::WA_DeleteOnClose); - QHBoxLayout *lh = new QHBoxLayout(this); QVBoxLayout *lv = new QVBoxLayout(this); + QHBoxLayout *lh = new QHBoxLayout(); pbAccept = new QPushButton(tr("Accept"), this); pbCall = new QPushButton(tr("Call"), this); pbHang = new QPushButton(tr("Hang Up"), this); + lbTimer = new QLabel(this); + lbTimer->setAlignment(Qt::AlignCenter); + lbTimer->hide(); + callTimer = new QTimer(this); + callElapsedSeconds = 0; + + lv->addWidget(lbTimer); lh->addWidget(pbAccept, Qt::AlignLeft); lh->addWidget(pbCall, Qt::AlignLeft); lh->addWidget(pbHang, Qt::AlignRight); - lh->addLayout(lv); - setLayout(lh); + lv->addLayout(lh); + setLayout(lv); connect(pbCall, SIGNAL(clicked()), this, SLOT(call())); connect(pbHang, SIGNAL(clicked()), this, SLOT(hang())); connect(pbAccept, SIGNAL(clicked()), this, SLOT(accept())); + connect(callTimer, SIGNAL(timeout()), this, SLOT(update_call_timer())); if (is_incoming) { @@ -52,6 +60,47 @@ CallWindow::CallWindow(QByteArray peer_id, bool incoming) } } +void CallWindow::call_started() +{ + pbCall->hide(); + pbAccept->hide(); + + callElapsedSeconds = 0; + lbTimer->setText("00:00"); + lbTimer->show(); + callTimer->start(1000); +} + +void CallWindow::call_ended() +{ + callTimer->stop(); + pbHang->setDisabled(true); +} + +void CallWindow::update_call_timer() +{ + int hours, minutes, seconds; + QString text; + + callElapsedSeconds++; + + hours = callElapsedSeconds / 3600; + minutes = (callElapsedSeconds % 3600) / 60; + seconds = callElapsedSeconds % 60; + + if (hours > 0) + text = QString("%1:%2:%3"). + arg(hours, 2, 10, QChar('0')). + arg(minutes, 2, 10, QChar('0')). + arg(seconds, 2, 10, QChar('0')); + else + text = QString("%1:%2"). + arg(minutes, 2, 10, QChar('0')). + arg(seconds, 2, 10, QChar('0')); + + lbTimer->setText(text); +} + void CallWindow::call() { emit start_call_pressed(); diff --git a/pica-client/callwindow.h b/pica-client/callwindow.h index 30f75d3..2cc0eeb 100644 --- a/pica-client/callwindow.h +++ b/pica-client/callwindow.h @@ -21,6 +21,7 @@ #include <QWidget> #include <QPushButton> #include <QLabel> +#include <QTimer> class CallWindow : public QWidget { @@ -38,13 +39,20 @@ private: QPushButton *pbAccept; QPushButton *pbCall; QPushButton *pbHang; + QLabel *lbTimer; + QTimer *callTimer; + int callElapsedSeconds; void closeEvent(QCloseEvent *e); +public slots: + void call_started(); + void call_ended(); private slots: void call(); void accept(); void hang(); + void update_call_timer(); }; #endif |
