Skip to content

Commit

Permalink
changed the way to create qml pages, now the page is created when you…
Browse files Browse the repository at this point in the history
… go to it

- added PageSetupWizardConfigSource, PageSetupWizardInstalling, PageSetupWizardProtocolSettings, PageSetupWizardTextKey
  • Loading branch information
Nethius committed May 3, 2023
1 parent 68b2745 commit 4f36349
Show file tree
Hide file tree
Showing 25 changed files with 504 additions and 159 deletions.
6 changes: 6 additions & 0 deletions client/amnezia_application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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()
Expand Down
2 changes: 2 additions & 0 deletions client/amnezia_application.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ class AmneziaApplication : public AMNEZIA_BASE_CLASS
QTranslator* m_translator;
QCommandLineParser m_parser;

QScopedPointer<ContainersModel> m_containersModel;

};

#endif // AMNEZIA_APPLICATION_H
3 changes: 3 additions & 0 deletions client/images/controls/folder-open.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 14 additions & 0 deletions client/images/controls/qr-code.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions client/images/controls/text-cursor.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions client/resources.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -202,5 +202,12 @@
<file>ui/qml/Controls2/SwitcherType.qml</file>
<file>ui/qml/Pages2/PageTest.qml</file>
<file>ui/qml/Controls2/TabButtonType.qml</file>
<file>ui/qml/Pages2/PageSetupWizardProtocolSettings.qml</file>
<file>ui/qml/Pages2/PageSetupWizardInstalling.qml</file>
<file>ui/qml/Pages2/PageSetupWizardConfigSource.qml</file>
<file>images/controls/folder-open.svg</file>
<file>images/controls/qr-code.svg</file>
<file>images/controls/text-cursor.svg</file>
<file>ui/qml/Pages2/PageSetupWizardTextKey.qml</file>
</qresource>
</RCC>
10 changes: 10 additions & 0 deletions client/ui/models/containers_model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
4 changes: 4 additions & 0 deletions client/ui/models/containers_model.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<int, QByteArray> roleNames() const override;

private:
int m_selectedServerIndex;
QModelIndex m_currentlyInstalledContainerIndex;
std::shared_ptr<Settings> m_settings;
};

Expand Down
4 changes: 3 additions & 1 deletion client/ui/pages.h
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
4 changes: 2 additions & 2 deletions client/ui/pages_logic/ServerContainersLogic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ ServerContainersLogic::ServerContainersLogic(UiLogic *logic, QObject *parent):

void ServerContainersLogic::onUpdatePage()
{
ContainersModel *c_model = qobject_cast<ContainersModel *>(uiLogic()->containersModel());
c_model->setSelectedServerIndex(uiLogic()->m_selectedServerIndex);
// ContainersModel *c_model = qobject_cast<ContainersModel *>(uiLogic()->containersModel());
// c_model->setSelectedServerIndex(uiLogic()->m_selectedServerIndex);

ProtocolsModel *p_model = qobject_cast<ProtocolsModel *>(uiLogic()->protocolsModel());
p_model->setSelectedServerIndex(uiLogic()->m_selectedServerIndex);
Expand Down
1 change: 0 additions & 1 deletion client/ui/qml/Controls2/BasicButtonType.qml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ Button {
property string borderColor: "#D7D8DB"
property int borderWidth: 0

implicitWidth: 328
implicitHeight: 56

hoverEnabled: true
Expand Down
10 changes: 10 additions & 0 deletions client/ui/qml/Controls2/LabelWithButtonType.qml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -18,13 +20,21 @@ 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"
font.styleName: "normal"
font.pixelSize: 18
color: "#d7d8db"
text: root.text
wrapMode: Text.WordWrap

Layout.fillWidth: true
height: 22
Expand Down
105 changes: 68 additions & 37 deletions client/ui/qml/Controls2/TextFieldWithHeaderType.qml
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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()
}
}
}
}
Expand Down
58 changes: 4 additions & 54 deletions client/ui/qml/PageLoader.qml
Original file line number Diff line number Diff line change
@@ -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"
}
Loading

0 comments on commit 4f36349

Please sign in to comment.