From 4f36349630a1ee350c63bb2717c4f75c9973ddf1 Mon Sep 17 00:00:00 2001 From: "vladimir.kuznetsov" Date: Wed, 3 May 2023 19:06:16 +0300 Subject: [PATCH] changed the way to create qml pages, now the page is created when you go to it - added PageSetupWizardConfigSource, PageSetupWizardInstalling, PageSetupWizardProtocolSettings, PageSetupWizardTextKey --- client/amnezia_application.cpp | 6 + client/amnezia_application.h | 2 + client/images/controls/folder-open.svg | 3 + client/images/controls/qr-code.svg | 14 +++ client/images/controls/text-cursor.svg | 5 + client/resources.qrc | 7 ++ client/ui/models/containers_model.cpp | 10 ++ client/ui/models/containers_model.h | 4 + client/ui/pages.h | 4 +- .../ui/pages_logic/ServerContainersLogic.cpp | 4 +- client/ui/qml/Controls2/BasicButtonType.qml | 1 - .../ui/qml/Controls2/LabelWithButtonType.qml | 10 ++ .../qml/Controls2/TextFieldWithHeaderType.qml | 105 ++++++++++------ client/ui/qml/PageLoader.qml | 58 +-------- .../Pages2/PageSetupWizardConfigSource.qml | 114 ++++++++++++++++++ .../qml/Pages2/PageSetupWizardCredentials.qml | 6 +- client/ui/qml/Pages2/PageSetupWizardEasy.qml | 2 +- .../qml/Pages2/PageSetupWizardInstalling.qml | 46 +++++++ .../PageSetupWizardProtocolSettings.qml | 96 +++++++++++++++ .../qml/Pages2/PageSetupWizardProtocols.qml | 12 +- .../ui/qml/Pages2/PageSetupWizardTextKey.qml | 74 ++++++++++++ client/ui/qml/Pages2/PageStart.qml | 13 +- client/ui/qml/main2.qml | 56 ++------- client/ui/uilogic.cpp | 8 +- client/ui/uilogic.h | 3 +- 25 files changed, 504 insertions(+), 159 deletions(-) create mode 100644 client/images/controls/folder-open.svg create mode 100644 client/images/controls/qr-code.svg create mode 100644 client/images/controls/text-cursor.svg create mode 100644 client/ui/qml/Pages2/PageSetupWizardConfigSource.qml create mode 100644 client/ui/qml/Pages2/PageSetupWizardInstalling.qml create mode 100644 client/ui/qml/Pages2/PageSetupWizardProtocolSettings.qml create mode 100644 client/ui/qml/Pages2/PageSetupWizardTextKey.qml diff --git a/client/amnezia_application.cpp b/client/amnezia_application.cpp index 231b94e4a..b4255a0c0 100644 --- a/client/amnezia_application.cpp +++ b/client/amnezia_application.cpp @@ -99,6 +99,10 @@ void AmneziaApplication::init() }, Qt::QueuedConnection); m_engine->rootContext()->setContextProperty("Debug", &Logger::Instance()); + + m_containersModel.reset(new ContainersModel(m_settings, this)); + m_engine->rootContext()->setContextProperty("ContainersModel", m_containersModel.get()); + m_uiLogic->registerPagesLogic(); #if defined(Q_OS_IOS) @@ -180,6 +184,8 @@ void AmneziaApplication::loadFonts() QFontDatabase::addApplicationFont(":/fonts/Lato-Regular.ttf"); QFontDatabase::addApplicationFont(":/fonts/Lato-Thin.ttf"); QFontDatabase::addApplicationFont(":/fonts/Lato-ThinItalic.ttf"); + + QFontDatabase::addApplicationFont(":/fonts/pt-root-ui_vf.ttf"); } void AmneziaApplication::loadTranslator() diff --git a/client/amnezia_application.h b/client/amnezia_application.h index 1ac6e772e..abdb1f2a3 100644 --- a/client/amnezia_application.h +++ b/client/amnezia_application.h @@ -56,6 +56,8 @@ class AmneziaApplication : public AMNEZIA_BASE_CLASS QTranslator* m_translator; QCommandLineParser m_parser; + QScopedPointer m_containersModel; + }; #endif // AMNEZIA_APPLICATION_H diff --git a/client/images/controls/folder-open.svg b/client/images/controls/folder-open.svg new file mode 100644 index 000000000..f126e5c5a --- /dev/null +++ b/client/images/controls/folder-open.svg @@ -0,0 +1,3 @@ + + + diff --git a/client/images/controls/qr-code.svg b/client/images/controls/qr-code.svg new file mode 100644 index 000000000..a8f760fe1 --- /dev/null +++ b/client/images/controls/qr-code.svg @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + diff --git a/client/images/controls/text-cursor.svg b/client/images/controls/text-cursor.svg new file mode 100644 index 000000000..17876d776 --- /dev/null +++ b/client/images/controls/text-cursor.svg @@ -0,0 +1,5 @@ + + + + + diff --git a/client/resources.qrc b/client/resources.qrc index 1d79af1c9..20eed74db 100644 --- a/client/resources.qrc +++ b/client/resources.qrc @@ -202,5 +202,12 @@ ui/qml/Controls2/SwitcherType.qml ui/qml/Pages2/PageTest.qml ui/qml/Controls2/TabButtonType.qml + ui/qml/Pages2/PageSetupWizardProtocolSettings.qml + ui/qml/Pages2/PageSetupWizardInstalling.qml + ui/qml/Pages2/PageSetupWizardConfigSource.qml + images/controls/folder-open.svg + images/controls/qr-code.svg + images/controls/text-cursor.svg + ui/qml/Pages2/PageSetupWizardTextKey.qml diff --git a/client/ui/models/containers_model.cpp b/client/ui/models/containers_model.cpp index 5468452ee..f56613c74 100644 --- a/client/ui/models/containers_model.cpp +++ b/client/ui/models/containers_model.cpp @@ -56,4 +56,14 @@ void ContainersModel::setSelectedServerIndex(int index) endResetModel(); } +void ContainersModel::setCurrentlyInstalledContainerIndex(int index) +{ +// beginResetModel(); + m_currentlyInstalledContainerIndex = createIndex(index, 0); +// endResetModel(); +} +QString ContainersModel::getCurrentlyInstalledContainerName() +{ + return data(m_currentlyInstalledContainerIndex, NameRole).toString(); +} diff --git a/client/ui/models/containers_model.h b/client/ui/models/containers_model.h index 362068557..9c409fc00 100644 --- a/client/ui/models/containers_model.h +++ b/client/ui/models/containers_model.h @@ -27,12 +27,16 @@ class ContainersModel : public QAbstractListModel QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; Q_INVOKABLE void setSelectedServerIndex(int index); + Q_INVOKABLE void setCurrentlyInstalledContainerIndex(int index); + + Q_INVOKABLE QString getCurrentlyInstalledContainerName(); protected: QHash roleNames() const override; private: int m_selectedServerIndex; + QModelIndex m_currentlyInstalledContainerIndex; std::shared_ptr m_settings; }; diff --git a/client/ui/pages.h b/client/ui/pages.h index 9c5db53c0..32ac775dc 100644 --- a/client/ui/pages.h +++ b/client/ui/pages.h @@ -28,7 +28,9 @@ enum class Page {Start = 0, NewServer, NewServerProtocols, Vpn, ProtocolSettings, ProtocolShare, QrDecoder, QrDecoderIos, About, ViewConfig, AdvancedServerSettings, ClientManagement, ClientInfo, - Test, WizardCredentials, WizardProtocols, WizardEasySetup}; + PageStart, PageTest, PageSetupWizardCredentials, PageSetupWizardProtocols, PageSetupWizardEasy, + PageSetupWizardProtocolSettings, PageSetupWizardInstalling, PageSetupWizardConfigSource, + PageSetupWizardTextKey}; Q_ENUM_NS(Page) static void declareQmlPageEnum() { diff --git a/client/ui/pages_logic/ServerContainersLogic.cpp b/client/ui/pages_logic/ServerContainersLogic.cpp index 80bf362c9..2b556dcc4 100644 --- a/client/ui/pages_logic/ServerContainersLogic.cpp +++ b/client/ui/pages_logic/ServerContainersLogic.cpp @@ -22,8 +22,8 @@ ServerContainersLogic::ServerContainersLogic(UiLogic *logic, QObject *parent): void ServerContainersLogic::onUpdatePage() { - ContainersModel *c_model = qobject_cast(uiLogic()->containersModel()); - c_model->setSelectedServerIndex(uiLogic()->m_selectedServerIndex); +// ContainersModel *c_model = qobject_cast(uiLogic()->containersModel()); +// c_model->setSelectedServerIndex(uiLogic()->m_selectedServerIndex); ProtocolsModel *p_model = qobject_cast(uiLogic()->protocolsModel()); p_model->setSelectedServerIndex(uiLogic()->m_selectedServerIndex); diff --git a/client/ui/qml/Controls2/BasicButtonType.qml b/client/ui/qml/Controls2/BasicButtonType.qml index cbb664e4a..da5d2abfe 100644 --- a/client/ui/qml/Controls2/BasicButtonType.qml +++ b/client/ui/qml/Controls2/BasicButtonType.qml @@ -14,7 +14,6 @@ Button { property string borderColor: "#D7D8DB" property int borderWidth: 0 - implicitWidth: 328 implicitHeight: 56 hoverEnabled: true diff --git a/client/ui/qml/Controls2/LabelWithButtonType.qml b/client/ui/qml/Controls2/LabelWithButtonType.qml index 92606940f..b6d113bb2 100644 --- a/client/ui/qml/Controls2/LabelWithButtonType.qml +++ b/client/ui/qml/Controls2/LabelWithButtonType.qml @@ -9,7 +9,9 @@ Item { property string descriptionText property var onClickedFunc + property alias buttonImage: button.image + property string iconImage implicitWidth: content.implicitWidth implicitHeight: content.implicitHeight @@ -18,6 +20,13 @@ Item { id: content anchors.fill: parent + Image { + id: icon + source: iconImage + visible: iconImage ? true : false + Layout.rightMargin: visible ? 16 : 0 + } + ColumnLayout { Text { font.family: "PT Root UI" @@ -25,6 +34,7 @@ Item { font.pixelSize: 18 color: "#d7d8db" text: root.text + wrapMode: Text.WordWrap Layout.fillWidth: true height: 22 diff --git a/client/ui/qml/Controls2/TextFieldWithHeaderType.qml b/client/ui/qml/Controls2/TextFieldWithHeaderType.qml index 350306bb4..3458f7411 100644 --- a/client/ui/qml/Controls2/TextFieldWithHeaderType.qml +++ b/client/ui/qml/Controls2/TextFieldWithHeaderType.qml @@ -10,7 +10,11 @@ Item { property string textFieldPlaceholderText property bool textFieldEditable: true - implicitWidth: 328 + property string buttonText + property var clickedFunc + + property alias textField: textField + implicitHeight: 74 Rectangle { @@ -26,50 +30,77 @@ Item { } } - ColumnLayout { + RowLayout { anchors.fill: backgroud + ColumnLayout { - Text { - text: root.headerText - color: "#878b91" - font.pixelSize: 13 - font.weight: 400 - font.family: "PT Root UI VF" - font.letterSpacing: 0.02 - - height: 16 - Layout.fillWidth: true - Layout.rightMargin: 16 - Layout.leftMargin: 16 - Layout.topMargin: 16 - } + Text { + text: root.headerText + color: "#878b91" + font.pixelSize: 13 + font.weight: 400 + font.family: "PT Root UI VF" + font.letterSpacing: 0.02 + + height: 16 + Layout.fillWidth: true + Layout.rightMargin: 16 + Layout.leftMargin: 16 + Layout.topMargin: 16 + } + + TextField { + id: textField + + enabled: root.textFieldEditable + text: root.textFieldText + color: "#d7d8db" - TextField { - id: textField + placeholderText: textFieldPlaceholderText + placeholderTextColor: "#494B50" + + selectionColor: "#412102" + selectedTextColor: "#D7D8DB" + + font.pixelSize: 16 + font.weight: 400 + font.family: "PT Root UI VF" + + height: 24 + Layout.fillWidth: true + Layout.rightMargin: 16 + Layout.leftMargin: 16 + Layout.bottomMargin: 16 + topPadding: 0 + rightPadding: 0 + leftPadding: 0 + bottomPadding: 0 + + background: Rectangle { + anchors.fill: parent + color: "#1c1d21" + } + } + } - enabled: root.textFieldEditable - text: root.textFieldText - color: "#d7d8db" + BasicButtonType { + visible: root.buttonText !== "" - placeholderText: textFieldPlaceholderText + defaultColor: "transparent" + hoveredColor: Qt.rgba(1, 1, 1, 0.08) + pressedColor: Qt.rgba(1, 1, 1, 0.12) + disabledColor: "#878B91" + textColor: "#D7D8DB" + borderWidth: 0 - font.pixelSize: 16 - font.weight: 400 - font.family: "PT Root UI VF" + text: buttonText - height: 24 - Layout.fillWidth: true - Layout.rightMargin: 16 - Layout.leftMargin: 16 - Layout.bottomMargin: 16 - topPadding: 0 - rightPadding: 0 - leftPadding: 0 - bottomPadding: 0 + Layout.rightMargin: 24 - background: Rectangle { - anchors.fill: parent - color: "#1c1d21" + onClicked: { + if (clickedFunc && typeof clickedFunc === "function") { + clickedFunc() + } } } } diff --git a/client/ui/qml/PageLoader.qml b/client/ui/qml/PageLoader.qml index 5f2fc3c2c..a44fa4b52 100644 --- a/client/ui/qml/PageLoader.qml +++ b/client/ui/qml/PageLoader.qml @@ -1,57 +1,7 @@ import QtQuick +import QtQuick.Controls -import Qt.labs.folderlistmodel - -import PageType 1.0 - -Item { - property var pages: ({}) - - signal finished() - - FolderListModel { - id: folderModelPages - folder: "qrc:/ui/qml/Pages2/" - nameFilters: ["*.qml"] - showDirs: false - - onStatusChanged: { - if (status == FolderListModel.Ready) { - for (var i = 0; i < folderModelPages.count; i++) { - createPagesObjects(folderModelPages.get(i, "filePath"), PageType.Basic); - } - finished() - } - } - - function createPagesObjects(file, type) { - if (file.indexOf("Base") !== -1) { - return; // skip Base Pages - } - - var c = Qt.createComponent("qrc" + file); - - var finishCreation = function(component) { - if (component.status === Component.Ready) { - var obj = component.createObject(root); - if (obj === null) { - console.debug("Error creating object " + component.url); - } else { - obj.visible = false - if (type === PageType.Basic) { - pages[obj.page] = obj - } - } - } else if (component.status === Component.Error) { - console.debug("Error loading component:", component.errorString()); - } - } - - if (c.status === Component.Ready) { - finishCreation(c); - } else { - console.debug("Warning: " + file + " page components are not ready " + c.errorString()); - } - } - } +StackView { + id: stackView + initialItem: "PageStart" } diff --git a/client/ui/qml/Pages2/PageSetupWizardConfigSource.qml b/client/ui/qml/Pages2/PageSetupWizardConfigSource.qml new file mode 100644 index 000000000..26f25a15d --- /dev/null +++ b/client/ui/qml/Pages2/PageSetupWizardConfigSource.qml @@ -0,0 +1,114 @@ +import QtQuick +import QtQuick.Controls +import QtQuick.Layouts +import QtQuick.Dialogs + +import PageEnum 1.0 + +import "./" +import "../Pages" +import "../Controls2" +import "../Controls2/TextTypes" +import "../Config" + +PageBase { + id: root + page: PageEnum.PageSetupWizardInstalling + + FlickableType { + id: fl + anchors.top: root.top + anchors.bottom: root.bottom + contentHeight: content.height + + ColumnLayout { + id: content + + anchors.top: parent.top + anchors.left: parent.left + anchors.right: parent.right + anchors.rightMargin: 16 + anchors.leftMargin: 16 + + spacing: 16 + + HeaderType { + Layout.fillWidth: true + Layout.topMargin: 20 + + buttonImage: "qrc:/images/controls/arrow-left.svg" + + headerText: "Подключение к серверу" + descriptionText: "Не используйте код подключения из публичных источников. Его могли создать, чтобы перехватывать ваши данные.\n +Всё в порядке, если код передал друг." + } + + Header2TextType { + Layout.fillWidth: true + Layout.topMargin: 32 + + text: "Что у вас есть?" + } + + LabelWithButtonType { + Layout.fillWidth: true + Layout.topMargin: 16 + + text: "Файл с настройками подключения" + buttonImage: "qrc:/images/controls/chevron-right.svg" + iconImage: "qrc:/images/controls/folder-open.svg" + + onClickedFunc: function() { + onClicked: fileDialog.open() + } + + FileDialog { + id: fileDialog +// currentFolder: StandardPaths.standardLocations(StandardPaths.PicturesLocation)[0] + onAccepted: { + + } + } + } + Rectangle { + Layout.fillWidth: true + height: 1 + color: "#2C2D30" + } + + //todo ifdef mobile platforms> + LabelWithButtonType { + Layout.fillWidth: true + + text: "QR-код" + buttonImage: "qrc:/images/controls/chevron-right.svg" + iconImage: "qrc:/images/controls/qr-code.svg" + + onClickedFunc: function() { + } + } + Rectangle { + Layout.fillWidth: true + height: 1 + color: "#2C2D30" + } + + LabelWithButtonType { + Layout.fillWidth: true + + text: "Ключ в виде текста" + buttonImage: "qrc:/images/controls/chevron-right.svg" + iconImage: "qrc:/images/controls/text-cursor.svg" + + onClickedFunc: function() { + UiLogic.goToPage(PageEnum.PageSetupWizardTextKey) + } + } + Rectangle { + Layout.fillWidth: true + height: 1 + color: "#2C2D30" + } + } + } +} diff --git a/client/ui/qml/Pages2/PageSetupWizardCredentials.qml b/client/ui/qml/Pages2/PageSetupWizardCredentials.qml index 20472de2b..a6e98fee6 100644 --- a/client/ui/qml/Pages2/PageSetupWizardCredentials.qml +++ b/client/ui/qml/Pages2/PageSetupWizardCredentials.qml @@ -11,7 +11,7 @@ import "../Config" PageBase { id: root - page: PageEnum.WizardCredentials + page: PageEnum.PageSetupWizardCredentials FlickableType { id: fl @@ -61,7 +61,7 @@ PageBase { text: qsTr("Настроить сервер простым образом") onClicked: function() { - UiLogic.goToPage(PageEnum.WizardEasySetup) + UiLogic.goToPage(PageEnum.PageSetupWizardEasy) } } @@ -79,7 +79,7 @@ PageBase { text: qsTr("Выбрать протокол для установки") onClicked: function() { - UiLogic.goToPage(PageEnum.WizardProtocols) + UiLogic.goToPage(PageEnum.PageSetupWizardProtocols) } } } diff --git a/client/ui/qml/Pages2/PageSetupWizardEasy.qml b/client/ui/qml/Pages2/PageSetupWizardEasy.qml index b41215920..8c75a1dfa 100644 --- a/client/ui/qml/Pages2/PageSetupWizardEasy.qml +++ b/client/ui/qml/Pages2/PageSetupWizardEasy.qml @@ -11,7 +11,7 @@ import "../Config" PageBase { id: root - page: PageEnum.WizardEasySetup + page: PageEnum.PageSetupWizardEasy FlickableType { id: fl diff --git a/client/ui/qml/Pages2/PageSetupWizardInstalling.qml b/client/ui/qml/Pages2/PageSetupWizardInstalling.qml new file mode 100644 index 000000000..3445b5334 --- /dev/null +++ b/client/ui/qml/Pages2/PageSetupWizardInstalling.qml @@ -0,0 +1,46 @@ +import QtQuick +import QtQuick.Controls +import QtQuick.Layouts + +import PageEnum 1.0 + +import "./" +import "../Pages" +import "../Controls2" +import "../Controls2/TextTypes" +import "../Config" + +PageBase { + id: root + page: PageEnum.PageSetupWizardInstalling + + FlickableType { + id: fl + anchors.top: root.top + anchors.bottom: root.bottom + contentHeight: content.height + + ColumnLayout { + id: content + + anchors.top: parent.top + anchors.left: parent.left + anchors.right: parent.right + anchors.rightMargin: 16 + anchors.leftMargin: 16 + + spacing: 16 + + HeaderType { + Layout.fillWidth: true + Layout.topMargin: 20 + + //TODO remove later + buttonImage: "qrc:/images/controls/arrow-left.svg" + + headerText: "Установка" + descriptionText: ContainersModel.getCurrentlyInstalledContainerName() + } + } + } +} diff --git a/client/ui/qml/Pages2/PageSetupWizardProtocolSettings.qml b/client/ui/qml/Pages2/PageSetupWizardProtocolSettings.qml new file mode 100644 index 000000000..9b6e788fe --- /dev/null +++ b/client/ui/qml/Pages2/PageSetupWizardProtocolSettings.qml @@ -0,0 +1,96 @@ +import QtQuick +import QtQuick.Controls +import QtQuick.Layouts + +import PageEnum 1.0 + +import "./" +import "../Pages" +import "../Controls2" +import "../Controls2/TextTypes" +import "../Config" + +PageBase { + id: root + page: PageEnum.PageSetupWizardProtocolSettings + + FlickableType { + id: fl + anchors.top: root.top + anchors.bottom: root.bottom + contentHeight: content.height + + ColumnLayout { + id: content + + anchors.top: parent.top + anchors.left: parent.left + anchors.right: parent.right + anchors.rightMargin: 16 + anchors.leftMargin: 16 + + spacing: 16 + + HeaderType { + Layout.fillWidth: true + Layout.topMargin: 20 + + buttonImage: "qrc:/images/controls/arrow-left.svg" + + headerText: "Установка " + ContainersModel.getCurrentlyInstalledContainerName() + descriptionText: "Эти настройки можно будет изменить позже" + } + + BodyTextType { + Layout.topMargin: 16 + + text: "Network protocol" + } + + //TODO move to separete control + Rectangle { + implicitWidth: buttonGroup.implicitWidth + implicitHeight: buttonGroup.implicitHeight + + color: "#1C1D21" + radius: 16 + + RowLayout { + id: buttonGroup + + spacing: 0 + + HorizontalRadioButton { + implicitWidth: (root.width - 32) / 2 + text: "UDP" + } + + HorizontalRadioButton { + implicitWidth: (root.width - 32) / 2 + text: "TCP" + } + } + } + + TextFieldWithHeaderType { + Layout.fillWidth: true + headerText: "Port" + } + } + } + + BasicButtonType { + anchors.bottom: parent.bottom + anchors.left: parent.left + anchors.right: parent.right + anchors.rightMargin: 16 + anchors.leftMargin: 16 + anchors.bottomMargin: 32 + + text: qsTr("Установить") + + onClicked: function() { + UiLogic.goToPage(PageEnum.PageSetupWizardInstalling) + } + } +} diff --git a/client/ui/qml/Pages2/PageSetupWizardProtocols.qml b/client/ui/qml/Pages2/PageSetupWizardProtocols.qml index a50da64bf..ad4efbc21 100644 --- a/client/ui/qml/Pages2/PageSetupWizardProtocols.qml +++ b/client/ui/qml/Pages2/PageSetupWizardProtocols.qml @@ -14,11 +14,11 @@ import "../Config" PageBase { id: root - page: PageEnum.WizardProtocols + page: PageEnum.PageSetupWizardProtocols SortFilterProxyModel { - id: containersModel - sourceModel: UiLogic.containersModel + id: proxyContainersModel + sourceModel: ContainersModel filters: [ ValueFilter { roleName: "is_installed_role" @@ -64,7 +64,7 @@ PageBase { currentIndex: -1 clip: true interactive: false - model: containersModel + model: proxyContainersModel delegate: Item { implicitWidth: containers.width @@ -87,6 +87,10 @@ PageBase { descriptionText: desc_role buttonImage: "qrc:/images/controls/chevron-right.svg" + onClickedFunc: function() { + ContainersModel.setCurrentlyInstalledContainerIndex(proxyContainersModel.mapToSource(index)) + UiLogic.goToPage(PageEnum.PageSetupWizardProtocolSettings) + } } Rectangle { diff --git a/client/ui/qml/Pages2/PageSetupWizardTextKey.qml b/client/ui/qml/Pages2/PageSetupWizardTextKey.qml new file mode 100644 index 000000000..9fddc573d --- /dev/null +++ b/client/ui/qml/Pages2/PageSetupWizardTextKey.qml @@ -0,0 +1,74 @@ +import QtQuick +import QtQuick.Controls +import QtQuick.Layouts + +import PageEnum 1.0 + +import "./" +import "../Pages" +import "../Controls2" +import "../Controls2/TextTypes" +import "../Config" + +PageBase { + id: root + page: PageEnum.PageSetupWizardInstalling + + FlickableType { + id: fl + anchors.top: root.top + anchors.bottom: root.bottom + contentHeight: content.height + + ColumnLayout { + id: content + + anchors.top: parent.top + anchors.left: parent.left + anchors.right: parent.right + anchors.rightMargin: 16 + anchors.leftMargin: 16 + + spacing: 16 + + HeaderType { + Layout.fillWidth: true + Layout.topMargin: 20 + + buttonImage: "qrc:/images/controls/arrow-left.svg" + + headerText: "Ключ для подключения" + descriptionText: "Строка, которая начинается с vpn://..." + } + + TextFieldWithHeaderType { + Layout.fillWidth: true + Layout.topMargin: 32 + + headerText: "Ключ" + textFieldPlaceholderText: "vpn://" + buttonText: "Вставить" + + clickedFunc: function() { + textField.text = "" + textField.paste() + } + } + } + } + + BasicButtonType { + anchors.bottom: parent.bottom + anchors.left: parent.left + anchors.right: parent.right + anchors.rightMargin: 16 + anchors.leftMargin: 16 + anchors.bottomMargin: 32 + + text: qsTr("Подключиться") + + onClicked: function() { +// UiLogic.goToPage(PageEnum.PageSetupWizardInstalling) + } + } +} diff --git a/client/ui/qml/Pages2/PageStart.qml b/client/ui/qml/Pages2/PageStart.qml index 8d8fbb9d2..e04ebbb6c 100644 --- a/client/ui/qml/Pages2/PageStart.qml +++ b/client/ui/qml/Pages2/PageStart.qml @@ -12,7 +12,7 @@ import "../Controls2/TextTypes" PageBase { id: root - page: PageEnum.Start + page: PageEnum.PageStart FlickableType { id: fl @@ -77,7 +77,7 @@ PageBase { text: qsTr("У меня ничего нет") onClicked: { - UiLogic.goToPage(PageEnum.Test) + UiLogic.goToPage(PageEnum.PageTest) } } } @@ -129,7 +129,7 @@ PageBase { buttonImage: "qrc:/images/controls/chevron-right.svg" onClickedFunc: function() { - UiLogic.goToPage(PageEnum.WizardCredentials) + UiLogic.goToPage(PageEnum.PageSetupWizardCredentials) drawer.visible = false } } @@ -144,9 +144,10 @@ PageBase { text: "QR-код, ключ или файл настроек" buttonImage: "qrc:/images/controls/chevron-right.svg" - // onClickedFunc: function() { - // UiLogic.goToPage(PageEnum.Start) - // } + onClickedFunc: function() { + UiLogic.goToPage(PageEnum.PageSetupWizardConfigSource) + drawer.visible = false + } } Rectangle { Layout.fillWidth: true diff --git a/client/ui/qml/main2.qml b/client/ui/qml/main2.qml index c7e06eaaf..6261e9a70 100644 --- a/client/ui/qml/main2.qml +++ b/client/ui/qml/main2.qml @@ -14,6 +14,7 @@ Window { height: GC.screenHeight minimumWidth: GC.isDesktop() ? 360 : 0 minimumHeight: GC.isDesktop() ? 640 : 0 + onClosing: function() { console.debug("QML onClosing signal") UiLogic.onCloseWindow() @@ -21,28 +22,18 @@ Window { title: "AmneziaVPN" - function gotoPage(type, page, reset, slide) { - let p_obj; - if (type === PageType.Basic) p_obj = pageLoader.pages[page] - else if (type === PageType.Proto) p_obj = protocolPages[page] - else if (type === PageType.ShareProto) p_obj = sharePages[page] - else return - + function gotoPage(page, reset, slide) { if (pageStackView.depth > 0) { pageStackView.currentItem.deactivated() } if (slide) { - pageStackView.push(p_obj, {}, StackView.PushTransition) + pageStackView.push(UiLogic.pageEnumToString(page), {}, StackView.PushTransition) } else { - pageStackView.push(p_obj, {}, StackView.Immediate) + pageStackView.push(UiLogic.pageEnumToString(page), {}, StackView.Immediate) } -// if (reset) { -// p_obj.logic.onUpdatePage(); -// } - - p_obj.activated(reset) + pageStackView.currentItem.activated(reset) } function closePage() { @@ -60,9 +51,9 @@ Window { pageStackView.clear() if (slide) { - pageStackView.push(pages[page], {}, StackView.PushTransition) + pageStackView.push(UiLogic.pageEnumToString(page), {}, StackView.PushTransition) } else { - pageStackView.push(pages[page], {}, StackView.Immediate) + pageStackView.push(UiLogic.pageEnumToString(page), {}, StackView.Immediate) } if (page === PageEnum.Start) { UiLogic.pushButtonBackFromStartVisible = !pageStackView.empty @@ -79,33 +70,12 @@ Window { id: pageStackView anchors.fill: parent focus: true - - onCurrentItemChanged: function() { - UiLogic.currentPageValue = currentItem.page - } - - onDepthChanged: function() { - UiLogic.pagesStackDepth = depth - } - - Keys.onPressed: function(event) { - UiLogic.keyPressEvent(event.key) - event.accepted = true - } } Connections { target: UiLogic function onGoToPage(page, reset, slide) { - root.gotoPage(PageType.Basic, page, reset, slide) - } - - function onGoToProtocolPage(protocol, reset, slide) { - root.gotoPage(PageType.Proto, protocol, reset, slide) - } - - function onGoToShareProtocolPage(protocol, reset, slide) { - root.gotoPage(PageType.ShareProto, protocol, reset, slide) + root.gotoPage(page, reset, slide) } function onClosePage() { @@ -118,6 +88,7 @@ Window { function onShow() { root.show() + UiLogic.initializeUiLogic() } function onHide() { @@ -130,13 +101,4 @@ Window { root.requestActivate() } } - - PageLoader { - id: pageLoader - - onFinished: { - UiLogic.initializeUiLogic() - } - } - } diff --git a/client/ui/uilogic.cpp b/client/ui/uilogic.cpp index d47c11864..63371420f 100644 --- a/client/ui/uilogic.cpp +++ b/client/ui/uilogic.cpp @@ -84,7 +84,6 @@ UiLogic::UiLogic(std::shared_ptr settings, std::shared_ptrdefaultServerIndex(); @@ -619,3 +618,8 @@ bool UiLogic::isContainerAlreadyAddedToGui(DockerContainer container) return false; } +QString UiLogic::pageEnumToString(Page page) { + QMetaEnum metaEnum = QMetaEnum::fromType(); + QString pageName = metaEnum.valueToKey(static_cast(page)); + return "Pages2/" + pageName + ".qml"; +} diff --git a/client/ui/uilogic.h b/client/ui/uilogic.h index 3b7797a88..4b3920666 100644 --- a/client/ui/uilogic.h +++ b/client/ui/uilogic.h @@ -67,7 +67,6 @@ class UiLogic : public QObject AUTO_PROPERTY(int, pagesStackDepth) AUTO_PROPERTY(int, currentPageValue) - READONLY_PROPERTY(QObject *, containersModel) READONLY_PROPERTY(QObject *, protocolsModel) READONLY_PROPERTY(QObject *, clientManagementModel) @@ -124,6 +123,8 @@ class UiLogic : public QObject Q_INVOKABLE amnezia::ErrorCode addAlreadyInstalledContainersGui(bool &isServerCreated); + Q_INVOKABLE QString pageEnumToString(PageEnumNS::Page page); + void shareTempFile(const QString &suggestedName, QString ext, const QString& data); static QString getOpenFileName(QWidget *parent = nullptr, const QString &caption = QString(),