|
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");
|
@@ -1002,4 +1011,31 @@ void ShowModalDialogAsynchronously(QDialog* dialog)
|
1002 | 1011 | dialog->show();
|
1003 | 1012 | }
|
1004 | 1013 |
|
| 1014 | +void AddItemsToAddressTypeCombo(QComboBox* addressType, bool taprootEnabled, const std::map<OutputType, QString>& outputTypeTooltipsMap, std::optional<OutputType> defaultType) |
| 1015 | +{ |
| 1016 | + auto add_address_type = [&](OutputType type, QString description) { |
| 1017 | + const auto index{addressType->count()}; |
| 1018 | + // getting the tooltip (provided by the caller) that will be displayed on the item in the combo |
| 1019 | + QString tooltip{}; |
| 1020 | + auto it{outputTypeTooltipsMap.find(type)}; |
| 1021 | + // if can't find it no tooltip will be displayed |
| 1022 | + if (it != outputTypeTooltipsMap.end()) tooltip = it->second; |
| 1023 | + addressType->addItem(description, static_cast<int>(type)); |
| 1024 | + addressType->setItemData(index, tooltip, Qt::ToolTipRole); |
| 1025 | + // setting default selected value for the combo if it has been passed |
| 1026 | + if (defaultType.has_value() && defaultType.value() == type) addressType->setCurrentIndex(index); |
| 1027 | + }; |
| 1028 | + |
| 1029 | + // Adding all output types defined in the map to the combo |
| 1030 | + for (const auto& pair : outputTypeDescriptionsMap()) { |
| 1031 | + OutputType type{pair.first}; |
| 1032 | + OutputTypeInfo typeInfo{pair.second}; |
| 1033 | + // if it requires taproot check it with arg taprootEnabled |
| 1034 | + // eg call from receivecoindialog.cpp |
| 1035 | + if ((!typeInfo.requiresTaprootEnabled) || (typeInfo.requiresTaprootEnabled == taprootEnabled)) { |
| 1036 | + add_address_type(type, typeInfo.description); |
| 1037 | + } |
| 1038 | + } |
| 1039 | +} |
| 1040 | + |
1005 | 1041 | } // namespace GUIUtil
|
0 commit comments