Добавлены настройки login и password

This commit is contained in:
2024-05-18 13:40:15 +02:00
parent e793c1a375
commit 5443c573e2
8 changed files with 122 additions and 41 deletions

View File

@@ -5,6 +5,7 @@ project(nooLight VERSION 1.0 LANGUAGES CXX)
set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_AUTORCC ON) set(CMAKE_AUTORCC ON)
include_directories(src)
find_package(Qt6 6.5 REQUIRED COMPONENTS Quick) find_package(Qt6 6.5 REQUIRED COMPONENTS Quick)
@@ -15,6 +16,13 @@ qt_add_executable(appnooLight
resources/resources.qrc resources/resources.qrc
) )
qt_add_qml_module(appnooLight
URI ru.ded.noolight
VERSION 1.0
SOURCES
src/settings.h src/settings.cpp
)
if (ANDROID) if (ANDROID)
set_property(TARGET appnooLight APPEND PROPERTY QT_ANDROID_EXTRA_LIBS set_property(TARGET appnooLight APPEND PROPERTY QT_ANDROID_EXTRA_LIBS
${QT_ANDROID_SSL_DIR}/no-asm/ssl_3/${ANDROID_ABI}/libcrypto_3.so ${QT_ANDROID_SSL_DIR}/no-asm/ssl_3/${ANDROID_ABI}/libcrypto_3.so

View File

@@ -69,7 +69,7 @@ Item {
Label { Label {
anchors.horizontalCenter: parent.horizontalCenter anchors.horizontalCenter: parent.horizontalCenter
horizontalAlignment: Text.horizontalCenter horizontalAlignment: Qt.horizontalCenter
text: name text: name
} }
} }

View File

@@ -1,6 +1,9 @@
import QtQuick 2.0 import QtQuick 2.0
import QtQuick.Controls 2.2 import QtQuick.Controls 2.2
import ru.ded.noolight 1.0
import ru.ded.components 1.0
Page { Page {
id: root id: root
@@ -14,6 +17,16 @@ Page {
title: qsTr("nooLite service URL") title: qsTr("nooLite service URL")
inputMethodHint: Qt.ImhUrlCharactersOnly inputMethodHint: Qt.ImhUrlCharactersOnly
} }
ListElement {
name: "login"
title: qsTr("Login")
inputMethodHint: Qt.ImhLatinOnly
}
ListElement {
name: "password"
title: qsTr("Password")
hideText: true
}
} }
ListView { ListView {
@@ -24,15 +37,14 @@ Page {
delegate: SubtitledItemDelegate { delegate: SubtitledItemDelegate {
width: parent.width width: parent.width
text: model.title text: model.title
subtitle: settings[model.name] subtitle: model.hideText && Settings[model.name] ? qsTr("Hidden") : Settings[model.name]
onClicked: inputDialog.open() onClicked: inputDialog.open()
Dialog { Dialog {
id: inputDialog id: inputDialog
x: (parent.width - width) / 2 anchors.centerIn: parent
y: (parent.height - height) / 2
parent: ApplicationWindow.overlay parent: ApplicationWindow.overlay
focus: true focus: true
@@ -49,14 +61,15 @@ Page {
width: parent.width width: parent.width
focus: true focus: true
inputMethodHints: Qt.ImhNoAutoUppercase | model.inputMethodHint inputMethodHints: model.inputMethodHint
echoMode: model.hideText ? TextInput.Password : TextInput.Normal
placeholderText: model.title placeholderText: model.title
text: settings[model.name] text: Settings[model.name]
} }
} }
onAccepted: { onAccepted: {
settings[model.name] = textField.text Settings[model.name] = textField.text
} }
} }
} }

View File

@@ -1,24 +0,0 @@
import QtQuick 2.0
import QtQuick.Controls 2.2
ItemDelegate {
id: root
property string subtitle: ""
contentItem: Column {
Label {
id: titleLabel
width: parent.width
text: root.text
}
Label {
width: parent.width
font.pixelSize: titleLabel.font.pixelSize - 2
text: root.subtitle ? root.subtitle : qsTr("undefined")
opacity: 0.8
}
}
}

View File

@@ -1,7 +1,7 @@
import QtQuick 2.9 import QtQuick 2.9
import QtQuick.Controls 2.2 import QtQuick.Controls 2.2
import Qt.labs.settings 1.0
import ru.ded.noolight 1.0
import ru.ded.components 1.0 import ru.ded.components 1.0
ApplicationWindow { ApplicationWindow {
@@ -12,16 +12,10 @@ ApplicationWindow {
height: 480 height: 480
title: qsTr("Stack") title: qsTr("Stack")
Settings {
id: settings
property string serviceUrl: ""
}
LightsModel { LightsModel {
id: lightsModel id: lightsModel
serviceUrl: settings.serviceUrl serviceUrl: Settings.serviceUrl
onError: (text) => stackView.showError(text) onError: (text) => stackView.showError(text)
} }
@@ -102,7 +96,7 @@ ApplicationWindow {
} }
} }
onClosing: { onClosing: (close) => {
if (stackView.depth > 1) { if (stackView.depth > 1) {
close.accepted = false close.accepted = false
stackView.pop() stackView.pop()

View File

@@ -4,7 +4,6 @@
<file>qtquickcontrols2.conf</file> <file>qtquickcontrols2.conf</file>
<file>qml/HomeForm.qml</file> <file>qml/HomeForm.qml</file>
<file>qml/SettingsForm.qml</file> <file>qml/SettingsForm.qml</file>
<file>qml/SubtitledItemDelegate.qml</file>
<file>qml/LightsModel.qml</file> <file>qml/LightsModel.qml</file>
<file>qml/LightGroup.qml</file> <file>qml/LightGroup.qml</file>
<file>qml/GradientButton.qml</file> <file>qml/GradientButton.qml</file>

54
src/settings.cpp Normal file
View File

@@ -0,0 +1,54 @@
#include "settings.h"
namespace Keys {
constexpr auto ServiceUrl = "serviceUrl";
constexpr auto Login = "login";
constexpr auto Password = "password";
}
QString Settings::serviceUrl() const
{
return m_settings.value(Keys::ServiceUrl, "https://mynoolightservice.org").toString();
}
void Settings::setServiceUrl(const QString &newServiceUrl)
{
if (serviceUrl() == newServiceUrl) {
return;
}
m_settings.setValue(Keys::ServiceUrl, newServiceUrl);
emit serviceUrlChanged();
}
QString Settings::login() const
{
return m_settings.value(Keys::Login).toString();
}
void Settings::setLogin(const QString &newLogin)
{
if (login() == newLogin) {
return;
}
m_settings.setValue(Keys::Login, newLogin);
emit loginChanged();
}
QString Settings::password() const
{
return m_settings.value(Keys::Password).toString();
}
void Settings::setPassword(const QString &newPassword)
{
if (password() == newPassword) {
return;
}
m_settings.setValue(Keys::Password, newPassword);
emit passwordChanged();
}

37
src/settings.h Normal file
View File

@@ -0,0 +1,37 @@
#ifndef SETTINGS_H
#define SETTINGS_H
#include <QObject>
#include <QQmlEngine>
#include <QSettings>
class Settings : public QObject
{
Q_OBJECT
QML_ELEMENT
QML_SINGLETON
Q_PROPERTY(QString serviceUrl READ serviceUrl WRITE setServiceUrl NOTIFY serviceUrlChanged FINAL)
Q_PROPERTY(QString login READ login WRITE setLogin NOTIFY loginChanged FINAL)
Q_PROPERTY(QString password READ password WRITE setPassword NOTIFY passwordChanged FINAL)
public:
QString serviceUrl() const;
void setServiceUrl(const QString &newServiceUrl);
QString login() const;
void setLogin(const QString &newLogin);
QString password() const;
void setPassword(const QString &newPassword);
signals:
void serviceUrlChanged();
void loginChanged();
void passwordChanged();
private:
QSettings m_settings;
};
#endif // SETTINGS_H