From 67ee3963a6484a334de353f776ed94d9d288b960 Mon Sep 17 00:00:00 2001 From: Dorian Zedler Date: Tue, 13 Oct 2020 17:00:25 +0200 Subject: [PATCH] some changes --- OmobiDisplayApp/omobidisplaybackend.cpp | 23 +++++++++++++++++++---- OmobiDisplayApp/omobidisplaybackend.h | 10 ++++++++++ OmobiDisplayApp/omobidisplaytextmodel.cpp | 5 +++++ OmobiDisplayApp/omobidisplaytextmodel.h | 13 +++++++++++-- 4 files changed, 45 insertions(+), 6 deletions(-) diff --git a/OmobiDisplayApp/omobidisplaybackend.cpp b/OmobiDisplayApp/omobidisplaybackend.cpp index 88890dd..f7ce257 100644 --- a/OmobiDisplayApp/omobidisplaybackend.cpp +++ b/OmobiDisplayApp/omobidisplaybackend.cpp @@ -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)); } diff --git a/OmobiDisplayApp/omobidisplaybackend.h b/OmobiDisplayApp/omobidisplaybackend.h index 26f242e..319ad1b 100644 --- a/OmobiDisplayApp/omobidisplaybackend.h +++ b/OmobiDisplayApp/omobidisplaybackend.h @@ -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; diff --git a/OmobiDisplayApp/omobidisplaytextmodel.cpp b/OmobiDisplayApp/omobidisplaytextmodel.cpp index 476ea81..2ceb892 100644 --- a/OmobiDisplayApp/omobidisplaytextmodel.cpp +++ b/OmobiDisplayApp/omobidisplaytextmodel.cpp @@ -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 roles = { { TextRole, text }, { ActiveRole, active }, diff --git a/OmobiDisplayApp/omobidisplaytextmodel.h b/OmobiDisplayApp/omobidisplaytextmodel.h index 43a97bf..e30bbc7 100644 --- a/OmobiDisplayApp/omobidisplaytextmodel.h +++ b/OmobiDisplayApp/omobidisplaytextmodel.h @@ -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;