some changes

This commit is contained in:
Dorian Zedler 2020-10-13 17:00:25 +02:00
parent fb7063de2c
commit 67ee3963a6
Signed by: dorian
GPG key ID: D3B255CB8BC7CD37
4 changed files with 45 additions and 6 deletions

View file

@ -1,4 +1,4 @@
#include "omobidisplaybackend.h"
#include "omobidisplaybackend.h"
OmobiDisplayBackend::OmobiDisplayBackend(QObject *parent) : QObject(parent)
{
@ -96,8 +96,15 @@ void OmobiDisplayBackend::DataHandler(QString s){
};
for(QString key : textMap.toMap().keys()) {
if(keyTranslations.contains(key))
text.insert(keyTranslations[key], textMap.toMap()[key]);
if(keyTranslations.contains(key)) {
if(key == "color") {
QVariantMap colorMap = textMap.toMap()[key].toMap();
QColor color(colorMap["r"].toInt(), colorMap["g"].toInt(), colorMap["b"].toInt());
text.insert(keyTranslations[key], color.name());
}
else
text.insert(keyTranslations[key], textMap.toMap()[key]);
}
}
texts.append(text);
@ -120,7 +127,13 @@ void OmobiDisplayBackend::handleDisplayTextModelDataChanged() {
QVariantHash textMap;
for(int key : text.keys()) {
textMap.insert(this->displayTextModel->roleNames()[key], text[key]);
if(key == OmobiDisplayTextModel::ColorRole) {
QColor color = QColor(text[key].toString());
color = color.toRgb();
QVariantMap colorMap = {{"r", color.red()}, {"g", color.green()}, {"b", color.blue()}};
}
else
textMap.insert(this->displayTextModel->roleNames()[key], text[key]);
}
textList.append(textMap);
@ -128,6 +141,8 @@ void OmobiDisplayBackend::handleDisplayTextModelDataChanged() {
QJsonDocument doc = QJsonDocument::fromVariant(textList);
qDebug() << doc.toJson(QJsonDocument::Indented);
this->ble->sendData("SET_TEXTS:" + doc.toJson(QJsonDocument::Compact));
}

View file

@ -27,6 +27,16 @@ public:
};
Q_ENUM(OmobiDisplayAppState)
typedef struct text_set_t
{
const char text[5];
uint time_ms;
uint color;
bool text_scroll;
uint text_scroll_pass;
bool active;
} text_set_t;
private:
OmobiDisplayAppState state;
QBluetoothLeUart *ble;

View file

@ -47,6 +47,11 @@ void OmobiDisplayTextModel::append(
unsigned int scrollSpeed,
unsigned int scrollCount
) {
// the current Maximum is 5
if(this->texts.length() >= 5)
return;
QMap<int, QVariant> roles = {
{ TextRole, text },
{ ActiveRole, active },

View file

@ -12,7 +12,7 @@ class OmobiDisplayTextModel : public QAbstractListModel
public:
friend class OmobiDisplayBackend;
enum QBluetoothLeUartDeviceModelRole {
enum OmobiDisplayTextModelRole {
TextRole = Qt::DisplayRole,
ActiveRole,
RuntimeRole,
@ -23,7 +23,16 @@ public:
ScrollCountRole,
IndexRole
};
Q_ENUM(QBluetoothLeUartDeviceModelRole)
Q_ENUM(OmobiDisplayTextModelRole)
enum text_align_t
{
AlignLeft,
AlignCenter,
AlignRignt
};
int rowCount(const QModelIndex & = QModelIndex()) const;
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;