Ben des affaires...

This commit is contained in:
2021-04-11 13:18:40 -04:00
parent 940287a97e
commit 50d091c68c
33 changed files with 38430 additions and 67 deletions
+6
View File
@@ -0,0 +1,6 @@
#include "LEDAnimation.h"
CLEDAnimation::CLEDAnimation()
{
}
+16
View File
@@ -0,0 +1,16 @@
#ifndef LEDANIMATION_H
#define LEDANIMATION_H
#include <QList>
class QColor;
class CLEDAnimation
{
public:
CLEDAnimation();
int LedStringSize;
virtual QList<QColor> *GetCurrentFrame() = 0;
};
#endif // LEDANIMATION_H
+16
View File
@@ -0,0 +1,16 @@
#include "LEDAnimator.h"
CLEDAnimator::CLEDAnimator(QObject *parent) : QObject(parent)
{
mAnimationRefreshTimer = new QTimer();
mAnimationRefreshTimer->setSingleShot(false);
mAnimationRefreshTimer->setInterval(ANIMATION_REFRESH_TIMEOUT);
connect(mAnimationRefreshTimer,SIGNAL(timeout()),this,SLOT(AnimationTimerExipired()));
}
void CLEDAnimator::AnimationTimerExipired()
{
}
+24
View File
@@ -0,0 +1,24 @@
#ifndef LEDANIMATOR_H
#define LEDANIMATOR_H
#include <QObject>
#include <QTimer>
#define ANIMATION_REFRESH_TIMEOUT 33 //ms = 30 FPS
class CLEDAnimator : public QObject
{
Q_OBJECT
public:
explicit CLEDAnimator(QObject *parent = 0);
QTimer *mAnimationRefreshTimer;
signals:
public slots:
void AnimationTimerExipired();
};
#endif // LEDANIMATOR_H
+129
View File
@@ -0,0 +1,129 @@
#include "LedStringWidget.h"
#include <QPainter>
CLedStringWidget::CLedStringWidget(int NbLed, QGraphicsItem *parent)
{
mLEDSpacing = 5;
mNbLED = NbLed;
mBoundingRect.setTop(0);
mBoundingRect.setLeft(0);
int color = 0;
// for(int i = 0; i < NbLed; i++)
// {
// QColor LedColor;
// if(color == 0)
// {
// LedColor = QColor(Qt::red);
// color++;
// }
// else if(color == 1)
// {
// LedColor = QColor(Qt::green);
// color++;
// }
// else
// {
// LedColor = QColor(Qt::blue);
// color = 0;
// }
// CRGBLedWidget *NewLED = new CRGBLedWidget(LedColor,this);
// NewLED->setPos(i*(NewLED->boundingRect().width()+mLEDSpacing),0);
// mLEDList.append(NewLED);
// }
for(int i = 0; i < 30; i++)
{
// for(int led = 0; led < 10; led++)
{
QColor LedColor = QColor(50,0,0);
CRGBLedWidget *NewLED = new CRGBLedWidget(LedColor,this);
NewLED->setPos(((i*10)+1)*(NewLED->boundingRect().width()+mLEDSpacing),0);
mLEDList.append(NewLED);
LedColor = QColor(100,0,0);
NewLED = new CRGBLedWidget(LedColor,this);
NewLED->setPos(((i*10)+2)*(NewLED->boundingRect().width()+mLEDSpacing),0);
mLEDList.append(NewLED);
LedColor = QColor(150,0,0);
NewLED = new CRGBLedWidget(LedColor,this);
NewLED->setPos(((i*10)+3)*(NewLED->boundingRect().width()+mLEDSpacing),0);
mLEDList.append(NewLED);
LedColor = QColor(200,0,0);
NewLED = new CRGBLedWidget(LedColor,this);
NewLED->setPos(((i*10)+4)*(NewLED->boundingRect().width()+mLEDSpacing),0);
mLEDList.append(NewLED);
LedColor = QColor(255,0,0);
NewLED = new CRGBLedWidget(LedColor,this);
NewLED->setPos(((i*10)+5)*(NewLED->boundingRect().width()+mLEDSpacing),0);
mLEDList.append(NewLED);
LedColor = QColor(200,0,0);
NewLED = new CRGBLedWidget(LedColor,this);
NewLED->setPos(((i*10)+6)*(NewLED->boundingRect().width()+mLEDSpacing),0);
mLEDList.append(NewLED);
LedColor = QColor(150,0,0);
NewLED = new CRGBLedWidget(LedColor,this);
NewLED->setPos(((i*10)+7)*(NewLED->boundingRect().width()+mLEDSpacing),0);
mLEDList.append(NewLED);
LedColor = QColor(100,0,0);
NewLED = new CRGBLedWidget(LedColor,this);
NewLED->setPos(((i*10)+8)*(NewLED->boundingRect().width()+mLEDSpacing),0);
mLEDList.append(NewLED);
LedColor = QColor(50,0,0);
NewLED = new CRGBLedWidget(LedColor,this);
NewLED->setPos(((i*10)+9)*(NewLED->boundingRect().width()+mLEDSpacing),0);
mLEDList.append(NewLED);
LedColor = QColor(25,0,0);
NewLED = new CRGBLedWidget(LedColor,this);
NewLED->setPos(((i*10)+10)*(NewLED->boundingRect().width()+mLEDSpacing),0);
mLEDList.append(NewLED);
}
}
}
void CLedStringWidget::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
painter->setPen(QPen(Qt::darkGreen));
// painter->drawRect(boundingRect());
}
QRectF CLedStringWidget::boundingRect() const
{
if(mLEDList.size() == 0)
return QRectF();
//This assumes all leds are the same size...
return QRectF(0,
0,
mLEDList.size()*(mLEDSpacing + mLEDList.at(0)->boundingRect().width()),
mLEDList.at(0)->boundingRect().height());
}
int CLedStringWidget::SetLedStringColors(QList<QColor> *LEDColors)
{
if(LEDColors->size() != mLEDList.size())
{
return 0;
}
for(int i = 0; i < mLEDList.size(); i++)
{
mLEDList[i]->SetColor(LEDColors->at(i));
}
this->boundingRect();
}
+25
View File
@@ -0,0 +1,25 @@
#ifndef LEDSTRINGWIDGET_H
#define LEDSTRINGWIDGET_H
#include <QGraphicsItem>
#include <QList>
#include "RGBLedWidget.h"
class CLedStringWidget : public QGraphicsItem
{
public:
CLedStringWidget(int NbLed, QGraphicsItem *parent = 0);
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
QRectF boundingRect() const;
int SetLedStringColors(QList<QColor> *LEDColors);
int mNbLED;
int mLEDSpacing;
QRectF mBoundingRect;
QList<CRGBLedWidget*> mLEDList;
};
#endif // LEDSTRINGWIDGET_H
+145
View File
@@ -0,0 +1,145 @@
#include "LightShowWidget.h"
#include <QGraphicsScene>
#include <QGraphicsRectItem>
#include <math.h>
#include <QScrollBar>
#define VIEW_CENTER viewport()->rect().center()
#define VIEW_WIDTH viewport()->rect().width()
#define VIEW_HEIGHT viewport()->rect().height()
CLightShowWidget::CLightShowWidget(QWidget *parent)
{
mScale = 1.0;
mDoMousePan = false;
setParent(parent);
mScene = new QGraphicsScene(this);
mScene->setItemIndexMethod(QGraphicsScene::NoIndex);
mScene->setSceneRect(-5000, -5000, 10000, 10000);
// scene->setSceneRect(-100,-100,10000,10000);
setScene(mScene);
// setMinimumSize(500,500);
// setMaximumSize(parent->size());
setTransformationAnchor(AnchorUnderMouse);
// setTransformationAnchor(AnchorViewCenter);
setDragMode(QGraphicsView::NoDrag);
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
mViewportRect = new QGraphicsRectItem(0,0,50,50);
mViewportRect->setPen(QPen(Qt::darkBlue));
mSceneRect = new QGraphicsRectItem(sceneRect());
mSceneRect->setPen(QPen(Qt::red));
mLedStringRect = new QGraphicsRectItem();
mLedStringRect->setPen(QPen(Qt::darkGreen));
// test->setBrush(QBrush(Qt::darkBlue));
// mScene->addItem(mViewportRect);
// mScene->addItem(mSceneRect);
// mScene->addItem(mLedStringRect);
mLedStringWidget = new CLedStringWidget(300);
mScene->addItem(mLedStringWidget);
// mLedStringWidget->setTransform(QTransform::fromScale(10, 10), true);
mLedStringWidget->setPos(0,100);
setSceneRect(-100,-100,parentWidget()->geometry().width(),parentWidget()->geometry().height());
setMinimumSize(parentWidget()->geometry().width(),parentWidget()->geometry().height());
}
void CLightShowWidget::wheelEvent(QWheelEvent *event)
{
ScaleView(pow((double)2, event->delta() / 240.0));
}
void CLightShowWidget::ScaleView(qreal scaleFactor)
{
qreal factor = transform().scale(scaleFactor, scaleFactor).mapRect(QRectF(0, 0, 1, 1)).width();
if (/*factor < 0.07 || */factor > 1)
return;
scale(scaleFactor, scaleFactor);
mScale *= scaleFactor;
qreal deltaW = factor * sceneRect().width();
qreal deltaH = factor * sceneRect().height();
}
void CLightShowWidget::ZoomIn()
{
ScaleView(qreal(1.2));
}
void CLightShowWidget::ZoomOut()
{
ScaleView(1 / qreal(1.2));
}
void CLightShowWidget::showEvent(QShowEvent *event)
{
mNominalTransform = transform();
mLedStringRect->setRect(mLedStringWidget->boundingRect());
}
void CLightShowWidget::mousePressEvent(QMouseEvent *event)
{
if (event->button() == Qt::LeftButton){
mLasMousePos = event->pos();
mDoMousePan = true;
}
QGraphicsView::mousePressEvent(event);
}
void CLightShowWidget::mouseMoveEvent(QMouseEvent *event)
{
if (mDoMousePan){
QPointF mouseDelta = mapToScene(event->pos()) - mapToScene(mLasMousePos);
Pan(mouseDelta);
}
QGraphicsView::mouseMoveEvent(event);
mLasMousePos = event->pos();
}
void CLightShowWidget::mouseReleaseEvent(QMouseEvent *event)
{
if (event->button() == Qt::LeftButton){
mDoMousePan = false;
}
QGraphicsView::mouseReleaseEvent(event);
}
void CLightShowWidget::Pan(QPointF delta)
{
// Scale the pan amount by the current zoom.
// delta *= mScale;
delta *= PAN_SPEED;
// qDebug("Moving by x:%f, y:%f",delta.x(),delta.y());
delta.setX(-delta.rx());
delta.setY(-delta.ry());
QRectF NewViewRect = sceneRect();
NewViewRect.translate(delta.x(),delta.y());
mCurTransform = transform();
setSceneRect(NewViewRect);
mViewportRect->setRect(viewport()->geometry());
mSceneRect->setRect(sceneRect());
// qDebug("Scene Rect: left: %f, right:%f, top:%f, bottom:%f",sceneRect().left(),sceneRect().right(),sceneRect().top(),sceneRect().bottom());
// Have panning be anchored from the mouse.
setTransformationAnchor(QGraphicsView::AnchorUnderMouse);
}
+47
View File
@@ -0,0 +1,47 @@
#ifndef LIGHTSHOWWIDGET_H
#define LIGHTSHOWWIDGET_H
#include <QGraphicsView>
#include <QWheelEvent>
#include "LedStringWidget.h"
#include <QObject>
#define PAN_SPEED 1
class CLightShowWidget : public QGraphicsView
{
Q_OBJECT
public:
CLightShowWidget(QWidget *parent = 0);
void ScaleView(qreal scaleFactor);
void Pan(QPointF delta);
void showEvent(QShowEvent *event);
void mousePressEvent(QMouseEvent *event);
void mouseReleaseEvent(QMouseEvent *event);
void mouseMoveEvent(QMouseEvent *event);
bool mDoMousePan;
qreal mScale;
QPoint mLasMousePos;
QGraphicsRectItem *mViewportRect, *mSceneRect, *mLedStringRect;
QGraphicsScene *mScene;
QTransform mCurTransform, mNominalTransform;
CLedStringWidget *mLedStringWidget;
public slots:
void ZoomIn();
void ZoomOut();
protected:
void wheelEvent(QWheelEvent *event);
};
#endif // LIGHTSHOWWIDGET_H
+62
View File
@@ -0,0 +1,62 @@
#include "RGBLedWidget.h"
#include <math.h>
#include <QPainter>
#include <QGraphicsSceneMouseEvent>
#include <QGraphicsView>
CRGBLedWidget::CRGBLedWidget(QColor Color, QGraphicsItem *parent)
{
setParentItem(parent);
mLEDColor = Color;
mIsSelected = false;
mLedDiameter = LED_DIAMETER;
}
void CRGBLedWidget::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
painter->setPen(Qt::NoPen);
painter->setBrush(QBrush(mLEDColor));
painter->drawEllipse(0,0,mLedDiameter,mLedDiameter);
if(mIsSelected == true)
{
painter->setPen(Qt::black);
painter->setBrush(Qt::NoBrush);
painter->drawRect(0,0,mLedDiameter,mLedDiameter);
}
}
QRectF CRGBLedWidget::boundingRect() const
{
return QRectF(0,0,mLedDiameter,mLedDiameter);
}
void CRGBLedWidget::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
{
mIsSelected = !mIsSelected;
update(boundingRect());
qDebug("LedMouseRelease");
}
void CRGBLedWidget::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
event->accept();
qDebug("LedMousePress");
}
int CRGBLedWidget::SetColor(QColor color)
{
mLEDColor = color;
return 1;
}
int CRGBLedWidget::SetColor(int r, int g, int b)
{
mLEDColor = QColor(r,g,b);
return 1;
}
+27
View File
@@ -0,0 +1,27 @@
#ifndef RGBLEDWIDGET_H
#define RGBLEDWIDGET_H
#include <QGraphicsItem>
#define LED_DIAMETER 30.0
class CRGBLedWidget : public QGraphicsItem
{
public:
CRGBLedWidget(QColor Color = Qt::darkBlue, QGraphicsItem *parent = 0);
QColor mLEDColor;
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
QRectF boundingRect() const;
int SetColor(QColor color);
int SetColor(int r, int g, int b);
bool mIsSelected;
qreal mLedDiameter;
void mouseReleaseEvent(QGraphicsSceneMouseEvent * event);
void mousePressEvent(QGraphicsSceneMouseEvent * event);
};
#endif // RGBLEDWIDGET_H
+18
View File
@@ -0,0 +1,18 @@
#include "TowerLightShowGui.h"
#include "ui_TowerLightShowGui.h"
CTowerLightShowGui::CTowerLightShowGui(QWidget *parent) :
QDialog(parent),
ui(new Ui::CTowerLightShowGui)
{
ui->setupUi(this);
mLightShowWidget = new CLightShowWidget(ui->mLightCtrlWidget);
//mLightShowWidget->resize(ui->mLightCtrlWidget->size());
}
CTowerLightShowGui::~CTowerLightShowGui()
{
delete ui;
}
+25
View File
@@ -0,0 +1,25 @@
#ifndef TOWERLIGHTSHOWGUI_H
#define TOWERLIGHTSHOWGUI_H
#include <QDialog>
#include "LightShowWidget.h"
namespace Ui {
class CTowerLightShowGui;
}
class CTowerLightShowGui : public QDialog
{
Q_OBJECT
public:
explicit CTowerLightShowGui(QWidget *parent = 0);
~CTowerLightShowGui();
CLightShowWidget *mLightShowWidget;
private:
Ui::CTowerLightShowGui *ui;
};
#endif // TOWERLIGHTSHOWGUI_H
+60
View File
@@ -0,0 +1,60 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>CTowerLightShowGui</class>
<widget class="QDialog" name="CTowerLightShowGui">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>1694</width>
<height>658</height>
</rect>
</property>
<property name="windowTitle">
<string>Dialog</string>
</property>
<widget class="QLabel" name="label">
<property name="geometry">
<rect>
<x>470</x>
<y>20</y>
<width>171</width>
<height>31</height>
</rect>
</property>
<property name="font">
<font>
<pointsize>16</pointsize>
</font>
</property>
<property name="text">
<string>Tower Light Show</string>
</property>
</widget>
<widget class="QWidget" name="mLightCtrlWidget" native="true">
<property name="geometry">
<rect>
<x>39</x>
<y>119</y>
<width>1621</width>
<height>531</height>
</rect>
</property>
</widget>
<widget class="QPushButton" name="pushButton">
<property name="geometry">
<rect>
<x>40</x>
<y>100</y>
<width>75</width>
<height>23</height>
</rect>
</property>
<property name="text">
<string>PushButton</string>
</property>
</widget>
</widget>
<resources/>
<connections/>
</ui>