Skip to content

Commit

Permalink
#82 Keyboard + Config + Mqtt Sending
Browse files Browse the repository at this point in the history
  • Loading branch information
Peyton-McKee committed Feb 27, 2024
1 parent 9c17732 commit 0c45523
Show file tree
Hide file tree
Showing 14 changed files with 384 additions and 98 deletions.
4 changes: 3 additions & 1 deletion NERODevelopment/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,9 @@ set(PROJECT_SOURCES
find_package(Qt6 REQUIRED COMPONENTS Core Gui Qml Quick Network Mqtt Protobuf)

qt_add_executable(NEROApp ${PROJECT_SOURCES}
src/controllers/flappybirdcontroller.h src/controllers/flappybirdcontroller.cpp)
src/controllers/flappybirdcontroller.h src/controllers/flappybirdcontroller.cpp
src/controllers/keyboardcontroller.h src/controllers/keyboardcontroller.cpp
src/controllers/configurationcontroller.h src/controllers/configurationcontroller.cpp)

qt_add_resources(NEROApp "configuration"
PREFIX "/"
Expand Down
101 changes: 81 additions & 20 deletions NERODevelopment/content/Configuration.qml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import QtQuick 2.15
import QtQuick.Controls
import NERO

Item {
id: configuration
Expand All @@ -8,56 +9,116 @@ Item {
property string driverText: ""
property string locationText: ""
property string systemText: ""
property int selectedConfigurationIndex: configurationController.selectedConfigurationIndex
property bool isKeyboardSelected: configurationController.isKeyboardSelected
property int inputHeight: 70

Keys.onPressed: event => {
switch (event.key) {
case Qt.Key_Up:
configurationController.upButtonPressed()
break
case Qt.Key_Down:
configurationController.downButtonPressed()
break
case Qt.Key_Return:
configurationController.enterButtonPressed()
break
}
}

ValueText {
id: title
anchors.top: parent.top
anchors.topMargin: 5
anchors.horizontalCenter: parent.horizontalCenter
id: title
text: qsTr("Configuration")
}

Row {
id: driverRow
id: driverBackground
anchors.top: title.bottom
anchors.topMargin: 5
anchors.horizontalCenter: parent.horizontalCenter

LabelText {
text: "Driver"
}

KeyboardInput {
label: "joe mama"
id: driverKeyboard
label: "Enter Driver"
onAccepted: {
configuration.driverText = text
configuration.focus = true
configurationController.setDriverName(text)
configurationController.setIsKeyboardSelected(false)
}
selected: configuration.isKeyboardSelected
&& configuration.selectedConfigurationIndex === 0

border.width: configuration.selectedConfigurationIndex === 0 ? 2 : 0
border.color: "blue"
height: configuration.inputHeight
}
}

Row {
id: locationRow
anchors.top: driverRow.bottom
id: locationBackground
anchors.top: driverBackground.bottom
anchors.topMargin: 5
LabelText {
text: "Location"
}
anchors.horizontalCenter: parent.horizontalCenter

KeyboardInput {
label: "Enter Location"
onAccepted: {
configuration.locationText = text
configuration.focus = true
configurationController.setLocationName(text)
configurationController.setIsKeyboardSelected(false)
}
selected: configuration.isKeyboardSelected
&& configuration.selectedConfigurationIndex === 1

ValueText {
text: configuration.locationText
border.width: configuration.selectedConfigurationIndex === 1 ? 2 : 0
border.color: "blue"
height: configuration.inputHeight
}
}

Row {
id: systemRow
anchors.top: locationRow.bottom
id: systemBackground
anchors.top: locationBackground.bottom
anchors.topMargin: 5
LabelText {
text: "System"
anchors.horizontalCenter: parent.horizontalCenter
KeyboardInput {
label: "Enter System"
onAccepted: {
configuration.systemText = text
configuration.focus = true
configurationController.setSystemName(text)
configurationController.setIsKeyboardSelected(false)
}
selected: configuration.isKeyboardSelected
&& configuration.selectedConfigurationIndex === 2

border.width: configuration.selectedConfigurationIndex === 2 ? 2 : 0
border.color: "blue"
height: configuration.inputHeight
}
}

Button {
id: submitButton
anchors.top: systemBackground.bottom
anchors.topMargin: 5
anchors.horizontalCenter: parent.horizontalCenter

background: Rectangle {
border.color: "blue"
border.width: configuration.selectedConfigurationIndex === 3 ? 2 : 0
radius: 10
}

ValueText {
text: configuration.systemText
contentItem: LabelText {
text: "Save"
color: "black"
}
}
}
129 changes: 71 additions & 58 deletions NERODevelopment/content/Keyboard.qml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import QtQuick 2.15
import QtQuick.Controls
import NERO

Item {
id: root
Expand All @@ -22,24 +23,26 @@ Item {
property bool symbols: false
property double columns: 10
property double rows: 5
property int selectedIndex: 0
property int selectedIndex: keyboardViewController.selectedIndex
property bool isKeySelected: keyboardViewController.selectedKey
property int numKeys: 44

Keys.onPressed: event => {
console.log(selectedIndex)
switch (event.key) {
case Qt.Key_Up:
selectedIndex = Math.max(0, selectedIndex - columns)
keyboardViewController.upButtonPressed()
break
case Qt.Key_Down:
selectedIndex = Math.min(numKeys,
selectedIndex + columns)
keyboardViewController.downButtonPressed()
break
case Qt.Key_Left:
selectedIndex = Math.max(0, selectedIndex - 1)
keyboardViewController.leftButtonPressed()
break
case Qt.Key_Right:
selectedIndex = Math.min(numKeys, selectedIndex + 1)
keyboardViewController.rightButtonPressed()
break
case Qt.Key_Return:
keyboardViewController.enterButtonPressed()
break
}
}
Expand Down Expand Up @@ -161,13 +164,15 @@ Item {
width: modelData.width * keyboard.width / columns - rowSpacing
height: keyboard.height / rows - columnSpacing
highlighted: root.selectedIndex === index
focus: root.selectedIndex === index
property bool isKeySelected: root.isKeySelected

onClicked: root.clicked(text)

Keys.onReturnPressed: {
clicked()
event.accepted = true
onIsKeySelectedChanged: {
if (root.isKeySelected && highlighted) {
clicked()
event.accepted = true
}
}
}
}
Expand Down Expand Up @@ -227,15 +232,16 @@ Item {
) : modelData.text
width: modelData.width * keyboard.width / columns - rowSpacing
height: keyboard.height / rows - columnSpacing

highlighted: root.selectedIndex === index + root.columns
focus: root.selectedIndex === index + root.columns

onClicked: root.clicked(text)

Keys.onReturnPressed: {
clicked()
event.accepted = true
property bool isKeySelected: root.isKeySelected

onIsKeySelectedChanged: {
if (root.isKeySelected && highlighted) {
clicked()
event.accepted = true
}
}
}
}
Expand Down Expand Up @@ -298,13 +304,15 @@ Item {
width: modelData.width * keyboard.width / columns - rowSpacing
height: keyboard.height / rows - columnSpacing
highlighted: root.selectedIndex === index + 2 * root.columns
focus: root.selectedIndex === index + 2 * root.columns
property bool isKeySelected: root.isKeySelected

onClicked: root.clicked(text)

Keys.onReturnPressed: {
clicked()
event.accepted = true
onIsKeySelectedChanged: {
if (root.isKeySelected && highlighted) {
clicked()
event.accepted = true
}
}
}
}
Expand Down Expand Up @@ -361,13 +369,15 @@ Item {
width: modelData.width * keyboard.width / columns - rowSpacing
height: keyboard.height / rows - columnSpacing
highlighted: root.selectedIndex === index + 3 * root.columns + 1
focus: root.selectedIndex === index + 3 * root.columns + 1
property bool isKeySelected: root.isKeySelected

onClicked: root.clicked(text)

Keys.onReturnPressed: {
clicked()
event.accepted = true
onIsKeySelectedChanged: {
if (root.isKeySelected && highlighted) {
clicked()
event.accepted = true
}
}
}
}
Expand Down Expand Up @@ -402,13 +412,15 @@ Item {
width: modelData.width * keyboard.width / columns - rowSpacing
height: keyboard.height / rows - columnSpacing
highlighted: root.selectedIndex === index + 4 * root.columns
focus: root.selectedIndex === index + 4 * root.columns
property bool isKeySelected: root.isKeySelected

onClicked: root.clicked(text)

Keys.onReturnPressed: {
clicked()
event.accepted = true
onIsKeySelectedChanged: {
if (root.isKeySelected && highlighted) {
clicked()
event.accepted = true
}
}
}
}
Expand All @@ -418,33 +430,34 @@ Item {
}

signal clicked(string text)
onClicked: {
if (text == '\u2190') {
// LEFTWARDS ARROW (backspace)
var position = textInput.cursorPosition
textInput.text = textInput.text.substring(
0,
textInput.cursorPosition - 1) + textInput.text.substring(
textInput.cursorPosition, textInput.text.length)
textInput.cursorPosition = position - 1
} else if (text == '\u2191')
shift = !shift // UPWARDS ARROW (shift)
else if (text == '@#')
symbols = true
else if (text == 'AB')
symbols = false
else if (text == '\u21B5')
accepted(textInput.text) // DOWNWARDS ARROW WITH CORNER LEFTWARDS (enter)
else {
// insert text
var position = textInput.cursorPosition
textInput.text = textInput.text.substring(
0,
textInput.cursorPosition) + text + textInput.text.substring(
textInput.cursorPosition, textInput.text.length)
textInput.cursorPosition = position + 1

shift = false // momentary
}
}
onClicked: text => {
if (text === '\u2190') {
// LEFTWARDS ARROW (backspace)
var position = textInput.cursorPosition
textInput.text = textInput.text.substring(
0,
textInput.cursorPosition - 1) + textInput.text.substring(
textInput.cursorPosition, textInput.text.length)
textInput.cursorPosition = position - 1
} else if (text === '\u2191')
shift = !shift // UPWARDS ARROW (shift)
else if (text === '@#')
symbols = true
else if (text === 'AB')
symbols = false
else if (text === '\u21B5')
accepted(
textInput.text) // DOWNWARDS ARROW WITH CORNER LEFTWARDS (enter)
else {
// insert text
var position = textInput.cursorPosition
textInput.text = textInput.text.substring(
0,
textInput.cursorPosition) + text + textInput.text.substring(
textInput.cursorPosition, textInput.text.length)
textInput.cursorPosition = position + 1

shift = false // momentary
}
}
}
Loading

0 comments on commit 0c45523

Please sign in to comment.