refs #299 floating components for

* logs
* info status bar
This commit is contained in:
Klaus Basan
2014-08-02 23:05:49 +02:00
parent c197ec8296
commit 841abd9c14
5 changed files with 437 additions and 0 deletions

View File

@@ -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 <QPoint>
#include <QMenu>
#include <QProcess>
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<INetwork::ConnectionStatus>(from);
INetwork::ConnectionStatus toStatus = static_cast<INetwork::ConnectionStatus>(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 *>(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<QAction *> 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
}
}

View File

@@ -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 <QFrame>
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

View File

@@ -0,0 +1,169 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>CInfoBarStatus</class>
<widget class="QFrame" name="CInfoBarStatus">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>27</height>
</rect>
</property>
<property name="windowTitle">
<string>Frame</string>
</property>
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<layout class="QHBoxLayout" name="hl_InfoBarStatus">
<property name="spacing">
<number>3</number>
</property>
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QLabel" name="lbl_Network">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip">
<string>Network</string>
</property>
<property name="text">
<string>Net</string>
</property>
</widget>
</item>
<item>
<widget class="BlackGui::CLed" name="led_Network" native="true"/>
</item>
<item>
<widget class="QLabel" name="lbl_Simulator">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip">
<string>Simulator</string>
</property>
<property name="text">
<string>Sim</string>
</property>
</widget>
</item>
<item>
<widget class="BlackGui::CLed" name="led_Simulator" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="lbl_DBus">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>DBus</string>
</property>
</widget>
</item>
<item>
<widget class="BlackGui::CLed" name="led_DBus" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="lbl_Ptt">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip">
<string>Push to talk</string>
</property>
<property name="text">
<string>Ptt</string>
</property>
</widget>
</item>
<item>
<widget class="BlackGui::CLed" name="led_Ptt" native="true"/>
</item>
<item>
<widget class="QLabel" name="lbl_Audio">
<property name="toolTip">
<string>Audio</string>
</property>
<property name="lineWidth">
<number>0</number>
</property>
<property name="text">
<string>Audio</string>
</property>
<property name="margin">
<number>0</number>
</property>
</widget>
</item>
<item>
<widget class="BlackGui::CLed" name="led_Audio" native="true"/>
</item>
<item>
<spacer name="hs_InfoStatusBar">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>239</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>BlackGui::CLed</class>
<extends>QWidget</extends>
<header>blackgui/led.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<resources/>
<connections/>
</ui>

View File

@@ -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);
}
}
}

View File

@@ -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 <QFrame>
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;
};