mirror of
https://github.com/QuasarApp/QMLLoginView.git
synced 2025-05-12 09:29:41 +00:00
added support of module
This commit is contained in:
parent
ce8e1688b3
commit
42d84d1b02
@ -10,29 +10,23 @@ import QtQuick.Controls 2.12
|
||||
import QtQuick.Layouts 1.12
|
||||
import QtQuick.Controls.Material 2.12
|
||||
import QtQuick.Controls.Universal 2.12
|
||||
import QtQuick.Window 2.12
|
||||
|
||||
Control {
|
||||
|
||||
height: 110
|
||||
height: (withTitle)? 35 * Screen.pixelDensity: 15 * Screen.pixelDensity
|
||||
|
||||
property string title: ""
|
||||
property string help: ""
|
||||
property bool lightMode: themeSwitch.lightMode
|
||||
property string title: ""
|
||||
property bool withTitle: true
|
||||
|
||||
ColumnLayout {
|
||||
LVMSwitch {
|
||||
id: themeSwitch
|
||||
text: qsTr("Light theme");
|
||||
Layout.alignment: Qt.AlignRight
|
||||
Layout.preferredHeight: 30
|
||||
}
|
||||
|
||||
Label {
|
||||
text: title;
|
||||
font.pixelSize: 24
|
||||
font.bold: true
|
||||
Layout.alignment: Qt.AlignLeft
|
||||
|
||||
visible: withTitle
|
||||
}
|
||||
|
||||
Label {
|
||||
|
@ -13,24 +13,40 @@ import QtQuick.Controls.Universal 2.12
|
||||
|
||||
Page {
|
||||
|
||||
id: root;
|
||||
height: 500
|
||||
width: 400
|
||||
|
||||
header: LVMHeader{
|
||||
id: header
|
||||
title: (conntent.isRegisterNewUser)? qsTr("Sign Up"): qsTr("Login In")
|
||||
help: (conntent.isRegisterNewUser)? qsTr('please fill this form to create an account'):
|
||||
qsTr('please fill this form to login in your account')
|
||||
withTitle: root.withTitle
|
||||
title: (conntent.isRegisterNewUser)? qsTr("SignUp"): qsTr("LogIn")
|
||||
help: (conntent.isRegisterNewUser)? qsTr('Please fill this form to create an account'):
|
||||
qsTr('Please fill this form to login in your account')
|
||||
}
|
||||
property bool withTitle: (lognViewModel)? lognViewModel.fTitle: false
|
||||
property bool lastName: (lognViewModel)? lognViewModel.fLastName: false
|
||||
property bool firstName: (lognViewModel)? lognViewModel.fFirstName: false
|
||||
property bool nickName: (lognViewModel)? lognViewModel.fNickname: false
|
||||
property bool email: (lognViewModel)? lognViewModel.fEMail: false
|
||||
|
||||
property bool lightMode: header.lightMode
|
||||
property var lognViewModel: null
|
||||
property bool registerNewUser: true
|
||||
signal loginClicked(var isregister);
|
||||
function clear() {
|
||||
|
||||
Material.theme: (lightMode)? Material.Light: Material.Dark
|
||||
Material.accent: (lightMode)? Material.LightBlue: Material.Orange
|
||||
Universal.theme: (lightMode)? Material.Light: Material.Dark
|
||||
Universal.accent: (lightMode)? Material.LightBlue: Material.Orange
|
||||
countryInput.currentIndex = -1
|
||||
pass1.text = ""
|
||||
pass2.text = ""
|
||||
termOfUse.checked = false
|
||||
}
|
||||
|
||||
Connections {
|
||||
target: userLogin
|
||||
onClearView: {
|
||||
clear();
|
||||
}
|
||||
}
|
||||
|
||||
contentItem:
|
||||
Item {
|
||||
@ -69,10 +85,11 @@ Page {
|
||||
}
|
||||
|
||||
LVMTextInput {
|
||||
id: firstNameInput
|
||||
placeholderText: qsTr("First Name")
|
||||
Layout.columnSpan: (content.width > 350)? 1 : 2;
|
||||
Layout.fillWidth: true
|
||||
visible: conntent.isRegisterNewUser
|
||||
visible: conntent.isRegisterNewUser && root.firstName
|
||||
tooltip: (hasError)? qsTr("Empy or incorrect name. Please enter yuor name."): ""
|
||||
hasError: (conntent.errors && conntent.errors.firstName);
|
||||
onTextChanged: {
|
||||
@ -81,13 +98,17 @@ Page {
|
||||
}
|
||||
hasEdited = true
|
||||
}
|
||||
text: lognViewModel.data.firstName;
|
||||
|
||||
}
|
||||
|
||||
LVMTextInput {
|
||||
id: lastNameInput
|
||||
|
||||
placeholderText: qsTr("Last Name")
|
||||
Layout.columnSpan: (content.width > 350)? 1 : 2;
|
||||
Layout.fillWidth: true
|
||||
visible: conntent.isRegisterNewUser
|
||||
visible: conntent.isRegisterNewUser && root.lastName
|
||||
hasError: (conntent.errors && conntent.errors.lastName);
|
||||
|
||||
onTextChanged: {
|
||||
@ -97,27 +118,35 @@ Page {
|
||||
hasEdited = true
|
||||
|
||||
}
|
||||
text: lognViewModel.data.lastName;
|
||||
|
||||
|
||||
}
|
||||
|
||||
LVMComboBox {
|
||||
id: countryInput
|
||||
|
||||
placeholderText: qsTr("Select you country")
|
||||
Layout.columnSpan: 2
|
||||
Layout.fillWidth: true
|
||||
visible: conntent.isRegisterNewUser
|
||||
visible: conntent.isRegisterNewUser && model.length
|
||||
onCurrentIndexChanged: {
|
||||
if (lognViewModel) {
|
||||
lognViewModel.data.country = lognViewModel.countryCodeList[currentIndex];
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
LVMTextInput {
|
||||
id: emailInput
|
||||
|
||||
placeholderText: qsTr("EMail")
|
||||
Layout.columnSpan: 2
|
||||
Layout.columnSpan: (root.email && root.nickName)? (content.width > 350)? 1 : 2 : 2;
|
||||
Layout.fillWidth: true
|
||||
visible: root.email
|
||||
hasError: (conntent.errors && conntent.errors.email);
|
||||
tooltip: (hasError)? qsTr("Empy or incorrect email address. Please enter yuor name.") : ""
|
||||
tooltip: (hasError)? qsTr("Empty or incorrect email address. Please enter yuor name.") : ""
|
||||
onTextChanged: {
|
||||
if (lognViewModel) {
|
||||
lognViewModel.data.email = text;
|
||||
@ -125,6 +154,29 @@ Page {
|
||||
hasEdited = true
|
||||
|
||||
}
|
||||
text: lognViewModel.data.email;
|
||||
|
||||
}
|
||||
|
||||
LVMTextInput {
|
||||
id: nicknameInput
|
||||
|
||||
placeholderText: qsTr("Nickname")
|
||||
Layout.columnSpan: (root.email && root.nickName)? (content.width > 350)? 1 : 2 : 2;
|
||||
Layout.fillWidth: true
|
||||
visible: root.nickName
|
||||
hasError: (conntent.errors && conntent.errors.nickname);
|
||||
tooltip: (hasError)? qsTr("Empty or incorrect Nickname. Please enter yuor name.") : ""
|
||||
onTextChanged: {
|
||||
if (lognViewModel) {
|
||||
lognViewModel.data.nickname = text;
|
||||
}
|
||||
hasEdited = true
|
||||
|
||||
}
|
||||
|
||||
text: lognViewModel.data.nickname;
|
||||
|
||||
}
|
||||
|
||||
LVMTextInput {
|
||||
@ -137,6 +189,7 @@ Page {
|
||||
onTextChanged: {
|
||||
content.paswordValidation()
|
||||
}
|
||||
|
||||
echoMode: TextInput.Password
|
||||
}
|
||||
|
||||
@ -174,7 +227,7 @@ Page {
|
||||
}
|
||||
|
||||
LVMButton {
|
||||
text: (conntent.isRegisterNewUser)? qsTr("Sign Up") : qsTr("Login In")
|
||||
text: (conntent.isRegisterNewUser)? qsTr("SignUp") : qsTr("LogIn")
|
||||
visible: true
|
||||
enabled: (conntent.errors && conntent.errors.noError) &&
|
||||
((conntent.isRegisterNewUser)? !pass2.hasError && termOfUse.checked: true)
|
||||
@ -187,6 +240,7 @@ Page {
|
||||
lognViewModel.loginRequest();
|
||||
}
|
||||
}
|
||||
loginClicked(conntent.isRegisterNewUser);
|
||||
}
|
||||
}
|
||||
|
||||
|
34
LoginView/src/LoginViewModule/LoginViewDialog.qml
Normal file
34
LoginView/src/LoginViewModule/LoginViewDialog.qml
Normal file
@ -0,0 +1,34 @@
|
||||
import QtQuick 2.12
|
||||
import QtQuick.Controls 2.12
|
||||
import QtQuick.Layouts 1.12
|
||||
import QtQuick.Controls.Material 2.12
|
||||
import QtQuick.Controls.Universal 2.12
|
||||
import QtQuick.Window 2.12
|
||||
|
||||
Popup {
|
||||
id: root
|
||||
property var lognViewModel: null
|
||||
|
||||
width: Math.min(100 * Screen.pixelDensity * (parent.width / parent.height),
|
||||
parent.width * 0.9);
|
||||
height: Math.min(200 * Screen.pixelDensity, parent.height * 0.9);
|
||||
|
||||
|
||||
x: parent.width / 2 - width / 2
|
||||
y: parent.height / 2 - height / 2
|
||||
|
||||
LoginView {
|
||||
id: source
|
||||
lognViewModel: root.lognViewModel
|
||||
anchors.fill: parent
|
||||
|
||||
onLoginClicked: {
|
||||
root.close();
|
||||
}
|
||||
}
|
||||
|
||||
onClosed: {
|
||||
source.clear();
|
||||
}
|
||||
|
||||
}
|
@ -1,2 +1,3 @@
|
||||
module LoginViewModule
|
||||
LoginView 1.0 LoginView.qml
|
||||
LoginViewDialog 1.0 LoginViewDialog.qml
|
||||
|
@ -9,5 +9,6 @@
|
||||
<file>LoginViewModule/LVMCheckBox.qml</file>
|
||||
<file>LoginViewModule/LVMButton.qml</file>
|
||||
<file>LoginViewModule/ValidatIonIndicator.qml</file>
|
||||
<file>LoginViewModule/LoginViewDialog.qml</file>
|
||||
</qresource>
|
||||
</RCC>
|
@ -93,7 +93,7 @@ void LVMainModel::setCountry(int country) {
|
||||
emit countryListChanged();
|
||||
}
|
||||
|
||||
void LVMainModel::setData(UserData data) {
|
||||
void LVMainModel::setData(const UserData& data) {
|
||||
if (m_data == data)
|
||||
return;
|
||||
|
||||
@ -110,6 +110,42 @@ void LVMainModel::setPasswordError(QString passwordError) {
|
||||
emit passwordErrorChanged(m_passwordError);
|
||||
}
|
||||
|
||||
ShowExtraComponent LVMainModel::components() const {
|
||||
return _components;
|
||||
}
|
||||
|
||||
void LVMainModel::setComponents(const ShowExtraComponent &components) {
|
||||
if (_components != components) {
|
||||
_components = components;
|
||||
emit showChanged();
|
||||
}
|
||||
}
|
||||
|
||||
bool LVMainModel::fTitle() const {
|
||||
return _components & ShowExtraComponent::Title;
|
||||
}
|
||||
|
||||
bool LVMainModel::fFirstName() const {
|
||||
return _components & ShowExtraComponent::FirstName;
|
||||
}
|
||||
|
||||
bool LVMainModel::fLastName() const {
|
||||
return _components & ShowExtraComponent::LastName;
|
||||
}
|
||||
|
||||
bool LVMainModel::fNickname() const {
|
||||
return _components & ShowExtraComponent::Nickname;
|
||||
}
|
||||
|
||||
bool LVMainModel::fEMail() const {
|
||||
return _components & ShowExtraComponent::EMail;
|
||||
}
|
||||
|
||||
void LVMainModel::clear() {
|
||||
emit clearView();
|
||||
setData({});
|
||||
}
|
||||
|
||||
void LVMainModel::setValidData(UserViewValidationData validationData) {
|
||||
if (m_validationData == validationData)
|
||||
return;
|
||||
@ -146,10 +182,11 @@ void LVMainModel::checkValid(const UserData& data) {
|
||||
|
||||
UserViewValidationData result;
|
||||
|
||||
result.setEmail(!data.email().contains(QRegExp("^([a-zA-Z0-9_\-\.]+)@([a-zA-Z0-9_\-\.]+)\.([a-zA-Z]{2,5})$")));
|
||||
result.setCountry(!m_countryList.contains(data.country()));
|
||||
result.setLastName(false);
|
||||
result.setFirstName(data.firstName().contains(" ") || data.firstName().isEmpty());
|
||||
result.setNickname(fNickname() && (data.nickname().contains(" ") || data.nickname().isEmpty()));
|
||||
result.setEmail(fEMail() && !data.email().contains(QRegExp("^([a-zA-Z0-9_\-\.]+)@([a-zA-Z0-9_\-\.]+)\.([a-zA-Z]{2,5})$")));
|
||||
result.setCountry(m_countryList.size() && !m_countryList.contains(data.country()));
|
||||
result.setLastName(fLastName() && false);
|
||||
result.setFirstName(fFirstName() && (data.firstName().contains(" ") || data.firstName().isEmpty()));
|
||||
|
||||
bool passwordValidation = true;
|
||||
|
||||
|
@ -36,6 +36,21 @@ enum PasswordValidationLvl {
|
||||
ExtraChars = 0x10
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief The ShowExtraComponent enum
|
||||
* default Title | FirstName | LastName
|
||||
*/
|
||||
enum ShowExtraComponent {
|
||||
NoShow = 0x00,
|
||||
Title = 0x01,
|
||||
FirstName = 0x02,
|
||||
LastName = 0x04,
|
||||
EMail = 0x08,
|
||||
Nickname = 0x10,
|
||||
|
||||
All = EMail | Title | FirstName | LastName
|
||||
};
|
||||
|
||||
class LOGINVIEW_EXPORT LVMainModel: public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
@ -43,6 +58,12 @@ class LOGINVIEW_EXPORT LVMainModel: public QObject
|
||||
Q_PROPERTY(QStringList countryList READ countryList NOTIFY countryListChanged)
|
||||
Q_PROPERTY(QList<int> countryCodeList READ countryCodeList NOTIFY countryCodeListChanged)
|
||||
|
||||
Q_PROPERTY(bool fTitle READ fTitle NOTIFY showChanged)
|
||||
Q_PROPERTY(bool fLastName READ fLastName NOTIFY showChanged)
|
||||
Q_PROPERTY(bool fFirstName READ fFirstName NOTIFY showChanged)
|
||||
Q_PROPERTY(bool fNickname READ fNickname NOTIFY showChanged)
|
||||
Q_PROPERTY(bool fEMail READ fEMail NOTIFY showChanged)
|
||||
|
||||
Q_PROPERTY(int country READ country WRITE setCountry NOTIFY countryChanged)
|
||||
Q_PROPERTY(UserData data READ data WRITE setData NOTIFY dataChanged)
|
||||
Q_PROPERTY(UserViewValidationData validationData READ validData WRITE setValidData NOTIFY validDataChanged)
|
||||
@ -78,9 +99,29 @@ public:
|
||||
Q_INVOKABLE void showTermOfUseRequest();
|
||||
|
||||
|
||||
ShowExtraComponent components() const;
|
||||
void setComponents(const ShowExtraComponent &components);
|
||||
|
||||
bool fTitle() const;
|
||||
bool fFirstName() const;
|
||||
bool fLastName() const;
|
||||
bool fNickname() const;
|
||||
|
||||
bool fEMail() const;
|
||||
|
||||
/**
|
||||
* @brief clear - clear all data from view
|
||||
*/
|
||||
void clear();
|
||||
|
||||
public slots:
|
||||
void setCountry(int country);
|
||||
void setData(UserData data);
|
||||
|
||||
/**
|
||||
* @brief setData set new data for view
|
||||
* @param data
|
||||
*/
|
||||
void setData(const UserData &data);
|
||||
|
||||
signals:
|
||||
void countryChanged(int country);
|
||||
@ -91,19 +132,19 @@ signals:
|
||||
* @brief sigLoginRequest
|
||||
* emited when user try login
|
||||
*/
|
||||
void sigLoginRequest(UserData);
|
||||
void sigLoginRequest(const UserData&);
|
||||
|
||||
/**
|
||||
* @brief sigRegisterRequest
|
||||
* emited when user try create new accaunt
|
||||
*/
|
||||
void sigRegisterRequest(UserData);
|
||||
void sigRegisterRequest(const UserData&);
|
||||
|
||||
/**
|
||||
* @brief sigForgotPasswordRequest
|
||||
* emited when user forgot own password
|
||||
*/
|
||||
void sigForgotPasswordRequest(UserData);
|
||||
void sigForgotPasswordRequest(const UserData&);
|
||||
|
||||
/**
|
||||
* @brief sigShowTermOfUseRequest
|
||||
@ -116,6 +157,13 @@ signals:
|
||||
void validDataChanged(UserViewValidationData validationData);
|
||||
void passwordErrorChanged(QString passwordError);
|
||||
|
||||
/**
|
||||
* @brief showChanged - emited when show components changed
|
||||
* @param ftitle
|
||||
*/
|
||||
void showChanged();
|
||||
void clearView();
|
||||
|
||||
private:
|
||||
void checkValid(const UserData &data);
|
||||
void setValidData(UserViewValidationData validationData);
|
||||
@ -130,6 +178,7 @@ private:
|
||||
|
||||
UserViewValidationData m_validationData;
|
||||
QString m_passwordError;
|
||||
ShowExtraComponent _components = ShowExtraComponent::All;
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -30,6 +30,10 @@ QString UserData::email() const {
|
||||
return m_email;
|
||||
}
|
||||
|
||||
QString UserData::nickname() const {
|
||||
return m_nickname;
|
||||
}
|
||||
|
||||
void UserData::setCountry(int country) {
|
||||
m_country = country;
|
||||
}
|
||||
@ -50,11 +54,16 @@ void UserData::setEmail(const QString &email) {
|
||||
m_email = email;
|
||||
}
|
||||
|
||||
void UserData::setNickname(const QString& nickname) {
|
||||
m_nickname = nickname;
|
||||
}
|
||||
|
||||
bool operator !=(const UserData &left, const UserData &right) {
|
||||
return left.m_email != right.m_email ||
|
||||
left.m_country != right.m_country ||
|
||||
left.m_rawPassword != right.m_rawPassword ||
|
||||
left.m_firstName != right.m_firstName ||
|
||||
left.m_nickname != right.m_nickname ||
|
||||
left.m_lastName != right.m_lastName;
|
||||
}
|
||||
|
||||
|
@ -20,6 +20,7 @@ class LOGINVIEW_EXPORT UserData
|
||||
Q_PROPERTY(QString lastName READ lastName WRITE setLastName)
|
||||
Q_PROPERTY(QString rawPassword READ rawPassword WRITE setRawPassword)
|
||||
Q_PROPERTY(QString email READ email WRITE setEmail)
|
||||
Q_PROPERTY(QString nickname READ nickname WRITE setNickname)
|
||||
|
||||
public:
|
||||
UserData();
|
||||
@ -32,6 +33,7 @@ public:
|
||||
friend bool operator !=(const UserData& left, const UserData& right);
|
||||
friend bool operator ==(const UserData& left, const UserData& right);
|
||||
|
||||
QString nickname() const;
|
||||
|
||||
public slots:
|
||||
void setCountry(int country);
|
||||
@ -40,12 +42,16 @@ public slots:
|
||||
void setRawPassword(const QString& rawPassword);
|
||||
void setEmail(const QString& email);
|
||||
|
||||
void setNickname(const QString &nickname);
|
||||
|
||||
private:
|
||||
int m_country;
|
||||
QString m_firstName;
|
||||
QString m_lastName;
|
||||
QString m_rawPassword;
|
||||
QString m_email;
|
||||
|
||||
QString m_nickname;
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -14,7 +14,9 @@ enum class ValidationAddersses {
|
||||
FirstName = 0x02,
|
||||
LastName = 0x04,
|
||||
RawPassword = 0x08,
|
||||
Email = 0x10
|
||||
Email = 0x10,
|
||||
Nickname = 0x20
|
||||
|
||||
};
|
||||
|
||||
UserViewValidationData::UserViewValidationData() {
|
||||
@ -22,6 +24,7 @@ UserViewValidationData::UserViewValidationData() {
|
||||
static_cast<int>(ValidationAddersses::Country) |
|
||||
static_cast<int>(ValidationAddersses::LastName) |
|
||||
static_cast<int>(ValidationAddersses::RawPassword) |
|
||||
static_cast<int>(ValidationAddersses::Nickname) |
|
||||
static_cast<int>(ValidationAddersses::Email);
|
||||
}
|
||||
|
||||
@ -49,6 +52,10 @@ bool UserViewValidationData::noError() const {
|
||||
return !m_data;
|
||||
}
|
||||
|
||||
bool UserViewValidationData::nickname() const {
|
||||
return m_data & static_cast<int>(ValidationAddersses::Nickname);
|
||||
}
|
||||
|
||||
bool operator !=(const UserViewValidationData &left,
|
||||
const UserViewValidationData &right) {
|
||||
return left.m_data != right.m_data;
|
||||
@ -84,4 +91,9 @@ void UserViewValidationData::setEmail(bool email) {
|
||||
m_data |= (static_cast<int>(ValidationAddersses::Email) * (email & 0x01));
|
||||
}
|
||||
|
||||
void UserViewValidationData::setNickname(bool nickname) {
|
||||
m_data &= ~static_cast<int>(ValidationAddersses::Nickname);
|
||||
m_data |= (static_cast<int>(ValidationAddersses::Nickname) * (nickname & 0x01));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -20,6 +20,7 @@ class UserViewValidationData
|
||||
Q_PROPERTY(bool lastName READ lastName WRITE setLastName) // ValidationAddersses::LastName
|
||||
Q_PROPERTY(bool rawPassword READ rawPassword WRITE setRawPassword) // ValidationAddersses::RawPassword
|
||||
Q_PROPERTY(bool email READ email WRITE setEmail) // ValidationAddersses::Email
|
||||
Q_PROPERTY(bool nickname READ nickname WRITE setNickname) // ValidationAddersses::Email
|
||||
Q_PROPERTY(bool noError READ noError)
|
||||
|
||||
public:
|
||||
@ -39,6 +40,7 @@ public:
|
||||
const UserViewValidationData &right);
|
||||
|
||||
bool noError() const;
|
||||
bool nickname() const;
|
||||
|
||||
public slots:
|
||||
void setCountry(bool country);
|
||||
@ -47,6 +49,8 @@ public slots:
|
||||
void setRawPassword(bool rawPassword);
|
||||
void setEmail(bool email);
|
||||
|
||||
void setNickname(bool nickname);
|
||||
|
||||
private:
|
||||
int m_data;
|
||||
};
|
||||
|
@ -26,12 +26,12 @@ find_package(Qt5 COMPONENTS Core QuickControls2 REQUIRED)
|
||||
if(ANDROID)
|
||||
add_library(${PROJECT_NAME} SHARED
|
||||
main.cpp
|
||||
qml.qrc
|
||||
lv_example_res.qrc
|
||||
)
|
||||
else()
|
||||
add_executable(${PROJECT_NAME}
|
||||
main.cpp
|
||||
qml.qrc
|
||||
lv_example_res.qrc
|
||||
icon.rc
|
||||
)
|
||||
endif()
|
||||
|
@ -7,7 +7,6 @@
|
||||
import QtQuick 2.12
|
||||
import QtQuick.Window 2.12
|
||||
import QtQuick.Controls 2.12
|
||||
import QtQuick.Controls 2.12 as Controls
|
||||
import QtQuick.Layouts 1.12
|
||||
import LoginViewModule 1.0
|
||||
import QtQuick.Dialogs 1.3
|
||||
|
Loading…
x
Reference in New Issue
Block a user