37
37
#include < QAbstractItemView>
38
38
#include < QApplication>
39
39
#include < QClipboard>
40
+ #include < QComboBox>
40
41
#include < QDateTime>
41
42
#include < QDesktopServices>
42
43
#include < QDialog>
@@ -87,6 +88,14 @@ using namespace std::chrono_literals;
87
88
88
89
namespace GUIUtil {
89
90
91
+ std::map<OutputType, OutputTypeInfo> outputTypeDescriptionsMap (){
92
+ return {
93
+ {OutputType::LEGACY, {QObject::tr (" Base58 (Legacy)" ), false }},
94
+ {OutputType::P2SH_SEGWIT, {QObject::tr (" Base58 (P2SH-SegWit)" ), false }},
95
+ {OutputType::BECH32, {QObject::tr (" Bech32 (SegWit)" ), false }},
96
+ {OutputType::BECH32M, {QObject::tr (" Bech32m (Taproot)" ), true }}};
97
+ }
98
+
90
99
QString dateTimeStr (const QDateTime &date)
91
100
{
92
101
return QLocale::system ().toString (date.date (), QLocale::ShortFormat) + QString (" " ) + date.toString (" hh:mm" );
@@ -1008,6 +1017,33 @@ void ShowModalDialogAsynchronously(QDialog* dialog)
1008
1017
dialog->show ();
1009
1018
}
1010
1019
1020
+ void AddItemsToAddressTypeCombo (QComboBox* addressType, bool taprootEnabled, const std::map<OutputType, QString>& outputTypeTooltipsMap, std::optional<OutputType> defaultType)
1021
+ {
1022
+ auto add_address_type = [&](OutputType type, QString description) {
1023
+ const auto index{addressType->count ()};
1024
+ // getting the tooltip (provided by the caller) that will be displayed on the item in the combo
1025
+ QString tooltip{};
1026
+ auto it{outputTypeTooltipsMap.find (type)};
1027
+ // if can't find it no tooltip will be displayed
1028
+ if (it != outputTypeTooltipsMap.end ()) tooltip = it->second ;
1029
+ addressType->addItem (description, static_cast <int >(type));
1030
+ addressType->setItemData (index, tooltip, Qt::ToolTipRole);
1031
+ // setting default selected value for the combo if it has been passed
1032
+ if (defaultType.has_value () && defaultType.value () == type) addressType->setCurrentIndex (index);
1033
+ };
1034
+
1035
+ // Adding all output types defined in the map to the combo
1036
+ for (const auto & pair : outputTypeDescriptionsMap ()) {
1037
+ OutputType type{pair.first };
1038
+ OutputTypeInfo typeInfo{pair.second };
1039
+ // if it requires taproot check it with arg taprootEnabled
1040
+ // eg call from receivecoindialog.cpp
1041
+ if ((!typeInfo.requiresTaprootEnabled ) || (typeInfo.requiresTaprootEnabled == taprootEnabled)) {
1042
+ add_address_type (type, typeInfo.description );
1043
+ }
1044
+ }
1045
+ }
1046
+
1011
1047
QString WalletDisplayName (const QString& name)
1012
1048
{
1013
1049
return name.isEmpty () ? " [" + QObject::tr (" default wallet" ) + " ]" : name;
@@ -1017,4 +1053,32 @@ QString WalletDisplayName(const std::string& name)
1017
1053
{
1018
1054
return WalletDisplayName (QString::fromStdString (name));
1019
1055
}
1056
+
1057
+ void AddItemsToAddressTypeCombo (QComboBox* addressType, bool taprootEnabled, const std::map<OutputType, QString>& outputTypeTooltipsMap, std::optional<OutputType> defaultType)
1058
+ {
1059
+ auto add_address_type = [&](OutputType type, QString description) {
1060
+ const auto index{addressType->count ()};
1061
+ // getting the tooltip (provided by the caller) that will be displayed on the item in the combo
1062
+ QString tooltip{};
1063
+ auto it{outputTypeTooltipsMap.find (type)};
1064
+ // if can't find it no tooltip will be displayed
1065
+ if (it != outputTypeTooltipsMap.end ()) tooltip = it->second ;
1066
+ addressType->addItem (description, static_cast <int >(type));
1067
+ addressType->setItemData (index, tooltip, Qt::ToolTipRole);
1068
+ // setting default selected value for the combo if it has been passed
1069
+ if (defaultType.has_value () && defaultType.value () == type) addressType->setCurrentIndex (index);
1070
+ };
1071
+
1072
+ // Adding all output types defined in the map to the combo
1073
+ for (const auto & pair : outputTypeDescriptionsMap ()) {
1074
+ OutputType type{pair.first };
1075
+ OutputTypeInfo typeInfo{pair.second };
1076
+ // if it requires taproot check it with arg taprootEnabled
1077
+ // eg call from receivecoindialog.cpp
1078
+ if ((!typeInfo.requiresTaprootEnabled ) || (typeInfo.requiresTaprootEnabled == taprootEnabled)) {
1079
+ add_address_type (type, typeInfo.description );
1080
+ }
1081
+ }
1082
+ }
1083
+
1020
1084
} // namespace GUIUtil
0 commit comments