Skip to content

Commit

Permalink
added PageHome, PageSettings, PageShare, PageStart
Browse files Browse the repository at this point in the history
- renamed old PageStart to PageSetupWizardStart
- added various text types
- moved servers model to "global" scope
  • Loading branch information
Nethius committed May 6, 2023
1 parent 4f36349 commit 1c8dbae
Show file tree
Hide file tree
Showing 28 changed files with 728 additions and 219 deletions.
3 changes: 3 additions & 0 deletions client/amnezia_application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@ void AmneziaApplication::init()
m_containersModel.reset(new ContainersModel(m_settings, this));
m_engine->rootContext()->setContextProperty("ContainersModel", m_containersModel.get());

m_serversModel.reset(new ServersModel(m_settings, this));
m_engine->rootContext()->setContextProperty("ServersModel", m_serversModel.get());

m_uiLogic->registerPagesLogic();

#if defined(Q_OS_IOS)
Expand Down
3 changes: 3 additions & 0 deletions client/amnezia_application.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

#include "ui/uilogic.h"
#include "configurators/vpn_configurator.h"
#include "ui/models/servers_model.h"
#include "ui/models/containers_model.h"

#define amnApp (static_cast<AmneziaApplication *>(QCoreApplication::instance()))

Expand Down Expand Up @@ -57,6 +59,7 @@ class AmneziaApplication : public AMNEZIA_BASE_CLASS
QCommandLineParser m_parser;

QScopedPointer<ContainersModel> m_containersModel;
QScopedPointer<ServersModel> m_serversModel;

};

Expand Down
4 changes: 4 additions & 0 deletions client/images/controls/home.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions client/images/controls/settings-2.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/images/controls/share-2.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 14 additions & 2 deletions client/resources.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@
<file>ui/qml/Controls2/CheckBoxType.qml</file>
<file>images/controls/check.svg</file>
<file>ui/qml/Controls2/DropDownType.qml</file>
<file>ui/qml/Pages2/PageStart.qml</file>
<file>ui/qml/Pages2/PageSetupWizardStart.qml</file>
<file>ui/qml/main2.qml</file>
<file>ui/qml/PageLoader.qml</file>
<file>images/amneziaBigLogo.png</file>
Expand All @@ -195,7 +195,7 @@
<file>ui/qml/Pages2/PageSetupWizardEasy.qml</file>
<file>images/controls/chevron-down.svg</file>
<file>images/controls/chevron-up.svg</file>
<file>ui/qml/Controls2/TextTypes/BodyTextType.qml</file>
<file>ui/qml/Controls2/TextTypes/ParagraphTextType.qml</file>
<file>ui/qml/Controls2/TextTypes/Header2TextType.qml</file>
<file>ui/qml/Controls2/HorizontalRadioButton.qml</file>
<file>ui/qml/Controls2/VerticalRadioButton.qml</file>
Expand All @@ -209,5 +209,17 @@
<file>images/controls/qr-code.svg</file>
<file>images/controls/text-cursor.svg</file>
<file>ui/qml/Pages2/PageSetupWizardTextKey.qml</file>
<file>ui/qml/Pages2/PageStart.qml</file>
<file>ui/qml/Controls2/TabImageButtonType.qml</file>
<file>images/controls/home.svg</file>
<file>images/controls/settings-2.svg</file>
<file>images/controls/share-2.svg</file>
<file>ui/qml/Pages2/PageHome.qml</file>
<file>ui/qml/Pages2/PageSettings.qml</file>
<file>ui/qml/Pages2/PageShare.qml</file>
<file>ui/qml/Controls2/TextTypes/Header1TextType.qml</file>
<file>ui/qml/Controls2/TextTypes/LabelTextType.qml</file>
<file>ui/qml/Controls2/TextTypes/ButtonTextType.qml</file>
<file>ui/qml/Controls2/Header2Type.qml</file>
</qresource>
</RCC>
35 changes: 24 additions & 11 deletions client/ui/models/servers_model.cpp
Original file line number Diff line number Diff line change
@@ -1,29 +1,42 @@
#include "servers_model.h"

ServersModel::ServersModel(QObject *parent) :
QAbstractListModel(parent)
ServersModel::ServersModel(std::shared_ptr<Settings> settings, QObject *parent) : m_settings(settings), QAbstractListModel(parent)
{

const QJsonArray &servers = m_settings->serversArray();
int defaultServer = m_settings->defaultServerIndex();
QVector<ServerModelContent> serverListContent;
for(int i = 0; i < servers.size(); i++) {
ServerModelContent c;
auto server = servers.at(i).toObject();
c.desc = server.value(config_key::description).toString();
c.address = server.value(config_key::hostName).toString();
if (c.desc.isEmpty()) {
c.desc = c.address;
}
c.isDefault = (i == defaultServer);
serverListContent.push_back(c);
}
setContent(serverListContent);
}

void ServersModel::clearData()
{
beginResetModel();
content.clear();
m_content.clear();
endResetModel();
}

void ServersModel::setContent(const std::vector<ServerModelContent> &data)
void ServersModel::setContent(const QVector<ServerModelContent> &data)
{
beginResetModel();
content = data;
m_content = data;
endResetModel();
}

int ServersModel::rowCount(const QModelIndex &parent) const
{
Q_UNUSED(parent);
return static_cast<int>(content.size());
return static_cast<int>(m_content.size());
}

QHash<int, QByteArray> ServersModel::roleNames() const {
Expand All @@ -37,17 +50,17 @@ QHash<int, QByteArray> ServersModel::roleNames() const {
QVariant ServersModel::data(const QModelIndex &index, int role) const
{
if (!index.isValid() || index.row() < 0
|| index.row() >= static_cast<int>(content.size())) {
|| index.row() >= static_cast<int>(m_content.size())) {
return QVariant();
}
if (role == DescRole) {
return content[index.row()].desc;
return m_content[index.row()].desc;
}
if (role == AddressRole) {
return content[index.row()].address;
return m_content[index.row()].address;
}
if (role == IsDefaultRole) {
return content[index.row()].isDefault;
return m_content[index.row()].isDefault;
}
return QVariant();
}
Expand Down
11 changes: 6 additions & 5 deletions client/ui/models/servers_model.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
#define SERVERSMODEL_H

#include <QAbstractListModel>
#include <vector>
#include <utility>

#include "settings.h"

struct ServerModelContent {
QString desc;
Expand All @@ -15,7 +15,7 @@ class ServersModel : public QAbstractListModel
{
Q_OBJECT
public:
ServersModel(QObject *parent = nullptr);
ServersModel(std::shared_ptr<Settings> settings, QObject *parent = nullptr);
public:
enum SiteRoles {
DescRole = Qt::UserRole + 1,
Expand All @@ -24,7 +24,7 @@ class ServersModel : public QAbstractListModel
};

void clearData();
void setContent(const std::vector<ServerModelContent>& data);
void setContent(const QVector<ServerModelContent>& data);
int rowCount(const QModelIndex &parent = QModelIndex()) const override;

QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
Expand All @@ -33,7 +33,8 @@ class ServersModel : public QAbstractListModel
QHash<int, QByteArray> roleNames() const override;

private:
std::vector<ServerModelContent> content;
QVector<ServerModelContent> m_content;
std::shared_ptr<Settings> m_settings;
};

#endif // SERVERSMODEL_H
6 changes: 4 additions & 2 deletions client/ui/pages.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,11 @@ enum class Page {Start = 0, NewServer, NewServerProtocols, Vpn,
ProtocolSettings, ProtocolShare, QrDecoder, QrDecoderIos, About, ViewConfig,
AdvancedServerSettings, ClientManagement, ClientInfo,

PageStart, PageTest, PageSetupWizardCredentials, PageSetupWizardProtocols, PageSetupWizardEasy,
PageSetupWizardStart, PageTest, PageSetupWizardCredentials, PageSetupWizardProtocols, PageSetupWizardEasy,
PageSetupWizardProtocolSettings, PageSetupWizardInstalling, PageSetupWizardConfigSource,
PageSetupWizardTextKey};
PageSetupWizardTextKey,

PageStart, PageHome, PageSettings, PageShare};
Q_ENUM_NS(Page)

static void declareQmlPageEnum() {
Expand Down
4 changes: 2 additions & 2 deletions client/ui/pages_logic/ServerListLogic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

ServerListLogic::ServerListLogic(UiLogic *logic, QObject *parent):
PageLogicBase(logic, parent),
m_serverListModel{new ServersModel(this)}
m_serverListModel{new ServersModel(m_settings, this)}
{

}
Expand All @@ -33,7 +33,7 @@ void ServerListLogic::onUpdatePage()
{
const QJsonArray &servers = m_settings->serversArray();
int defaultServer = m_settings->defaultServerIndex();
std::vector<ServerModelContent> serverListContent;
QVector<ServerModelContent> serverListContent;
for(int i = 0; i < servers.size(); i++) {
ServerModelContent c;
auto server = servers.at(i).toObject();
Expand Down
59 changes: 26 additions & 33 deletions client/ui/qml/Controls2/DropDownType.qml
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,20 @@ Item {

property var onClickedFunc
property string buttonImage: "qrc:/images/controls/chevron-down.svg"
property string buttonImageColor: "#494B50"


property string defaultColor: "#1C1D21"

property string textColor: "#d7d8db"

property string borderColor: "#494B50"
property int borderWidth: 1

property alias menuModel: menuContent.model

height: buttonContent.implicitHeight
implicitWidth: buttonContent.implicitWidth
implicitHeight: buttonContent.implicitHeight

Rectangle {
id: buttonBackground
Expand All @@ -28,6 +34,7 @@ Item {
radius: 16
color: defaultColor
border.color: borderColor
border.width: borderWidth

Behavior on border.width {
PropertyAnimation { duration: 200 }
Expand All @@ -37,72 +44,55 @@ Item {
RowLayout {
id: buttonContent
anchors.fill: parent
anchors.rightMargin: 16
anchors.leftMargin: 16

spacing: 0

ColumnLayout {
Layout.leftMargin: 16
Layout.rightMargin: 16
Layout.topMargin: 16
Layout.bottomMargin: 16

Text {
LabelTextType {
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter

visible: root.descriptionText !== ""

font.family: "PT Root UI"
font.styleName: "normal"
font.pixelSize: 13
font.letterSpacing: 0.02
color: "#878B91"
text: root.descriptionText
wrapMode: Text.WordWrap

Layout.fillWidth: true
height: 16
}

horizontalAlignment: Text.AlignLeft
ButtonTextType {
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter
}

Text {
font.family: "PT Root UI"
font.styleName: "normal"
font.pixelSize: 16
color: "#d7d8db"
color: root.textColor
text: root.text

Layout.fillWidth: true
height: 24

horizontalAlignment: Text.AlignLeft
verticalAlignment: Text.AlignVCenter
}
}

ImageButtonType {
id: button

Layout.leftMargin: 4
Layout.rightMargin: 16

hoverEnabled: false
image: buttonImage
imageColor: buttonImageColor
onClicked: {
if (onClickedFunc && typeof onClickedFunc === "function") {
onClickedFunc()
}
}

Layout.alignment: Qt.AlignRight
}
}

MouseArea {
anchors.fill: parent
anchors.fill: buttonContent
cursorShape: Qt.PointingHandCursor
hoverEnabled: true

onEntered: {
buttonBackground.border.width = 1
buttonBackground.border.width = borderWidth
}

onExited: {
Expand All @@ -119,7 +109,7 @@ Item {

edge: Qt.BottomEdge
width: parent.width
height: parent.height * 0.8
height: parent.height * 0.9

clip: true
modal: true
Expand All @@ -129,6 +119,9 @@ Item {
anchors.bottomMargin: -radius
radius: 16
color: "#1C1D21"

border.color: borderColor
border.width: 1
}

Overlay.modal: Rectangle {
Expand Down
Loading

0 comments on commit 1c8dbae

Please sign in to comment.