diff --git a/logic/include/model/ButtonHelper.h b/logic/include/model/ButtonHelper.h index a85ade7..d497a89 100644 --- a/logic/include/model/ButtonHelper.h +++ b/logic/include/model/ButtonHelper.h @@ -24,9 +24,9 @@ public: \ Q_SIGNAL void SMALL_NAME ## LedChanged(char value) /*************************************************************************************************/ -#define PUSH_BUTTON_NO_LED(CAPITAL_NAME, SMALL_NAME, FUNC_CODE) \ +#define PUSH_BUTTON_PROBE_SLOT(CAPITAL_NAME, SMALL_NAME, SLOT_NUMBER) \ private: \ - PushButton _ ## SMALL_NAME{FUNC_CODE}; \ + PushButton _ ## SMALL_NAME{SLOT_NUMBER}; \ void init ## CAPITAL_NAME() \ { \ connect(this, &Console::dataReady, _ ## SMALL_NAME.getLed(), &Led::newData); \ @@ -37,19 +37,20 @@ public: \ void press ## CAPITAL_NAME() \ { \ auto arr = _ ## SMALL_NAME.press(); \ - _dataSender->send(arr); \ + arr[5] = static_cast(this->selectedProbe ## SLOT_NUMBER); \ + _dataSender->sendProbeSlots(arr); \ + emit changeProbeSelectionEnable ## SLOT_NUMBER(); \ } \ void release ## CAPITAL_NAME() \ { \ - auto arr = _ ## SMALL_NAME.release(); \ - _dataSender->send(arr); \ } \ - Q_SIGNAL void SMALL_NAME ## LedChanged(char value) + Q_SIGNAL void SMALL_NAME ## LedChanged(char value); \ + Q_SIGNAL void changeProbeSelectionEnable ## SLOT_NUMBER() /*************************************************************************************************/ -#define ROTARY_BUTTON(CAPITAL_NAME, SMALL_NAME, FUNC_CODE, LED_FUNC_CODE) \ +#define PUSH_BUTTON_NO_LED(CAPITAL_NAME, SMALL_NAME, FUNC_CODE) \ private: \ - RotaryButton _ ## SMALL_NAME{FUNC_CODE, LED_FUNC_CODE}; \ + PushButton _ ## SMALL_NAME {FUNC_CODE}; \ void init ## CAPITAL_NAME() \ { \ connect(this, &Console::dataReady, _ ## SMALL_NAME.getLed(), &Led::newData); \ @@ -57,17 +58,22 @@ private: \ SIGNAL(SMALL_NAME ## LedChanged(char))); \ } \ public: \ - void rotate ## CAPITAL_NAME(int value) \ + void press ## CAPITAL_NAME() \ { \ - auto arr = _ ## SMALL_NAME.rotate(value); \ + auto arr = _ ## SMALL_NAME.press(); \ + _dataSender->send(arr); \ + } \ + void release ## CAPITAL_NAME() \ + { \ + auto arr = _ ## SMALL_NAME.release(); \ _dataSender->send(arr); \ } \ Q_SIGNAL void SMALL_NAME ## LedChanged(char value) /*************************************************************************************************/ -#define ROTARY_BUTTON_NO_LED(CAPITAL_NAME, SMALL_NAME, FUNC_CODE) \ +#define ROTARY_BUTTON(CAPITAL_NAME, SMALL_NAME, FUNC_CODE, LED_FUNC_CODE) \ private: \ - RotaryButton _ ## SMALL_NAME{FUNC_CODE}; \ + RotaryButton _ ## SMALL_NAME{FUNC_CODE, LED_FUNC_CODE}; \ void init ## CAPITAL_NAME() \ { \ connect(this, &Console::dataReady, _ ## SMALL_NAME.getLed(), &Led::newData); \ @@ -83,9 +89,9 @@ public: \ Q_SIGNAL void SMALL_NAME ## LedChanged(char value) /*************************************************************************************************/ -#define DROP_DOWN(CAPITAL_NAME, SMALL_NAME, FUNC_CODE, LED_FUNC_CODE) \ +#define ROTARY_BUTTON_NO_LED(CAPITAL_NAME, SMALL_NAME, FUNC_CODE) \ private: \ - DropDown _ ## SMALL_NAME{FUNC_CODE, LED_FUNC_CODE}; \ + RotaryButton _ ## SMALL_NAME{FUNC_CODE}; \ void init ## CAPITAL_NAME() \ { \ connect(this, &Console::dataReady, _ ## SMALL_NAME.getLed(), &Led::newData); \ @@ -93,9 +99,9 @@ private: \ SIGNAL(SMALL_NAME ## LedChanged(char))); \ } \ public: \ - void select ## CAPITAL_NAME(int value) \ + void rotate ## CAPITAL_NAME(int value) \ { \ - auto arr = _ ## SMALL_NAME.select(value); \ + auto arr = _ ## SMALL_NAME.rotate(value); \ _dataSender->send(arr); \ } \ Q_SIGNAL void SMALL_NAME ## LedChanged(char value) diff --git a/logic/include/model/Console.h b/logic/include/model/Console.h index 4846fc0..200906b 100644 --- a/logic/include/model/Console.h +++ b/logic/include/model/Console.h @@ -14,7 +14,6 @@ #include "FunctionCodes.h" #include "PushButton.h" #include "RotaryButton.h" -#include "DropDown.h" #include "DataSender.h" #include "Logger.h" @@ -23,11 +22,11 @@ class Console : public QObject { Q_OBJECT - //Slotes - DROP_DOWN(Slot1, slot1, SLOT1_FC, static_cast(SLOT1_LED_FC)); - DROP_DOWN(Slot2, slot2, SLOT2_FC, static_cast(SLOT2_LED_FC)); - DROP_DOWN(Slot3, slot3, SLOT3_FC, static_cast(SLOT3_LED_FC)); - DROP_DOWN(Slot4, slot4, SLOT4_FC, static_cast(SLOT4_LED_FC)); + //Probe slotes + PUSH_BUTTON_PROBE_SLOT(Slot1, slot1, 1); + PUSH_BUTTON_PROBE_SLOT(Slot2, slot2, 2); + PUSH_BUTTON_PROBE_SLOT(Slot3, slot3, 3); + PUSH_BUTTON_PROBE_SLOT(Slot4, slot4, 4); //PushButton with LED PUSH_BUTTON(Dual, dual, DUAL_FC, static_cast(DUAL_LED_FC)); @@ -118,6 +117,11 @@ private: public: Console(); + int selectedProbe1 = 0; + int selectedProbe2 = 0; + int selectedProbe3 = 0; + int selectedProbe4 = 0; + void injectDataSender(DataSender* sender); void injectLogger(Logger* logger); void hasValidDataFormat(const QByteArray& data); diff --git a/logic/include/model/DataSender.h b/logic/include/model/DataSender.h index e0f4ad6..3b5873c 100644 --- a/logic/include/model/DataSender.h +++ b/logic/include/model/DataSender.h @@ -10,12 +10,14 @@ class DataSender : public QObject public: virtual void send(const QByteArray& data) = 0; + virtual void sendProbeSlots(const QByteArray& data) = 0; virtual ~DataSender() { } signals: void dataReady(const QByteArray& data); + void probeSlotsDataReady(const QByteArray& data); }; #endif //DATASENDER_H diff --git a/logic/include/model/DatabaseManager.h b/logic/include/model/DatabaseManager.h index f321a33..891fc3f 100644 --- a/logic/include/model/DatabaseManager.h +++ b/logic/include/model/DatabaseManager.h @@ -1,13 +1,20 @@ -#ifndef DatabaseManager_H -#define DatabaseManager_H +#ifndef DATABASEMANAGER_H +#define DATABASEMANAGER_H + +#include +#include class DatabaseManager { private: - char _functionCode; + QSqlDatabase _db; public: - DatabaseManager(char functionCode); + DatabaseManager(const QString& databasePath); + ~DatabaseManager(); + + QList getProbeIds(); + QList getProbeNames(); }; -#endif //DatabaseManager_H +#endif //DATABASEMANAGER_H diff --git a/logic/include/model/FunctionCodes.h b/logic/include/model/FunctionCodes.h index cfad5dc..ac2dd94 100644 --- a/logic/include/model/FunctionCodes.h +++ b/logic/include/model/FunctionCodes.h @@ -1,16 +1,6 @@ #ifndef FUNCTIONCODES_H #define FUNCTIONCODES_H -//Probes and LED of probes -#define SLOT1_FC 0x01 -#define SLOT2_FC 0x09 -#define SLOT3_FC 0x19 -#define SLOT4_FC 0x18 -#define SLOT1_LED_FC 0x20 -#define SLOT2_LED_FC 0x27 -#define SLOT3_LED_FC 0x30 -#define SLOT4_LED_FC 0x48 - //Buttons #define DUAL_FC 0x1D #define QUAD_FC 0x1C diff --git a/logic/include/network/UdpDataSender.h b/logic/include/network/UdpDataSender.h index 6a38573..f3b225b 100644 --- a/logic/include/network/UdpDataSender.h +++ b/logic/include/network/UdpDataSender.h @@ -10,18 +10,21 @@ class UdpDataSender : public DataSender Q_OBJECT private: - QUdpSocket* _socket; + QUdpSocket* _socketDashboard; + QUdpSocket* _socketProbeSlots; public: UdpDataSender(); ~UdpDataSender() override; void send(const QByteArray& data) override; + void sendProbeSlots(const QByteArray& data) override; //uncrustify off public slots: //uncrustify on void read(); + void readProbeSlots(); }; #endif //UDPDATASENDER_H diff --git a/logic/include/viewModel/MainViewModel.h b/logic/include/viewModel/MainViewModel.h index 8204ccc..1c54b8c 100644 --- a/logic/include/viewModel/MainViewModel.h +++ b/logic/include/viewModel/MainViewModel.h @@ -20,11 +20,23 @@ class MainViewModel : public QtMvvm::ViewModel MVVM_PROPERTY(int, stepInc, 1) MVVM_PROPERTY(int, stepDec, -1) - //Slots - DROP_DOWN_PROPERTY(slot1, Slot1, LED_OFF) - DROP_DOWN_PROPERTY(slot2, Slot2, LED_OFF) - DROP_DOWN_PROPERTY(slot3, Slot3, LED_OFF) - DROP_DOWN_PROPERTY(slot4, Slot4, LED_OFF) + //Probes + BUTTON_LED_PROPERTY(slot1, Slot1, false, LED_COLOR_GREEN) + BUTTON_LED_PROPERTY(slot2, Slot2, false, LED_COLOR_WHITE) + BUTTON_LED_PROPERTY(slot3, Slot3, false, LED_COLOR_WHITE) + BUTTON_LED_PROPERTY(slot4, Slot4, false, LED_COLOR_WHITE) + + MVVM_PROPERTY(QList, probeList, {}) + + MVVM_PROPERTY(int, currentSelectedProbe1, 0) + MVVM_PROPERTY(int, currentSelectedProbe2, 0) + MVVM_PROPERTY(int, currentSelectedProbe3, 0) + MVVM_PROPERTY(int, currentSelectedProbe4, 0) + + MVVM_PROPERTY(bool, isProbeSelectionEnable1, false) + MVVM_PROPERTY(bool, isProbeSelectionEnable2, true) + MVVM_PROPERTY(bool, isProbeSelectionEnable3, true) + MVVM_PROPERTY(bool, isProbeSelectionEnable4, true) //Top Left BUTTON_LED_PROPERTY(patient, Patient, false, LED_OFF) @@ -135,29 +147,17 @@ class MainViewModel : public QtMvvm::ViewModel BUTTON_PROPERTY(js4Bottom, Js4Bottom, false) BUTTON_PROPERTY(js5Bottom, Js5Bottom, false) - JOYSTICK_PROPERTY(js1, Js1) - JOYSTICK_PROPERTY(js2, Js2) - JOYSTICK_PROPERTY(js3, Js3) - JOYSTICK_PROPERTY(js4, Js4) - JOYSTICK_PROPERTY(js5, Js5) - - //Probes -//BUTTON_LED_PROPERTY(probe1, Probe1, false, LED_OFF) -//BUTTON_LED_PROPERTY(probe2, Probe2, false, LED_OFF) -//BUTTON_LED_PROPERTY(probe3, Probe3, false, LED_OFF) -//BUTTON_LED_PROPERTY(probe4, Probe4, false, LED_OFF) - - MVVM_PROPERTY(QList, probeList, QList({"Pouya", "Mamad"})) - - MVVM_PROPERTY(int, currentSelectedProbe1, 0) - MVVM_PROPERTY(int, currentSelectedProbe2, 0) - MVVM_PROPERTY(int, currentSelectedProbe3, 0) - MVVM_PROPERTY(int, currentSelectedProbe4, 0) + JOYSTICK_PROPERTY(js1, Js1) + JOYSTICK_PROPERTY(js2, Js2) + JOYSTICK_PROPERTY(js3, Js3) + JOYSTICK_PROPERTY(js4, Js4) + JOYSTICK_PROPERTY(js5, Js5) public: Q_INVOKABLE explicit MainViewModel(QObject* parent = nullptr); private: + const QString _dbPath = "database/ProbeProperties.db"; signals: void ledChanged(char value); @@ -165,10 +165,10 @@ signals: //uncrustify off public slots: //Probes -// LED_SLOT(slot1) -// LED_SLOT(slot2) -// LED_SLOT(slot3) -// LED_SLOT(slot4) + LED_SLOT(slot1) + LED_SLOT(slot2) + LED_SLOT(slot3) + LED_SLOT(slot4) //Top Left LED_SLOT(patient) @@ -235,7 +235,6 @@ public slots: LED_SLOT(focusCenter) LED_SLOT(depthBottom) LED_SLOT(focusBottom) - //uncrustify on }; diff --git a/logic/include/viewModel/utils/Property.h b/logic/include/viewModel/utils/Property.h index 459de35..db5ea7d 100644 --- a/logic/include/viewModel/utils/Property.h +++ b/logic/include/viewModel/utils/Property.h @@ -8,8 +8,8 @@ #define MVVM_PROPERTY(TYPE, NAME, DEFAULT_VALUE) \ Q_PROPERTY(TYPE NAME READ NAME WRITE NAME NOTIFY NAME ## Changed ) \ public: \ - TYPE NAME() const { return _ ## NAME ; } \ - void NAME(TYPE value) { \ + TYPE NAME() const { return _ ## NAME ; } \ + void NAME(TYPE value) { \ if (_ ## NAME == value) return; \ _ ## NAME = value; \ emit NAME ## Changed(value); \ @@ -77,16 +77,5 @@ NAME ## Led(static_cast(value)); \ } \ -/**************************************************************************************************/ -#define DROP_DOWN_PROPERTY(NAME, CAP_NAME, LED_DEF_VAL) \ - MVVM_PROPERTY_CUSTOM(bool, NAME, false) \ - void NAME ## Handle() { \ - if(NAME()) \ - { \ - panel->select ## CAP_NAME('stepDec()'); \ - } \ - } \ - -//uncrustify on #endif //PROPERTY_H diff --git a/logic/logic.pro b/logic/logic.pro index eef9d5b..c49c991 100644 --- a/logic/logic.pro +++ b/logic/logic.pro @@ -1,6 +1,7 @@ TEMPLATE = lib -QT += mvvmcore network +QT += mvvmcore network sql + # Creating a static library is typically more efficient. You can still create a shared library if you want to CONFIG += c++14 static @@ -9,10 +10,10 @@ TARGET = logic DEFINES += QT_DEPRECATED_WARNINGS SOURCES += $$files(src/*.cpp, true) \ - src/model/DropDown.cpp + HEADERS += $$files(include/*.h, true) \ - include/model/DropDown.h + INCLUDEPATH += $$PWD/include/ diff --git a/logic/src/model/DatabaseManager.cpp b/logic/src/model/DatabaseManager.cpp index b3ab640..30b9e30 100644 --- a/logic/src/model/DatabaseManager.cpp +++ b/logic/src/model/DatabaseManager.cpp @@ -1,6 +1,69 @@ #include "model/DatabaseManager.h" -DatabaseManager::DatabaseManager(char functionCode) +#include +#include +#include + +DatabaseManager::DatabaseManager(const QString& databasePath) +{ + _db = QSqlDatabase::addDatabase("QSQLITE"); + _db.setDatabaseName(databasePath); + + if(!_db.open()) + { + qDebug() << "Error: " << _db.lastError().text(); + } +} + +/*************************************************************************************************/ +DatabaseManager::~DatabaseManager() +{ + if(_db.isOpen()) + { + _db.close(); + } +} + +/*************************************************************************************************/ +QList DatabaseManager::getProbeIds() { - _functionCode = functionCode; + QList globalIds; + + QSqlQuery query; + if(query.exec("SELECT globalId FROM Probe")) + { + while(query.next()) + { + QString globalId = query.value(0).toString(); + globalIds.append(QVariant(globalId)); + } + } + else + { + qDebug() << "Error executing query: " << query.lastError().text(); + } + + return globalIds; +} + +/*************************************************************************************************/ +QList DatabaseManager::getProbeNames() +{ + QList names; + + QSqlQuery query; + if(query.exec("SELECT name FROM Probe")) + { + while(query.next()) + { + QString name = query.value(0).toString(); + names.append(QVariant(name)); + } + } + else + { + qDebug() << "Error executing query: " << query.lastError().text(); + } + + return names; } diff --git a/logic/src/network/UdpDataSender.cpp b/logic/src/network/UdpDataSender.cpp index 2f3f65e..57e1ec4 100644 --- a/logic/src/network/UdpDataSender.cpp +++ b/logic/src/network/UdpDataSender.cpp @@ -4,31 +4,51 @@ void UdpDataSender::send(const QByteArray& data) { - _socket->writeDatagram(data, QHostAddress::LocalHost, 5446); + _socketDashboard->writeDatagram(data, QHostAddress::LocalHost, 5446); +} + +/*************************************************************************************************/ +void UdpDataSender::sendProbeSlots(const QByteArray& data) +{ + _socketProbeSlots->writeDatagram(data, QHostAddress::LocalHost, 5450); } /*************************************************************************************************/ void UdpDataSender::read() { char data[DATAGRAM_SIZE]; - int cnt = _socket->readDatagram(data, DATAGRAM_SIZE); + int cnt = _socketDashboard->readDatagram(data, DATAGRAM_SIZE); QByteArray a(data, cnt); emit dataReady(a); } /*************************************************************************************************/ -UdpDataSender::UdpDataSender() +void UdpDataSender::readProbeSlots() { - _socket = new QUdpSocket(); + char data[DATAGRAM_SIZE]; + int cnt = _socketProbeSlots->readDatagram(data, DATAGRAM_SIZE); + QByteArray a(data, cnt); + emit probeSlotsDataReady(a); +} - _socket->bind(QHostAddress::Any, 5445); +/*************************************************************************************************/ +UdpDataSender::UdpDataSender() +{ + _socketDashboard = new QUdpSocket(); + _socketDashboard->bind(QHostAddress::Any, 5445); + connect(_socketDashboard, SIGNAL(readyRead()), this, SLOT(read())); - connect(_socket, SIGNAL(readyRead()), this, SLOT(read())); + _socketProbeSlots = new QUdpSocket(); + _socketProbeSlots->bind(QHostAddress::Any, 5449); + connect(_socketProbeSlots, SIGNAL(readyRead()), this, SLOT(readProbeSlots())); } /*************************************************************************************************/ UdpDataSender::~UdpDataSender() { - _socket->close(); - delete _socket; + _socketDashboard->close(); + delete _socketDashboard; + + _socketProbeSlots->close(); + delete _socketProbeSlots; } diff --git a/logic/src/viewModel/MainViewModel.cpp b/logic/src/viewModel/MainViewModel.cpp index 0e7232f..02faedd 100644 --- a/logic/src/viewModel/MainViewModel.cpp +++ b/logic/src/viewModel/MainViewModel.cpp @@ -5,12 +5,13 @@ #include "model/Console.h" #include "logger/ConsoleLogger.h" #include "network/UdpDataSender.h" +#include "model/DatabaseManager.h" +#define US_HOME_PATH "US_HOME" #define CONNECT_LED(NAME) \ connect(panel, SIGNAL(NAME ## LedChanged(char)), this, SLOT(NAME ## LedHandle(char))); -MainViewModel::MainViewModel(QObject* parent) : - ViewModel(parent) +MainViewModel::MainViewModel(QObject* parent) : ViewModel(parent) { panel = new Console; auto network = new UdpDataSender; @@ -19,12 +20,64 @@ MainViewModel::MainViewModel(QObject* parent) : panel->injectLogger(logger); connect(network, &UdpDataSender::dataReady, panel, &Console::newData); + connect(network, &UdpDataSender::probeSlotsDataReady, panel, &Console::newData); + + QString databasePath = QString("%1/%2").arg(qgetenv(US_HOME_PATH), _dbPath); + DatabaseManager manager(databasePath); + QList globalNames = manager.getProbeNames(); + + //probeList(QList({"prb A fromcpp", "prb B fromcpp"})); + probeList(QList(globalNames)); + + //Current Selected Probes + connect(this, &MainViewModel::currentSelectedProbe1Changed, [ = ]() + { + panel->selectedProbe1 = currentSelectedProbe1(); + }); + connect(this, &MainViewModel::currentSelectedProbe2Changed, [ = ]() + { + panel->selectedProbe2 = currentSelectedProbe2(); + }); + connect(this, &MainViewModel::currentSelectedProbe3Changed, [ = ]() + { + panel->selectedProbe3 = currentSelectedProbe3(); + }); + connect(this, &MainViewModel::currentSelectedProbe4Changed, [ = ]() + { + panel->selectedProbe4 = currentSelectedProbe4(); + }); + + //Enable and disable changes in probe selection box + connect(panel, &Console::changeProbeSelectionEnable1, [ = ]() + { + this->isProbeSelectionEnable1(!this->isProbeSelectionEnable1()); + this->slot1Led(this->isProbeSelectionEnable1() ? LED_COLOR_WHITE : LED_COLOR_GREEN); + }); + + connect(panel, &Console::changeProbeSelectionEnable2, [ = ]() + { + this->isProbeSelectionEnable2(!this->isProbeSelectionEnable2()); + this->slot2Led(this->isProbeSelectionEnable2() ? LED_COLOR_WHITE : LED_COLOR_GREEN); + }); + + connect(panel, &Console::changeProbeSelectionEnable3, [ = ]() + { + this->isProbeSelectionEnable3(!this->isProbeSelectionEnable3()); + this->slot3Led(this->isProbeSelectionEnable3() ? LED_COLOR_WHITE : LED_COLOR_GREEN); + }); + + connect(panel, &Console::changeProbeSelectionEnable4, [ = ]() + { + this->isProbeSelectionEnable4(!this->isProbeSelectionEnable4()); + this->slot4Led(this->isProbeSelectionEnable4() ? LED_COLOR_WHITE : LED_COLOR_GREEN); + }); +//connect(this, ); //Add Probes in 4 Slots -//CONNECT_LED(slot1) -//CONNECT_LED(slot2) -//CONNECT_LED(slot3) -//CONNECT_LED(slot4) + CONNECT_LED(slot1) + CONNECT_LED(slot2) + CONNECT_LED(slot3) + CONNECT_LED(slot4) //Top Left CONNECT_LED(patient) diff --git a/test/TestDataSender.h b/test/TestDataSender.h index 1915d36..f9f287b 100644 --- a/test/TestDataSender.h +++ b/test/TestDataSender.h @@ -7,11 +7,17 @@ class TestDataSender : public DataSender { public: QByteArray consoleData; + QByteArray slotData; void send(const QByteArray& data) override { consoleData = data; } + + void sendProbeSlots(const QByteArray& data) override + { + slotData = data; + } }; #endif //TESTDATASENDER_H diff --git a/test/test.pro b/test/test.pro index 0ab78d9..96364c5 100644 --- a/test/test.pro +++ b/test/test.pro @@ -1,5 +1,5 @@ QT += testlib -QT -= gui +QT -= gui mvvmcore network sql CONFIG += qt console warn_on depend_includepath testcase CONFIG -= app_bundle diff --git a/ui/emulator/elements/ProbeButton.qml b/ui/emulator/elements/ProbeButton.qml index aa84609..0ea74f5 100644 --- a/ui/emulator/elements/ProbeButton.qml +++ b/ui/emulator/elements/ProbeButton.qml @@ -6,7 +6,6 @@ import "qrc:/theme" import "qrc:/const" import "qrc:/emulator/components" - import de.skycoder42.QtMvvm.Core 1.0 import de.skycoder42.QtMvvm.Quick 1.0 import com.example.consoleemulator 1.0 @@ -14,6 +13,10 @@ import com.example.consoleemulator 1.0 Button { id: button + width: Const.macroButton + height: Const.macroButton * 2 + implicitWidth: width + implicitHeight: height //========================================= property var name property var nameLed: name + "Led" @@ -30,9 +33,8 @@ Button { viewProperty: "colorMode" viewModelProperty: nameLed } - //========================================= - + //========================================= property var image: "" property var radius: Math.min(width / 2, height / 2) property var timeToPress: 100 @@ -45,45 +47,51 @@ Button { signal pressed signal released - implicitWidth: width - implicitHeight: height - - onPressed: { button.down = true } - onReleased: { button.down = false } + onPressed: { + button.down = true + } + onReleased: { + button.down = false + } function getColor() { - switch(colorMode) { - case(0): return Theme.current.none - case(1): return Theme.current.white - case(2): return Theme.current.green - case(3): return Theme.current.yellow + switch (colorMode) { + case (0): + return Theme.current.none + case (1): + return Theme.current.white + case (2): + return Theme.current.green + case (3): + return Theme.current.yellow } } function getColorGlow() { - switch(colorMode) { - case(0): return Theme.current.noneGlow - case(1): return Theme.current.whiteGlow - case(2): return Theme.current.greenGlow - case(3): return Theme.current.yellowGlow + switch (colorMode) { + case (0): + return Theme.current.noneGlow + case (1): + return Theme.current.whiteGlow + case (2): + return Theme.current.greenGlow + case (3): + return Theme.current.yellowGlow } } - width: Const.macroButton - height: Const.macroButton*2 - contentItem: Item { id: content anchors.fill: parent z: 1 Item { - property var factor: button.state == "Pressed" ? - Const.imageScalePressed : Const.imageScale + property var factor: button.state + == "Pressed" ? Const.imageScalePressed : Const.imageScale property var elevator: button.state == "Pressed" ? 3 : 0 anchors.horizontalCenter: parent.horizontalCenter - y: (parent.height * (1-factor)) / 2 + elevator + y: (parent.height * (1 - factor)) / 2 + elevator width: parent.width * factor height: parent.height * factor @@ -127,7 +135,7 @@ Button { } } - background: Item{ + background: Item { width: parent.width height: parent.height @@ -138,7 +146,7 @@ Button { height: backLight.height + diffusion radius: width / 2 anchors.horizontalCenter: backLight.horizontalCenter - y: - diffusion / 4 + y: -diffusion / 4 color: Theme.current.background border { width: diffusion / 2 @@ -164,13 +172,23 @@ Button { RadialGradient { anchors.fill: parent gradient: Gradient { - GradientStop { position: 0.0; color: lightGlow } GradientStop { - position: 0.5 * (backLight.width - backLightGlow.diffusion / backLightGlow.width) + position: 0.0 + color: lightGlow + } + GradientStop { + position: 0.5 * (backLight.width - backLightGlow.diffusion + / backLightGlow.width) color: lightGlow } - GradientStop { position: 0.5; color: "transparent" } - GradientStop { position: 1.0; color: "transparent" } + GradientStop { + position: 0.5 + color: "transparent" + } + GradientStop { + position: 1.0 + color: "transparent" + } } } } @@ -211,7 +229,7 @@ Button { height: parent.height radius: width / 2 color: "transparent" - border{ + border { color: background.color width: button.border } @@ -224,8 +242,7 @@ Button { anchors.fill: parent layer.enabled: true - layer.effect: - OpacityMask { + layer.effect: OpacityMask { maskSource: lightRing } @@ -312,7 +329,7 @@ Button { id: hoverGlow width: 2 * parent.width height: parent.height - x: - 2 * parent.width + x: -2 * parent.width color: "transparent" HoverGlow {} @@ -349,7 +366,8 @@ Button { transitions: [ Transition { - from: ""; to: "Hovering" + from: "" + to: "Hovering" NumberAnimation { properties: "x" duration: 500 @@ -358,4 +376,3 @@ Button { } ] } - diff --git a/ui/emulator/items/DropDownWithDisable.qml b/ui/emulator/items/DropDownWithDisable.qml new file mode 100644 index 0000000..fe88386 --- /dev/null +++ b/ui/emulator/items/DropDownWithDisable.qml @@ -0,0 +1,46 @@ +import QtQuick 2.0 +import QtQuick.Layouts 1.13 +import QtQuick.Controls 2.12 +import de.skycoder42.QtMvvm.Core 1.0 +import de.skycoder42.QtMvvm.Quick 1.0 +import com.example.consoleemulator 1.0 + +import "qrc:/emulator/elements" +import "qrc:/emulator/components" +import "qrc:/const" +import "qrc:/qtmvvm/views" + +Item { + id: root + implicitWidth: width + implicitHeight: 25 + property var isDisable: false + property var viewModelProperty + property var isProbeEnableProperty + property alias model: idComobBox.model + ComboBox { + id: idComobBox + visible: isDisable + model: probeList + width: parent.width + implicitWidth: width + implicitHeight: parent.height + MvvmBinding { + viewModel: mainView.viewModel + viewProperty: "currentIndex" + viewModelProperty: root.viewModelProperty + } + } + Text { + visible: !isDisable + text: idComobBox.currentText + anchors.fill: parent + horizontalAlignment: Text.AlignHCenter + } + + MvvmBinding { + viewModel: mainView.viewModel + viewProperty: "isDisable" + viewModelProperty: isProbeEnableProperty + } +} diff --git a/ui/emulator/items/TopLeftTop.qml b/ui/emulator/items/TopLeftTop.qml index 34462ab..56a55b9 100644 --- a/ui/emulator/items/TopLeftTop.qml +++ b/ui/emulator/items/TopLeftTop.qml @@ -11,77 +11,84 @@ import "qrc:/const" import "qrc:/qtmvvm/views" GridLayout { - x: 70 + x: 20 y: 50 - rowSpacing: 36 + rowSpacing: 30 columns: 4 - ProbeButton { - name: "probe1" - image: "qrc:/icons/topLeft/probe.png" + property var widthOfBtns: 130 + property var probeList: [] + + Item { + Layout.fillWidth: true + implicitHeight: Const.macroButton * 2 + ProbeButton { + anchors.centerIn: parent + implicitWidth: width * 1.25 + name: "slot4" + image: "qrc:/icons/topLeft/probe.png" + } } - ProbeButton { - name: "probe2" - image: "qrc:/icons/topLeft/probe.png" + Item { + Layout.fillWidth: true + implicitHeight: Const.macroButton * 2 + ProbeButton { + anchors.centerIn: parent + implicitWidth: width * 1.25 + name: "slot3" + image: "qrc:/icons/topLeft/probe.png" + } } - ProbeButton { - name: "probe3" - image: "qrc:/icons/topLeft/probe.png" + Item { + Layout.fillWidth: true + implicitHeight: Const.macroButton * 2 + ProbeButton { + anchors.centerIn: parent + implicitWidth: width * 1.25 + name: "slot2" + image: "qrc:/icons/topLeft/probe.png" + } } - ProbeButton { - name: "probe4" - image: "qrc:/icons/topLeft/probe.png" + Item { + Layout.fillWidth: true + implicitHeight: Const.macroButton * 2 + ProbeButton { + anchors.centerIn: parent + implicitWidth: width * 1.25 + name: "slot1" + image: "qrc:/icons/topLeft/probe.png" + } } - property var widthOfBtns: 130 - property var probeList: [] MvvmBinding { viewModel: mainView.viewModel viewProperty: "probeList" viewModelProperty: "probeList" } - ComboBox { + + DropDownWithDisable { + viewModelProperty: "currentSelectedProbe4" model: probeList width: widthOfBtns - implicitWidth: width - implicitHeight: 25 - MvvmBinding { - viewModel: mainView.viewModel - viewProperty: "currentIndex" - viewModelProperty: "currentSelectedProbe1" - } + isProbeEnableProperty: "isProbeSelectionEnable4" } - ComboBox { + + DropDownWithDisable { + viewModelProperty: "currentSelectedProbe3" model: probeList width: widthOfBtns - implicitWidth: width - implicitHeight: 25 - MvvmBinding { - viewModel: mainView.viewModel - viewProperty: "currentIndex" - viewModelProperty: "currentSelectedProbe2" - } + isProbeEnableProperty: "isProbeSelectionEnable3" } - ComboBox { + DropDownWithDisable { + viewModelProperty: "currentSelectedProbe2" model: probeList width: widthOfBtns - implicitWidth: width - implicitHeight: 25 - MvvmBinding { - viewModel: mainView.viewModel - viewProperty: "currentIndex" - viewModelProperty: "currentSelectedProbe3" - } + isProbeEnableProperty: "isProbeSelectionEnable2" } - ComboBox { + DropDownWithDisable { + viewModelProperty: "currentSelectedProbe1" model: probeList width: widthOfBtns - implicitWidth: width - implicitHeight: 25 - MvvmBinding { - viewModel: mainView.viewModel - viewProperty: "currentIndex" - viewModelProperty: "currentSelectedProbe4" - } + isProbeEnableProperty: "isProbeSelectionEnable1" } } diff --git a/ui/ui.pro b/ui/ui.pro index 454f661..28feafa 100644 --- a/ui/ui.pro +++ b/ui/ui.pro @@ -1,6 +1,6 @@ TEMPLATE = app -QT += quick mvvmquick +QT += quick mvvmquick network sql CONFIG += c++14 TARGET = ConsoleEmulator diff --git a/ui/ui.qrc b/ui/ui.qrc index d7f0fdb..cd95bb2 100644 --- a/ui/ui.qrc +++ b/ui/ui.qrc @@ -97,6 +97,7 @@ emulator/items/Setting.qml emulator/items/TopLeftTop.qml emulator/elements/ProbeButton.qml + emulator/items/DropDownWithDisable.qml MainView.qml