added display of protocols on PageHome

This commit is contained in:
Vladimir Kuznetsov 2023-05-11 14:50:50 +08:00
parent 1c8dbae359
commit b66f4bf2be
22 changed files with 237 additions and 138 deletions

View file

@ -187,7 +187,6 @@ void AmneziaApplication::loadFonts()
QFontDatabase::addApplicationFont(":/fonts/Lato-Regular.ttf"); QFontDatabase::addApplicationFont(":/fonts/Lato-Regular.ttf");
QFontDatabase::addApplicationFont(":/fonts/Lato-Thin.ttf"); QFontDatabase::addApplicationFont(":/fonts/Lato-Thin.ttf");
QFontDatabase::addApplicationFont(":/fonts/Lato-ThinItalic.ttf"); QFontDatabase::addApplicationFont(":/fonts/Lato-ThinItalic.ttf");
QFontDatabase::addApplicationFont(":/fonts/pt-root-ui_vf.ttf"); QFontDatabase::addApplicationFont(":/fonts/pt-root-ui_vf.ttf");
} }

View file

@ -0,0 +1,4 @@
<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M12 5V19" stroke="#CBCBCB" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M5 12H19" stroke="#CBCBCB" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
</svg>

After

Width:  |  Height:  |  Size: 307 B

View file

@ -221,5 +221,6 @@
<file>ui/qml/Controls2/TextTypes/LabelTextType.qml</file> <file>ui/qml/Controls2/TextTypes/LabelTextType.qml</file>
<file>ui/qml/Controls2/TextTypes/ButtonTextType.qml</file> <file>ui/qml/Controls2/TextTypes/ButtonTextType.qml</file>
<file>ui/qml/Controls2/Header2Type.qml</file> <file>ui/qml/Controls2/Header2Type.qml</file>
<file>images/controls/plus.svg</file>
</qresource> </qresource>
</RCC> </RCC>

View file

@ -2,41 +2,34 @@
ServersModel::ServersModel(std::shared_ptr<Settings> settings, QObject *parent) : m_settings(settings), QAbstractListModel(parent) ServersModel::ServersModel(std::shared_ptr<Settings> settings, QObject *parent) : m_settings(settings), QAbstractListModel(parent)
{ {
refresh();
}
void ServersModel::refresh()
{
beginResetModel();
const QJsonArray &servers = m_settings->serversArray(); const QJsonArray &servers = m_settings->serversArray();
int defaultServer = m_settings->defaultServerIndex(); int defaultServer = m_settings->defaultServerIndex();
QVector<ServerModelContent> serverListContent; QVector<ServerModelContent> serverListContent;
for(int i = 0; i < servers.size(); i++) { for(int i = 0; i < servers.size(); i++) {
ServerModelContent c; ServerModelContent content;
auto server = servers.at(i).toObject(); auto server = servers.at(i).toObject();
c.desc = server.value(config_key::description).toString(); content.desc = server.value(config_key::description).toString();
c.address = server.value(config_key::hostName).toString(); content.address = server.value(config_key::hostName).toString();
if (c.desc.isEmpty()) { if (content.desc.isEmpty()) {
c.desc = c.address; content.desc = content.address;
} }
c.isDefault = (i == defaultServer); content.isDefault = (i == defaultServer);
serverListContent.push_back(c); serverListContent.push_back(content);
} }
setContent(serverListContent); m_data = serverListContent;
}
void ServersModel::clearData()
{
beginResetModel();
m_content.clear();
endResetModel();
}
void ServersModel::setContent(const QVector<ServerModelContent> &data)
{
beginResetModel();
m_content = data;
endResetModel(); endResetModel();
} }
int ServersModel::rowCount(const QModelIndex &parent) const int ServersModel::rowCount(const QModelIndex &parent) const
{ {
Q_UNUSED(parent); Q_UNUSED(parent);
return static_cast<int>(m_content.size()); return static_cast<int>(m_data.size());
} }
QHash<int, QByteArray> ServersModel::roleNames() const { QHash<int, QByteArray> ServersModel::roleNames() const {
@ -50,19 +43,24 @@ QHash<int, QByteArray> ServersModel::roleNames() const {
QVariant ServersModel::data(const QModelIndex &index, int role) const QVariant ServersModel::data(const QModelIndex &index, int role) const
{ {
if (!index.isValid() || index.row() < 0 if (!index.isValid() || index.row() < 0
|| index.row() >= static_cast<int>(m_content.size())) { || index.row() >= static_cast<int>(m_data.size())) {
return QVariant(); return QVariant();
} }
if (role == DescRole) { if (role == DescRole) {
return m_content[index.row()].desc; return m_data[index.row()].desc;
} }
if (role == AddressRole) { if (role == AddressRole) {
return m_content[index.row()].address; return m_data[index.row()].address;
} }
if (role == IsDefaultRole) { if (role == IsDefaultRole) {
return m_content[index.row()].isDefault; return m_data[index.row()].isDefault;
} }
return QVariant(); return QVariant();
} }
void ServersModel::setDefaultServerIndex(int index)
{
}

View file

@ -23,8 +23,7 @@ public:
IsDefaultRole IsDefaultRole
}; };
void clearData(); void refresh();
void setContent(const QVector<ServerModelContent>& data);
int rowCount(const QModelIndex &parent = QModelIndex()) const override; int rowCount(const QModelIndex &parent = QModelIndex()) const override;
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
@ -33,7 +32,7 @@ protected:
QHash<int, QByteArray> roleNames() const override; QHash<int, QByteArray> roleNames() const override;
private: private:
QVector<ServerModelContent> m_content; QVector<ServerModelContent> m_data;
std::shared_ptr<Settings> m_settings; std::shared_ptr<Settings> m_settings;
}; };

View file

@ -45,5 +45,5 @@ void ServerListLogic::onUpdatePage()
c.isDefault = (i == defaultServer); c.isDefault = (i == defaultServer);
serverListContent.push_back(c); serverListContent.push_back(c);
} }
qobject_cast<ServersModel*>(m_serverListModel)->setContent(serverListContent); // qobject_cast<ServersModel*>(m_serverListModel)->setContent(serverListContent);
} }

View file

@ -48,7 +48,7 @@ Button {
contentItem: Text { contentItem: Text {
anchors.fill: background anchors.fill: background
font.family: "PT Root UI" font.family: "PT Root UI VF"
font.styleName: "normal" font.styleName: "normal"
font.weight: 400 font.weight: 400
font.pixelSize: 16 font.pixelSize: 16

View file

@ -10,6 +10,9 @@ Item {
property string text property string text
property string descriptionText property string descriptionText
property string headerText
property string headerBackButtonImage
property var onClickedFunc property var onClickedFunc
property string buttonImage: "qrc:/images/controls/chevron-down.svg" property string buttonImage: "qrc:/images/controls/chevron-down.svg"
property string buttonImageColor: "#494B50" property string buttonImageColor: "#494B50"
@ -22,7 +25,10 @@ Item {
property string borderColor: "#494B50" property string borderColor: "#494B50"
property int borderWidth: 1 property int borderWidth: 1
property alias menuModel: menuContent.model property Component menuDelegate
property variant menuModel
property alias menuVisible: menu.visible
implicitWidth: buttonContent.implicitWidth implicitWidth: buttonContent.implicitWidth
implicitHeight: buttonContent.implicitHeight implicitHeight: buttonContent.implicitHeight
@ -128,12 +134,13 @@ Item {
color: Qt.rgba(14/255, 14/255, 17/255, 0.8) color: Qt.rgba(14/255, 14/255, 17/255, 0.8)
} }
Header2TextType { Header2Type {
id: header id: header
width: parent.width
text: "Данные для подключения" headerText: root.headerText
wrapMode: Text.WordWrap backButtonImage: root.headerBackButtonImage
width: parent.width
anchors.top: parent.top anchors.top: parent.top
anchors.left: parent.left anchors.left: parent.left
@ -170,64 +177,13 @@ Item {
clip: true clip: true
interactive: false interactive: false
delegate: Item { model: root.menuModel
implicitWidth: menuContent.width
implicitHeight: radioButton.implicitHeight
RadioButton { delegate: Row {
id: radioButton Loader {
id: loader
implicitWidth: parent.width sourceComponent: root.menuDelegate
implicitHeight: radioButtonContent.implicitHeight property QtObject modelData: model
hoverEnabled: true
ButtonGroup.group: radioButtonGroup
indicator: Rectangle {
anchors.fill: parent
color: radioButton.hovered ? "#2C2D30" : "#1C1D21"
}
RowLayout {
id: radioButtonContent
anchors.fill: parent
anchors.rightMargin: 16
anchors.leftMargin: 16
z: 1
Text {
id: text
text: modelData
color: "#D7D8DB"
font.pixelSize: 16
font.weight: 400
font.family: "PT Root UI VF"
height: 24
Layout.fillWidth: true
Layout.topMargin: 20
Layout.bottomMargin: 20
}
Image {
source: "qrc:/images/controls/check.svg"
visible: radioButton.checked
width: 24
height: 24
Layout.rightMargin: 8
}
}
onClicked: {
root.text = modelData
menu.visible = false
}
} }
} }
} }

View file

@ -6,7 +6,12 @@ import "TextTypes"
Item { Item {
id: root id: root
property string buttonImage property string backButtonImage
property string actionButtonImage
property var backButtonFunction
property var actionButtonFunction
property string headerText property string headerText
property string descriptionText property string descriptionText
@ -22,16 +27,19 @@ Item {
Layout.leftMargin: -6 Layout.leftMargin: -6
image: root.buttonImage image: root.backButtonImage
imageColor: "#D7D8DB" imageColor: "#D7D8DB"
visible: image ? true : false visible: image ? true : false
onClicked: { onClicked: {
UiLogic.closePage() if (backButtonFunction && typeof backButtonFunction === "function") {
backButtonFunction()
}
} }
} }
RowLayout {
Header2TextType { Header2TextType {
id: header id: header
@ -40,6 +48,22 @@ Item {
text: root.headerText text: root.headerText
} }
ImageButtonType {
id: headerActionButton
image: root.actionButtonImage
imageColor: "#D7D8DB"
visible: image ? true : false
onClicked: {
if (actionButtonImage && typeof actionButtonImage === "function") {
actionButtonImage()
}
}
}
}
ParagraphTextType { ParagraphTextType {
id: description id: description

View file

@ -6,7 +6,12 @@ import "TextTypes"
Item { Item {
id: root id: root
property string buttonImage property string backButtonImage
property string actionButtonImage
property var backButtonFunction
property var actionButtonFunction
property string headerText property string headerText
property string descriptionText property string descriptionText
@ -22,16 +27,19 @@ Item {
Layout.leftMargin: -6 Layout.leftMargin: -6
image: root.buttonImage image: root.backButtonImage
imageColor: "#D7D8DB" imageColor: "#D7D8DB"
visible: image ? true : false visible: image ? true : false
onClicked: { onClicked: {
UiLogic.closePage() if (backButtonFunction && typeof backButtonFunction === "function") {
backButtonFunction()
}
} }
} }
RowLayout {
Header1TextType { Header1TextType {
id: header id: header
@ -40,6 +48,24 @@ Item {
text: root.headerText text: root.headerText
} }
ImageButtonType {
id: headerActionButton
Layout.alignment: Qt.AlignRight
image: root.actionButtonImage
imageColor: "#D7D8DB"
visible: image ? true : false
onClicked: {
if (actionButtonImage && typeof actionButtonImage === "function") {
actionButtonImage()
}
}
}
}
ParagraphTextType { ParagraphTextType {
id: description id: description
@ -49,6 +75,8 @@ Item {
text: root.descriptionText text: root.descriptionText
color: "#878B91" color: "#878B91"
visible: root.descriptionText !== ""
} }
} }
} }

View file

@ -29,7 +29,7 @@ Item {
ColumnLayout { ColumnLayout {
Text { Text {
font.family: "PT Root UI" font.family: "PT Root UI VF"
font.styleName: "normal" font.styleName: "normal"
font.pixelSize: 18 font.pixelSize: 18
color: "#d7d8db" color: "#d7d8db"
@ -44,7 +44,7 @@ Item {
} }
Text { Text {
font.family: "PT Root UI" font.family: "PT Root UI VF"
font.styleName: "normal" font.styleName: "normal"
font.pixelSize: 13 font.pixelSize: 13
font.letterSpacing: 0.02 font.letterSpacing: 0.02

View file

@ -43,7 +43,7 @@ TabButton {
anchors.fill: background anchors.fill: background
height: 24 height: 24
font.family: "PT Root UI" font.family: "PT Root UI VF"
font.styleName: "normal" font.styleName: "normal"
font.weight: 500 font.weight: 500
font.pixelSize: 16 font.pixelSize: 16

View file

@ -136,7 +136,7 @@ RadioButton {
} }
Text { Text {
font.family: "PT Root UI" font.family: "PT Root UI VF"
font.styleName: "normal" font.styleName: "normal"
font.pixelSize: 13 font.pixelSize: 13
font.letterSpacing: 0.02 font.letterSpacing: 0.02

View file

@ -2,7 +2,10 @@ import QtQuick
import QtQuick.Controls import QtQuick.Controls
import QtQuick.Layouts import QtQuick.Layouts
import SortFilterProxyModel 0.2
import PageEnum 1.0 import PageEnum 1.0
import ProtocolEnum 1.0
import "./" import "./"
import "../Pages" import "../Pages"
@ -125,11 +128,27 @@ PageBase {
} }
RowLayout { RowLayout {
Layout.alignment: Qt.AlignHCenter | Qt.AlignVCenter Layout.alignment: Qt.AlignHCenter | Qt.AlignVCenter
spacing: 8 spacing: 8
SortFilterProxyModel {
id: proxyContainersModel
sourceModel: ContainersModel
filters: [
ValueFilter {
roleName: "service_type_role"
value: ProtocolEnum.Vpn
},
ValueFilter {
roleName: "is_installed_role"
value: true
}
]
}
DropDownType { DropDownType {
id: protocolsDropDown
implicitHeight: 40 implicitHeight: 40
borderWidth: 0 borderWidth: 0
@ -138,7 +157,83 @@ PageBase {
defaultColor: "#D7D8DB" defaultColor: "#D7D8DB"
textColor: "#0E0E11" textColor: "#0E0E11"
text: "testtesttest" headerText: "Протокол подключения"
headerBackButtonImage: "qrc:/images/controls/arrow-left.svg"
menuModel: proxyContainersModel
menuDelegate: Item {
implicitWidth: menuContent.width
implicitHeight: radioButton.implicitHeight
RadioButton {
id: radioButton
implicitWidth: parent.width
implicitHeight: radioButtonContent.implicitHeight
hoverEnabled: true
ButtonGroup.group: radioButtonGroup
indicator: Rectangle {
anchors.fill: parent
color: radioButton.hovered ? "#2C2D30" : "#1C1D21"
}
RowLayout {
id: radioButtonContent
anchors.fill: parent
anchors.rightMargin: 16
anchors.leftMargin: 16
z: 1
Text {
id: text
// todo remove dirty hack?
text: {
if (modelData !== null) {
return modelData.name_role
} else
return ""
}
color: "#D7D8DB"
font.pixelSize: 16
font.weight: 400
font.family: "PT Root UI VF"
height: 24
Layout.fillWidth: true
Layout.topMargin: 20
Layout.bottomMargin: 20
}
Image {
source: "qrc:/images/controls/check.svg"
visible: radioButton.checked
width: 24
height: 24
Layout.rightMargin: 8
}
}
onClicked: {
protocolsDropDown.text = text.text
protocolsDropDown.menuVisible = false
}
}
Component.onCompleted: {
if (modelData !== null && modelData.default_role) {
protocolsDropDown.text = modelData.name_role
}
}
}
} }
BasicButtonType { BasicButtonType {
@ -149,29 +244,17 @@ PageBase {
} }
Header2Type { Header2Type {
Layout.fillWidth: true
Layout.topMargin: 48
Layout.leftMargin: 16 Layout.leftMargin: 16
Layout.rightMargin: 16 Layout.rightMargin: 16
actionButtonImage: "qrc:/images/controls/plus.svg"
headerText: "Серверы" headerText: "Серверы"
} }
} }
// Header2TextType {
// id: menuHeader
// width: parent.width
// text: "Данные для подключения"
// wrapMode: Text.WordWrap
// anchors.top: parent.top
// anchors.left: parent.left
// anchors.right: parent.right
// anchors.topMargin: 16
// anchors.leftMargin: 16
// anchors.rightMargin: 16
// }
FlickableType { FlickableType {
anchors.top: menuHeader.bottom anchors.top: menuHeader.bottom
anchors.topMargin: 16 anchors.topMargin: 16
@ -257,6 +340,13 @@ PageBase {
Layout.rightMargin: 8 Layout.rightMargin: 8
} }
} }
onClicked: {
console.log(index)
ContainersModel.setSelectedServerIndex(index)
root.currentServerName = desc
root.currentServerDescription = address
}
} }
} }
} }

View file

@ -36,7 +36,7 @@ PageBase {
Layout.fillWidth: true Layout.fillWidth: true
Layout.topMargin: 20 Layout.topMargin: 20
buttonImage: "qrc:/images/controls/arrow-left.svg" backButtonImage: "qrc:/images/controls/arrow-left.svg"
headerText: "Подключение к серверу" headerText: "Подключение к серверу"
descriptionText: "Не используйте код подключения из публичных источников. Его могли создать, чтобы перехватывать ваши данные.\n descriptionText: "Не используйте код подключения из публичных источников. Его могли создать, чтобы перехватывать ваши данные.\n

View file

@ -34,7 +34,7 @@ PageBase {
Layout.fillWidth: true Layout.fillWidth: true
Layout.topMargin: 20 Layout.topMargin: 20
buttonImage: "qrc:/images/controls/arrow-left.svg" backButtonImage: "qrc:/images/controls/arrow-left.svg"
headerText: "Подключение к серверу" headerText: "Подключение к серверу"
} }

View file

@ -34,7 +34,7 @@ PageBase {
Layout.fillWidth: true Layout.fillWidth: true
Layout.topMargin: 20 Layout.topMargin: 20
buttonImage: "qrc:/images/controls/arrow-left.svg" backButtonImage: "qrc:/images/controls/arrow-left.svg"
headerText: "Какой уровень контроля интернета в вашем регионе?" headerText: "Какой уровень контроля интернета в вашем регионе?"
} }

View file

@ -36,7 +36,7 @@ PageBase {
Layout.topMargin: 20 Layout.topMargin: 20
//TODO remove later //TODO remove later
buttonImage: "qrc:/images/controls/arrow-left.svg" backButtonImage: "qrc:/images/controls/arrow-left.svg"
headerText: "Установка" headerText: "Установка"
descriptionText: ContainersModel.getCurrentlyInstalledContainerName() descriptionText: ContainersModel.getCurrentlyInstalledContainerName()

View file

@ -35,7 +35,7 @@ PageBase {
Layout.fillWidth: true Layout.fillWidth: true
Layout.topMargin: 20 Layout.topMargin: 20
buttonImage: "qrc:/images/controls/arrow-left.svg" backButtonImage: "qrc:/images/controls/arrow-left.svg"
headerText: "Установка " + ContainersModel.getCurrentlyInstalledContainerName() headerText: "Установка " + ContainersModel.getCurrentlyInstalledContainerName()
descriptionText: "Эти настройки можно будет изменить позже" descriptionText: "Эти настройки можно будет изменить позже"

View file

@ -51,7 +51,7 @@ PageBase {
HeaderType { HeaderType {
width: parent.width width: parent.width
buttonImage: "qrc:/images/controls/arrow-left.svg" backButtonImage: "qrc:/images/controls/arrow-left.svg"
headerText: "Протокол подключения" headerText: "Протокол подключения"
descriptionText: "Выберите более приоритетный для вас. Позже можно будет установить остальные протоколы и доп сервисы, вроде DNS-прокси и SFTP." descriptionText: "Выберите более приоритетный для вас. Позже можно будет установить остальные протоколы и доп сервисы, вроде DNS-прокси и SFTP."

View file

@ -35,7 +35,7 @@ PageBase {
Layout.fillWidth: true Layout.fillWidth: true
Layout.topMargin: 20 Layout.topMargin: 20
buttonImage: "qrc:/images/controls/arrow-left.svg" backButtonImage: "qrc:/images/controls/arrow-left.svg"
headerText: "Ключ для подключения" headerText: "Ключ для подключения"
descriptionText: "Строка, которая начинается с vpn://..." descriptionText: "Строка, которая начинается с vpn://..."

View file

@ -29,7 +29,7 @@ PageBase {
Layout.bottomMargin: 32 Layout.bottomMargin: 32
Layout.fillWidth: true Layout.fillWidth: true
buttonImage: "qrc:/images/controls/arrow-left.svg" backButtonImage: "qrc:/images/controls/arrow-left.svg"
headerText: "Server 1" headerText: "Server 1"
descriptionText: "root 192.168.111.111" descriptionText: "root 192.168.111.111"
} }