From 18b31b49acd189940e4339c98fd31664a74e9961 Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Mon, 10 Feb 2014 23:37:56 +0100 Subject: [PATCH] refs #129 , updated GUI to play notification sounds: * prepared for login/off sounds * prepared for text message sounds * helper method to play sounds * enabled mute / mixer also in cockpit, including context menus * settings for notification sounds * some minor tweaks, e.g. changed signal/slot to C++ style where missing --- samples/blackgui/mainwindow.cpp | 17 +++- samples/blackgui/mainwindow.h | 5 + samples/blackgui/mainwindow.ui | 100 +++++++++++++------ samples/blackgui/mainwindow_init.cpp | 2 +- samples/blackgui/mainwindow_menus.cpp | 10 +- samples/blackgui/mainwindow_settings.cpp | 4 + samples/blackgui/mainwindow_textmessages.cpp | 3 + samples/blackgui/mainwindow_voice.cpp | 16 ++- 8 files changed, 118 insertions(+), 39 deletions(-) diff --git a/samples/blackgui/mainwindow.cpp b/samples/blackgui/mainwindow.cpp index a5c78d7ff..a1146ed12 100644 --- a/samples/blackgui/mainwindow.cpp +++ b/samples/blackgui/mainwindow.cpp @@ -215,7 +215,6 @@ void MainWindow::toggleNetworkConnection() mode = INetwork::LoginAsObserver; this->displayStatusMessage(CStatusMessage::getInfoMessage("login in observer mode")); } - msgs = this->m_contextNetwork->connectToNetwork(static_cast(mode)); } else @@ -296,6 +295,22 @@ void MainWindow::connectionStatusChanged(uint /** from **/, uint to) this->startUpdateTimers(); else if (newStatus == INetwork::Disconnecting || newStatus == INetwork::Disconnected || newStatus == INetwork::DisconnectedError) this->stopUpdateTimers(); + + // sounds + switch (newStatus) + { + case INetwork::Connected: + this->playNotifcationSound(BlackSound::CSoundGenerator::NotificationLogin); + break; + case INetwork::Disconnected: + this->playNotifcationSound(BlackSound::CSoundGenerator::NotificationLogoff); + break; + case INetwork::DisconnectedError: + this->playNotifcationSound(BlackSound::CSoundGenerator::NotificationError); + break; + default: + break; + } } /* diff --git a/samples/blackgui/mainwindow.h b/samples/blackgui/mainwindow.h index 0bee740d9..672f18057 100644 --- a/samples/blackgui/mainwindow.h +++ b/samples/blackgui/mainwindow.h @@ -307,6 +307,11 @@ private: */ void audioTestUpdate(); + /*! + * \brief Play notifcation sound + */ + void playNotifcationSound(BlackSound::CSoundGenerator::Notification notification) const; + private slots: // diff --git a/samples/blackgui/mainwindow.ui b/samples/blackgui/mainwindow.ui index ff6d50945..6aa9d67ea 100644 --- a/samples/blackgui/mainwindow.ui +++ b/samples/blackgui/mainwindow.ui @@ -454,7 +454,7 @@ QStatusBar QLabel { QFrame::NoFrame - 0 + 7 @@ -540,7 +540,7 @@ QStatusBar QLabel { - + @@ -564,8 +564,8 @@ QStatusBar QLabel { 0 0 - 326 - 267 + 86 + 59 @@ -607,8 +607,8 @@ QStatusBar QLabel { 0 0 - 326 - 267 + 90 + 55 @@ -1387,22 +1387,6 @@ QStatusBar QLabel { - - - - Qt::Vertical - - - QSizePolicy::Fixed - - - - 20 - 28 - - - - @@ -1459,8 +1443,24 @@ QStatusBar QLabel { - - + + + + + 0 + 28 + + + + + + + :/blackgui/icons/audiovolumelow.png + + + + + Qt::Vertical @@ -2224,21 +2224,14 @@ QStatusBar QLabel { - + Result - - - - 0 - - - - + @@ -2251,6 +2244,47 @@ QStatusBar QLabel { + + + + 0 + + + + + + + Qt::Vertical + + + + 20 + 20 + + + + + + + + play notification sounds + + + + + + + notification for text messages + + + + + + + Notification sounds + + + diff --git a/samples/blackgui/mainwindow_init.cpp b/samples/blackgui/mainwindow_init.cpp index 6b941e5ec..3391df036 100644 --- a/samples/blackgui/mainwindow_init.cpp +++ b/samples/blackgui/mainwindow_init.cpp @@ -34,7 +34,7 @@ void MainWindow::init(GuiModes::CoreMode coreMode) QPushButton *closeIcon = new QPushButton(this); closeIcon->setStyleSheet("margin: 0; padding: 0; background: transparent;"); closeIcon->setIcon(QIcon(":/blackgui/icons/close.png")); - QObject::connect(closeIcon, SIGNAL(clicked()), this, SLOT(close())); + QObject::connect(closeIcon, &QPushButton::clicked, this, &QMainWindow::close); menuBarLayout->addWidget(this->ui->mb_MainMenuBar, 0, Qt::AlignTop | Qt::AlignLeft); menuBarLayout->addWidget(closeIcon, 0, Qt::AlignTop | Qt::AlignRight); this->ui->vl_CentralWidgetOutside->insertLayout(0, menuBarLayout, 0); diff --git a/samples/blackgui/mainwindow_menus.cpp b/samples/blackgui/mainwindow_menus.cpp index 31e38a0dc..92c179e65 100644 --- a/samples/blackgui/mainwindow_menus.cpp +++ b/samples/blackgui/mainwindow_menus.cpp @@ -53,8 +53,10 @@ void MainWindow::menuClicked() */ void MainWindow::initContextMenus() { - this->ui->lbl_VoiceStatus->setContextMenuPolicy(Qt::CustomContextMenu); - connect(this->ui->lbl_VoiceStatus, &QLabel::customContextMenuRequested, this, &MainWindow::audioIconContextMenu); + this->ui->lbl_StatusVoiceStatus->setContextMenuPolicy(Qt::CustomContextMenu); + this->ui->lbl_CockpitVoiceStatus->setContextMenuPolicy(Qt::CustomContextMenu); + connect(this->ui->lbl_StatusVoiceStatus, &QLabel::customContextMenuRequested, this, &MainWindow::audioIconContextMenu); + connect(this->ui->lbl_CockpitVoiceStatus, &QLabel::customContextMenuRequested, this, &MainWindow::audioIconContextMenu); this->ui->tv_StatusMessages->setContextMenuPolicy(Qt::CustomContextMenu); connect(this->ui->tv_StatusMessages, &QTableView::customContextMenuRequested, this, &MainWindow::messageListContextMenu); } @@ -65,7 +67,9 @@ void MainWindow::initContextMenus() void MainWindow::audioIconContextMenu(const QPoint &position) { // position for most widgets - QPoint globalPosition = this->ui->lbl_VoiceStatus->mapToGlobal(position); + QWidget *sender = qobject_cast(QWidget::sender()); + Q_ASSERT(sender); + QPoint globalPosition = sender->mapToGlobal(position); if (!this->m_contextMenuAudio) { diff --git a/samples/blackgui/mainwindow_settings.cpp b/samples/blackgui/mainwindow_settings.cpp index 93b296976..412b0573e 100644 --- a/samples/blackgui/mainwindow_settings.cpp +++ b/samples/blackgui/mainwindow_settings.cpp @@ -26,6 +26,10 @@ void MainWindow::reloadSettings() this->m_trafficServerList->update(nws.getTrafficNetworkServers()); this->ui->tv_SettingsTnServers->resizeColumnsToContents(); this->ui->tv_SettingsTnServers->resizeRowsToContents(); + + // fake setting for sound notifications + this->ui->cb_SettingsAudioPlayNotificationSounds->setChecked(true); + this->ui->cb_SettingsAudioNotificationTextMessage->setChecked(true); } /* diff --git a/samples/blackgui/mainwindow_textmessages.cpp b/samples/blackgui/mainwindow_textmessages.cpp index b6b658860..a022b41c0 100644 --- a/samples/blackgui/mainwindow_textmessages.cpp +++ b/samples/blackgui/mainwindow_textmessages.cpp @@ -153,6 +153,9 @@ void MainWindow::addPrivateChannelTextMessage(const CTextMessage &textMessage, b Q_ASSERT(textEdit != nullptr); if (textEdit == nullptr) return; // do not crash, though this situation could not happen textEdit->append(textMessage.asString(true, false, "\t")); + + // sound + this->playNotifcationSound(BlackSound::CSoundGenerator::NotificationTextMessage); } /* diff --git a/samples/blackgui/mainwindow_voice.cpp b/samples/blackgui/mainwindow_voice.cpp index b3fa15833..f56fa862d 100644 --- a/samples/blackgui/mainwindow_voice.cpp +++ b/samples/blackgui/mainwindow_voice.cpp @@ -4,10 +4,12 @@ #include "blackcore/dbus_server.h" #include "blackcore/context_network.h" #include "blackcore/context_voice.h" +#include "blacksound/soundgenerator.h" using namespace BlackCore; using namespace BlackMisc; using namespace BlackGui; +using namespace BlackSound; using namespace BlackMisc::Network; using namespace BlackMisc::Voice; using namespace BlackMisc::Aviation; @@ -136,7 +138,8 @@ void MainWindow::audioVolumes() com1.setEnabled(!muted); com2.setEnabled(!muted); this->ui->pb_SoundMute->setText(muted ? "Unmute" : "Mute"); - this->ui->lbl_VoiceStatus->setPixmap(muted ? this->m_resPixmapVoiceMuted : this->m_resPixmapVoiceHigh); + this->ui->lbl_StatusVoiceStatus->setPixmap(muted ? this->m_resPixmapVoiceMuted : this->m_resPixmapVoiceHigh); + this->ui->lbl_CockpitVoiceStatus->setPixmap(muted ? this->m_resPixmapVoiceMuted : this->m_resPixmapVoiceHigh); this->ui->pb_SoundMute->setStyleSheet(muted ? "background-color: red;" : ""); if (muted) this->displayOverlayInfo("Sound is muted!"); @@ -227,3 +230,14 @@ void MainWindow::audioTestUpdate() this->ui->prb_SettingsAudioTestProgress->setVisible(false); } } + +/* + * Notification + */ +void MainWindow::playNotifcationSound(CSoundGenerator::Notification notification) const +{ + if (!this->m_contextVoiceAvailable) return; + if (!this->ui->cb_SettingsAudioPlayNotificationSounds->isChecked()) return; + if (notification == CSoundGenerator::NotificationTextMessage && !this->ui->cb_SettingsAudioNotificationTextMessage->isChecked()) return; + this->m_contextVoice->playNotification(static_cast(notification)); +}