mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-27 02:55:44 +08:00
During refs #319, refactoring of QLed (as it is used with a LED formatter)
* renamed to CLedWidget * added missing SVG * rendering to pixmap possible * QScopedPointer<QSvgRenderer> * Led, copyright
This commit is contained in:
@@ -40,14 +40,14 @@ namespace BlackGui
|
|||||||
|
|
||||||
void CInfoBarStatusComponent::initLeds()
|
void CInfoBarStatusComponent::initLeds()
|
||||||
{
|
{
|
||||||
CLed::LedShape shape = CLed::Circle;
|
CLedWidget::LedShape shape = CLedWidget::Circle;
|
||||||
this->ui->led_DBus->setValues(CLed::Yellow, CLed::Black, shape, "DBus connected", "DBus disconnected", 14);
|
this->ui->led_DBus->setValues(CLedWidget::Yellow, CLedWidget::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_Network->setValues(CLedWidget::Yellow, CLedWidget::Black, shape, "Network connected", "Network disconnected", 14);
|
||||||
this->ui->led_Simulator->setValues(CLed::Yellow, CLed::Black, shape, "Simulator connected", "Simulator disconnected", 14);
|
this->ui->led_Simulator->setValues(CLedWidget::Yellow, CLedWidget::Black, shape, "Simulator connected", "Simulator disconnected", 14);
|
||||||
|
|
||||||
shape = CLed::Rounded;
|
shape = CLedWidget::Rounded;
|
||||||
this->ui->led_Ptt->setValues(CLed::Yellow, CLed::Red, shape, "Ptt", "Silence", 18);
|
this->ui->led_Ptt->setValues(CLedWidget::Yellow, CLedWidget::Red, shape, "Ptt", "Silence", 18);
|
||||||
this->ui->led_Audio->setValues(CLed::Yellow, CLed::Red, shape, "On", "Muted", 18);
|
this->ui->led_Audio->setValues(CLedWidget::Yellow, CLedWidget::Red, shape, "On", "Muted", 18);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CInfoBarStatusComponent::setDBusStatus(bool dbus)
|
void CInfoBarStatusComponent::setDBusStatus(bool dbus)
|
||||||
@@ -125,7 +125,7 @@ namespace BlackGui
|
|||||||
this->ui->led_Network->setOn(true);
|
this->ui->led_Network->setOn(true);
|
||||||
break;
|
break;
|
||||||
case INetwork::Connecting:
|
case INetwork::Connecting:
|
||||||
this->ui->led_Network->setTemporaryColor(CLed::Yellow);
|
this->ui->led_Network->setTemporaryColor(CLedWidget::Yellow);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
this->ui->led_Network->setOn(false);
|
this->ui->led_Network->setOn(false);
|
||||||
|
|||||||
@@ -56,7 +56,7 @@
|
|||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="BlackGui::CLed" name="led_Network" native="true"/>
|
<widget class="BlackGui::CLedWidget" name="led_Network" native="true"/>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QLabel" name="lbl_Simulator">
|
<widget class="QLabel" name="lbl_Simulator">
|
||||||
@@ -75,7 +75,7 @@
|
|||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="BlackGui::CLed" name="led_Simulator" native="true">
|
<widget class="BlackGui::CLedWidget" name="led_Simulator" native="true">
|
||||||
<property name="sizePolicy">
|
<property name="sizePolicy">
|
||||||
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
|
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
|
||||||
<horstretch>0</horstretch>
|
<horstretch>0</horstretch>
|
||||||
@@ -98,7 +98,7 @@
|
|||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="BlackGui::CLed" name="led_DBus" native="true">
|
<widget class="BlackGui::CLedWidget" name="led_DBus" native="true">
|
||||||
<property name="sizePolicy">
|
<property name="sizePolicy">
|
||||||
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
|
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
|
||||||
<horstretch>0</horstretch>
|
<horstretch>0</horstretch>
|
||||||
@@ -124,7 +124,7 @@
|
|||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="BlackGui::CLed" name="led_Ptt" native="true"/>
|
<widget class="BlackGui::CLedWidget" name="led_Ptt" native="true"/>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QLabel" name="lbl_Audio">
|
<widget class="QLabel" name="lbl_Audio">
|
||||||
@@ -143,7 +143,7 @@
|
|||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="BlackGui::CLed" name="led_Audio" native="true"/>
|
<widget class="BlackGui::CLedWidget" name="led_Audio" native="true"/>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<spacer name="hs_InfoStatusBar">
|
<spacer name="hs_InfoStatusBar">
|
||||||
@@ -162,7 +162,7 @@
|
|||||||
</widget>
|
</widget>
|
||||||
<customwidgets>
|
<customwidgets>
|
||||||
<customwidget>
|
<customwidget>
|
||||||
<class>BlackGui::CLed</class>
|
<class>BlackGui::CLedWidget</class>
|
||||||
<extends>QWidget</extends>
|
<extends>QWidget</extends>
|
||||||
<header>blackgui/led.h</header>
|
<header>blackgui/led.h</header>
|
||||||
<container>1</container>
|
<container>1</container>
|
||||||
|
|||||||
@@ -6,12 +6,7 @@
|
|||||||
* including this file, may be copied, modified, propagated, or distributed except according to the terms
|
* including this file, may be copied, modified, propagated, or distributed except according to the terms
|
||||||
* contained in the LICENSE file.
|
* contained in the LICENSE file.
|
||||||
*
|
*
|
||||||
* Copyright (C) 2010 by P. Sereno
|
* Class based on qLed: Copyright (C) 2010 by P. Sereno, http://www.sereno-online.com
|
||||||
* http://www.sereno-online.com
|
|
||||||
*
|
|
||||||
* This program is free software; you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU Lesser General Public License
|
|
||||||
* version 2.1 as published by the Free Software Foundation
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "led.h"
|
#include "led.h"
|
||||||
@@ -22,22 +17,29 @@
|
|||||||
#include <QPolygon>
|
#include <QPolygon>
|
||||||
#include <QtSvg>
|
#include <QtSvg>
|
||||||
#include <QSvgRenderer>
|
#include <QSvgRenderer>
|
||||||
|
#include <QImage>
|
||||||
|
|
||||||
namespace BlackGui
|
namespace BlackGui
|
||||||
{
|
{
|
||||||
CLed::CLed(QWidget *parent) : QWidget(parent)
|
CLedWidget::CLedWidget(QWidget *parent) : QWidget(parent), m_renderer(new QSvgRenderer)
|
||||||
{
|
{
|
||||||
this->setLed();
|
this->setLed();
|
||||||
}
|
}
|
||||||
|
|
||||||
CLed::CLed(bool on, CLed::LedColor onColor, CLed::LedColor offColor, CLed::LedShape shape, QWidget *parent) :
|
CLedWidget::CLedWidget(bool on, LedColor onColor, LedColor offColor, LedShape shape, const QString &onName, const QString &offName, QWidget *parent) :
|
||||||
QWidget(parent), m_value(on ? On : Off), m_onColor(onColor), m_offColor(offColor), m_shape(shape)
|
m_value(on ? On : Off), m_colorOn(onColor), m_colorOff(offColor),
|
||||||
|
m_shape(shape), m_tooltipOn(onName), m_tooltipOff(offName), m_renderer(new QSvgRenderer(parent))
|
||||||
{
|
{
|
||||||
this->setLed();
|
this->setLed();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CLed::setLed(LedColor ledColor)
|
CLedWidget::~CLedWidget()
|
||||||
|
{ }
|
||||||
|
|
||||||
|
void CLedWidget::setLed(LedColor ledColor)
|
||||||
{
|
{
|
||||||
|
Q_ASSERT(!this->m_renderer.isNull());
|
||||||
|
|
||||||
// load image, init renderer
|
// load image, init renderer
|
||||||
QString ledShapeAndColor;
|
QString ledShapeAndColor;
|
||||||
ledShapeAndColor = shapes().at(static_cast<int>(this->m_shape));
|
ledShapeAndColor = shapes().at(static_cast<int>(this->m_shape));
|
||||||
@@ -45,29 +47,23 @@ namespace BlackGui
|
|||||||
{
|
{
|
||||||
if (m_value == On)
|
if (m_value == On)
|
||||||
{
|
{
|
||||||
this->setToolTip(this->m_tooltipOn);
|
this->m_currentToolTip = this->m_tooltipOn;
|
||||||
ledShapeAndColor.append(CLed::colorString(this->m_onColor));
|
ledShapeAndColor.append(CLedWidget::colorString(this->m_colorOn));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
this->setToolTip(this->m_tooltipOff);
|
this->m_currentToolTip = this->m_tooltipOff;
|
||||||
ledShapeAndColor.append(CLed::colorString(this->m_offColor));
|
ledShapeAndColor.append(CLedWidget::colorString(this->m_colorOff));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
this->setToolTip("transition");
|
this->m_currentToolTip = "transition";
|
||||||
ledShapeAndColor.append(CLed::colorString(ledColor));
|
ledShapeAndColor.append(CLedWidget::colorString(ledColor));
|
||||||
}
|
|
||||||
|
|
||||||
// init renderer, allow re-init
|
|
||||||
bool firstTime = false;
|
|
||||||
if (!m_renderer)
|
|
||||||
{
|
|
||||||
firstTime = true;
|
|
||||||
m_renderer = new QSvgRenderer(this);
|
|
||||||
}
|
}
|
||||||
|
this->setToolTip(this->m_currentToolTip); // for widget
|
||||||
|
|
||||||
|
// init renderer, load led.
|
||||||
m_renderer->load(ledShapeAndColor);
|
m_renderer->load(ledShapeAndColor);
|
||||||
|
|
||||||
// original size
|
// original size
|
||||||
@@ -75,105 +71,95 @@ namespace BlackGui
|
|||||||
this->m_whRatio = s.width() / s.height();
|
this->m_whRatio = s.width() / s.height();
|
||||||
|
|
||||||
// size
|
// size
|
||||||
if (this->m_targetWidth < 0)
|
if (this->m_widthTarget < 0)
|
||||||
{
|
{
|
||||||
this->m_targetWidth = widths().at(static_cast<int>(m_shape));
|
this->m_widthTarget = widths().at(static_cast<int>(m_shape));
|
||||||
}
|
}
|
||||||
double w = this->m_targetWidth;
|
double h = this->m_widthTarget / this->m_whRatio;
|
||||||
double h = w / this->m_whRatio;
|
this->m_heightCalculated = qRound(h);
|
||||||
this->setFixedHeight(qRound(h));
|
|
||||||
this->setFixedWidth(qRound(w));
|
|
||||||
|
|
||||||
if (!firstTime)
|
this->setFixedHeight(this->m_heightCalculated);
|
||||||
{
|
this->setFixedWidth(this->m_widthTarget);
|
||||||
// re-init widget (adjust size etc.)
|
this->update();
|
||||||
this->update();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const QString &CLed::colorString(CLed::LedColor color)
|
QPixmap CLedWidget::renderToPixmap() const
|
||||||
|
{
|
||||||
|
Q_ASSERT(!this->m_renderer.isNull());
|
||||||
|
|
||||||
|
// Prepare a QImage with desired characteritiscs
|
||||||
|
QImage image(QSize(this->m_widthTarget, this->m_heightCalculated), QImage::Format_ARGB32);
|
||||||
|
image.fill(qRgba(0, 0, 0, 0)); // transparent background
|
||||||
|
|
||||||
|
// Get QPainter that paints to the image
|
||||||
|
QPainter painter(&image);
|
||||||
|
this->m_renderer->render(&painter);
|
||||||
|
return QPixmap::fromImage(image);
|
||||||
|
}
|
||||||
|
|
||||||
|
const QString &CLedWidget::colorString(CLedWidget::LedColor color)
|
||||||
{
|
{
|
||||||
static const QString empty;
|
static const QString empty;
|
||||||
if (color == NoColor) return empty;
|
if (color == NoColor) return empty;
|
||||||
return colors().at(static_cast<int>(color));
|
return colors().at(static_cast<int>(color));
|
||||||
}
|
}
|
||||||
|
|
||||||
CLed::~CLed()
|
void CLedWidget::setToolTips(const QString &on, const QString &off)
|
||||||
{
|
|
||||||
delete m_renderer;
|
|
||||||
}
|
|
||||||
|
|
||||||
void CLed::setToolTips(const QString &on, const QString &off)
|
|
||||||
{
|
{
|
||||||
this->m_tooltipOn = on;
|
this->m_tooltipOn = on;
|
||||||
this->m_tooltipOff = off;
|
this->m_tooltipOff = off;
|
||||||
if (this->m_value)
|
this->setLed();
|
||||||
{
|
|
||||||
this->setToolTip(on);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
this->setToolTip(off);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CLed::setOnToolTip(const QString &on)
|
void CLedWidget::setOnToolTip(const QString &on)
|
||||||
{
|
{
|
||||||
this->setToolTips(on, this->m_tooltipOff);
|
this->setToolTips(on, this->m_tooltipOff);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CLed::paintEvent(QPaintEvent *)
|
void CLedWidget::setOnColor(LedColor color)
|
||||||
{
|
{
|
||||||
// init style sheets with this widget
|
if (color == this->m_colorOn) return;
|
||||||
QStyleOption opt;
|
m_colorOn = color;
|
||||||
opt.init(this);
|
|
||||||
|
|
||||||
// paint
|
|
||||||
QPainter painter(this);
|
|
||||||
painter.setRenderHint(QPainter::Antialiasing, true);
|
|
||||||
painter.setBackgroundMode(Qt::TransparentMode);
|
|
||||||
m_renderer->render(&painter);
|
|
||||||
}
|
|
||||||
|
|
||||||
void CLed::setOnColor(LedColor color)
|
|
||||||
{
|
|
||||||
if (color == this->m_onColor) return;
|
|
||||||
m_onColor = color;
|
|
||||||
setLed();
|
setLed();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CLed::setOffColor(LedColor color)
|
void CLedWidget::setOffColor(LedColor color)
|
||||||
{
|
{
|
||||||
if (color == this->m_offColor) return;
|
if (color == this->m_colorOff) return;
|
||||||
m_offColor = color;
|
m_colorOff = color;
|
||||||
setLed();
|
setLed();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CLed::setTemporaryColor(CLed::LedColor color)
|
void CLedWidget::setTemporaryColor(CLedWidget::LedColor color)
|
||||||
{
|
{
|
||||||
m_value = Temporary;
|
m_value = Temporary;
|
||||||
setLed(color);
|
setLed(color);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CLed::setShape(LedShape newShape)
|
void CLedWidget::setShape(LedShape newShape)
|
||||||
{
|
{
|
||||||
if (newShape == this->m_shape) return;
|
if (newShape == this->m_shape) return;
|
||||||
m_shape = newShape;
|
m_shape = newShape;
|
||||||
setLed();
|
setLed();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CLed::setValues(CLed::LedColor onColor, CLed::LedColor offColor, CLed::LedShape shape, const QString &toolTipOn, const QString &toolTipOff, int width)
|
void CLedWidget::setValues(LedColor onColor, LedColor offColor, LedShape shape, const QString &toolTipOn, const QString &toolTipOff, int width)
|
||||||
{
|
{
|
||||||
m_onColor = onColor;
|
m_colorOn = onColor;
|
||||||
m_offColor = offColor;
|
m_colorOff = offColor;
|
||||||
m_shape = shape;
|
m_shape = shape;
|
||||||
m_tooltipOn = toolTipOn;
|
m_tooltipOn = toolTipOn;
|
||||||
m_tooltipOff = toolTipOff;
|
m_tooltipOff = toolTipOff;
|
||||||
m_targetWidth = width;
|
m_widthTarget = width;
|
||||||
setLed();
|
setLed();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CLed::setOn(bool on)
|
QPixmap CLedWidget::asPixmap() const
|
||||||
|
{
|
||||||
|
return this->renderToPixmap();
|
||||||
|
}
|
||||||
|
|
||||||
|
void CLedWidget::setOn(bool on)
|
||||||
{
|
{
|
||||||
State s = on ? On : Off;
|
State s = on ? On : Off;
|
||||||
if (m_value == s) return;
|
if (m_value == s) return;
|
||||||
@@ -181,7 +167,7 @@ namespace BlackGui
|
|||||||
setLed();
|
setLed();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CLed::toggleValue()
|
void CLedWidget::toggleValue()
|
||||||
{
|
{
|
||||||
if (m_value == Temporary || m_value == On)
|
if (m_value == Temporary || m_value == On)
|
||||||
{
|
{
|
||||||
@@ -194,19 +180,32 @@ namespace BlackGui
|
|||||||
setLed();
|
setLed();
|
||||||
}
|
}
|
||||||
|
|
||||||
const QStringList &CLed::shapes()
|
void CLedWidget::paintEvent(QPaintEvent *)
|
||||||
|
{
|
||||||
|
// init style sheets with this widget
|
||||||
|
QStyleOption opt;
|
||||||
|
opt.init(this);
|
||||||
|
|
||||||
|
// paint
|
||||||
|
QPainter painter(this);
|
||||||
|
painter.setRenderHint(QPainter::Antialiasing, true);
|
||||||
|
painter.setBackgroundMode(Qt::TransparentMode);
|
||||||
|
m_renderer->render(&painter);
|
||||||
|
}
|
||||||
|
|
||||||
|
const QStringList &CLedWidget::shapes()
|
||||||
{
|
{
|
||||||
static const QStringList shapes( {":/qled/icons/qled/circle_" , ":/qled/icons/qled/square_" , ":/qled/icons/qled/triang_" , ":/qled/icons/qled/round_"});
|
static const QStringList shapes( {":/qled/icons/qled/circle_" , ":/qled/icons/qled/square_" , ":/qled/icons/qled/triang_" , ":/qled/icons/qled/round_"});
|
||||||
return shapes;
|
return shapes;
|
||||||
}
|
}
|
||||||
|
|
||||||
const QStringList &CLed::colors()
|
const QStringList &CLedWidget::colors()
|
||||||
{
|
{
|
||||||
static const QStringList colors( { "red.svg", "green.svg", "yellow.svg", "grey.svg", "orange.svg", "purple.svg", "blue.svg", "black.svg" });
|
static const QStringList colors( { "red.svg", "green.svg", "yellow.svg", "grey.svg", "orange.svg", "purple.svg", "blue.svg", "black.svg" });
|
||||||
return colors;
|
return colors;
|
||||||
}
|
}
|
||||||
|
|
||||||
const QList<int> &CLed::widths()
|
const QList<int> &CLedWidget::widths()
|
||||||
{
|
{
|
||||||
static const QList<int> widths({ 16, 16, 16, 16});
|
static const QList<int> widths({ 16, 16, 16, 16});
|
||||||
return widths;
|
return widths;
|
||||||
|
|||||||
@@ -6,12 +6,7 @@
|
|||||||
* including this file, may be copied, modified, propagated, or distributed except according to the terms
|
* including this file, may be copied, modified, propagated, or distributed except according to the terms
|
||||||
* contained in the LICENSE file.
|
* contained in the LICENSE file.
|
||||||
*
|
*
|
||||||
* Copyright (C) 2010 by P. Sereno
|
* Class based on qLed: Copyright (C) 2010 by P. Sereno, http://www.sereno-online.com
|
||||||
* http://www.sereno-online.com
|
|
||||||
*
|
|
||||||
* This program is free software; you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU Lesser General Public License
|
|
||||||
* version 2.1 as published by the Free Software Foundation
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
//! \file
|
//! \file
|
||||||
@@ -21,29 +16,19 @@
|
|||||||
|
|
||||||
#include <Qt>
|
#include <Qt>
|
||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
|
#include <QSvgRenderer>
|
||||||
class QColor;
|
#include <QColor>
|
||||||
class QSvgRenderer;
|
|
||||||
|
|
||||||
namespace BlackGui
|
namespace BlackGui
|
||||||
{
|
{
|
||||||
//! Displaying an LED
|
//! Displaying an LED as widget. Non copyable.
|
||||||
//! \remarks Based on qLed
|
//! \remarks Based on qLed
|
||||||
class CLed : public QWidget
|
class CLedWidget : public QWidget
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
Q_ENUMS(LedColor)
|
Q_ENUMS(LedColor)
|
||||||
Q_ENUMS(LedShape)
|
Q_ENUMS(LedShape)
|
||||||
|
|
||||||
//! Value on/off
|
|
||||||
Q_PROPERTY(bool value READ value WRITE setOn)
|
|
||||||
//! Color when on
|
|
||||||
Q_PROPERTY(LedColor onColor READ onColor WRITE setOnColor)
|
|
||||||
//! Color when off
|
|
||||||
Q_PROPERTY(LedColor offColor READ offColor WRITE setOffColor)
|
|
||||||
//! Shape
|
|
||||||
Q_PROPERTY(LedShape shape READ shape WRITE setShape)
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
//! Colors
|
//! Colors
|
||||||
@@ -56,29 +41,32 @@ namespace BlackGui
|
|||||||
//! States
|
//! States
|
||||||
enum State { On, Off, Temporary };
|
enum State { On, Off, Temporary };
|
||||||
|
|
||||||
//! Constructor
|
//! Default constructor
|
||||||
CLed(QWidget *parent = nullptr);
|
CLedWidget(QWidget *parent = nullptr);
|
||||||
|
|
||||||
//! Constructor
|
//! Constructor
|
||||||
CLed(bool on, LedColor onColor, LedColor offColor, LedShape shape, QWidget *parent = nullptr);
|
CLedWidget(bool on, LedColor onColor, LedColor offColor, LedShape shape, const QString &onName = "on", const QString &offName = "off", QWidget *parent = nullptr);
|
||||||
|
|
||||||
//! Destructor
|
//! Destructor
|
||||||
virtual ~CLed();
|
virtual ~CLedWidget();
|
||||||
|
|
||||||
//! Value
|
//! Value
|
||||||
bool value() const { return m_value; }
|
bool value() const { return m_value; }
|
||||||
|
|
||||||
//! On color
|
//! Allows to set the led value {true,false}
|
||||||
LedColor onColor() const { return m_onColor; }
|
void setOn(bool on);
|
||||||
|
|
||||||
//! Off color
|
//! Toggle on / off
|
||||||
LedColor offColor() const { return m_offColor; }
|
void toggleValue();
|
||||||
|
|
||||||
//! Shape
|
//! Shape
|
||||||
LedShape shape() const { return m_shape; }
|
LedShape shape() const { return m_shape; }
|
||||||
|
|
||||||
//! Allows to set the led value {true,false}
|
//! On color
|
||||||
void setOn(bool on);
|
LedColor onColor() const { return m_colorOn; }
|
||||||
|
|
||||||
|
//! Off color
|
||||||
|
LedColor offColor() const { return m_colorOff; }
|
||||||
|
|
||||||
//! Allows to change the On color {Red,Green,Yellow,Grey,Orange,Purple,blue}
|
//! Allows to change the On color {Red,Green,Yellow,Grey,Orange,Purple,blue}
|
||||||
void setOnColor(LedColor color);
|
void setOnColor(LedColor color);
|
||||||
@@ -89,31 +77,52 @@ namespace BlackGui
|
|||||||
//! Temporary color until next value change
|
//! Temporary color until next value change
|
||||||
void setTemporaryColor(LedColor color);
|
void setTemporaryColor(LedColor color);
|
||||||
|
|
||||||
|
//! Allows to change the led shape {Circle,Square,Triangle,Rounded rectangle}
|
||||||
|
void setShape(LedShape);
|
||||||
|
|
||||||
|
//! Target width
|
||||||
|
void setTargetWidth(int width) { this->m_widthTarget = width; }
|
||||||
|
|
||||||
|
//! Tool tip
|
||||||
|
QString getOnToolTip() const { return m_tooltipOn; }
|
||||||
|
|
||||||
|
//! Tool tip
|
||||||
|
QString getOffToolTip() const { return m_tooltipOff; }
|
||||||
|
|
||||||
//! Tool tips
|
//! Tool tips
|
||||||
void setToolTips(const QString &on, const QString &off);
|
void setToolTips(const QString &on, const QString &off);
|
||||||
|
|
||||||
//! On tool tip
|
//! On tool tip
|
||||||
void setOnToolTip(const QString &on);
|
void setOnToolTip(const QString &on);
|
||||||
|
|
||||||
//! Allows to change the led shape {Circle,Square,Triangle,Rounded rectangle}
|
|
||||||
void setShape(LedShape);
|
|
||||||
|
|
||||||
//! Target width
|
|
||||||
void setTargetWidth(int width) { this->m_targetWidth = width; }
|
|
||||||
|
|
||||||
//! New values
|
//! New values
|
||||||
void setValues(LedColor onColor, LedColor offColor, LedShape shape, const QString &toolTipOn, const QString &toolTipOff, int width = -1);
|
void setValues(LedColor onColor, LedColor offColor, LedShape shape, const QString &toolTipOn, const QString &toolTipOff, int width = -1);
|
||||||
|
|
||||||
//! Toggle on / off
|
//! Render as pixmap, so it can be used with TableViews
|
||||||
void toggleValue();
|
QPixmap asPixmap() const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
State m_value = Off; //!< current value
|
State m_value = Off; //!< current value
|
||||||
LedColor m_onColor = Red; //!< On color
|
LedColor m_colorOn = Red; //!< On color
|
||||||
LedColor m_offColor = Grey; //!< Off color
|
LedColor m_colorOff = Grey; //!< Off color
|
||||||
LedShape m_shape = Circle; //!< shape
|
LedShape m_shape = Circle; //!< shape
|
||||||
double m_whRatio = 1.0; //!< width/height ratio
|
double m_whRatio = 1.0; //!< width/height ratio
|
||||||
int m_targetWidth = -1; //!< TargetWidth
|
int m_widthTarget = -1; //!< desired width
|
||||||
|
int m_heightCalculated = 1; //!< calculated height
|
||||||
|
|
||||||
|
QString m_tooltipOn; //!< tooltip when on
|
||||||
|
QString m_tooltipOff; //!< tooltip when off
|
||||||
|
QString m_currentToolTip; //!< currently used tooltip
|
||||||
|
QScopedPointer<QSvgRenderer> m_renderer; //!< Renderer
|
||||||
|
|
||||||
|
//! Paint event
|
||||||
|
virtual void paintEvent(QPaintEvent *event) override;
|
||||||
|
|
||||||
|
//! Set / init LED
|
||||||
|
void setLed(LedColor ledColor = NoColor);
|
||||||
|
|
||||||
|
//! Render to pixmap
|
||||||
|
QPixmap renderToPixmap() const;
|
||||||
|
|
||||||
//! All shapes
|
//! All shapes
|
||||||
static const QStringList &shapes();
|
static const QStringList &shapes();
|
||||||
@@ -124,15 +133,13 @@ namespace BlackGui
|
|||||||
//! All target widths
|
//! All target widths
|
||||||
static const QList<int> &widths();
|
static const QList<int> &widths();
|
||||||
|
|
||||||
//! Paint event
|
//! Color string
|
||||||
void paintEvent(QPaintEvent *event);
|
static const QString &colorString(LedColor color); //!<Color string
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QSvgRenderer *m_renderer = nullptr; //!< Renderer
|
//! Fix widget after widths calculated
|
||||||
QString m_tooltipOn;
|
void firstTimeReInit();
|
||||||
QString m_tooltipOff;
|
|
||||||
void setLed(LedColor ledColor = NoColor); //!< Init LED
|
|
||||||
static const QString &colorString(LedColor color); //!<Color string
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -304,5 +304,7 @@
|
|||||||
<file>icons/qled/triang_purple.svg</file>
|
<file>icons/qled/triang_purple.svg</file>
|
||||||
<file>icons/qled/triang_red.svg</file>
|
<file>icons/qled/triang_red.svg</file>
|
||||||
<file>icons/qled/triang_yellow.svg</file>
|
<file>icons/qled/triang_yellow.svg</file>
|
||||||
|
<file>icons/qled/round_black.svg</file>
|
||||||
</qresource>
|
</qresource>
|
||||||
|
<qresource prefix="/"/>
|
||||||
</RCC>
|
</RCC>
|
||||||
|
|||||||
254
src/blackmisc/icons/qled/round_black.svg
Normal file
254
src/blackmisc/icons/qled/round_black.svg
Normal file
@@ -0,0 +1,254 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||||
|
<!-- Created with Inkscape (http://www.inkscape.org/) -->
|
||||||
|
<svg
|
||||||
|
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
|
||||||
|
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
|
||||||
|
xmlns="http://www.w3.org/2000/svg"
|
||||||
|
xmlns:xlink="http://www.w3.org/1999/xlink"
|
||||||
|
xmlns:cc="http://web.resource.org/cc/"
|
||||||
|
xmlns:dc="http://purl.org/dc/elements/1.1/"
|
||||||
|
xmlns:sodipodi="http://inkscape.sourceforge.net/DTD/sodipodi-0.dtd"
|
||||||
|
xmlns:svg="http://www.w3.org/2000/svg"
|
||||||
|
xmlns:ns1="http://sozi.baierouge.fr"
|
||||||
|
id="svg9493"
|
||||||
|
sodipodi:docname="led_rounded_h_black.svg"
|
||||||
|
inkscape:export-ydpi="90.000000"
|
||||||
|
inkscape:export-filename="/datas/Projs/Cliparts Stocker/led/led_rounded_h_black.png"
|
||||||
|
viewBox="0 0 100 50"
|
||||||
|
sodipodi:version="0.32"
|
||||||
|
inkscape:export-xdpi="90.000000"
|
||||||
|
inkscape:version="0.42"
|
||||||
|
sodipodi:docbase="/datas/Projs/Cliparts Stocker/led"
|
||||||
|
>
|
||||||
|
<defs
|
||||||
|
id="defs9495"
|
||||||
|
>
|
||||||
|
<linearGradient
|
||||||
|
id="linearGradient13472"
|
||||||
|
y2="46.774"
|
||||||
|
gradientUnits="userSpaceOnUse"
|
||||||
|
y1="47.917"
|
||||||
|
gradientTransform="matrix(.92813 0 0 .63901 21.556 15.276)"
|
||||||
|
x2="21.594"
|
||||||
|
x1="21.594"
|
||||||
|
inkscape:collect="always"
|
||||||
|
>
|
||||||
|
<stop
|
||||||
|
id="stop6508"
|
||||||
|
style="stop-color:#ffffff;stop-opacity:0"
|
||||||
|
offset="0"
|
||||||
|
/>
|
||||||
|
<stop
|
||||||
|
id="stop6510"
|
||||||
|
style="stop-color:#ffffff;stop-opacity:.87451"
|
||||||
|
offset="1"
|
||||||
|
/>
|
||||||
|
</linearGradient
|
||||||
|
>
|
||||||
|
<linearGradient
|
||||||
|
id="linearGradient13475"
|
||||||
|
y2="47.781"
|
||||||
|
gradientUnits="userSpaceOnUse"
|
||||||
|
y1="46.617"
|
||||||
|
gradientTransform="translate(20 -1.6)"
|
||||||
|
x2="21.594"
|
||||||
|
x1="21.591"
|
||||||
|
inkscape:collect="always"
|
||||||
|
>
|
||||||
|
<stop
|
||||||
|
id="stop9165"
|
||||||
|
style="stop-color:#000000"
|
||||||
|
offset="0"
|
||||||
|
/>
|
||||||
|
<stop
|
||||||
|
id="stop9167"
|
||||||
|
style="stop-color:#8c8c8c"
|
||||||
|
offset="1"
|
||||||
|
/>
|
||||||
|
</linearGradient
|
||||||
|
>
|
||||||
|
<linearGradient
|
||||||
|
id="linearGradient13478"
|
||||||
|
y2="47.844"
|
||||||
|
gradientUnits="userSpaceOnUse"
|
||||||
|
y1="46.557"
|
||||||
|
gradientTransform="translate(20 -1.6)"
|
||||||
|
x2="21.835"
|
||||||
|
x1="21.409"
|
||||||
|
inkscape:collect="always"
|
||||||
|
>
|
||||||
|
<stop
|
||||||
|
id="stop5758"
|
||||||
|
style="stop-color:#828282"
|
||||||
|
offset="0"
|
||||||
|
/>
|
||||||
|
<stop
|
||||||
|
id="stop5760"
|
||||||
|
style="stop-color:#929292;stop-opacity:.35294"
|
||||||
|
offset="1"
|
||||||
|
/>
|
||||||
|
</linearGradient
|
||||||
|
>
|
||||||
|
<linearGradient
|
||||||
|
id="linearGradient13481"
|
||||||
|
y2="48"
|
||||||
|
gradientUnits="userSpaceOnUse"
|
||||||
|
y1="46.377"
|
||||||
|
gradientTransform="translate(20 -1.6)"
|
||||||
|
x2="21.6"
|
||||||
|
x1="21.594"
|
||||||
|
inkscape:collect="always"
|
||||||
|
>
|
||||||
|
<stop
|
||||||
|
id="stop5744"
|
||||||
|
style="stop-color:#adadad"
|
||||||
|
offset="0"
|
||||||
|
/>
|
||||||
|
<stop
|
||||||
|
id="stop5746"
|
||||||
|
style="stop-color:#f0f0f0"
|
||||||
|
offset="1"
|
||||||
|
/>
|
||||||
|
</linearGradient
|
||||||
|
>
|
||||||
|
</defs
|
||||||
|
>
|
||||||
|
<sodipodi:namedview
|
||||||
|
id="base"
|
||||||
|
bordercolor="#666666"
|
||||||
|
inkscape:pageshadow="2"
|
||||||
|
inkscape:window-width="1024"
|
||||||
|
pagecolor="#ffffff"
|
||||||
|
inkscape:zoom="9.3000000"
|
||||||
|
inkscape:window-x="0"
|
||||||
|
borderopacity="1.0"
|
||||||
|
inkscape:current-layer="layer1"
|
||||||
|
inkscape:cx="50.000000"
|
||||||
|
inkscape:cy="25.000000"
|
||||||
|
inkscape:window-y="25"
|
||||||
|
inkscape:window-height="693"
|
||||||
|
inkscape:pageopacity="0.0"
|
||||||
|
inkscape:document-units="px"
|
||||||
|
/>
|
||||||
|
<g
|
||||||
|
id="layer1"
|
||||||
|
inkscape:label="Calque 1"
|
||||||
|
inkscape:groupmode="layer"
|
||||||
|
>
|
||||||
|
<g
|
||||||
|
id="g13501"
|
||||||
|
transform="matrix(31.25 0 0 31.25 -1250 -1400)"
|
||||||
|
>
|
||||||
|
<path
|
||||||
|
id="path13389"
|
||||||
|
style="fill:url(#linearGradient13481)"
|
||||||
|
d="m40.8 44.8h1.6c0.443 0 0.8 0.357 0.8 0.8s-0.357 0.8-0.8 0.8h-1.6c-0.443 0-0.8-0.357-0.8-0.8s0.357-0.8 0.8-0.8z"
|
||||||
|
/>
|
||||||
|
<path
|
||||||
|
id="path13391"
|
||||||
|
style="fill:url(#linearGradient13478)"
|
||||||
|
d="m40.812 44.962c-0.365 0-0.656 0.268-0.656 0.625 0 0.358 0.299 0.657 0.656 0.657h1.594c0.358 0 0.625-0.291 0.625-0.657 0-0.365-0.26-0.625-0.625-0.625h-1.594z"
|
||||||
|
/>
|
||||||
|
<path
|
||||||
|
id="path13393"
|
||||||
|
style="fill:url(#linearGradient13475)"
|
||||||
|
d="m40.812 45.025c-0.326 0-0.593 0.247-0.593 0.562 0 0.316 0.278 0.594 0.593 0.594h1.594c0.316 0 0.563-0.267 0.563-0.594 0-0.326-0.236-0.562-0.563-0.562h-1.594z"
|
||||||
|
/>
|
||||||
|
<path
|
||||||
|
id="path13395"
|
||||||
|
style="fill:url(#linearGradient13472)"
|
||||||
|
d="m40.873 45.07c-0.303 0-0.551 0.157-0.551 0.359s0.258 0.38 0.551 0.38h1.479c0.293 0 0.522-0.171 0.522-0.38 0-0.208-0.219-0.359-0.522-0.359h-1.479z"
|
||||||
|
/>
|
||||||
|
</g
|
||||||
|
>
|
||||||
|
</g
|
||||||
|
>
|
||||||
|
<metadata
|
||||||
|
>
|
||||||
|
<rdf:RDF
|
||||||
|
>
|
||||||
|
<cc:Work
|
||||||
|
>
|
||||||
|
<dc:format
|
||||||
|
>image/svg+xml</dc:format
|
||||||
|
>
|
||||||
|
<dc:type
|
||||||
|
rdf:resource="http://purl.org/dc/dcmitype/StillImage"
|
||||||
|
/>
|
||||||
|
<cc:license
|
||||||
|
rdf:resource="http://creativecommons.org/licenses/publicdomain/"
|
||||||
|
/>
|
||||||
|
<dc:publisher
|
||||||
|
>
|
||||||
|
<cc:Agent
|
||||||
|
rdf:about="http://openclipart.org/"
|
||||||
|
>
|
||||||
|
<dc:title
|
||||||
|
>Openclipart</dc:title
|
||||||
|
>
|
||||||
|
</cc:Agent
|
||||||
|
>
|
||||||
|
</dc:publisher
|
||||||
|
>
|
||||||
|
<dc:title
|
||||||
|
>led rounded h black</dc:title
|
||||||
|
>
|
||||||
|
<dc:date
|
||||||
|
>2009-11-04T15:27:55</dc:date
|
||||||
|
>
|
||||||
|
<dc:description
|
||||||
|
>Glossy black button with rounded corners by Jean-Victor Balin. From OCAL 0.18 release.</dc:description
|
||||||
|
>
|
||||||
|
<dc:source
|
||||||
|
>https://openclipart.org/detail/28078/led-rounded-h-black-by-anonymous</dc:source
|
||||||
|
>
|
||||||
|
<dc:creator
|
||||||
|
>
|
||||||
|
<cc:Agent
|
||||||
|
>
|
||||||
|
<dc:title
|
||||||
|
>Anonymous</dc:title
|
||||||
|
>
|
||||||
|
</cc:Agent
|
||||||
|
>
|
||||||
|
</dc:creator
|
||||||
|
>
|
||||||
|
<dc:subject
|
||||||
|
>
|
||||||
|
<rdf:Bag
|
||||||
|
>
|
||||||
|
<rdf:li
|
||||||
|
>black</rdf:li
|
||||||
|
>
|
||||||
|
<rdf:li
|
||||||
|
>button</rdf:li
|
||||||
|
>
|
||||||
|
<rdf:li
|
||||||
|
>glossy</rdf:li
|
||||||
|
>
|
||||||
|
</rdf:Bag
|
||||||
|
>
|
||||||
|
</dc:subject
|
||||||
|
>
|
||||||
|
</cc:Work
|
||||||
|
>
|
||||||
|
<cc:License
|
||||||
|
rdf:about="http://creativecommons.org/licenses/publicdomain/"
|
||||||
|
>
|
||||||
|
<cc:permits
|
||||||
|
rdf:resource="http://creativecommons.org/ns#Reproduction"
|
||||||
|
/>
|
||||||
|
<cc:permits
|
||||||
|
rdf:resource="http://creativecommons.org/ns#Distribution"
|
||||||
|
/>
|
||||||
|
<cc:permits
|
||||||
|
rdf:resource="http://creativecommons.org/ns#DerivativeWorks"
|
||||||
|
/>
|
||||||
|
</cc:License
|
||||||
|
>
|
||||||
|
</rdf:RDF
|
||||||
|
>
|
||||||
|
</metadata
|
||||||
|
>
|
||||||
|
</svg
|
||||||
|
>
|
||||||
|
After Width: | Height: | Size: 6.6 KiB |
Reference in New Issue
Block a user