8#include <chainparams.h>
37#include <QAbstractItemView>
38#include <QApplication>
41#include <QDesktopServices>
42#include <QDoubleValidator>
45#include <QFontDatabase>
46#include <QFontMetrics>
47#include <QGuiApplication>
54#include <QProgressDialog>
60#include <QTextDocument>
80 QString(
" ") + date.toString(
"hh:mm");
88 return QFontDatabase::systemFont(QFontDatabase::FixedFont);
93 if (addr.size() < 2) {
98 std::swap(addr[addr.size() - 1], addr[addr.size() - 2]);
109 static const std::vector<uint8_t>
dummydata = {
110 0xeb, 0x15, 0x23, 0x1d, 0xfc, 0xeb, 0x60, 0x92, 0x58, 0x86,
111 0xb6, 0x7d, 0x06, 0x52, 0x99, 0x92, 0x59, 0x15, 0xae, 0xb1};
131 parent->setFocusProxy(
widget);
136 widget->setPlaceholderText(
137 QObject::tr(
"Enter a Bitcoin address (e.g. %1)")
155 if (
rv.address.endsWith(
"/")) {
156 rv.address.truncate(
rv.address.length() - 1);
163 i !=
items.end(); i++) {
165 if (i->first.startsWith(
"req-")) {
166 i->first.remove(0, 4);
170 if (i->first ==
"label") {
171 rv.label = i->second;
174 if (i->first ==
"message") {
175 rv.message = i->second;
177 }
else if (i->first ==
"amount") {
178 if (!i->second.isEmpty()) {
203 if (
uri.startsWith(
scheme +
"://", Qt::CaseInsensitive)) {
227 if (!info.
label.isEmpty()) {
264 if (!
view || !
view->selectionModel()) {
276 if (!
view || !
view->selectionModel()) {
279 return view->selectionModel()->selectedRows(column);
287 return !
selection.at(0).data(role).toString().isEmpty();
302 QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation);
307 QString result = QDir::toNativeSeparators(QFileDialog::getSaveFileName(
320 if (!result.isEmpty()) {
323 if (!result.endsWith(
".")) {
345 QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation);
350 QString result = QDir::toNativeSeparators(QFileDialog::getOpenFileName(
367 if (QThread::currentThread() !=
qApp->thread()) {
368 return Qt::BlockingQueuedConnection;
370 return Qt::DirectConnection;
375 QWidget *
atW = QApplication::widgetAt(w->mapToGlobal(
p));
379 return atW->window() == w;
397 if (w->isMinimized()) {
409 &QShortcut::activated, w, &QWidget::close);
417 QDesktopServices::openUrl(
435 bool res = QDesktopServices::openUrl(
440 res = QProcess::startDetached(
453 QString::SkipEmptyParts
463 if (
evt->type() == QEvent::ToolTipChange) {
464 QWidget *
widget =
static_cast<QWidget *
>(
obj);
467 !Qt::mightBeRichText(
tooltip)) {
475 return QObject::eventFilter(
obj,
evt);
482 if (event->type() == QEvent::FocusOut) {
484 if (
focus_out->reason() != Qt::PopupFocusReason) {
487 auto flags = label->textInteractionFlags();
488 label->setTextInteractionFlags(Qt::NoTextInteraction);
489 label->setTextInteractionFlags(
flags);
494 return QObject::eventFilter(
watched, event);
507 disconnect(
tableView->horizontalHeader(), &QHeaderView::sectionResized,
509 disconnect(
tableView->horizontalHeader(), &QHeaderView::geometriesChanged,
543 tableView->horizontalHeader()->sectionSize(column);
602 : QObject(parent), tableView(table),
608 tableView->horizontalHeader()->setMinimumSectionSize(
654 strArgs += QString::fromStdString(
662 psl->SetArguments(
strArgs.toStdWString().c_str());
668 reinterpret_cast<void **
>(&
ppf));
684#elif defined(Q_OS_LINUX)
718 if (line.find(
"Hidden") != std::string::npos &&
719 line.find(
"true") != std::string::npos) {
743 std::ios_base::out | std::ios_base::trunc};
757 <<
strprintf(
" -min -chain=%s\n", chain);
777 QApplication::clipboard()->setText(str, QClipboard::Clipboard);
778 QApplication::clipboard()->setText(str, QClipboard::Selection);
786 return QString::fromStdString(path.
u8string());
792 return QObject::tr(
"Unroutable");
804 return QObject::tr(
"Internal");
841 strList.append(QString::fromStdString(flag));
847 return QObject::tr(
"None");
854 :
QString(QObject::tr(
"%1 ms"))
855 .arg(QString::number(
860 return QString(QObject::tr(
"%1 s"))
861 .arg(QString::number((
int)nTimeOffset, 10));
886 .arg(QObject::tr(
"%n year(s)",
"",
years))
887 .arg(QObject::tr(
"%n week(s)",
"",
895 return QString(QObject::tr(
"%1 B")).arg(bytes);
897 if (bytes < 1024 * 1024) {
898 return QString(QObject::tr(
"%1 KB")).arg(bytes / 1024);
900 if (bytes < 1024 * 1024 * 1024) {
901 return QString(QObject::tr(
"%1 MB")).arg(bytes / 1024 / 1024);
904 return QString(QObject::tr(
"%1 GB")).arg(bytes / 1024 / 1024 / 1024);
908#if (QT_VERSION >= QT_VERSION_CHECK(5, 15, 0))
909 return !pixmap(Qt::ReturnByValue).isNull();
911 return pixmap() !=
nullptr;
937 if (event->type() == QEvent::KeyPress) {
938 if (
static_cast<QKeyEvent *
>(event)->key() == Qt::Key_Escape) {
942 return QItemDelegate::eventFilter(
object, event);
946#if (QT_VERSION >= QT_VERSION_CHECK(5, 11, 0))
947 return fm.horizontalAdvance(text);
949 return fm.width(text);
966 const std::string
qt_link{
"static"};
968 const std::string
qt_link{
"dynamic"};
970#ifdef QT_STATICPLUGIN
979 for (
const QScreen *s : QGuiApplication::screens()) {
980 LogPrintf(
"Screen: %s %dx%d, pixel ratio=%.1f\n",
981 s->name().toStdString(), s->size().width(),
982 s->size().height(), s->devicePixelRatio());
988 if (QApplication::platformName() ==
"minimal") {
fs::path GetDefaultDataDir()
std::string EncodeCashAddr(const CTxDestination &dst, const CChainParams ¶ms)
const CChainParams & Params()
Return the currently selected parameters.
fs::path GetDataDirNet() const
Get data directory path with appended network identifier.
fs::path GetConfigFilePath() const
Return config file path (read-only)
std::string GetChainName() const
Looks for -regtest, -testnet and returns the appropriate BIP70 chain name.
Bitcoin address widget validator, checks for a valid bitcoin address.
Bitcoin address entry widget validator, checks for valid characters and removes some whitespace.
static QString format(int unit, const Amount amount, bool plussign=false, SeparatorStyle separators=SeparatorStyle::STANDARD, bool justify=false)
Format as string.
static bool parse(int unit, const QString &value, Amount *val_out)
Parse string to coin amount.
static const std::string TESTNET
static const std::string MAIN
BIP70 chain name strings (main, test or regtest)
CChainParams defines various tweakable parameters of a given instance of the Bitcoin system.
An output of a transaction.
void mouseReleaseEvent(QMouseEvent *event) override
void clicked(const QPoint &point)
Emitted when the label is clicked.
void mouseReleaseEvent(QMouseEvent *event) override
void clicked(const QPoint &point)
Emitted when the progressbar is clicked.
bool eventFilter(QObject *object, QEvent *event) override
bool eventFilter(QObject *watched, QEvent *event) override
LabelOutOfFocusEventFilter(QObject *parent)
void setViewHeaderResizeMode(int logicalIndex, QHeaderView::ResizeMode resizeMode)
int allColumnsMinimumWidth
void resizeColumn(int nColumnIndex, int width)
void on_sectionResized(int logicalIndex, int oldSize, int newSize)
TableViewLastColumnResizingFixer(QTableView *table, int lastColMinimumWidth, int allColsMinimumWidth, QObject *parent)
Initializes all internal variables and prepares the the resize modes of the last 2 columns of the tab...
int secondToLastColumnIndex
void stretchColumnWidth(int column)
void on_geometriesChanged()
void connectViewHeadersSignals()
void adjustTableColumnsWidth()
int getAvailableWidthForColumn(int column)
void disconnectViewHeadersSignals()
int lastColumnMinimumWidth
bool eventFilter(QObject *obj, QEvent *evt) override
ToolTipToRichTextFilter(int size_threshold, QObject *parent=0)
Line edit that can be marked as "invalid" to show input validation feedback.
Path class wrapper to block calls to the fs::path(std::string) implicit constructor and the fs::path:...
std::string u8string() const
Top-level interface for a bitcoin node (bitcoind process).
bool IsValidDestinationString(const std::string &str, const CChainParams ¶ms)
CTxDestination DecodeDestination(const std::string &addr, const CChainParams ¶ms)
void ForceActivation()
Force application activation on macOS.
Utility functions used by the Bitcoin Qt UI.
QString NetworkToQString(Network net)
Convert enum Network to QString.
fs::path qstringToBoostPath(const QString &path)
Convert QString to OS specific boost path through UTF-8.
bool isObscured(QWidget *w)
bool parseBitcoinURI(const QString &scheme, const QUrl &uri, SendCoinsRecipient *out)
bool isDust(interfaces::Node &node, const QString &address, const Amount amount, const CChainParams &chainParams)
Qt::ConnectionType blockingGUIThreadConnection()
Get connection type to call object slot in GUI thread with invokeMethod.
QString HtmlEscape(const QString &str, bool fMultiLine)
void PopupMenu(QMenu *menu, const QPoint &point, QAction *at_action)
Call QMenu::popup() only on supported QT_QPA_PLATFORM.
QList< QModelIndex > getEntryData(const QAbstractItemView *view, int column)
Return a field of the currently selected entry as a QString.
QString formatBytes(uint64_t bytes)
QString formatDurationStr(std::chrono::seconds dur)
Convert seconds into a QString with days, hours, mins, secs.
void handleCloseWindowShortcut(QWidget *w)
void PolishProgressDialog(QProgressDialog *dialog)
QString getOpenFileName(QWidget *parent, const QString &caption, const QString &dir, const QString &filter, QString *selectedSuffixOut)
Get open filename, convenience wrapper for QFileDialog::getOpenFileName.
std::string DummyAddress(const CChainParams ¶ms)
static std::string MakeAddrInvalid(std::string addr, const CChainParams ¶ms)
QString getDefaultDataDirectory()
Determine default data directory for operating system.
void copyEntryData(const QAbstractItemView *view, int column, int role)
Copy a field of the currently selected entry of a view to the clipboard.
QString getSaveFileName(QWidget *parent, const QString &caption, const QString &dir, const QString &filter, QString *selectedSuffixOut)
Get save filename, mimics QFileDialog::getSaveFileName, except that it appends a default suffix when ...
QString boostPathToQString(const fs::path &path)
Convert OS specific boost path to QString through UTF-8.
bool SetStartOnSystemStartup(bool fAutoStart)
void bringToFront(QWidget *w)
void LogQtInfo()
Writes to debug.log short info about the used Qt and the host system.
QString formatPingTime(std::chrono::microseconds ping_time)
Format a CNodeStats.m_last_ping_time into a user-readable string or display N/A, if 0.
QString dateTimeStr(const QDateTime &date)
bool checkPoint(const QPoint &p, const QWidget *w)
QString formatBitcoinURI(const SendCoinsRecipient &info)
QString formatTimeOffset(int64_t nTimeOffset)
Format a CNodeCombinedStats.nTimeOffset into a user-readable string.
QString convertToCashAddr(const CChainParams ¶ms, const QString &addr)
QString formatServicesStr(quint64 mask)
Format CNodeStats.nServices bitmask into a user-readable string.
QString formatNiceTimeOffset(qint64 secs)
bool GetStartOnSystemStartup()
QStringList splitSkipEmptyParts(const QString &s, const QString &separator)
int TextWidth(const QFontMetrics &fm, const QString &text)
Returns the distance in pixels appropriate for drawing a subsequent character after text.
void setupAddressWidget(QValidatedLineEdit *widget, QWidget *parent)
void setClipboard(const QString &str)
bool hasEntryData(const QAbstractItemView *view, int column, int role)
Returns true if the specified field of the currently selected view entry is not empty.
qreal calculateIdealFontSize(int width, const QString &text, QFont font, qreal minPointSize, qreal font_size)
static path u8path(const std::string &utf8_str)
static bool create_directories(const std::filesystem::path &p)
Create directory (and if necessary its parents), unless the leaf directory already exists or is a sym...
static bool exists(const path &p)
@ NET_MAX
Dummy value to indicate the number of NET_* constants.
@ NET_ONION
TOR (v2 or v3)
@ NET_UNROUTABLE
Addresses from these networks are not publicly routable on the global Internet.
@ NET_INTERNAL
A set of addresses that represent the hash of a string or FQDN.
bool IsDust(const CTxOut &txout, const CFeeRate &dustRelayFeeIn)
std::vector< std::string > serviceFlagsToStr(const uint64_t flags)
Convert service flags (a bitmask of NODE_*) to human readable strings.
@ NODE_LAST_NON_EXPERIMENTAL_SERVICE_BIT
T GetRand(T nMax=std::numeric_limits< T >::max()) noexcept
Generate a uniform random integer of type T in the range [0..nMax) nMax defaults to std::numeric_limi...
CScript GetScriptForDestination(const CTxDestination &dest)
Generate a Bitcoin scriptPubKey for the given CTxDestination.
std::variant< CNoDestination, PKHash, ScriptHash > CTxDestination
A txout script template with a specific destination.
static constexpr Amount zero() noexcept
constexpr int64_t count_microseconds(std::chrono::microseconds t)
constexpr int64_t count_seconds(std::chrono::seconds t)