Initial commit
This commit is contained in:
commit
b7d90b9afe
16245 files changed
+3396666
No files matched your search
Executable
+6
@@ -0,0 +1,6 @@
|
||||
Release 0.6 (March 15, 2009)
|
||||
================================================================================
|
||||
|
||||
Changes
|
||||
-------
|
||||
1. Initial public release.
|
||||
Executable
+32
@@ -0,0 +1,32 @@
|
||||
#
|
||||
# $Id$
|
||||
# $HeadURL$
|
||||
# $Author$
|
||||
#
|
||||
# CMakeLists.txt fuer qledmatrix
|
||||
#
|
||||
|
||||
|
||||
SET(qledmatrix_SRCS
|
||||
qledmatrix.cpp
|
||||
)
|
||||
|
||||
SET(qledmatrix_HDRS
|
||||
qledmatrix.h
|
||||
)
|
||||
|
||||
NGL_ADD_LIBRARY(AAR SV WS qledmatrix SHARED ${qledmatrix_SRCS} ${qledmatrix_HDRS})
|
||||
|
||||
|
||||
NGL_TARGET_INCLUDE_DIRECTORIES(qledmatrix
|
||||
PUBLIC
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/../
|
||||
)
|
||||
|
||||
NGL_TARGET_LINK_LIBRARIES(qledmatrix
|
||||
PUBLIC
|
||||
Qt5::Core
|
||||
Qt5::Widgets
|
||||
)
|
||||
|
||||
NGL_INSTALL_TARGET(qledmatrix)
|
||||
Executable
+165
@@ -0,0 +1,165 @@
|
||||
GNU LESSER GENERAL PUBLIC LICENSE
|
||||
Version 3, 29 June 2007
|
||||
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
|
||||
This version of the GNU Lesser General Public License incorporates
|
||||
the terms and conditions of version 3 of the GNU General Public
|
||||
License, supplemented by the additional permissions listed below.
|
||||
|
||||
0. Additional Definitions.
|
||||
|
||||
As used herein, "this License" refers to version 3 of the GNU Lesser
|
||||
General Public License, and the "GNU GPL" refers to version 3 of the GNU
|
||||
General Public License.
|
||||
|
||||
"The Library" refers to a covered work governed by this License,
|
||||
other than an Application or a Combined Work as defined below.
|
||||
|
||||
An "Application" is any work that makes use of an interface provided
|
||||
by the Library, but which is not otherwise based on the Library.
|
||||
Defining a subclass of a class defined by the Library is deemed a mode
|
||||
of using an interface provided by the Library.
|
||||
|
||||
A "Combined Work" is a work produced by combining or linking an
|
||||
Application with the Library. The particular version of the Library
|
||||
with which the Combined Work was made is also called the "Linked
|
||||
Version".
|
||||
|
||||
The "Minimal Corresponding Source" for a Combined Work means the
|
||||
Corresponding Source for the Combined Work, excluding any source code
|
||||
for portions of the Combined Work that, considered in isolation, are
|
||||
based on the Application, and not on the Linked Version.
|
||||
|
||||
The "Corresponding Application Code" for a Combined Work means the
|
||||
object code and/or source code for the Application, including any data
|
||||
and utility programs needed for reproducing the Combined Work from the
|
||||
Application, but excluding the System Libraries of the Combined Work.
|
||||
|
||||
1. Exception to Section 3 of the GNU GPL.
|
||||
|
||||
You may convey a covered work under sections 3 and 4 of this License
|
||||
without being bound by section 3 of the GNU GPL.
|
||||
|
||||
2. Conveying Modified Versions.
|
||||
|
||||
If you modify a copy of the Library, and, in your modifications, a
|
||||
facility refers to a function or data to be supplied by an Application
|
||||
that uses the facility (other than as an argument passed when the
|
||||
facility is invoked), then you may convey a copy of the modified
|
||||
version:
|
||||
|
||||
a) under this License, provided that you make a good faith effort to
|
||||
ensure that, in the event an Application does not supply the
|
||||
function or data, the facility still operates, and performs
|
||||
whatever part of its purpose remains meaningful, or
|
||||
|
||||
b) under the GNU GPL, with none of the additional permissions of
|
||||
this License applicable to that copy.
|
||||
|
||||
3. Object Code Incorporating Material from Library Header Files.
|
||||
|
||||
The object code form of an Application may incorporate material from
|
||||
a header file that is part of the Library. You may convey such object
|
||||
code under terms of your choice, provided that, if the incorporated
|
||||
material is not limited to numerical parameters, data structure
|
||||
layouts and accessors, or small macros, inline functions and templates
|
||||
(ten or fewer lines in length), you do both of the following:
|
||||
|
||||
a) Give prominent notice with each copy of the object code that the
|
||||
Library is used in it and that the Library and its use are
|
||||
covered by this License.
|
||||
|
||||
b) Accompany the object code with a copy of the GNU GPL and this license
|
||||
document.
|
||||
|
||||
4. Combined Works.
|
||||
|
||||
You may convey a Combined Work under terms of your choice that,
|
||||
taken together, effectively do not restrict modification of the
|
||||
portions of the Library contained in the Combined Work and reverse
|
||||
engineering for debugging such modifications, if you also do each of
|
||||
the following:
|
||||
|
||||
a) Give prominent notice with each copy of the Combined Work that
|
||||
the Library is used in it and that the Library and its use are
|
||||
covered by this License.
|
||||
|
||||
b) Accompany the Combined Work with a copy of the GNU GPL and this license
|
||||
document.
|
||||
|
||||
c) For a Combined Work that displays copyright notices during
|
||||
execution, include the copyright notice for the Library among
|
||||
these notices, as well as a reference directing the user to the
|
||||
copies of the GNU GPL and this license document.
|
||||
|
||||
d) Do one of the following:
|
||||
|
||||
0) Convey the Minimal Corresponding Source under the terms of this
|
||||
License, and the Corresponding Application Code in a form
|
||||
suitable for, and under terms that permit, the user to
|
||||
recombine or relink the Application with a modified version of
|
||||
the Linked Version to produce a modified Combined Work, in the
|
||||
manner specified by section 6 of the GNU GPL for conveying
|
||||
Corresponding Source.
|
||||
|
||||
1) Use a suitable shared library mechanism for linking with the
|
||||
Library. A suitable mechanism is one that (a) uses at run time
|
||||
a copy of the Library already present on the user's computer
|
||||
system, and (b) will operate properly with a modified version
|
||||
of the Library that is interface-compatible with the Linked
|
||||
Version.
|
||||
|
||||
e) Provide Installation Information, but only if you would otherwise
|
||||
be required to provide such information under section 6 of the
|
||||
GNU GPL, and only to the extent that such information is
|
||||
necessary to install and execute a modified version of the
|
||||
Combined Work produced by recombining or relinking the
|
||||
Application with a modified version of the Linked Version. (If
|
||||
you use option 4d0, the Installation Information must accompany
|
||||
the Minimal Corresponding Source and Corresponding Application
|
||||
Code. If you use option 4d1, you must provide the Installation
|
||||
Information in the manner specified by section 6 of the GNU GPL
|
||||
for conveying Corresponding Source.)
|
||||
|
||||
5. Combined Libraries.
|
||||
|
||||
You may place library facilities that are a work based on the
|
||||
Library side by side in a single library together with other library
|
||||
facilities that are not Applications and are not covered by this
|
||||
License, and convey such a combined library under terms of your
|
||||
choice, if you do both of the following:
|
||||
|
||||
a) Accompany the combined library with a copy of the same work based
|
||||
on the Library, uncombined with any other library facilities,
|
||||
conveyed under the terms of this License.
|
||||
|
||||
b) Give prominent notice with the combined library that part of it
|
||||
is a work based on the Library, and explaining where to find the
|
||||
accompanying uncombined form of the same work.
|
||||
|
||||
6. Revised Versions of the GNU Lesser General Public License.
|
||||
|
||||
The Free Software Foundation may publish revised and/or new versions
|
||||
of the GNU Lesser General Public License from time to time. Such new
|
||||
versions will be similar in spirit to the present version, but may
|
||||
differ in detail to address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the
|
||||
Library as you received it specifies that a certain numbered version
|
||||
of the GNU Lesser General Public License "or any later version"
|
||||
applies to it, you have the option of following the terms and
|
||||
conditions either of that published version or of any later version
|
||||
published by the Free Software Foundation. If the Library as you
|
||||
received it does not specify a version number of the GNU Lesser
|
||||
General Public License, you may choose any version of the GNU Lesser
|
||||
General Public License ever published by the Free Software Foundation.
|
||||
|
||||
If the Library as you received it specifies that a proxy can decide
|
||||
whether future versions of the GNU Lesser General Public License shall
|
||||
apply, that proxy's public statement of acceptance of any version is
|
||||
permanent authorization for you to choose that version for the
|
||||
Library.
|
||||
Executable
+50
@@ -0,0 +1,50 @@
|
||||
|
||||
QLedMatrix Widget
|
||||
-----------------
|
||||
|
||||
The QLedMatrix widget simulates a LED matrix (dot matrix) display.
|
||||
|
||||
A LED matrix display is a 2-dimensional array of dots used to generate
|
||||
characters, symbols and images. It is often seen on machines, clocks and
|
||||
display boards.
|
||||
|
||||
This generic implementation can configured for any size of rows (greater
|
||||
than 0) and columns. The number of colors is not limited, therefore it
|
||||
can be used to make a monochrome, bi-color or even a full RGB display.
|
||||
|
||||
Individual LEDs can be addressed in the matrix by their row and column
|
||||
position. The index (0,0) is located in the upper left corner. Columns
|
||||
grow from left to right, and rows grow from top to bottom.
|
||||
|
||||
Installation
|
||||
------------
|
||||
|
||||
QLedMatrix library:
|
||||
qmake
|
||||
make
|
||||
make install (or copy the plugin into "<Qt4 dir>/plugins/designer")
|
||||
|
||||
QLedMatrix example:
|
||||
cd example
|
||||
qmake
|
||||
make
|
||||
./qledmatrix_demo
|
||||
|
||||
Copyright
|
||||
---------
|
||||
|
||||
Copyright (C) 2009 Pierre-Etienne Messier <pierre.etienne.messier@gmail.com>
|
||||
http://pemessier.hexpresso.org/
|
||||
|
||||
This library is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
Executable
+546
@@ -0,0 +1,546 @@
|
||||
/*******************************************************************************
|
||||
**
|
||||
** Copyright (C) 2009 Pierre-Etienne Messier <pierre.etienne.messier@gmail.com>
|
||||
** http://pemessier.hexpresso.org/
|
||||
**
|
||||
** This library is free software: you can redistribute it and/or modify
|
||||
** it under the terms of the GNU Lesser General Public License as published by
|
||||
** the Free Software Foundation, either version 3 of the License, or
|
||||
** (at your option) any later version.
|
||||
**
|
||||
** This library is distributed in the hope that it will be useful,
|
||||
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
** GNU Lesser General Public License for more details.
|
||||
**
|
||||
** You should have received a copy of the GNU Lesser General Public License
|
||||
** along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
**
|
||||
*******************************************************************************/
|
||||
|
||||
#include "qledmatrix.h"
|
||||
|
||||
#include <qpainter.h>
|
||||
|
||||
/**
|
||||
* \internal
|
||||
*/
|
||||
class QLedMatrixPrivate
|
||||
{
|
||||
Q_DECLARE_PUBLIC(QLedMatrix)
|
||||
|
||||
public:
|
||||
bool isValid(int row, int col) const;
|
||||
void setColorAt(int row, int col, QRgb rgb, bool doUpdate);
|
||||
void drawLEDs(QPainter& painter) const;
|
||||
void calculateAspectRatio();
|
||||
|
||||
QLedMatrix* q_ptr;
|
||||
QBrush backgroundBrush;
|
||||
Qt::BGMode backgroundMode;
|
||||
QColor darkLedColor;
|
||||
QVector< QVector<QRgb> > colorTable;
|
||||
int rowCount;
|
||||
int columnCount;
|
||||
qreal rowHeight;
|
||||
qreal columnWidth;
|
||||
qreal aspectRatio;
|
||||
mutable qreal sizeFactor;
|
||||
};
|
||||
|
||||
/**
|
||||
* \internal
|
||||
*/
|
||||
bool QLedMatrixPrivate::isValid(int row, int col) const
|
||||
{
|
||||
return ( (row >= 0) &&
|
||||
(row < rowCount) &&
|
||||
(col >= 0) &&
|
||||
(col < columnCount) );
|
||||
}
|
||||
|
||||
/**
|
||||
* \internal
|
||||
*/
|
||||
void QLedMatrixPrivate::setColorAt(int row, int col, QRgb rgb, bool doUpdate)
|
||||
{
|
||||
Q_Q(QLedMatrix);
|
||||
if(isValid(row, col))
|
||||
{
|
||||
colorTable[col][row] = rgb;
|
||||
|
||||
if(doUpdate == true)
|
||||
{
|
||||
q->update();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
qWarning("QLedMatrix::setColorAt: coordinate (row=%d, col=%d) out of range", row, col);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* \internal
|
||||
*/
|
||||
void QLedMatrixPrivate::drawLEDs(QPainter& painter) const
|
||||
{
|
||||
Q_Q(QLedMatrix const);
|
||||
for(int row = 0; row < rowCount; ++row)
|
||||
{
|
||||
painter.save();
|
||||
for(int col = 0; col < columnCount; ++col)
|
||||
{
|
||||
painter.setBrush(QColor(q->colorAt(row, col)));
|
||||
painter.drawEllipse(QRectF(0.0, 0.0, 8.0, 8.0));
|
||||
painter.translate(10.0, 0.0);
|
||||
}
|
||||
painter.restore();
|
||||
painter.translate(0.0, 10.0);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* \internal
|
||||
*/
|
||||
void QLedMatrixPrivate::calculateAspectRatio()
|
||||
{
|
||||
if(rowHeight > 0.0)
|
||||
{
|
||||
aspectRatio = columnWidth / rowHeight;
|
||||
}
|
||||
}
|
||||
|
||||
//////////////////////////////////
|
||||
|
||||
/**
|
||||
* \class QLedMatrix
|
||||
*
|
||||
* \brief The QLedMatrix widget simulates a LED matrix (dot matrix) display.
|
||||
*
|
||||
* A LED matrix display is a 2-dimensional array of dots used to generate
|
||||
* characters, symbols and images. It is often seen on machines, clocks and
|
||||
* display boards.
|
||||
*
|
||||
* This generic implementation can configured for any size of rows (greater
|
||||
* than 0) and columns. The number of colors is not limited, therefore it can
|
||||
* be used to make a monochrome, bi-color or even a full RGB display.
|
||||
*
|
||||
* Individual LEDs can be addressed in the matrix by their row and column
|
||||
* position. The index (0,0) is located in the upper left corner. Columns
|
||||
* grow from left to right, and rows grow from top to bottom.
|
||||
*
|
||||
* \version 0.6
|
||||
*
|
||||
* \author Pierre-Etienne Messier <pierre.etienne.messier\@gmail.com>
|
||||
*/
|
||||
|
||||
/**
|
||||
* \enum QLedMatrix::LEDColor
|
||||
*
|
||||
* This type defines standard LED colors in the QRgb format, provided purely
|
||||
* for convenience.
|
||||
*
|
||||
* \sa QRgb
|
||||
*/
|
||||
|
||||
/**
|
||||
* \var QLedMatrix::LEDColor QLedMatrix::NoColor
|
||||
* Default dark LED color (\#222222)
|
||||
**/
|
||||
|
||||
/**
|
||||
* \var QLedMatrix::LEDColor QLedMatrix::Red
|
||||
* Red (\#FF0000)
|
||||
**/
|
||||
|
||||
/**
|
||||
* \var QLedMatrix::LEDColor QLedMatrix::Green
|
||||
* Green (\#00FF00)
|
||||
**/
|
||||
|
||||
/**
|
||||
* \var QLedMatrix::LEDColor QLedMatrix::Blue
|
||||
* Blue (\#0000FF)
|
||||
**/
|
||||
|
||||
/**
|
||||
* \var QLedMatrix::LEDColor QLedMatrix::White
|
||||
* White (\#FFFFFF)
|
||||
**/
|
||||
|
||||
/**
|
||||
* \var QLedMatrix::LEDColor QLedMatrix::Orange
|
||||
* Orange (\#FF8800)
|
||||
**/
|
||||
|
||||
/**
|
||||
* \var QLedMatrix::LEDColor QLedMatrix::OrangeRed
|
||||
* Orange-Red (\#FF2200)
|
||||
**/
|
||||
|
||||
/**
|
||||
* \var QLedMatrix::LEDColor QLedMatrix::Yellow
|
||||
* Yellow (\#FFFF00)
|
||||
**/
|
||||
|
||||
/**
|
||||
* Constructs a LED Matrix display, sets the background color to black,
|
||||
* the background mode to opaque, the dark LED color to QLedMatrix::NoColor and
|
||||
* the number of rows and columns to 0.
|
||||
*
|
||||
* \sa setBackgroundColor(), setBackgroundMode(), setDarkLedColor(),
|
||||
* setRowCount(), setColumnCount()
|
||||
*
|
||||
* \param parent parent QWidget
|
||||
*/
|
||||
QLedMatrix::QLedMatrix(QWidget* parent): QWidget(parent),
|
||||
d_ptr(new QLedMatrixPrivate)
|
||||
{
|
||||
Q_D(QLedMatrix);
|
||||
d->q_ptr = this;
|
||||
d->backgroundBrush = QBrush(Qt::black, Qt::SolidPattern);
|
||||
d->backgroundMode = Qt::OpaqueMode;
|
||||
d->darkLedColor = QColor(QLedMatrix::NoColor);
|
||||
d->rowCount = 0;
|
||||
d->columnCount = 0;
|
||||
d->rowHeight = 0.0;
|
||||
d->columnWidth = 0.0;
|
||||
d->aspectRatio = 0.0;
|
||||
d->sizeFactor = 1.0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Destroys the LED Matrix display.
|
||||
*/
|
||||
QLedMatrix::~QLedMatrix()
|
||||
{
|
||||
delete d_ptr;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Clears the LED Matrix display.
|
||||
*
|
||||
* When the display is cleared, all the LEDs are set to the dark LED color.
|
||||
*
|
||||
* \sa darkLedColor(), setDarkLedColor()
|
||||
*/
|
||||
void QLedMatrix::clear()
|
||||
{
|
||||
Q_D(QLedMatrix);
|
||||
for(int i=0; i < d->rowCount; ++i)
|
||||
{
|
||||
for(int j=0; j < d->columnCount; ++j)
|
||||
{
|
||||
d->colorTable[j][i] = d->darkLedColor.rgb();
|
||||
}
|
||||
}
|
||||
update();
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Returns the background color of the widget.
|
||||
*
|
||||
* \return background color of the widget
|
||||
*
|
||||
* \sa setBackgroundColor()
|
||||
*/
|
||||
QColor QLedMatrix::backgroundColor() const
|
||||
{
|
||||
Q_D(const QLedMatrix);
|
||||
return d->backgroundBrush.color();
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Sets the background color of the widget to the given color.
|
||||
*
|
||||
* The background color of the widget will only be visible if the background
|
||||
* mode is set to Qt::OpaqueMode.
|
||||
*
|
||||
* \param color the background color to be set
|
||||
*
|
||||
* \sa backgroundColor(), backgroundMode(), setBackgroundMode()
|
||||
*/
|
||||
void QLedMatrix::setBackgroundColor(const QColor& color)
|
||||
{
|
||||
Q_D(QLedMatrix);
|
||||
d->backgroundBrush.setColor(color);
|
||||
update();
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Returns the background mode of the widget.
|
||||
*
|
||||
* \return background mode of the widget
|
||||
*
|
||||
* \sa setBackgroundMode()
|
||||
*/
|
||||
Qt::BGMode QLedMatrix::backgroundMode() const
|
||||
{
|
||||
Q_D(const QLedMatrix);
|
||||
return d->backgroundMode;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Sets the background mode of the widget to the given mode.
|
||||
*
|
||||
* Qt::OpaqueMode (the default) fills the widget's background with the current
|
||||
* background color. Qt::TransparentMode doesn't draw any background color.
|
||||
*
|
||||
* \param mode the background mode to be set
|
||||
*
|
||||
* \sa backgroundMode(), backgroundColor(), setBackgroundColor()
|
||||
*/
|
||||
void QLedMatrix::setBackgroundMode(Qt::BGMode mode)
|
||||
{
|
||||
Q_D(QLedMatrix);
|
||||
d->backgroundMode = mode;
|
||||
update();
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Returns the dark LED color.
|
||||
*
|
||||
* \return dark LED color
|
||||
*
|
||||
* \sa setDarkLedColor()
|
||||
*/
|
||||
QColor QLedMatrix::darkLedColor() const
|
||||
{
|
||||
Q_D(const QLedMatrix);
|
||||
return d->darkLedColor;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Sets the dark LED color to the given color.
|
||||
*
|
||||
* The dark LED color is used to represent a LED in the 'off' state. It is
|
||||
* used when adding rows or cols, and when using the clear() method.
|
||||
*
|
||||
* \param color the color to be set
|
||||
*
|
||||
* \sa darkLedColor(), clear(), setRowCount(), setColumnCount()
|
||||
*/
|
||||
void QLedMatrix::setDarkLedColor(const QColor& color)
|
||||
{
|
||||
Q_D(QLedMatrix);
|
||||
QRgb oldColor = d->darkLedColor.rgb();
|
||||
d->darkLedColor = color;
|
||||
|
||||
for(int i=0; i < d->rowCount; ++i)
|
||||
{
|
||||
for(int j=0; j < d->columnCount; ++j)
|
||||
{
|
||||
if(d->colorTable[j][i] == oldColor)
|
||||
{
|
||||
d->colorTable[j][i] = d->darkLedColor.rgb();
|
||||
}
|
||||
}
|
||||
}
|
||||
update();
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Returns the color of the LED at the specified position.
|
||||
*
|
||||
* This function uses the QRgb data format. If the specified position is
|
||||
* invalid, this function will return the current dark LED color.
|
||||
*
|
||||
* \param row the row index of the LED
|
||||
* \param col the column index of the LED
|
||||
*
|
||||
* \return the color of the LED at the given position
|
||||
*
|
||||
* \sa setColorAt(), darkLedColor()
|
||||
*/
|
||||
QRgb QLedMatrix::colorAt(int row, int col) const
|
||||
{
|
||||
Q_D(const QLedMatrix);
|
||||
if(d->isValid(row, col))
|
||||
{
|
||||
return d->colorTable[col][row];
|
||||
}
|
||||
|
||||
qWarning("QLedMatrix::colorAt: coordinate (row=%d, col=%d) out of range", row, col);
|
||||
return d->darkLedColor.rgb();
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Sets the given color to the LED at the specified position.
|
||||
*
|
||||
* If the specified position is invalid, this function will do nothing.
|
||||
*
|
||||
* \param row the row index of the LED
|
||||
* \param col the column index of the LED
|
||||
* \param rgb the color to be set (in QRgb format)
|
||||
*
|
||||
* \sa colorAt()
|
||||
*/
|
||||
void QLedMatrix::setColorAt(int row, int col, QRgb rgb)
|
||||
{
|
||||
Q_D(QLedMatrix);
|
||||
d->setColorAt(row, col, rgb, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Returns the number of rows in the LED matrix display.
|
||||
*
|
||||
* \return the number of rows in the LED matrix display
|
||||
*
|
||||
* \sa setRowCount(), columnCount()
|
||||
*/
|
||||
int QLedMatrix::rowCount() const
|
||||
{
|
||||
Q_D(const QLedMatrix);
|
||||
return d->rowCount;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Sets the number of rows in the LED matrix display.
|
||||
*
|
||||
* This function will do nothing if the new number of rows is less than 0
|
||||
* or if it is equal to the current number of rows. If the new number of
|
||||
* rows is less than the current number of rows, the display will be
|
||||
* cropped to the new value. Otherwise, if the new number of rows is
|
||||
* greater than the current number of rows, the new LEDs will be
|
||||
* initialized using the dark LED color.
|
||||
*
|
||||
* \param rows the new number of rows
|
||||
*
|
||||
* \sa rowsCount(), setColumnCount(), darkLedColor()
|
||||
*/
|
||||
void QLedMatrix::setRowCount(int rows)
|
||||
{
|
||||
Q_D(QLedMatrix);
|
||||
if((rows >= 0) && (rows != d->rowCount))
|
||||
{
|
||||
int previousRowCount = d->rowCount;
|
||||
d->rowCount = rows;
|
||||
d->rowHeight = 10.0 * rows;
|
||||
d->calculateAspectRatio();
|
||||
|
||||
for(int i=0; i < d->columnCount; ++i)
|
||||
{
|
||||
d->colorTable[i].resize(rows);
|
||||
if(rows > previousRowCount)
|
||||
{
|
||||
for(int j=previousRowCount; j < rows; ++j)
|
||||
{
|
||||
d->setColorAt(j, i, d->darkLedColor.rgb(), false);
|
||||
}
|
||||
}
|
||||
}
|
||||
update();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Returns the number of columns in the LED matrix display.
|
||||
*
|
||||
* \return the number of columns in the LED matrix display
|
||||
*
|
||||
* \sa setColumnCount(), rowCount()
|
||||
*/
|
||||
int QLedMatrix::columnCount() const
|
||||
{
|
||||
Q_D(const QLedMatrix);
|
||||
return d->columnCount;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Sets the number of columns in the LED matrix display.
|
||||
*
|
||||
* This function will do nothing if the new number of columns is less than 0
|
||||
* or if it is equal to the current number of columns. If the new number of
|
||||
* columns is less than the current number of columns, the display will be
|
||||
* cropped to the new value. Otherwise, if the new number of columns is
|
||||
* greater than the current number of columns, the new LEDs will be
|
||||
* initialized using the dark LED color.
|
||||
*
|
||||
* \param columns the new number of columns
|
||||
*
|
||||
* \sa columnCount(), setRowCount(), darkLedColor()
|
||||
*/
|
||||
void QLedMatrix::setColumnCount(int columns)
|
||||
{
|
||||
Q_D(QLedMatrix);
|
||||
if((columns >= 0) && (columns != d->columnCount))
|
||||
{
|
||||
int previousColumnsCount = d->columnCount;
|
||||
d->columnCount = columns;
|
||||
d->columnWidth = 10.0 * columns;
|
||||
d->calculateAspectRatio();
|
||||
|
||||
d->colorTable.resize(columns);
|
||||
if(columns > previousColumnsCount)
|
||||
{
|
||||
for(int i=previousColumnsCount; i<columns; ++i)
|
||||
{
|
||||
d->colorTable[i].resize(d->rowCount);
|
||||
for(int j=0; j < d->rowCount; ++j)
|
||||
{
|
||||
d->setColorAt(j, i, d->darkLedColor.rgb(), false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
update();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* \internal
|
||||
* Reimplemented from QWidget::sizeHint()
|
||||
*/
|
||||
QSize QLedMatrix::sizeHint() const
|
||||
{
|
||||
Q_D(const QLedMatrix);
|
||||
if((d->rowCount > 0) && (d->columnCount > 0))
|
||||
{
|
||||
const QSizeF s(d->columnWidth * d->sizeFactor, d->rowHeight * d->sizeFactor);
|
||||
return s.toSize();
|
||||
}
|
||||
else
|
||||
{
|
||||
qWarning("QLedMatrix::sizeHint: no rows or columns to display, defaulting size to (10,10)");
|
||||
return QSize(10, 10);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* \internal
|
||||
* Reimplemented from QWidget::paintEvent()
|
||||
*/
|
||||
void QLedMatrix::paintEvent(QPaintEvent* /*event*/)
|
||||
{
|
||||
Q_D(QLedMatrix);
|
||||
QPainter painter(this);
|
||||
painter.setPen(Qt::NoPen);
|
||||
painter.setRenderHint(QPainter::Antialiasing);
|
||||
|
||||
if(d->backgroundMode == Qt::OpaqueMode)
|
||||
{
|
||||
painter.setBrush(d->backgroundBrush);
|
||||
painter.drawRect(0, 0, d->columnWidth, d->rowHeight);
|
||||
}
|
||||
|
||||
if((d->rowHeight > 0.0) && (d->columnWidth > 0.0))
|
||||
{
|
||||
const qreal w = width();
|
||||
const qreal h = height();
|
||||
|
||||
painter.translate(w / 2.0, h / 2.0);
|
||||
|
||||
qreal sizeFactorHeight = h / d->rowHeight;
|
||||
qreal sizeFactorWidth = w / d->columnWidth;
|
||||
d->sizeFactor = (sizeFactorHeight < sizeFactorWidth ? sizeFactorHeight : sizeFactorWidth);
|
||||
|
||||
painter.scale(d->sizeFactor, d->sizeFactor);
|
||||
painter.translate(1.0 - (d->columnWidth/2), 1.0 - (d->rowHeight/2));
|
||||
|
||||
adjustSize();
|
||||
d->drawLEDs(painter);
|
||||
}
|
||||
}
|
||||
|
||||
// Todo: Matrizen sollen zusammen bleiben und dafür mitscalen
|
||||
Executable
+99
@@ -0,0 +1,99 @@
|
||||
/*******************************************************************************
|
||||
**
|
||||
** Copyright (C) 2009 Pierre-Etienne Messier <pierre.etienne.messier@gmail.com>
|
||||
** http://pemessier.hexpresso.org/
|
||||
**
|
||||
** This library is free software: you can redistribute it and/or modify
|
||||
** it under the terms of the GNU Lesser General Public License as published by
|
||||
** the Free Software Foundation, either version 3 of the License, or
|
||||
** (at your option) any later version.
|
||||
**
|
||||
** This library is distributed in the hope that it will be useful,
|
||||
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
** GNU Lesser General Public License for more details.
|
||||
**
|
||||
** You should have received a copy of the GNU Lesser General Public License
|
||||
** along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
**
|
||||
*******************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
|
||||
#ifndef QLEDMATRIX_EXPORT
|
||||
# ifdef BUILD_STATIC_LIBRARIES
|
||||
# define QLEDMATRIX_EXPORT
|
||||
# else
|
||||
# ifdef MAKE_QLEDMATRIX_LIB
|
||||
# define QLEDMATRIX_EXPORT Q_DECL_EXPORT
|
||||
# else
|
||||
# define QLEDMATRIX_EXPORT Q_DECL_IMPORT
|
||||
# endif
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#include <QWidget>
|
||||
|
||||
class QLedMatrixPrivate;
|
||||
class QLEDMATRIX_EXPORT QLedMatrix : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(QColor backgroundColor READ backgroundColor WRITE setBackgroundColor)
|
||||
Q_PROPERTY(Qt::BGMode backgroundMode READ backgroundMode WRITE setBackgroundMode)
|
||||
Q_PROPERTY(QColor darkLedColor READ darkLedColor WRITE setDarkLedColor)
|
||||
Q_PROPERTY(int rows READ rowCount WRITE setRowCount)
|
||||
Q_PROPERTY(int columns READ columnCount WRITE setColumnCount)
|
||||
|
||||
public:
|
||||
QLedMatrix(QWidget* parent = nullptr);
|
||||
virtual ~QLedMatrix();
|
||||
|
||||
enum LEDColor
|
||||
{
|
||||
NoColor = 0xFF222222,
|
||||
|
||||
Red = 0xFFFF0000,
|
||||
Green = 0xFF00FF00,
|
||||
Blue = 0xFF0000FF,
|
||||
|
||||
White = 0xFFFFFFFF,
|
||||
Orange = 0xFFFF8800,
|
||||
OrangeRed = 0xFFFF2200,
|
||||
Yellow = 0xFFFFFF00
|
||||
};
|
||||
Q_ENUM(LEDColor)
|
||||
|
||||
void clear();
|
||||
|
||||
QColor backgroundColor() const;
|
||||
void setBackgroundColor(const QColor& color);
|
||||
|
||||
Qt::BGMode backgroundMode() const;
|
||||
void setBackgroundMode(Qt::BGMode mode);
|
||||
|
||||
QColor darkLedColor() const;
|
||||
void setDarkLedColor(const QColor& color);
|
||||
|
||||
QRgb colorAt(int row, int col) const;
|
||||
void setColorAt(int row, int col, QRgb rgb);
|
||||
|
||||
int rowCount() const;
|
||||
void setRowCount(int rows);
|
||||
|
||||
int columnCount() const;
|
||||
void setColumnCount(int columns);
|
||||
|
||||
inline void setSize(const QSize &s) { setRowCount(s.height()); setColumnCount(s.width()); }
|
||||
|
||||
QSize sizeHint() const;
|
||||
|
||||
protected:
|
||||
QLedMatrixPrivate* const d_ptr;
|
||||
void paintEvent(QPaintEvent*);
|
||||
|
||||
private:
|
||||
Q_DISABLE_COPY(QLedMatrix)
|
||||
Q_DECLARE_PRIVATE(QLedMatrix)
|
||||
};
|
||||
|
||||
Reference in new issue
Block a user