This commit is contained in:
2025-09-28 17:05:51 +08:00
parent 8eb80ab66d
commit d97fa3e0fe
398 changed files with 18737 additions and 0 deletions

View File

@@ -0,0 +1,40 @@
# Copyright (c) Daniel Gakwaya.
# SPDX-License-Identifier: MIT
cmake_minimum_required(VERSION 3.16)
project(1-TextInput VERSION 0.1 LANGUAGES CXX)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
find_package(Qt6 6.5 REQUIRED COMPONENTS Quick)
qt_standard_project_setup(REQUIRES 6.5)
qt_add_executable(app1-TextInput
main.cpp
)
qt_add_qml_module(app1-TextInput
URI 1-TextInput
VERSION 1.0
QML_FILES Main.qml
)
set_target_properties(app1-TextInput PROPERTIES
MACOSX_BUNDLE_GUI_IDENTIFIER my.example.com
MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION}
MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}
MACOSX_BUNDLE TRUE
WIN32_EXECUTABLE TRUE
)
target_link_libraries(app1-TextInput
PRIVATE Qt6::Quick
)
install(TARGETS app1-TextInput
BUNDLE DESTINATION .
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)

View File

@@ -0,0 +1,82 @@
// Copyright (c) Daniel Gakwaya.
// SPDX-License-Identifier: MIT
import QtQuick
Window {
width: 640
height: 480
visible: true
title: qsTr("TextInput")
Row {
x: 10; y: 10
spacing: 10
Rectangle {
id: firstNameRectId
width: firstNameLabelId.implicitWidth + 20
height: firstNameLabelId.implicitHeight + 20
color: "beige"
Text {
id: firstNameLabelId
anchors.centerIn: parent
text: "FirstName: "
}
}
Rectangle {
id: firstNameTextRectId
color: "beige"
width: firstNameTextId.implicitWidth + 20
height: firstNameTextId.implicitHeight + 20
TextInput {
id: firstNameTextId
anchors.centerIn: parent
focus: true
text: "Type in your first name"
onEditingFinished: {
console.log("The first name changed to: " + text)
}
}
}
}
Row {
x: 10; y: 60
spacing: 10
Rectangle {
id: lastNameRectId
width: lastNameLabelId.implicitWidth + 20
height: lastNameLabelId.implicitHeight + 20
color: "beige"
Text {
id: lastNameLabelId
anchors.centerIn: parent
text: "LastName: "
}
}
Rectangle {
id: lastNameTextRectId
color: "beige"
width: lastNameTextId.implicitWidth + 20
height: lastNameTextId.implicitHeight + 20
TextInput {
id: lastNameTextId
anchors.centerIn: parent
focus: true
text: "Type in your last name"
onEditingFinished: {
console.log("The last name changed to: " + text)
}
}
}
}
}

View File

@@ -0,0 +1,18 @@
// Copyright (c) Daniel Gakwaya.
// SPDX-License-Identifier: MIT
#include <QGuiApplication>
#include <QQmlApplicationEngine>
int main(int argc, char *argv[])
{
QGuiApplication app(argc, argv);
QQmlApplicationEngine engine;
QObject::connect(&engine, &QQmlApplicationEngine::objectCreationFailed,
&app, []() { QCoreApplication::exit(-1); },
Qt::QueuedConnection);
engine.loadFromModule("1-TextInput", "Main");
return app.exec();
}

View File

@@ -0,0 +1,40 @@
# Copyright (c) Daniel Gakwaya.
# SPDX-License-Identifier: MIT
cmake_minimum_required(VERSION 3.16)
project(2-TextEdit VERSION 0.1 LANGUAGES CXX)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
find_package(Qt6 6.5 REQUIRED COMPONENTS Quick)
qt_standard_project_setup(REQUIRES 6.5)
qt_add_executable(app2-TextEdit
main.cpp
)
qt_add_qml_module(app2-TextEdit
URI 2-TextEdit
VERSION 1.0
QML_FILES Main.qml
)
set_target_properties(app2-TextEdit PROPERTIES
MACOSX_BUNDLE_GUI_IDENTIFIER my.example.com
MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION}
MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}
MACOSX_BUNDLE TRUE
WIN32_EXECUTABLE TRUE
)
target_link_libraries(app2-TextEdit
PRIVATE Qt6::Quick
)
install(TARGETS app2-TextEdit
BUNDLE DESTINATION .
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)

View File

@@ -0,0 +1,69 @@
// Copyright (c) Daniel Gakwaya.
// SPDX-License-Identifier: MIT
import QtQuick
Window {
visible: true
width: 640
height: 480
title: qsTr("TextEdit Demo")
/*
TextEdit {
id: textInputId
width: 240
anchors.centerIn: parent
text: "<strong>Because</strong> we want to use our server locally, we set our domain name \r to be <font color = 'red' >localhost </font>. If we had set it up to\n be something else, we would have to go mess with the host files to resolve whatever we put in here to a recognizable network address. ustleaveinlocalhostitisgoodenoughforourlocalusepurposes. Leave the rest to defaults and hit continue. You are then given a choice for the database you want to use"
wrapMode: TextEdit.Wrap
//textFormat: TextEdit.RichText
font.family: "Helvetica"
font.pointSize: 20
color: "blue"
focus: true
onEditingFinished: {
console.log("The current text is: "+ text)
}
}
*/
TextEdit {
id: textInputId
wrapMode: TextEdit.Wrap
textFormat: TextEdit.RichText
width: 240
//text: "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."
text: "<strong>Because</strong> we want to use our server locally, we set our domain name \r to be <font color = 'red' >localhost </font>."
font.family: "Helvetica"
font.pointSize: 20
color: "blue"
focus: true
onEditingFinished: {
console.log("The current text is: "+ text)
}
}
Rectangle {
id: mRectId
width: 240
height: 100
color: "red"
anchors.top: textInputId.bottom
MouseArea{
anchors.fill: parent
onClicked: {
console.log("The new text is: "+textInputId.text)
}
}
}
}

View File

@@ -0,0 +1,19 @@
// Copyright (c) Daniel Gakwaya.
// SPDX-License-Identifier: MIT
#include <QGuiApplication>
#include <QQmlApplicationEngine>
int main(int argc, char *argv[])
{
QGuiApplication app(argc, argv);
QQmlApplicationEngine engine;
QObject::connect(&engine, &QQmlApplicationEngine::objectCreationFailed,
&app, []() { QCoreApplication::exit(-1); },
Qt::QueuedConnection);
engine.loadFromModule("2-TextEdit", "Main");
return app.exec();
}

View File

@@ -0,0 +1,40 @@
# Copyright (c) Daniel Gakwaya.
# SPDX-License-Identifier: MIT
cmake_minimum_required(VERSION 3.16)
project(3-MouseArea VERSION 0.1 LANGUAGES CXX)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
find_package(Qt6 6.5 REQUIRED COMPONENTS Quick)
qt_standard_project_setup(REQUIRES 6.5)
qt_add_executable(app3-MouseArea
main.cpp
)
qt_add_qml_module(app3-MouseArea
URI 3-MouseArea
VERSION 1.0
QML_FILES Main.qml
)
set_target_properties(app3-MouseArea PROPERTIES
MACOSX_BUNDLE_GUI_IDENTIFIER my.example.com
MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION}
MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}
MACOSX_BUNDLE TRUE
WIN32_EXECUTABLE TRUE
)
target_link_libraries(app3-MouseArea
PRIVATE Qt6::Quick
)
install(TARGETS app3-MouseArea
BUNDLE DESTINATION .
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)

View File

@@ -0,0 +1,78 @@
// Copyright (c) Daniel Gakwaya.
// SPDX-License-Identifier: MIT
import QtQuick
Window {
visible: true
width: 640
height: 480
title: qsTr("MouseArea Demo")
Rectangle {
id: containerRectId
width: parent.width
height: 200
color: "beige"
Rectangle {
id: movingRectId
width: 50
height: width
color: "blue"
}
MouseArea{
anchors.fill: parent
onClicked: function(mouse) {
console.log(mouse.x)
movingRectId.x = mouse.x
}
onWheel:function(wheel) {
console.log(" x: "+ wheel.x + ", y: "+ wheel.y + ", angleData: "+ wheel.angleDelta)
}
hoverEnabled: true
onHoveredChanged: {
if (containsMouse)
{
containerRectId.color = "red"
}else {
containerRectId.color = "green"
}
}
}
}
Rectangle {
id: dragContainerId
width : parent.width
height: 200
color: "beige"
y: 250
Rectangle {
id: draggableRect
width: 50
height: width
color: "blue"
onXChanged: {
console.log("x coordinate is: "+ x)
}
}
MouseArea{
anchors.fill: parent
drag.target: draggableRect
drag.axis: Drag.XAxis
drag.minimumX: 0
drag.maximumX: dragContainerId.width - draggableRect.width
}
}
}

View File

@@ -0,0 +1,19 @@
// Copyright (c) Daniel Gakwaya.
// SPDX-License-Identifier: MIT
#include <QGuiApplication>
#include <QQmlApplicationEngine>
int main(int argc, char *argv[])
{
QGuiApplication app(argc, argv);
QQmlApplicationEngine engine;
QObject::connect(&engine, &QQmlApplicationEngine::objectCreationFailed,
&app, []() { QCoreApplication::exit(-1); },
Qt::QueuedConnection);
engine.loadFromModule("3-MouseArea", "Main");
return app.exec();
}

View File

@@ -0,0 +1,40 @@
# Copyright (c) Daniel Gakwaya.
# SPDX-License-Identifier: MIT
cmake_minimum_required(VERSION 3.16)
project(4-KeysAttachedProperty VERSION 0.1 LANGUAGES CXX)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
find_package(Qt6 6.5 REQUIRED COMPONENTS Quick)
qt_standard_project_setup(REQUIRES 6.5)
qt_add_executable(app4-KeysAttachedProperty
main.cpp
)
qt_add_qml_module(app4-KeysAttachedProperty
URI 4-KeysAttachedProperty
VERSION 1.0
QML_FILES Main.qml
)
set_target_properties(app4-KeysAttachedProperty PROPERTIES
MACOSX_BUNDLE_GUI_IDENTIFIER my.example.com
MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION}
MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}
MACOSX_BUNDLE TRUE
WIN32_EXECUTABLE TRUE
)
target_link_libraries(app4-KeysAttachedProperty
PRIVATE Qt6::Quick
)
install(TARGETS app4-KeysAttachedProperty
BUNDLE DESTINATION .
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)

View File

@@ -0,0 +1,49 @@
// Copyright (c) Daniel Gakwaya.
// SPDX-License-Identifier: MIT
import QtQuick
Window {
visible: true
width: 640
height: 480
title: qsTr("Keys Attached Property")
Rectangle {
id: containedRect
anchors.centerIn: parent
width: 300
height: 50
color: "dodgerblue"
focus: true // The rectangle needs focus for key events to fire properly
/*
Keys.onDigit5Pressed:function(event) {
console.log("Specific Signal: Pressed on Key 5")
event.accepted = true
}
*/
/*
Keys.onDigit5Pressed:function(event) {
if ( event.modifiers === Qt.ControlModifier)
{
console.log("Pressed Control + 5")
}else{
console.log("Pressed regular 5")
}
event.accepted = false
}
*/
Keys.onPressed: function(event){
if ((event.key === Qt.Key_5) && (event.modifiers & Qt.ControlModifier)){
console.log("General Signal: Pressed Control + 5")
}else if(event.key === Qt.Key_5){
console.log("General Signal: Key 5 was pressed alone.")
}
}
}
}

View File

@@ -0,0 +1,19 @@
// Copyright (c) Daniel Gakwaya.
// SPDX-License-Identifier: MIT
#include <QGuiApplication>
#include <QQmlApplicationEngine>
int main(int argc, char *argv[])
{
QGuiApplication app(argc, argv);
QQmlApplicationEngine engine;
QObject::connect(&engine, &QQmlApplicationEngine::objectCreationFailed,
&app, []() { QCoreApplication::exit(-1); },
Qt::QueuedConnection);
engine.loadFromModule("4-KeysAttachedProperty", "Main");
return app.exec();
}

View File

@@ -0,0 +1,40 @@
# Copyright (c) Daniel Gakwaya.
# SPDX-License-Identifier: MIT
cmake_minimum_required(VERSION 3.16)
project(5-KeyNavigation VERSION 0.1 LANGUAGES CXX)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
find_package(Qt6 6.5 REQUIRED COMPONENTS Quick)
qt_standard_project_setup(REQUIRES 6.5)
qt_add_executable(app5-KeyNavigation
main.cpp
)
qt_add_qml_module(app5-KeyNavigation
URI 5-KeyNavigation
VERSION 1.0
QML_FILES Main.qml
)
set_target_properties(app5-KeyNavigation PROPERTIES
MACOSX_BUNDLE_GUI_IDENTIFIER my.example.com
MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION}
MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}
MACOSX_BUNDLE TRUE
WIN32_EXECUTABLE TRUE
)
target_link_libraries(app5-KeyNavigation
PRIVATE Qt6::Quick
)
install(TARGETS app5-KeyNavigation
BUNDLE DESTINATION .
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)

View File

@@ -0,0 +1,98 @@
// Copyright (c) Daniel Gakwaya.
// SPDX-License-Identifier: MIT
import QtQuick
Window {
visible: true
width: 640
height: 480
title: qsTr("Key Navigation Demo")
Grid {
anchors.centerIn: parent
columns: 2
Rectangle {
id: topLeft
width: 100; height: 100
color: focus ? "red" : "lightgray"
focus: true
KeyNavigation.right: topRight
KeyNavigation.down: bottomLeft
}
Rectangle {
id: topRight
width: 100; height: 100
color: focus ? "red" : "lightgray"
KeyNavigation.left: topLeft
KeyNavigation.down: bottomRight
}
Rectangle {
id: bottomLeft
width: 100; height: 100
color: focus ? "red" : "lightgray"
KeyNavigation.right: bottomRight
KeyNavigation.up: topLeft
}
Rectangle {
id: bottomRight
width: 100; height: 100
color: focus ? "red" : "lightgray"
KeyNavigation.left: bottomLeft
KeyNavigation.up: topRight
}
}
/*
Row {
anchors.centerIn: parent
Rectangle{
id: firstRectId
width: 200
height: width
border.color: "black"
color: "red"
focus: true
onFocusChanged: {
color = focus?"red":"gray"
}
Keys.onDigit5Pressed: {
console.log("I am Rect1")
}
KeyNavigation.right: secondRectId
}
Rectangle{
id: secondRectId
width: 200
height: width
border.color: "black"
color: "gray"
onFocusChanged: {
color = focus?"red":"gray"
}
Keys.onDigit5Pressed: {
console.log("I am Rect2")
}
KeyNavigation.left: firstRectId
}
}
*/
}

View File

@@ -0,0 +1,19 @@
// Copyright (c) Daniel Gakwaya.
// SPDX-License-Identifier: MIT
#include <QGuiApplication>
#include <QQmlApplicationEngine>
int main(int argc, char *argv[])
{
QGuiApplication app(argc, argv);
QQmlApplicationEngine engine;
QObject::connect(&engine, &QQmlApplicationEngine::objectCreationFailed,
&app, []() { QCoreApplication::exit(-1); },
Qt::QueuedConnection);
engine.loadFromModule("5-KeyNavigation", "Main");
return app.exec();
}

View File

@@ -0,0 +1,40 @@
# Copyright (c) Daniel Gakwaya.
# SPDX-License-Identifier: MIT
cmake_minimum_required(VERSION 3.16)
project(6-FocusScope VERSION 0.1 LANGUAGES CXX)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
find_package(Qt6 6.5 REQUIRED COMPONENTS Quick)
qt_standard_project_setup(REQUIRES 6.5)
qt_add_executable(app6-FocusScope
main.cpp
)
qt_add_qml_module(app6-FocusScope
URI 6-FocusScope
VERSION 1.0
QML_FILES Main.qml MButton.qml
)
set_target_properties(app6-FocusScope PROPERTIES
MACOSX_BUNDLE_GUI_IDENTIFIER my.example.com
MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION}
MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}
MACOSX_BUNDLE TRUE
WIN32_EXECUTABLE TRUE
)
target_link_libraries(app6-FocusScope
PRIVATE Qt6::Quick
)
install(TARGETS app6-FocusScope
BUNDLE DESTINATION .
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)

View File

@@ -0,0 +1,40 @@
// Copyright (c) Daniel Gakwaya.
// SPDX-License-Identifier: MIT
import QtQuick
FocusScope {
width: containerRectId.width
height: containerRectId.height
property alias color: containerRectId.color
Rectangle {
id : containerRectId
width: 300
height: 50
color: "beige"
focus: true
Text {
id : textId
anchors.centerIn: parent
text: "Default"
}
Keys.onPressed:function(event) {
if(event.key === Qt.Key_1)
{
textId.text = "Pressed on Key1"
}else if(event.key === Qt.Key_2)
{
textId.text = "Pressed on Key2"
}else{
textId.text = "Pressed on another key : "+ event.key
}
}
}
}

View File

@@ -0,0 +1,22 @@
// Copyright (c) Daniel Gakwaya.
// SPDX-License-Identifier: MIT
import QtQuick
Window {
visible: true
width: 640
height: 480
title: qsTr("FocusScope Demo")
Column {
MButton{
color: "yellow"
focus: true
}
MButton{
color: "green"
}
}
}

View File

@@ -0,0 +1,19 @@
// Copyright (c) Daniel Gakwaya.
// SPDX-License-Identifier: MIT
#include <QGuiApplication>
#include <QQmlApplicationEngine>
int main(int argc, char *argv[])
{
QGuiApplication app(argc, argv);
QQmlApplicationEngine engine;
QObject::connect(&engine, &QQmlApplicationEngine::objectCreationFailed,
&app, []() { QCoreApplication::exit(-1); },
Qt::QueuedConnection);
engine.loadFromModule("6-FocusScope", "Main");
return app.exec();
}