From 841abd9c14d3d08aa693287437b10f8a3c39e513 Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Sat, 2 Aug 2014 23:05:49 +0200 Subject: [PATCH] refs #299 floating components for * logs * info status bar --- src/blackgui/components/infobarstatus.cpp | 170 ++++++++++++++++++++++ src/blackgui/components/infobarstatus.h | 67 +++++++++ src/blackgui/components/infobarstatus.ui | 169 +++++++++++++++++++++ src/blackgui/components/logcomponent.cpp | 17 +++ src/blackgui/components/logcomponent.h | 14 ++ 5 files changed, 437 insertions(+) create mode 100644 src/blackgui/components/infobarstatus.cpp create mode 100644 src/blackgui/components/infobarstatus.h create mode 100644 src/blackgui/components/infobarstatus.ui diff --git a/src/blackgui/components/infobarstatus.cpp b/src/blackgui/components/infobarstatus.cpp new file mode 100644 index 000000000..8af4b5ee0 --- /dev/null +++ b/src/blackgui/components/infobarstatus.cpp @@ -0,0 +1,170 @@ +/* Copyright (C) 2013 + * swift Project Community / Contributors + * + * This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level + * directory of this distribution and at http://www.swift-project.org/license.html. No part of Swift Project, + * including this file, may be copied, modified, propagated, or distributed except according to the terms + * contained in the LICENSE file. + */ + +#include "infobarstatus.h" +#include "ui_infobarstatus.h" +#include "blackmisc/icons.h" + +#include +#include +#include + +using namespace BlackCore; +using namespace BlackGui; +using namespace BlackMisc; + +namespace BlackGui +{ + namespace Components + { + CInfoBarStatus::CInfoBarStatus(QWidget *parent) : + QFrame(parent), ui(new Ui::CInfoBarStatus) + { + ui->setupUi(this); + this->initLeds(); + + this->ui->lbl_Audio->setContextMenuPolicy(Qt::CustomContextMenu); + connect(this->ui->lbl_Audio, &QLabel::customContextMenuRequested, this, &CInfoBarStatus::ps_customAudioContextMenuRequested); + } + + CInfoBarStatus::~CInfoBarStatus() + { + delete ui; + } + + void CInfoBarStatus::initLeds() + { + CLed::LedShapes shape = CLed::Circle; + this->ui->led_DBus->setValues(CLed::Yellow, CLed::Black, shape, "DBus connected", "DBus disconnected", 14); + this->ui->led_Network->setValues(CLed::Yellow, CLed::Black, shape, "Network connected", "Network disconnected", 14); + this->ui->led_Simulator->setValues(CLed::Yellow, CLed::Black, shape, "Simulator connected", "Simulator disconnected", 14); + + shape = CLed::Rounded; + this->ui->led_Ptt->setValues(CLed::Yellow, CLed::Red, shape, "Ptt", "Silence", 18); + this->ui->led_Audio->setValues(CLed::Yellow, CLed::Red, shape, "On", "Muted", 18); + } + + void CInfoBarStatus::setDBusStatus(bool dbus) + { + this->ui->led_DBus->setValue(dbus); + } + + void CInfoBarStatus::setDBusTooltip(const QString &tooltip) + { + this->ui->led_DBus->setOnToolTip(tooltip); + } + + void CInfoBarStatus::setVolume(int volume) + { + if (volume < 1) + { + this->ui->led_Audio->setValue(false); + } + else + { + this->ui->led_Audio->setValue(true); + } + } + + void CInfoBarStatus::runtimeHasBeenSet() + { + Q_ASSERT(getIContextSimulator()); + Q_ASSERT(getIContextAudio()); + Q_ASSERT(getIContextNetwork()); + + if (this->getIContextSimulator()) + { + connect(this->getIContextSimulator(), &IContextSimulator::connectionChanged, this, &CInfoBarStatus::ps_simulatorConnectionChanged); + } + + if (this->getIContextNetwork()) + { + connect(this->getIContextNetwork(), &IContextNetwork::connectionStatusChanged, this, &CInfoBarStatus::ps_networkConnectionChanged); + } + + if (this->getIContextApplication()) + { + if (this->getIContextApplication()->usingLocalObjects()) + { + this->ui->led_DBus->setValue(false); + } + else + { + this->ui->led_DBus->setValue(true); + } + } + } + + void CInfoBarStatus::ps_simulatorConnectionChanged(bool connected) + { + this->ui->led_Simulator->setValue(connected); + } + + void CInfoBarStatus::ps_networkConnectionChanged(uint from, uint to, const QString &message) + { + INetwork::ConnectionStatus fromStatus = static_cast(from); + INetwork::ConnectionStatus toStatus = static_cast(to); + Q_UNUSED(fromStatus); + Q_UNUSED(message); + + switch (toStatus) + { + case INetwork::Disconnected: + case INetwork::DisconnectedError: + case INetwork::DisconnectedFailed: + case INetwork::DisconnectedLost: + this->ui->led_Network->setValue(false); + break; + case INetwork::Connected: + this->ui->led_Network->setValue(true); + break; + case INetwork::Connecting: + this->ui->led_Network->setTemporaryColor(CLed::Yellow); + break; + default: + this->ui->led_Network->setValue(false); + break; + } + } + + void CInfoBarStatus::ps_customAudioContextMenuRequested(const QPoint &position) + { + QWidget *sender = qobject_cast(QWidget::sender()); + Q_ASSERT(sender); + QPoint globalPosition = sender->mapToGlobal(position); + + QMenu menuAudio(this); + menuAudio.addAction("Toogle mute"); + +#if defined(Q_OS_WIN) + // QSysInfo::WindowsVersion only available on Win platforms + if (QSysInfo::WindowsVersion & QSysInfo::WV_NT_based) + { + menuAudio.addAction("Mixer"); + } +#endif + + QAction *selectedItem = menuAudio.exec(globalPosition); + if (selectedItem) + { + // http://forum.technical-assistance.co.uk/sndvol32exe-command-line-parameters-vt1348.html + const QList actions = menuAudio.actions(); + if (selectedItem == actions.at(0)) + { + // TODO: toogle mute + } + else if (actions.size() > 1 && selectedItem == actions.at(1)) + { + QStringList parameterlist; + QProcess::startDetached("SndVol.exe", parameterlist); + } + } + } // custom menu + } +} diff --git a/src/blackgui/components/infobarstatus.h b/src/blackgui/components/infobarstatus.h new file mode 100644 index 000000000..109e0d4c3 --- /dev/null +++ b/src/blackgui/components/infobarstatus.h @@ -0,0 +1,67 @@ +/* Copyright (C) 2013 + * swift Project Community / Contributors + * + * This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level + * directory of this distribution and at http://www.swift-project.org/license.html. No part of Swift Project, + * including this file, may be copied, modified, propagated, or distributed except according to the terms + * contained in the LICENSE file. + */ + +//! \file + +#ifndef BLACKGUI_INFOBARSTATUS_H +#define BLACKGUI_INFOBARSTATUS_H + +#include "runtimebasedcomponent.h" +#include "../led.h" +#include + +namespace Ui { class CInfoBarStatus; } +namespace BlackGui +{ + namespace Components + { + //! Info bar displaying status (Network, Simulator, DBus) + class CInfoBarStatus : public QFrame, public CRuntimeBasedComponent + { + Q_OBJECT + + public: + //! Constructor + explicit CInfoBarStatus(QWidget *parent = nullptr); + + //!Constructor + ~CInfoBarStatus(); + + //! Init the LEDs + void initLeds(); + + //! DBus used + void setDBusStatus(bool dbus); + + //! Tooltip for DBus + void setDBusTooltip(const QString &tooltip); + + //! Volume 0.100 + void setVolume(int volume); + + protected: + //! \copydoc CRuntimeBasedComponent::runtimeHasBeenSet + virtual void runtimeHasBeenSet() override; + + private: + Ui::CInfoBarStatus *ui; + + private slots: + //! Simulator connection has been changed + void ps_simulatorConnectionChanged(bool connected); + + //! Network connection has been changed + void ps_networkConnectionChanged(uint from, uint to, const QString &message); + + //! Context menu requested + void ps_customAudioContextMenuRequested(const QPoint &position); + }; + } +} +#endif // guard diff --git a/src/blackgui/components/infobarstatus.ui b/src/blackgui/components/infobarstatus.ui new file mode 100644 index 000000000..7fbfdcb65 --- /dev/null +++ b/src/blackgui/components/infobarstatus.ui @@ -0,0 +1,169 @@ + + + CInfoBarStatus + + + + 0 + 0 + 400 + 27 + + + + Frame + + + QFrame::StyledPanel + + + QFrame::Raised + + + + 3 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + 0 + 0 + + + + Network + + + Net + + + + + + + + + + + 0 + 0 + + + + Simulator + + + Sim + + + + + + + + 0 + 0 + + + + + + + + + 0 + 0 + + + + DBus + + + + + + + + 0 + 0 + + + + + + + + + 0 + 0 + + + + Push to talk + + + Ptt + + + + + + + + + + Audio + + + 0 + + + Audio + + + 0 + + + + + + + + + + Qt::Horizontal + + + + 239 + 20 + + + + + + + + + BlackGui::CLed + QWidget +
blackgui/led.h
+ 1 +
+
+ + +
diff --git a/src/blackgui/components/logcomponent.cpp b/src/blackgui/components/logcomponent.cpp index e8e514fcb..3826c5819 100644 --- a/src/blackgui/components/logcomponent.cpp +++ b/src/blackgui/components/logcomponent.cpp @@ -25,5 +25,22 @@ namespace BlackGui { delete ui; } + + void CLogComponent::appendStatusMessageToConsole(const CStatusMessage &statusMessage) + { + if (statusMessage.isEmpty()) return; + this->ui->te_StatusPageConsole->appendHtml(statusMessage.toHtml()); + } + + void CLogComponent::appendPlainTextToConsole(const QString &text) + { + this->ui->te_StatusPageConsole->appendPlainText(text); + } + + void CLogComponent::appendStatusMessageToList(const CStatusMessage &statusMessage) + { + if (statusMessage.isEmpty()) return; + this->ui->tvp_StatusMessages->insert(statusMessage); + } } } diff --git a/src/blackgui/components/logcomponent.h b/src/blackgui/components/logcomponent.h index eabac2f6d..2120af99b 100644 --- a/src/blackgui/components/logcomponent.h +++ b/src/blackgui/components/logcomponent.h @@ -7,10 +7,13 @@ * contained in the LICENSE file. */ +//! \file + #ifndef BLACKGUI_LOGCOMPONENT_H #define BLACKGUI_LOGCOMPONENT_H #include "runtimebasedcomponent.h" +#include "blackmisc/statusmessagelist.h" #include namespace Ui { class CLogComponent; } @@ -32,6 +35,17 @@ namespace BlackGui //! Destructor ~CLogComponent(); + public slots: + //! Append status message to console + void appendStatusMessageToConsole(const BlackMisc::CStatusMessage &statusMessage); + + //! Append plain text to console + void appendPlainTextToConsole(const QString &text); + + //! Append status message to list + void appendStatusMessageToList(const BlackMisc::CStatusMessage &statusMessage); + + private: Ui::CLogComponent *ui; };