Hyelicht 2.0
Controller application for the Hyelicht shelf. Paint on the shelf with colors, turn on the fireplace mode, and more.
Loading...
Searching...
No Matches
shelfmodel.h
1/*
2 * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
3 * SPDX-FileCopyrightText: 2021-2024 Eike Hein <sho@eikehein.com>
4 */
5
6#pragma once
7
8#include <QAbstractListModel>
9#include <QColor>
10#include <QPointer>
11#include <QQmlParserStatus>
12#include <QRemoteObjectHost>
13#include <QUrl>
14#include <QVariantAnimation>
15
16#include "abstractanimation.h"
17#include "ledstrip.h"
18
20
47class ShelfModel : public QAbstractListModel, public QQmlParserStatus
48{
49 Q_OBJECT
50 Q_INTERFACES(QQmlParserStatus)
51
52
61 Q_PROPERTY(LedStrip* ledStrip READ ledStrip WRITE setLedStrip NOTIFY ledStripChanged)
62
64
74 Q_PROPERTY(bool enabled READ enabled WRITE setEnabled NOTIFY enabledChanged)
75
77
88 Q_PROPERTY(int rows READ rows WRITE setRows NOTIFY rowsChanged)
89
91
102 Q_PROPERTY(int columns READ columns WRITE setColumns NOTIFY columnsChanged)
103
105
116 Q_PROPERTY(int density READ density WRITE setDensity NOTIFY densityChanged)
117
119
133
135
145 Q_PROPERTY(qreal brightness READ brightness WRITE setBrightness NOTIFY brightnessChanged)
146
148
158
160
175
177
187
189
204
206
218
220
229 Q_PROPERTY(bool animating READ animating WRITE setAnimating NOTIFY animatingChanged)
230
232
245
247
257
258 public:
267 Q_ENUM(AdditionalRoles)
268
269
273 explicit ShelfModel(QObject *parent = nullptr);
274 ~ShelfModel() override;
275
277
283 LedStrip *ledStrip() const;
284
286
294
296
307 bool enabled() const;
308
310
320 void setEnabled(bool enabled);
321
323
332 int rows() const;
333
335
345 void setRows(int rows);
346
348
357 int columns() const;
358
360
370 void setColumns(int columns);
371
373
382 int density() const;
383
385
395 void setDensity(int density);
396
398
409 int wallThickness() const;
410
412
424 void setWallThickness(int thickness);
425
427
437 qreal brightness() const;
438
440
447 void setBrightness(qreal brightness);
448
450
459 bool animateBrightnessTransitions() const;
460
462
468 void setAnimateBrightnessTransitions(bool animate);
469
471
484 QColor averageColor() const;
485
487
495 void setAverageColor(const QColor &color);
496
498
508
510
516 void setAnimateAverageColorTransitions(bool animate);
517
519
529 int transitionDuration() const;
530
532
545 void setTransitionDuration(int duration);
546
548
556
558
569
571
580 bool animating() const;
581
583
591 void setAnimating(bool animating);
592
594
601 bool remotingEnabled() const;
602
604
615 void setRemotingEnabled(bool enabled);
616
618
625 QUrl listenAddress() const;
626
628
636 void setListenAddress(const QUrl &url);
637
639 QHash<int, QByteArray> roleNames() const override;
640
642 int rowCount(const QModelIndex &parent = QModelIndex()) const override;
643
645 QVariant headerData(int section, Qt::Orientation orientation,
646 int role = Qt::DisplayRole) const override;
647
652 QVariant data(const QModelIndex &proxyIndex, int role) const override;
653
658 bool setData(const QModelIndex &index, const QVariant &value,
659 int role = Qt::EditRole) override;
660
662 void classBegin() override;
664 void componentComplete() override;
665
666 Q_SIGNALS:
668
672 void ledStripChanged() const;
673
675
680 void enabledChanged(bool enabled) const;
681
683
688 void rowsChanged(int rows) const;
689
691
696 void columnsChanged(int columns) const;
697
699
704 void densityChanged(int density) const;
705
707
712 void wallThicknessChanged(int thickness) const;
713
715
720 void brightnessChanged(qreal brightness) const;
721
723
728 void animateBrightnessTransitionsChanged(bool animate) const;
729
731
736 void averageColorChanged(const QColor &color) const;
737
739
745
747
752 void transitionDurationChanged(int duration) const;
753
755
759 void animationChanged() const;
760
762
767 void animatingChanged(bool animating) const;
768
770
775
777
782
783 private:
784 inline QPair<int, int> rowIndexToRange(const int rowIndex) const;
785 void transitionToCurrentBrightness();
786 void syncBrightness(bool show = true);
787 void setRangesToColor(const QColor &color);
788 void abortTransitions();
789 void updateLedStrip();
790 void updateAnimation();
791 void updateRemoting();
792
793 QPointer<LedStrip> m_ledStrip;
794
795 bool m_enabled;
796
797 int m_rows;
798 int m_columns;
799 int m_density;
800 int m_wallThickness;
801
802 qreal m_brightness;
803 qreal m_targetBrightness;
804 bool m_animateBrightnessTransitions;
805 bool m_pendingBrightnessTransition;
806 QVariantAnimation m_brightnessTransition;
807
808 QColor m_averageColor;
809 bool m_animateAverageColorTransitions;
810 QVariantAnimation m_averageColorTransition;
811
812 int m_transitionDuration;
813
814 QPointer<AbstractAnimation> m_animation;
815 bool m_animating;
816
817 bool m_remotingEnabled;
818 QUrl m_listenAddress;
819 QRemoteObjectHost *m_remotingServer;
820
821 bool m_createdByQml;
822 bool m_complete;
823};
Abstract base class for LED strip animations operating on LedStrip.
Definition abstractanimation.h:29
Connects to and performs painting operations on a strip of SK9822/APA102 LEDs.
Definition ledstrip.h:45
Data model and business logic specific to the Hyelicht shelf.
Definition shelfmodel.h:48
bool animateBrightnessTransitions
Toggle animated transitions between brightness levels.
Definition shelfmodel.h:157
void brightnessChanged(qreal brightness) const
The brightness of the shelf has changed.
void setEnabled(bool enabled)
Turn the shelf on or off.
Definition shelfmodel.cpp:150
void setDensity(int density)
Set the number of LEDs in each shelf compartment.
Definition shelfmodel.cpp:273
void setColumns(int columns)
Set the number of compartments in each shelf board.
Definition shelfmodel.cpp:238
void densityChanged(int density) const
The number of LEDs in each shelf compartment has changed.
QUrl listenAddress
Listen address for the remoting API server.
Definition shelfmodel.h:256
bool enabled
Toggle the shelf on or off.
Definition shelfmodel.h:74
QVariant data(const QModelIndex &proxyIndex, int role) const override
Definition shelfmodel.cpp:691
void rowsChanged(int rows) const
The number of boards in the shelf has changed.
void setAnimating(bool animating)
Set whether to run the animation.
Definition shelfmodel.cpp:635
QVariant headerData(int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const override
Definition shelfmodel.cpp:679
int wallThickness
Number of LEDs behind each compartment-dividing wall.
Definition shelfmodel.h:132
bool animateAverageColorTransitions
Toggle animated transitions between full-shelf color fills.
Definition shelfmodel.h:186
void listenAddressChanged() const
The listen address for the remoting API server has changed.
void setLedStrip(LedStrip *ledStrip)
Set the LedStrip instance this model operates on.
Definition shelfmodel.cpp:100
qreal brightness
The shelf brightness level while on.
Definition shelfmodel.h:145
bool setData(const QModelIndex &index, const QVariant &value, int role=Qt::EditRole) override
Definition shelfmodel.cpp:739
QColor averageColor
Average color of the shelf.
Definition shelfmodel.h:174
void setAverageColor(const QColor &color)
Sets the average color of the shelf.
Definition shelfmodel.cpp:451
void setBrightness(qreal brightness)
Set the shelf brightness level while on.
Definition shelfmodel.cpp:343
void animateAverageColorTransitionsChanged(bool animate) const
Whether to animate transitions between full-shelf color fills has changed.
void setListenAddress(const QUrl &url)
Set the listen address for the remoting API server.
Definition shelfmodel.cpp:819
void animateBrightnessTransitionsChanged(bool animate) const
Whether to animate transitions between brightness levels has changed.
void setAnimateBrightnessTransitions(bool animate)
Set whether to animate transitions between brightness levels.
Definition shelfmodel.cpp:404
void transitionDurationChanged(int duration) const
The duration in milliseconds for an animated fade between brightness levels or full-shelf color fills...
int transitionDuration
Duration in milliseconds for an animated fade between brightness levels or full-shelf color fills.
Definition shelfmodel.h:203
void ledStripChanged() const
The LedStrip instance this model operates on has changed.
bool remotingEnabled
Toggle the remoting API server.
Definition shelfmodel.h:244
void wallThicknessChanged(int thickness) const
The number of LEDs behind each compartment-dividing wall has changed.
int columns
Number of compartments in each shelf board.
Definition shelfmodel.h:102
QHash< int, QByteArray > roleNames() const override
Definition shelfmodel.cpp:655
void setTransitionDuration(int duration)
Set the duration in milliseconds for an animated fade between brightness levels or full-shelf color f...
Definition shelfmodel.cpp:545
void componentComplete() override
Implements the QQmlParserStatus interface.
Definition shelfmodel.cpp:837
void setRemotingEnabled(bool enabled)
Set whether to enable the remoting API server.
Definition shelfmodel.cpp:801
int density
Number of LEDs in each shelf compartment.
Definition shelfmodel.h:116
int rows
Number of boards in the shelf.
Definition shelfmodel.h:88
void setRows(int rows)
Set the number of boards in the shelf.
Definition shelfmodel.cpp:204
AdditionalRoles
Non-standard model data roles offered by this model.
Definition shelfmodel.h:260
@ AverageBrightness
Average brightness channel of the LEDs in a shelf compartment.
Definition shelfmodel.h:265
@ AverageGreen
Average green channel of the LEDs in a shelf compartment.
Definition shelfmodel.h:263
@ AverageBlue
Average blue channel of the LEDs in a shelf compartment.
Definition shelfmodel.h:264
@ AverageColor
Average color of the LEDs in a shelf compartment.
Definition shelfmodel.h:261
@ AverageRed
Average red channel of the LEDs in a shelf compartment.
Definition shelfmodel.h:262
void averageColorChanged(const QColor &color) const
The average color of the shelf has changed.
AbstractAnimation * animation
Animation to operate on ledStrip.
Definition shelfmodel.h:217
void setWallThickness(int thickness)
Set the number of LEDs behind each compartment-dividing wall.
Definition shelfmodel.cpp:308
LedStrip * ledStrip
LedStrip instance this model operates on.
Definition shelfmodel.h:61
int rowCount(const QModelIndex &parent=QModelIndex()) const override
Definition shelfmodel.cpp:670
void remotingEnabledChanged() const
Whether to enable the remoting API server has changed.
void setAnimation(AbstractAnimation *animation)
Set animation operating on ledStrip.
Definition shelfmodel.cpp:562
void columnsChanged(int columns) const
The number of compartments in each shelf board has changed.
void enabledChanged(bool enabled) const
The shelf has turned on or off.
void classBegin() override
Implements the QQmlParserStatus interface.
Definition shelfmodel.cpp:832
bool animating
Toggle the animation.
Definition shelfmodel.h:229
void setAnimateAverageColorTransitions(bool animate)
Set whether to animate transitions between full-shelf color fills.
Definition shelfmodel.cpp:519
void animatingChanged(bool animating) const
Whether to run the animation has changed.
void animationChanged() const
The animation operating on ledStrip has changed.