Initial commit

This commit is contained in:
torsten committed 2026-08-13 18:33:10 +02:00
commit b7d90b9afe
16245 files changed
+3396666

No files matched your search

+38
View File
@@ -0,0 +1,38 @@
#
# $Id$
# $HeadURL$
# $Author$
#
# CMakeLists.txt fuer qledline
#
IF(BUILD_TESTING)
ADD_SUBDIRECTORY(Test)
ENDIF(BUILD_TESTING)
SET(qledline_SRCS
qledchar.cpp
qledline.cpp
)
SET(qledline_HDRS
qledchar.h
qledline.h
)
NGL_ADD_LIBRARY(AAR SV WS qledline SHARED ${qledline_SRCS} ${qledline_HDRS})
NGL_TARGET_INCLUDE_DIRECTORIES(qledline
PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/../
)
NGL_TARGET_LINK_LIBRARIES(qledline
PUBLIC
qledmatrix
Qt5::Core
Qt5::Widgets
)
NGL_INSTALL_TARGET(qledline)
+43
View File
@@ -0,0 +1,43 @@
#
# $Id$
# $HeadURL$
# $Author$
#
# CMakeLists.txt fuer test_qledline
#
SET(test_qledline_SRCS
content.cpp
fullline.cpp
main.cpp
mainwindow.cpp
props.cpp
)
SET(test_qledline_HDRS
content.h
fullline.h
mainwindow.h
props.h
)
SET(test_qledline_UICS
ui/mainwindow.ui
ui/content.ui
ui/fullline.ui
ui/props.ui
)
NGL_TARGET_INCLUDE_DIRECTORIES(test_qledline
PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/../
)
NGL_WRAP_UI(test_qledline_SRCS ${test_qledline_UICS})
NGL_ADD_EXECUTABLE(WS NO_TRANSLATION test_qledline ${test_qledline_SRCS} ${test_qledline_HDRS} ${test_qledline_UICS})
NGL_TARGET_LINK_LIBRARIES(test_qledline
qledline
)
+92
View File
@@ -0,0 +1,92 @@
#include <QLayout>
#include "content.h"
#include "fullline.h"
#include "ui_content.h"
Content::Content(QWidget *parent) : QWidget(parent)
, m_ui(new Ui::Content)
{
m_ui->setupUi(this);
}
Content::~Content()
{
delete m_ui;
}
void Content::init()
{
delete layout();
m_layout = new QVBoxLayout(this);
m_layout->setSpacing(0);
while (!m_lines.isEmpty())
deleteLastLine();
while (m_lines.size() < m_lineCount)
newLine();
}
void Content::setLineCount(int lineCount)
{
while(lineCount != m_lines.size())
{
if(lineCount > m_lineCount)
newLine();
else if (lineCount < m_lineCount)
deleteLastLine();
}
m_lineCount = m_lines.size();
}
void Content::setCharCount(int charCount)
{
m_charCount = charCount;
for (FullLine * l : qAsConst(m_lines))
l->setCharCount(m_charCount);
}
int Content::charCount() const
{
return m_charCount;
}
void Content::setHeight(int height)
{
m_height = height;
for (FullLine * l : qAsConst(m_lines))
l->setHeight(height);
}
int Content::height() const
{
return m_height;
}
void Content::setCharCountAndHeight(int charCount, int height)
{
m_charCount = charCount;
m_height = height;
init();
}
void Content::newLine()
{
FullLine *line = new FullLine(m_lines.count()+1, m_height, m_charCount, this);
m_layout->addWidget(line);
m_lines.append(line);
}
void Content::deleteLastLine()
{
if (m_lines.isEmpty())
return;
delete m_lines.last();
m_lines.remove(m_lines.size()-1);
}
+44
View File
@@ -0,0 +1,44 @@
#pragma once
#include <QWidget>
#include <QVector>
class QVBoxLayout;
class FullLine;
namespace Ui {
class Content;
}
class Content : public QWidget
{
Q_OBJECT
public:
explicit Content(QWidget *parent = nullptr);
~Content();
int charCount() const;
int height() const;
public slots:
void setLineCount(int lineCount);
void setCharCount(int charCount);
void setHeight(int height);
void setCharCountAndHeight(int charCount, int height);
private:
void init();
void newLine();
void deleteLastLine();
Ui::Content *m_ui = nullptr;
int m_lineCount = 0;
int m_charCount = 0;
int m_height = 0;
QVBoxLayout *m_layout = nullptr;
QVector<FullLine*> m_lines;
};
+39
View File
@@ -0,0 +1,39 @@
#include <QLayout>
#include "fullline.h"
#include "ui_fullline.h"
FullLine::FullLine(int lineIndex, int height, int charcount, QWidget *parent) :
QWidget(parent)
, m_ui(new Ui::FullLine)
{
m_ui->setupUi(this);
m_ui->props->setLineIndex(lineIndex);
m_ui->ledLine->setCharCountAndHeight(charcount, height);
connect(m_ui->props, &Props::flashTimeChanged, m_ui->ledLine, &QLedLine::setFlashing);
connect(m_ui->props, &Props::colorChanged, m_ui->ledLine, &QLedLine::setColor);
connect(m_ui->props, &Props::textChanged, m_ui->ledLine, &QLedLine::setText);
connect(m_ui->props, &Props::showText, m_ui->ledLine, &QLedLine::setTextVisible);
}
FullLine::~FullLine()
{
delete m_ui;
}
void FullLine::setCharCount(int count)
{
m_ui->ledLine->setCharCount(count);
}
int FullLine::charCount() const
{
return m_ui->ledLine->charCount();
}
void FullLine::setHeight(int height)
{
m_ui->ledLine->setHeight(height);
}
+22
View File
@@ -0,0 +1,22 @@
#pragma once
#include <QWidget>
namespace Ui {
class FullLine;
}
class FullLine : public QWidget
{
Q_OBJECT
public:
explicit FullLine(int lineIndex, int height, int charcount, QWidget *parent = nullptr);
~FullLine();
void setCharCount(int count);
int charCount() const;
void setHeight(int height);
private:
Ui::FullLine *m_ui;
};
+15
View File
@@ -0,0 +1,15 @@
#include <QApplication>
#include "mainwindow.h"
int main(int argc, char* argv[])
{
QApplication app( argc, argv );
//Testing examples ░ ▒ ▓ ☺ Hello world! العربي☺Üة
MainWindow *w = new MainWindow(1, 13, 13);
w->show();
return app.exec();
}
+30
View File
@@ -0,0 +1,30 @@
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "content.h"
MainWindow::MainWindow(int lineCount, int charCount, int height, QWidget *parent)
: QMainWindow(parent)
, m_ui(new Ui::MainWindow)
{
m_ui->setupUi(this);
m_ui->sbLineCount->setValue(lineCount);
m_ui->sbCharCount->setValue(charCount);
m_ui->sbHeight->setValue(height);
Content *content = new Content(this);
content->setCharCountAndHeight(charCount, height);
content->setLineCount(lineCount);
m_ui->scrollArea->setWidget(content);
connect(m_ui->sbLineCount, QOverload<int>::of(&QSpinBox::valueChanged), content, &Content::setLineCount);
connect(m_ui->sbCharCount, QOverload<int>::of(&QSpinBox::valueChanged), content, &Content::setCharCount);
connect(m_ui->sbHeight, QOverload<int>::of(&QSpinBox::valueChanged), content, &Content::setHeight);
connect(m_ui->pbClose, &QPushButton::clicked, this, &MainWindow::close);
}
MainWindow::~MainWindow()
{
delete m_ui;
}
+23
View File
@@ -0,0 +1,23 @@
#pragma once
#include <QMainWindow>
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(int lineCount, int charCount, int height, QWidget *parent = nullptr);
~MainWindow();
signals:
void onSbLineCountValueChanged(int lineCount);
private:
Ui::MainWindow *m_ui;
};
+47
View File
@@ -0,0 +1,47 @@
#include <QColorDialog>
#include "props.h"
#include "ui_props.h"
Props::Props(QWidget *parent) : QWidget(parent)
, m_ui(new Ui::Props)
{
m_ui->setupUi(this);
connect(m_ui->slFlashTime, &QSlider::valueChanged, this, &Props::flashTimeChanged);
connect(m_ui->leInput, &QLineEdit::textChanged, this, &Props::textChanged);
connect(m_ui->pbTextVisible, &QPushButton::clicked, this, &Props::showText);
connect(m_ui->pbColor, &QPushButton::clicked, this, &Props::onPbColorClicked);
}
Props::~Props()
{
delete m_ui;
}
int Props::lineIndex() const
{
return m_lineIndex;
}
void Props::setLineIndex(int lineIndex)
{
m_lineIndex = lineIndex;
m_ui->lbTitle->setText(tr("%1. Line").arg(m_lineIndex));
}
void Props::onPbColorClicked()
{
m_color = QColorDialog::getColor(m_color, this, tr("Farbe wählen"));
emit colorChanged(m_color);
}
QString Props::inputText() const
{
return m_ui->leInput->text();
}
void Props::setInputText(const QString &inputText)
{
m_ui->leInput->setText(inputText);
}
+34
View File
@@ -0,0 +1,34 @@
#pragma once
#include <QWidget>
namespace Ui {
class Props;
}
class Props : public QWidget
{
Q_OBJECT
public:
explicit Props(QWidget *parent = nullptr);
~Props();
int lineIndex() const;
void setLineIndex(int lineIndex);
QString inputText() const;
void setInputText(const QString &inputText);
signals:
void textChanged(const QString& newText);
void showText(bool visible);
void flashTimeChanged(int msecs);
void colorChanged(const QColor &newColor);
private slots:
void onPbColorClicked();
private:
int m_lineIndex = 0;
QColor m_color;
Ui::Props *m_ui = nullptr;
};
+20
View File
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Content</class>
<widget class="QWidget" name="Content">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>435</width>
<height>266</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QGridLayout" name="gridLayout"/>
</widget>
<resources/>
<connections/>
</ui>
+92
View File
@@ -0,0 +1,92 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>FullLine</class>
<widget class="QWidget" name="FullLine">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>871</width>
<height>130</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>0</width>
<height>130</height>
</size>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<property name="margin">
<number>4</number>
</property>
<property name="spacing">
<number>0</number>
</property>
<item row="0" column="0">
<layout class="QHBoxLayout" name="horizontalLayout">
<property name="spacing">
<number>0</number>
</property>
<item>
<widget class="Props" name="props" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>130</width>
<height>100</height>
</size>
</property>
</widget>
</item>
<item>
<widget class="QLedLine" name="ledLine" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>130</width>
<height>100</height>
</size>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>Props</class>
<extends>QWidget</extends>
<header>props.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>QLedLine</class>
<extends>QWidget</extends>
<header location="global">QLedLine/qledline.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<resources/>
<connections/>
</ui>
+218
View File
@@ -0,0 +1,218 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>MainWindow</class>
<widget class="QMainWindow" name="MainWindow">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>823</width>
<height>458</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="windowTitle">
<string>MainWindow</string>
</property>
<widget class="QWidget" name="centralwidget">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QScrollArea" name="scrollArea">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
</property>
<property name="widgetResizable">
<bool>true</bool>
</property>
<property name="alignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
</property>
<widget class="Content" name="content">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>813</width>
<height>204</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::MinimumExpanding</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QLabel" name="lbCharCount">
<property name="text">
<string>Charcount:</string>
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="sbCharCount">
<property name="minimum">
<number>1</number>
</property>
<property name="maximum">
<number>50</number>
</property>
<property name="value">
<number>10</number>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="lbHeight">
<property name="text">
<string>Height:</string>
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="sbHeight">
<property name="suffix">
<string>px</string>
</property>
<property name="minimum">
<number>7</number>
</property>
<property name="maximum">
<number>50</number>
</property>
<property name="value">
<number>20</number>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="lbLineCount">
<property name="text">
<string>Linecount:</string>
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="sbLineCount">
<property name="minimum">
<number>1</number>
</property>
<property name="maximum">
<number>10</number>
</property>
<property name="value">
<number>5</number>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_3">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Fixed</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="pbClose">
<property name="text">
<string>Close</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Fixed</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
</layout>
</item>
</layout>
</widget>
<widget class="QMenuBar" name="menubar">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>823</width>
<height>19</height>
</rect>
</property>
<property name="nativeMenuBar">
<bool>false</bool>
</property>
</widget>
<widget class="QStatusBar" name="statusbar"/>
</widget>
<customwidgets>
<customwidget>
<class>Content</class>
<extends>QWidget</extends>
<header>content.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<resources/>
<connections/>
</ui>
+125
View File
@@ -0,0 +1,125 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Props</class>
<widget class="QWidget" name="Props">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>130</width>
<height>100</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>0</width>
<height>100</height>
</size>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<property name="leftMargin">
<number>4</number>
</property>
<property name="topMargin">
<number>4</number>
</property>
<property name="rightMargin">
<number>4</number>
</property>
<item row="0" column="0">
<widget class="QWidget" name="verticalLayout_2" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<property name="spacing">
<number>0</number>
</property>
<property name="margin">
<number>0</number>
</property>
<item>
<widget class="QLabel" name="lbTitle">
<property name="font">
<font>
<pointsize>11</pointsize>
<weight>75</weight>
<bold>true</bold>
<kerning>false</kerning>
</font>
</property>
<property name="text">
<string/>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="leInput">
<property name="frame">
<bool>true</bool>
</property>
<property name="placeholderText">
<string>Input Text</string>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QPushButton" name="pbTextVisible">
<property name="text">
<string>On</string>
</property>
<property name="checkable">
<bool>true</bool>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pbColor">
<property name="text">
<string>Color</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QSlider" name="slFlashTime">
<property name="maximum">
<number>1500</number>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="tickInterval">
<number>10</number>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>
+210
View File
@@ -0,0 +1,210 @@
/**
* @RDE_HEADER@
* Implements a QLedMatrix to display a single character
* $Id$
* $HeadURL$
* $Author$
* Created by Florian Schult, SLSE, 2016-03-18
*/
#include "qledchar.h"
#include <QFontMetrics>
#include <QPainter>
#define s_fontName QStringLiteral("monospace")
QLedChar::QLedChar(int height, QWidget *parent, const QChar &letter)
: QLedMatrix(parent)
, m_ptHeight(findPtHeight(height))
, m_font()
, m_color()
, m_bgColor(QColor(34,34,34))
, m_image()
, m_size()
, m_letter(letter)
, m_isTransparent(false)
, m_isLetterVisible(true)
{
init();
}
void QLedChar::init()
{
m_font = QFont(s_fontName, m_ptHeight);
m_font.setStyleStrategy(QFont::NoAntialias);
QFontMetrics metrics(m_font);
m_size.setWidth(metrics.maxWidth());
m_size.setHeight(metrics.height());
setSize(m_size);
}
QChar QLedChar::letter() const
{
return m_letter;
}
QLedChar::~QLedChar()
{
}
void QLedChar::setLetter(const QChar &letter)
{
m_letter = letter;
if (!m_isLetterVisible)
{
for(int row = 0; row < m_size.height(); ++row)
{
for(int col = 0; col < m_size.width(); ++col)
{
setColorAt(row, col, NoColor);
}
}
return;
}
QImage image(m_size,QImage::Format_RGB32);
QPainter painter;
painter.begin(&image);
painter.setFont(m_font);
painter.fillRect(image.rect(), m_bgColor);
painter.setPen(m_color);
painter.drawText(QPoint(0,m_ptHeight), letter);
painter.end();
setImage(image);
drawImage();
}
void QLedChar::drawImage()
{
for(int row = 0; row < m_size.height(); ++row)
{
for(int col = 0; col < m_size.width(); ++col)
{
setColorAt(row, col, m_image.pixel(col, row));
}
}
}
QImage QLedChar::image() const
{
return m_image;
}
void QLedChar::setImage(const QImage &image)
{
m_image = image;
drawImage();
}
int QLedChar::findPtHeight(int maxPxHeight)
{
int bestPtHeight = 0;
// Starting difference, should be at least 0.35
float difference = 0.4f;
float differenceStep = difference / 2;
bool heightFound = false;
while(!heightFound)
{
differenceStep /= 2;
float ptHeight = maxPxHeight - (maxPxHeight * difference);
QFont font(s_fontName,ptHeight);
QFontMetrics metrics(font);
int pxHeight = metrics.height();
if(pxHeight < maxPxHeight)
difference -= differenceStep;
else if(pxHeight > maxPxHeight)
difference += differenceStep;
else
{
bestPtHeight = ptHeight;
heightFound = true;
}
if(differenceStep == 0)
{
// Catches invalid pixelsizes, which lack proper pointsizes
bestPtHeight = ptHeight-1;
heightFound = true;
}
}
return bestPtHeight;
}
QSize QLedChar::charSize() const
{
return m_size;
}
void QLedChar::setLetterVisible(bool visible)
{
m_isLetterVisible = visible;
setLetter(m_letter);
}
bool QLedChar::isTransparent() const
{
return m_isTransparent;
}
void QLedChar::setTransparent(bool isTransparent)
{
m_isTransparent = isTransparent;
if (isTransparent)
setBackgroundMode(Qt::TransparentMode);
else
setBackgroundMode(Qt::OpaqueMode);
}
bool QLedChar::letterVisible() const
{
return m_isLetterVisible;
}
void QLedChar::setCharHeight(int height)
{
m_ptHeight = findPtHeight(height);
init();
}
int QLedChar::charHeight() const
{
return m_size.height();
}
QColor QLedChar::color() const
{
return m_color;
}
void QLedChar::setColor(const QColor &color)
{
m_color = color;
setLetter(m_letter);
}
QColor QLedChar::bgColor() const
{
return m_bgColor;
}
void QLedChar::setBgColor(const QColor &bgColor)
{
m_bgColor = bgColor;
setLetter(m_letter);
}
void QLedChar::onFlashTimerTimeout()
{
m_isLetterVisible = !m_isLetterVisible;
setLetter(m_letter);
}
+64
View File
@@ -0,0 +1,64 @@
/**
* @RDE_HEADER@
* Implements a QLedMatrix to display a single character
* $Id$
* $HeadURL$
* $Author$
* Created by Florian Schult, SLSE, 2016-03-18
*/
#pragma once
#include <QLedMatrix/qledmatrix.h>
class QImage;
class QLedChar : public QLedMatrix
{
Q_OBJECT
public:
explicit QLedChar(int height, QWidget *parent, const QChar &letter);
~QLedChar();
QChar letter() const;
void setLetter(const QChar &letter);
QColor bgColor() const;
void setBgColor(const QColor &bgColor);
QColor color() const;
void setColor(const QColor &color);
bool isTransparent() const;
void setTransparent(bool isTransparent);
bool letterVisible() const;
void setLetterVisible(bool visible = true);
int charHeight() const;
void setCharHeight(int height);
QSize charSize() const;
QImage image() const;
void setImage(const QImage &image);
public slots:
void onFlashTimerTimeout();
void drawImage();
private:
void init();
int findPtHeight(int height);
int m_ptHeight;
QFont m_font;
QColor m_color;
QColor m_bgColor;
QImage m_image;
QSize m_size;
QChar m_letter;
bool m_isTransparent;
bool m_isLetterVisible;
};
+223
View File
@@ -0,0 +1,223 @@
/**
* @RDE_HEADER@
* Implements n QLedChars to display a line of Text/Image
* $Id$
* $HeadURL$
* $Author$
* Created by Florian Schult, SLSE, 2016-03-18
*/
#include "qledline.h"
#include <QString>
#include <QLayout>
#include <QTimer>
#include <QImage>
#include "qledchar.h"
QLedLine::QLedLine(QWidget *parent)
: QWidget(parent)
, m_charCount(0)
, m_height(0)
, m_visible(true)
, m_text()
, m_layout(new QHBoxLayout(this))
, m_chars()
, m_flashTimer(new QTimer(this))
, m_color(Qt::red) // Standard color
, m_image()
{
m_layout->setSpacing(0);
m_layout->setContentsMargins(0,0,0,0);
m_layout->setMargin(0);
QSpacerItem *sp1 = new QSpacerItem(0,0, QSizePolicy::Expanding, QSizePolicy::Expanding);
QSpacerItem *sp2 = new QSpacerItem(0,0, QSizePolicy::Expanding, QSizePolicy::Expanding);
m_layout->addSpacerItem(sp1);
m_layout->addSpacerItem(sp2);
m_layout->setAlignment(m_layout, Qt::AlignHCenter);
}
QLedLine::~QLedLine()
{
qDeleteAll(m_chars);
// optional. They have "this" as parent and are QT.
delete m_layout;
delete m_flashTimer;
}
QString QLedLine::shownText() const
{
return m_text.leftJustified(m_chars.size(), QLatin1Char(' '), true);
}
bool QLedLine::isTextVisible() const
{
return m_visible;
}
int QLedLine::flashTime() const
{
return m_flashTimer->interval();
}
QColor QLedLine::color() const
{
return m_color;
}
void QLedLine::setText(const QString &text)
{
m_text = text;
// Todo: Arabic: RightJustified? Automatic?
QString shown = shownText();
for (int i=0; i<m_chars.size(); ++i)
m_chars[i]->setLetter(shown[i]);
}
// Expects a properly sized QImage, corresponding to the count and Pixelsizes of QLedLine and QLedChar
void QLedLine::setImage(const QImage &image)
{
m_image = image;
QImage charImage;
QSize charSize = m_chars[0]->charSize();
for (int i=0; i<m_chars.size(); ++i)
{
charImage = m_image.copy((charSize.width() * i), 0, charSize.width(), charSize.height());
m_chars[i]->setImage(charImage);
}
}
QSize QLedLine::charSize() const
{
return m_chars[0]->charSize();
}
QString QLedLine::text() const
{
return m_text;
}
void QLedLine::addChar()
{
QLedChar *ledChar = new QLedChar(m_height, this, m_text[m_chars.size()]);
ledChar->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
if (!m_chars.isEmpty())
ledChar->setLetterVisible(m_chars[0]->letterVisible());
connect(m_flashTimer, &QTimer::timeout, ledChar, &QLedChar::onFlashTimerTimeout);
ledChar->setColor(m_color);
// Takes the last stretch-item and puts it behind the new added ledChar
QLayoutItem *spacer = m_layout->takeAt(m_layout->count()-1);
m_layout->addWidget(ledChar);
m_layout->addItem(spacer);
m_chars.append(ledChar);
ledChar->setLetter(shownText().at(m_chars.size()-1));
}
void QLedLine::deleteChar()
{
if (m_chars.isEmpty())
return;
delete m_chars.last();
m_chars.remove(m_chars.size()-1);
}
void QLedLine::setCharCount(int charCount)
{
m_charCount = charCount;
while(m_chars.size() != m_charCount)
{
if(m_chars.size() > m_charCount)
deleteChar();
else if(m_chars.size() < m_charCount)
addChar();
}
}
int QLedLine::charCount() const
{
return m_charCount;
}
void QLedLine::setHeight(int height)
{
m_height = height;
for(int i=0; i<m_chars.size(); ++i)
{
m_chars[i]->setCharHeight(m_height);
}
setText(m_text);
}
int QLedLine::height() const
{
return m_height;
}
void QLedLine::setCharCountAndHeight(int charCount, int height)
{
setHeight(height);
setCharCount(charCount);
}
void QLedLine::setColor(const QColor &color)
{
m_color = color;
for (int i=0; i<m_charCount; ++i)
m_chars[i]->setColor(color);
}
void QLedLine::clear()
{
for (int i=0; i<m_charCount; ++i)
{
m_chars[i]->setLetterVisible(false);
m_chars[i]->setLetterVisible(true);
}
}
void QLedLine::setFlashing(int msecs)
{
m_flashTimer->setInterval(msecs);
if (msecs == 0)
{
if (m_visible)
{
for (int i = 0; i < m_chars.size(); ++i)
m_chars[i]->setLetterVisible();
}
m_flashTimer->stop();
}
else
{
if(m_visible)
m_flashTimer->start();
else
m_flashTimer->stop();
}
}
void QLedLine::setTextVisible(bool visible)
{
m_visible = visible;
for (int i=0; i<m_chars.size(); ++i)
m_chars[i]->setLetterVisible(m_visible);
if(m_visible)
{
if(m_flashTimer->interval() > 0)
m_flashTimer->start();
}
else
{
m_flashTimer->stop();
}
}
+83
View File
@@ -0,0 +1,83 @@
/**
* @RDE_HEADER@
* Implements n QLedChars to display a line of Text/Image
* $Id$
* $HeadURL$
* $Author$
* Created by Florian Schult, SLSE, 2016-03-18
*/
#pragma once
#include <QVector>
#include <QWidget>
#ifndef QLEDLINE_EXPORT
# ifdef BUILD_STATIC_LIBRARIES
# define QLEDLINE_EXPORT
# else
# ifdef MAKE_QLEDLINE_LIB
# define QLEDLINE_EXPORT Q_DECL_EXPORT
# else
# define QLEDLINE_EXPORT Q_DECL_IMPORT
# endif
# endif
#endif
namespace Ui
{
class QLedLine;
}
class QHBoxLayout;
class QLedChar;
class QTimer;
class QImage;
class QLEDLINE_EXPORT QLedLine : public QWidget
{
Q_OBJECT
public:
explicit QLedLine(QWidget *parent = nullptr);
~QLedLine();
int height() const;
void setHeight(int height);
int charCount() const;
void setCharCount(int charCount);
// Returns the QSize of the first QLedChar
QSize charSize() const;
void setCharCountAndHeight(int charCount, int height);
bool isTextVisible() const;
int flashTime() const;
QColor color() const;
QString shownText() const;
QString text() const;
private:
void addChar();
void deleteChar();
public slots:
void setText(const QString &text);
void setFlashing(int msecs = 0);
void setTextVisible(bool visible = true);
void setColor(const QColor &color);
void clear();
void setImage(const QImage &image);
private:
int m_charCount;
int m_height;
bool m_visible;
QString m_text;
QHBoxLayout *m_layout;
QVector<QLedChar*> m_chars;
QTimer *m_flashTimer;
QColor m_color;
QImage m_image;
};