Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Basic version of QML app #38

Merged
merged 6 commits into from
Apr 22, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 19 additions & 51 deletions communicator/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,72 +1,40 @@
cmake_minimum_required(VERSION 3.5)
cmake_minimum_required(VERSION 3.16)

project(communicator VERSION 0.1 LANGUAGES CXX)

set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)

set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Widgets)
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Widgets)

add_compile_options(-Wall -Wextra -pedantic -Wno-unused-function -Werror)
find_package(Qt6 6.2 COMPONENTS Quick REQUIRED)

set(PROJECT_SOURCES
main.cpp
mainwindow.cpp
mainwindow.h
mainwindow.ui
qt_add_executable(appcommunicator
main.cpp
)

if(${QT_VERSION_MAJOR} GREATER_EQUAL 6)
qt_add_executable(communicator
MANUAL_FINALIZATION
${PROJECT_SOURCES}
)
# Define target properties for Android with Qt 6 as:
# set_property(TARGET communicator APPEND PROPERTY QT_ANDROID_PACKAGE_SOURCE_DIR
# ${CMAKE_CURRENT_SOURCE_DIR}/android)
# For more information, see https://doc.qt.io/qt-6/qt-add-executable.html#target-creation
else()
if(ANDROID)
add_library(communicator SHARED
${PROJECT_SOURCES}
)
# Define properties for Android with Qt 5 after find_package() calls as:
# set(ANDROID_PACKAGE_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/android")
else()
add_executable(communicator
${PROJECT_SOURCES}
)
endif()
endif()

target_link_libraries(communicator PRIVATE Qt${QT_VERSION_MAJOR}::Widgets)
qt_add_qml_module(appcommunicator
URI communicator
VERSION 1.0
QML_FILES main.qml
QML_FILES RegisterPage.qml
QML_FILES LoginPage.qml
QML_FILES StartPage.qml
)

# Qt for iOS sets MACOSX_BUNDLE_GUI_IDENTIFIER automatically since Qt 6.1.
# If you are developing for iOS or macOS you should consider setting an
# explicit, fixed bundle identifier manually though.
if(${QT_VERSION} VERSION_LESS 6.1.0)
set(BUNDLE_ID_OPTION MACOSX_BUNDLE_GUI_IDENTIFIER com.example.communicator)
endif()
set_target_properties(communicator PROPERTIES
${BUNDLE_ID_OPTION}
set_target_properties(appcommunicator PROPERTIES
# MACOSX_BUNDLE_GUI_IDENTIFIER com.example.appcommunicator
MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION}
MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}
MACOSX_BUNDLE TRUE
WIN32_EXECUTABLE TRUE
)

Vicx95 marked this conversation as resolved.
Show resolved Hide resolved
target_link_libraries(appcommunicator
PRIVATE Qt6::Quick)

include(GNUInstallDirs)
install(TARGETS communicator
install(TARGETS appcommunicator
BUNDLE DESTINATION .
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)

if(QT_VERSION_MAJOR EQUAL 6)
qt_finalize_executable(communicator)
endif()
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
46 changes: 46 additions & 0 deletions communicator/LoginPage.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import QtQuick
import QtQuick.Controls
import QtQuick.Layouts

Item {
width: 800
height: 600

ColumnLayout {
spacing: 10
anchors.centerIn: parent

TextField {
id: userNameField
placeholderText: "User Name"
}

TextField {
id: passwordField
placeholderText: "Password"
echoMode: TextInput.Password
}

Button {
text: "Login"
onClicked: {
var userName = userNameField.text;
var password = passwordField.text;
console.log("Login user: ")
console.log("User Name:", userName, "Password:", password);
}
}
}

RowLayout {
width: parent.width
anchors.top: parent.top
spacing: 10
Button {
text: "Back"
onClicked: {
stackView.pop()
}
}
}
}
52 changes: 52 additions & 0 deletions communicator/RegisterPage.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import QtQuick
import QtQuick.Controls
import QtQuick.Layouts

Item {
width: 800
height: 600

ColumnLayout {
anchors.centerIn: parent
spacing: 10

TextField {
id: userNameField
placeholderText: "User Name"
}

TextField {
id: passwordField
placeholderText: "Password"
echoMode: TextInput.Password
}

TextField {
id: emailField
placeholderText: "Email"
}

Button {
text: "Register"
onClicked: {
var userName = userNameField.text;
var password = passwordField.text;
var email = emailField.text;
console.log("Register user: ")
console.log("User Name:", userName, "Password:", password, "email:", email);
}
}
}

RowLayout {
width: parent.width
anchors.top: parent.top
spacing: 10
Button {
text: "Back"
onClicked: {
stackView.pop()
}
}
}
}
87 changes: 87 additions & 0 deletions communicator/StartPage.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
import QtQuick
import QtQuick.Controls
import QtQuick.Layouts
import QtQuick.Window
Item {
ColumnLayout {
anchors.fill: parent
spacing: 10

Text {
text: "Simple Text Communicator"
font.pixelSize: 40
color: "black"
// anchors.horizontalCenter: parent.horizontalCenter
Layout.alignment: Qt.AlignHCenter
}

//@TODO add logo here
// Item {
// Layout.alignment: Qt.AlignHCenter
// width: parent.width / 2
// height: parent.height / 4

// Image {
// anchors.top: parent.bottom
// source: "logo.png"
// width: parent.width / 2
// height: parent.height / 4
// }
// }

RowLayout {
anchors {
horizontalCenter: parent.horizontalCenter
bottom: parent.bottom

}
lukasz126 marked this conversation as resolved.
Show resolved Hide resolved

spacing: 10

Item {
width: parent.width / 2 - 5
height: parent.height / 2
}

Item {
width: parent.width / 2 - 5
height: parent.height / 2

GridLayout {
columns: 2
anchors.bottom: parent.bottom
anchors.bottomMargin: 20
anchors.horizontalCenter: parent.horizontalCenter

Button {
text: "Register"
Layout.alignment: Qt.AlignHCenter | Qt.AlignVCenter
width: parent.width / 15
height: parent.height / 40
font.pixelSize: 30
MouseArea {
anchors.fill: parent
onClicked: {
stackView.push(registerPage)
}
}
}

Button {
text: "Login"
Layout.alignment: Qt.AlignHCenter | Qt.AlignVCenter
width: parent.width / 15
height: parent.height / 40
font.pixelSize: 30
MouseArea {
anchors.fill: parent
onClicked: {
stackView.push(loginPage)
}
}
}
}
}
}
}
}
26 changes: 19 additions & 7 deletions communicator/main.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,22 @@
#include <QApplication>
#include <QGuiApplication>
#include <QQmlApplicationEngine>

#include "mainwindow.h"
int main(int argc, char *argv[])
{
QGuiApplication app(argc, argv);

int main(int argc, char *argv[]) {
QApplication a(argc, argv);
MainWindow w;
w.show();
return a.exec();
QQmlApplicationEngine engine;
const QUrl url(u"qrc:/communicator/main.qml"_qs);
QObject::connect(
&engine,
&QQmlApplicationEngine::objectCreated,
&app,
[url](QObject *obj, const QUrl &objUrl) {
if (!obj && url == objUrl)
QCoreApplication::exit(-1);
},
Qt::QueuedConnection);
engine.load(url);

return app.exec();
}
32 changes: 32 additions & 0 deletions communicator/main.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import QtQuick
import QtQuick.Controls
import QtQuick.Layouts

ApplicationWindow {
visible: true
width: 800
height: 600
title: "Login/Register"
lukasz126 marked this conversation as resolved.
Show resolved Hide resolved

StackView {
id: stackView
anchors.fill: parent

initialItem: startPage

Component {
id: startPage
StartPage {}
}

Component {
id: registerPage
RegisterPage {}
}

Component {
id: loginPage
LoginPage {}
}
}
}
7 changes: 0 additions & 7 deletions communicator/mainwindow.cpp

This file was deleted.

22 changes: 0 additions & 22 deletions communicator/mainwindow.h

This file was deleted.

Loading
Loading