-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
qml: Introduce the WalletSelect component
WalletSelect is a Popup that appears after clicking the main WalletBadge in the DesktopNavigation bar. It contains a ListView that allows the user to select one of the wallets listed in the wallet directory.
- Loading branch information
Showing
12 changed files
with
292 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
// Copyright (c) 2024 The Bitcoin Core developers | ||
// Distributed under the MIT software license, see the accompanying | ||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||
|
||
#include <qml/models/walletlistmodel.h> | ||
|
||
#include <interfaces/node.h> | ||
|
||
#include <QSet> | ||
|
||
WalletListModel::WalletListModel(interfaces::Node& node, QObject *parent) | ||
: QAbstractListModel(parent) | ||
, m_node(node) | ||
{ | ||
setSelectedWallet("Singlesig Wallet"); | ||
} | ||
|
||
void WalletListModel::listWalletDir() | ||
{ | ||
QSet<QString> existing_names; | ||
for (int i = 0; i < rowCount(); ++i) { | ||
QModelIndex index = this->index(i, 0); | ||
QString name = data(index, NameRole).toString(); | ||
existing_names.insert(name); | ||
} | ||
|
||
for (const std::string &name : m_node.walletLoader().listWalletDir()) { | ||
QString qname = QString::fromStdString(name); | ||
if (!existing_names.contains(qname)) { | ||
addItem({ qname }); | ||
} | ||
} | ||
} | ||
|
||
void WalletListModel::setSelectedWallet(QString wallet_name) | ||
{ | ||
if (m_selected_wallet != wallet_name) { | ||
m_selected_wallet = wallet_name; | ||
Q_EMIT selectedWalletChanged(); | ||
} | ||
} | ||
|
||
QString WalletListModel::selectedWallet() const | ||
{ | ||
return m_selected_wallet; | ||
} | ||
|
||
int WalletListModel::rowCount(const QModelIndex &parent) const | ||
{ | ||
Q_UNUSED(parent); | ||
return m_items.size(); | ||
} | ||
|
||
QVariant WalletListModel::data(const QModelIndex &index, int role) const | ||
{ | ||
if (!index.isValid() || index.row() < 0 || index.row() >= m_items.size()) | ||
return QVariant(); | ||
|
||
const auto &item = m_items[index.row()]; | ||
switch (role) { | ||
case Qt::DisplayRole: | ||
case NameRole: | ||
return item.name; | ||
default: | ||
return QVariant(); | ||
} | ||
} | ||
|
||
QHash<int, QByteArray> WalletListModel::roleNames() const | ||
{ | ||
QHash<int, QByteArray> roles; | ||
roles[NameRole] = "name"; | ||
return roles; | ||
} | ||
|
||
void WalletListModel::addItem(const Item &item) | ||
{ | ||
beginInsertRows(QModelIndex(), rowCount(), rowCount()); | ||
m_items.append(item); | ||
endInsertRows(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// Copyright (c) 2024 The Bitcoin Core developers | ||
// Distributed under the MIT software license, see the accompanying | ||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||
|
||
#ifndef BITCOIN_QML_MODELS_WALLETLISTMODEL_H | ||
#define BITCOIN_QML_MODELS_WALLETLISTMODEL_H | ||
|
||
#include <interfaces/wallet.h> | ||
#include <QAbstractListModel> | ||
#include <QList> | ||
|
||
namespace interfaces { | ||
class Node; | ||
} | ||
|
||
class WalletListModel : public QAbstractListModel | ||
{ | ||
Q_OBJECT | ||
Q_PROPERTY(QString selectedWallet READ selectedWallet WRITE setSelectedWallet NOTIFY selectedWalletChanged) | ||
|
||
public: | ||
WalletListModel(interfaces::Node& node, QObject *parent = nullptr); | ||
~WalletListModel() = default; | ||
|
||
enum Roles { | ||
NameRole = Qt::UserRole + 1 | ||
}; | ||
|
||
int rowCount(const QModelIndex &parent = QModelIndex()) const override; | ||
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; | ||
QHash<int, QByteArray> roleNames() const override; | ||
|
||
void setSelectedWallet(QString wallet_name); | ||
QString selectedWallet() const; | ||
|
||
public Q_SLOTS: | ||
void listWalletDir(); | ||
|
||
Q_SIGNALS: | ||
void selectedWalletChanged(); | ||
|
||
private: | ||
struct Item { | ||
QString name; | ||
}; | ||
|
||
void addItem(const Item &item); | ||
|
||
QList<Item> m_items; | ||
interfaces::Node& m_node; | ||
QString m_selected_wallet; | ||
|
||
}; | ||
|
||
#endif // BITCOIN_QML_MODELS_WALLETLISTMODEL_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
// Copyright (c) 2024 The Bitcoin Core developers | ||
// Distributed under the MIT software license, see the accompanying | ||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||
|
||
import QtQuick 2.15 | ||
import QtQuick.Controls 2.15 | ||
import QtQuick.Layouts 1.15 | ||
|
||
import "../../controls" | ||
|
||
Popup { | ||
id: root | ||
|
||
property alias model: listView.model | ||
implicitHeight: layout.height + arrow.height | ||
implicitWidth: 250 | ||
clip: true | ||
|
||
background: Item { | ||
anchors.fill: parent | ||
Rectangle { | ||
id: tooltipBg | ||
color: Theme.color.neutral0 | ||
border.color: Theme.color.neutral4 | ||
radius: 5 | ||
border.width: 1 | ||
width: parent.width | ||
height: parent.height - arrow.height - 1 | ||
anchors.top: arrow.bottom | ||
anchors.horizontalCenter: root.horizontalCenter | ||
anchors.topMargin: -1 | ||
} | ||
Image { | ||
id: arrow | ||
source: Theme.image.tooltipArrow | ||
width: 22 | ||
height: 10 | ||
anchors.left: parent.left | ||
anchors.leftMargin: 10 | ||
anchors.top: parent.top | ||
} | ||
} | ||
|
||
ButtonGroup { | ||
id: buttonGroup | ||
} | ||
|
||
ColumnLayout { | ||
id: layout | ||
width: 220 | ||
anchors.topMargin: arrow.height | ||
CoreText { | ||
Layout.alignment: Qt.AlignHCenter | ||
Layout.preferredWidth: 220 | ||
Layout.preferredHeight: 30 | ||
id: label | ||
text: qsTr("Wallets") | ||
visible: listView.count > 0 | ||
bold: true | ||
color: Theme.color.neutral9 | ||
font.pixelSize: 14 | ||
topPadding: 10 | ||
bottomPadding: 5 | ||
} | ||
|
||
ListView { | ||
Layout.preferredWidth: 220 | ||
Layout.preferredHeight: Math.min(listView.count * 34, 300) | ||
id: listView | ||
interactive: true | ||
spacing: 2 | ||
model: walletListModel | ||
|
||
delegate: WalletBadge { | ||
required property string name; | ||
|
||
width: 220 | ||
height: 32 | ||
text: name | ||
ButtonGroup.group: buttonGroup | ||
showBalance: false | ||
showIcon: false | ||
onClicked: { | ||
walletListModel.selectedWallet = name | ||
root.close() | ||
} | ||
} | ||
} | ||
|
||
RowLayout { | ||
id: addWallet | ||
Layout.preferredWidth: addIcon.size + addText.width | ||
Layout.preferredHeight: 45 | ||
Layout.alignment: Qt.AlignHCenter | ||
Icon { | ||
id: addIcon | ||
Layout.alignment: Qt.AlignHCenter | ||
source: "image://images/plus" | ||
color: Theme.color.neutral8 | ||
size: 14 | ||
topPadding: 5 | ||
bottomPadding: 10 | ||
} | ||
CoreText { | ||
id: addText | ||
Layout.alignment: Qt.AlignHCenter | ||
text: qsTr("Add Wallet") | ||
color: Theme.color.neutral9 | ||
font.pixelSize: 15 | ||
topPadding: 5 | ||
bottomPadding: 10 | ||
} | ||
} | ||
} | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.