2021-12-30 19:36:57 +02:00
|
|
|
// Copyright (c) 2011-2021 The Bitcoin Core developers
|
2014-12-13 12:09:33 +08:00
|
|
|
// Distributed under the MIT software license, see the accompanying
|
2013-11-04 16:20:43 +01:00
|
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
|
|
|
2014-11-03 16:16:40 +01:00
|
|
|
#ifndef BITCOIN_QT_GUIUTIL_H
|
|
|
|
#define BITCOIN_QT_GUIUTIL_H
|
2011-05-27 18:38:30 +02:00
|
|
|
|
2021-09-11 10:29:00 +08:00
|
|
|
#include <consensus/amount.h>
|
2017-11-10 13:57:53 +13:00
|
|
|
#include <fs.h>
|
2020-12-24 12:35:37 +01:00
|
|
|
#include <net.h>
|
2020-12-24 11:01:07 +01:00
|
|
|
#include <netaddress.h>
|
2021-03-27 18:52:22 +02:00
|
|
|
#include <util/check.h>
|
2014-04-22 15:46:19 -07:00
|
|
|
|
2021-03-27 18:52:22 +02:00
|
|
|
#include <QApplication>
|
2014-11-18 09:55:39 +01:00
|
|
|
#include <QEvent>
|
2014-03-21 09:12:01 +01:00
|
|
|
#include <QHeaderView>
|
2018-07-30 22:44:18 +01:00
|
|
|
#include <QItemDelegate>
|
2020-12-24 12:35:37 +01:00
|
|
|
#include <QLabel>
|
2012-05-20 15:49:17 +02:00
|
|
|
#include <QMessageBox>
|
2021-03-27 18:52:22 +02:00
|
|
|
#include <QMetaObject>
|
2013-04-13 00:13:08 -05:00
|
|
|
#include <QObject>
|
2014-11-18 09:55:39 +01:00
|
|
|
#include <QProgressBar>
|
2013-04-13 00:13:08 -05:00
|
|
|
#include <QString>
|
2014-03-21 01:45:47 -04:00
|
|
|
#include <QTableView>
|
2011-05-27 18:38:30 +02:00
|
|
|
|
2021-03-27 18:52:22 +02:00
|
|
|
#include <cassert>
|
2020-09-29 19:11:53 -07:00
|
|
|
#include <chrono>
|
2021-03-27 18:52:22 +02:00
|
|
|
#include <utility>
|
2020-09-29 19:11:53 -07:00
|
|
|
|
2021-04-08 14:27:14 +03:00
|
|
|
class PlatformStyle;
|
2013-11-20 15:56:51 +01:00
|
|
|
class QValidatedLineEdit;
|
2013-01-23 21:51:02 +01:00
|
|
|
class SendCoinsRecipient;
|
|
|
|
|
2018-04-07 03:42:02 -04:00
|
|
|
namespace interfaces
|
2017-04-18 17:06:13 -04:00
|
|
|
{
|
|
|
|
class Node;
|
|
|
|
}
|
|
|
|
|
2011-06-02 15:57:23 +02:00
|
|
|
QT_BEGIN_NAMESPACE
|
2021-04-18 15:21:57 +03:00
|
|
|
class QAbstractButton;
|
2013-04-13 00:13:08 -05:00
|
|
|
class QAbstractItemView;
|
2020-01-11 14:35:34 +02:00
|
|
|
class QAction;
|
2013-04-13 00:13:08 -05:00
|
|
|
class QDateTime;
|
2021-06-07 18:00:36 +03:00
|
|
|
class QDialog;
|
2011-06-02 15:57:23 +02:00
|
|
|
class QFont;
|
2021-04-18 15:21:57 +03:00
|
|
|
class QKeySequence;
|
2011-06-02 15:57:23 +02:00
|
|
|
class QLineEdit;
|
2020-01-11 14:35:34 +02:00
|
|
|
class QMenu;
|
|
|
|
class QPoint;
|
2018-12-26 22:19:14 +02:00
|
|
|
class QProgressDialog;
|
2011-08-07 16:04:48 +02:00
|
|
|
class QUrl;
|
2013-04-13 00:13:08 -05:00
|
|
|
class QWidget;
|
2011-06-02 15:57:23 +02:00
|
|
|
QT_END_NAMESPACE
|
|
|
|
|
2012-02-18 01:34:53 +11:00
|
|
|
/** Utility functions used by the Bitcoin Qt UI.
|
2011-11-13 13:19:52 +01:00
|
|
|
*/
|
2012-02-18 01:34:53 +11:00
|
|
|
namespace GUIUtil
|
2011-06-02 15:57:23 +02:00
|
|
|
{
|
2020-09-07 19:08:15 +03:00
|
|
|
// Use this flags to prevent a "What's This" button in the title bar of the dialog on Windows.
|
|
|
|
constexpr auto dialog_flags = Qt::WindowTitleHint | Qt::WindowSystemMenuHint | Qt::WindowCloseButtonHint;
|
|
|
|
|
2011-08-07 16:04:48 +02:00
|
|
|
// Create human-readable string from date
|
2012-02-18 01:34:53 +11:00
|
|
|
QString dateTimeStr(const QDateTime &datetime);
|
|
|
|
QString dateTimeStr(qint64 nTime);
|
2011-06-02 15:57:23 +02:00
|
|
|
|
2015-10-22 13:33:58 +02:00
|
|
|
// Return a monospace font
|
2021-02-21 20:12:02 +02:00
|
|
|
QFont fixedPitchFont(bool use_embedded_font = false);
|
2011-06-02 15:57:23 +02:00
|
|
|
|
2018-03-25 21:15:08 +02:00
|
|
|
// Set up widget for address
|
2013-11-20 15:56:51 +01:00
|
|
|
void setupAddressWidget(QValidatedLineEdit *widget, QWidget *parent);
|
2011-08-07 16:04:48 +02:00
|
|
|
|
2021-04-18 15:21:57 +03:00
|
|
|
/**
|
|
|
|
* Connects an additional shortcut to a QAbstractButton. Works around the
|
|
|
|
* one shortcut limitation of the button's shortcut property.
|
|
|
|
* @param[in] button QAbstractButton to assign shortcut to
|
|
|
|
* @param[in] shortcut QKeySequence to use as shortcut
|
|
|
|
*/
|
|
|
|
void AddButtonShortcut(QAbstractButton* button, const QKeySequence& shortcut);
|
|
|
|
|
2012-07-23 12:03:48 +08:00
|
|
|
// Parse "bitcoin:" URI into recipient object, return true on successful parsing
|
2012-02-18 01:34:53 +11:00
|
|
|
bool parseBitcoinURI(const QUrl &uri, SendCoinsRecipient *out);
|
|
|
|
bool parseBitcoinURI(QString uri, SendCoinsRecipient *out);
|
2013-10-18 14:03:17 +02:00
|
|
|
QString formatBitcoinURI(const SendCoinsRecipient &info);
|
2011-11-11 10:13:25 +01:00
|
|
|
|
2013-08-08 13:09:07 +10:00
|
|
|
// Returns true if given address+amount meets "dust" definition
|
2018-04-07 03:42:02 -04:00
|
|
|
bool isDust(interfaces::Node& node, const QString& address, const CAmount& amount);
|
2013-08-08 13:09:07 +10:00
|
|
|
|
2011-11-11 10:13:25 +01:00
|
|
|
// HTML escaping for rich text controls
|
2012-02-18 01:34:53 +11:00
|
|
|
QString HtmlEscape(const QString& str, bool fMultiLine=false);
|
|
|
|
QString HtmlEscape(const std::string& str, bool fMultiLine=false);
|
2011-12-04 14:14:10 +01:00
|
|
|
|
|
|
|
/** Copy a field of the currently selected entry of a view to the clipboard. Does nothing if nothing
|
|
|
|
is selected.
|
|
|
|
@param[in] column Data column to extract from the model
|
|
|
|
@param[in] role Data role to extract from the model
|
|
|
|
@see TransactionView::copyLabel, TransactionView::copyAmount, TransactionView::copyAddress
|
|
|
|
*/
|
2020-01-26 22:19:39 +02:00
|
|
|
void copyEntryData(const QAbstractItemView *view, int column, int role=Qt::EditRole);
|
2011-12-04 14:14:10 +01:00
|
|
|
|
2015-06-01 15:32:25 +02:00
|
|
|
/** Return a field of the currently selected entry as a QString. Does nothing if nothing
|
|
|
|
is selected.
|
|
|
|
@param[in] column Data column to extract from the model
|
|
|
|
@see TransactionView::copyLabel, TransactionView::copyAmount, TransactionView::copyAddress
|
|
|
|
*/
|
2020-01-26 22:19:39 +02:00
|
|
|
QList<QModelIndex> getEntryData(const QAbstractItemView *view, int column);
|
|
|
|
|
|
|
|
/** Returns true if the specified field of the currently selected view entry is not empty.
|
|
|
|
@param[in] column Data column to extract from the model
|
|
|
|
@param[in] role Data role to extract from the model
|
|
|
|
@see TransactionView::contextualMenu
|
|
|
|
*/
|
|
|
|
bool hasEntryData(const QAbstractItemView *view, int column, int role);
|
2015-06-01 15:32:25 +02:00
|
|
|
|
2013-08-12 17:03:03 +02:00
|
|
|
void setClipboard(const QString& str);
|
|
|
|
|
2021-10-06 15:06:40 +01:00
|
|
|
/**
|
|
|
|
* Loads the font from the file specified by file_name, aborts if it fails.
|
|
|
|
*/
|
|
|
|
void LoadFont(const QString& file_name);
|
|
|
|
|
2019-04-23 13:26:06 +02:00
|
|
|
/**
|
|
|
|
* Determine default data directory for operating system.
|
|
|
|
*/
|
|
|
|
QString getDefaultDataDirectory();
|
|
|
|
|
2012-07-26 00:48:39 +00:00
|
|
|
/** Get save filename, mimics QFileDialog::getSaveFileName, except that it appends a default suffix
|
2012-02-15 14:47:08 +01:00
|
|
|
when no suffix is provided by the user.
|
|
|
|
|
|
|
|
@param[in] parent Parent window (or 0)
|
|
|
|
@param[in] caption Window caption (or empty, for default)
|
|
|
|
@param[in] dir Starting directory (or empty, to default to documents directory)
|
|
|
|
@param[in] filter Filter specification such as "Comma Separated Files (*.csv)"
|
|
|
|
@param[out] selectedSuffixOut Pointer to return the suffix (file type) that was selected (or 0).
|
|
|
|
Can be useful when choosing the save file format based on suffix.
|
|
|
|
*/
|
2013-11-11 22:57:25 +01:00
|
|
|
QString getSaveFileName(QWidget *parent, const QString &caption, const QString &dir,
|
|
|
|
const QString &filter,
|
|
|
|
QString *selectedSuffixOut);
|
2012-02-15 14:47:08 +01:00
|
|
|
|
2013-11-06 15:08:56 +01:00
|
|
|
/** Get open filename, convenience wrapper for QFileDialog::getOpenFileName.
|
|
|
|
|
|
|
|
@param[in] parent Parent window (or 0)
|
|
|
|
@param[in] caption Window caption (or empty, for default)
|
|
|
|
@param[in] dir Starting directory (or empty, to default to documents directory)
|
|
|
|
@param[in] filter Filter specification such as "Comma Separated Files (*.csv)"
|
|
|
|
@param[out] selectedSuffixOut Pointer to return the suffix (file type) that was selected (or 0).
|
|
|
|
Can be useful when choosing the save file format based on suffix.
|
|
|
|
*/
|
|
|
|
QString getOpenFileName(QWidget *parent, const QString &caption, const QString &dir,
|
|
|
|
const QString &filter,
|
|
|
|
QString *selectedSuffixOut);
|
|
|
|
|
2012-03-24 17:07:29 +01:00
|
|
|
/** Get connection type to call object slot in GUI thread with invokeMethod. The call will be blocking.
|
|
|
|
|
|
|
|
@returns If called from the GUI thread, return a Qt::DirectConnection.
|
|
|
|
If called from another thread, return a Qt::BlockingQueuedConnection.
|
|
|
|
*/
|
2012-02-18 01:34:53 +11:00
|
|
|
Qt::ConnectionType blockingGUIThreadConnection();
|
|
|
|
|
|
|
|
// Determine whether a widget is hidden behind other windows
|
|
|
|
bool isObscured(QWidget *w);
|
2012-03-24 17:07:29 +01:00
|
|
|
|
2018-08-31 23:08:07 +01:00
|
|
|
// Activate, show and raise the widget
|
|
|
|
void bringToFront(QWidget* w);
|
|
|
|
|
2019-04-07 21:33:35 +02:00
|
|
|
// Set shortcut to close window
|
|
|
|
void handleCloseWindowShortcut(QWidget* w);
|
|
|
|
|
2012-05-09 22:07:00 +02:00
|
|
|
// Open debug.log
|
|
|
|
void openDebugLogfile();
|
|
|
|
|
2017-02-28 12:13:34 -05:00
|
|
|
// Open the config file
|
|
|
|
bool openBitcoinConf();
|
|
|
|
|
2012-04-13 17:10:50 +02:00
|
|
|
/** Qt event filter that intercepts ToolTipChange events, and replaces the tooltip with a rich text
|
|
|
|
representation if needed. This assures that Qt can word-wrap long tooltip messages.
|
|
|
|
Tooltips longer than the provided size threshold (in characters) are wrapped.
|
|
|
|
*/
|
2012-05-11 11:32:04 +02:00
|
|
|
class ToolTipToRichTextFilter : public QObject
|
2012-04-13 17:10:50 +02:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
2012-05-20 15:49:17 +02:00
|
|
|
|
2012-04-13 17:10:50 +02:00
|
|
|
public:
|
2018-07-30 12:37:09 +02:00
|
|
|
explicit ToolTipToRichTextFilter(int size_threshold, QObject *parent = nullptr);
|
2012-04-13 17:10:50 +02:00
|
|
|
|
|
|
|
protected:
|
2020-03-14 08:49:59 +02:00
|
|
|
bool eventFilter(QObject *obj, QEvent *evt) override;
|
2012-04-13 17:10:50 +02:00
|
|
|
|
|
|
|
private:
|
|
|
|
int size_threshold;
|
|
|
|
};
|
|
|
|
|
2020-06-08 16:48:45 +03:00
|
|
|
/**
|
|
|
|
* Qt event filter that intercepts QEvent::FocusOut events for QLabel objects, and
|
|
|
|
* resets their `textInteractionFlags' property to get rid of the visible cursor.
|
|
|
|
*
|
|
|
|
* This is a temporary fix of QTBUG-59514.
|
|
|
|
*/
|
|
|
|
class LabelOutOfFocusEventFilter : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
|
|
|
explicit LabelOutOfFocusEventFilter(QObject* parent);
|
|
|
|
bool eventFilter(QObject* watched, QEvent* event) override;
|
|
|
|
};
|
|
|
|
|
2012-05-01 18:44:11 +02:00
|
|
|
bool GetStartOnSystemStartup();
|
|
|
|
bool SetStartOnSystemStartup(bool fAutoStart);
|
|
|
|
|
2020-12-25 17:10:02 +01:00
|
|
|
/** Convert QString to OS specific boost path through UTF-8 */
|
2022-01-11 18:32:11 +02:00
|
|
|
fs::path QStringToPath(const QString &path);
|
2014-03-22 10:22:42 +01:00
|
|
|
|
2020-12-25 17:10:02 +01:00
|
|
|
/** Convert OS specific boost path to QString through UTF-8 */
|
2022-01-11 18:32:11 +02:00
|
|
|
QString PathToQString(const fs::path &path);
|
2014-03-22 10:22:42 +01:00
|
|
|
|
2020-12-24 11:01:07 +01:00
|
|
|
/** Convert enum Network to QString */
|
|
|
|
QString NetworkToQString(Network net);
|
|
|
|
|
2020-12-24 12:35:37 +01:00
|
|
|
/** Convert enum ConnectionType to QString */
|
2021-01-09 20:21:00 +01:00
|
|
|
QString ConnectionTypeToQString(ConnectionType conn_type, bool prepend_direction);
|
2020-12-24 12:35:37 +01:00
|
|
|
|
2020-12-25 17:10:02 +01:00
|
|
|
/** Convert seconds into a QString with days, hours, mins, secs */
|
2020-07-10 18:19:11 +02:00
|
|
|
QString formatDurationStr(std::chrono::seconds dur);
|
2014-05-23 12:09:59 -05:00
|
|
|
|
2022-02-13 19:44:05 +01:00
|
|
|
/** Convert peer connection time to a QString denominated in the most relevant unit. */
|
|
|
|
QString FormatPeerAge(std::chrono::seconds time_connected);
|
|
|
|
|
2020-12-25 17:10:02 +01:00
|
|
|
/** Format CNodeStats.nServices bitmask into a user-readable string */
|
2014-08-18 16:18:39 +02:00
|
|
|
QString formatServicesStr(quint64 mask);
|
2014-06-04 12:06:18 +02:00
|
|
|
|
2020-09-29 19:11:53 -07:00
|
|
|
/** Format a CNodeStats.m_last_ping_time into a user-readable string or display N/A, if 0 */
|
|
|
|
QString formatPingTime(std::chrono::microseconds ping_time);
|
2020-03-03 08:35:01 -05:00
|
|
|
|
2020-12-25 17:10:02 +01:00
|
|
|
/** Format a CNodeCombinedStats.nTimeOffset into a user-readable string */
|
2014-12-15 11:07:55 +01:00
|
|
|
QString formatTimeOffset(int64_t nTimeOffset);
|
|
|
|
|
2017-01-12 16:47:51 +01:00
|
|
|
QString formatNiceTimeOffset(qint64 secs);
|
2016-07-19 15:22:01 +02:00
|
|
|
|
2017-10-14 16:06:21 -07:00
|
|
|
QString formatBytes(uint64_t bytes);
|
|
|
|
|
2018-01-12 11:09:59 -10:00
|
|
|
qreal calculateIdealFontSize(int width, const QString& text, QFont font, qreal minPointSize = 4, qreal startPointSize = 14);
|
|
|
|
|
2021-04-08 14:27:14 +03:00
|
|
|
class ThemedLabel : public QLabel
|
2016-11-24 14:26:20 +01:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
2021-04-08 14:27:14 +03:00
|
|
|
public:
|
|
|
|
explicit ThemedLabel(const PlatformStyle* platform_style, QWidget* parent = nullptr);
|
|
|
|
void setThemedPixmap(const QString& image_filename, int width, int height);
|
|
|
|
|
|
|
|
protected:
|
|
|
|
void changeEvent(QEvent* e) override;
|
|
|
|
|
|
|
|
private:
|
|
|
|
const PlatformStyle* m_platform_style;
|
|
|
|
QString m_image_filename;
|
|
|
|
int m_pixmap_width;
|
|
|
|
int m_pixmap_height;
|
|
|
|
void updateThemedPixmap();
|
|
|
|
};
|
|
|
|
|
2021-04-08 16:14:12 +03:00
|
|
|
class ClickableLabel : public ThemedLabel
|
2016-11-24 14:26:20 +01:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
2021-04-08 16:14:12 +03:00
|
|
|
public:
|
|
|
|
explicit ClickableLabel(const PlatformStyle* platform_style, QWidget* parent = nullptr);
|
|
|
|
|
2016-11-24 14:26:20 +01:00
|
|
|
Q_SIGNALS:
|
|
|
|
/** Emitted when the label is clicked. The relative mouse coordinates of the click are
|
|
|
|
* passed to the signal.
|
|
|
|
*/
|
|
|
|
void clicked(const QPoint& point);
|
|
|
|
protected:
|
2020-03-14 08:49:59 +02:00
|
|
|
void mouseReleaseEvent(QMouseEvent *event) override;
|
2016-12-05 09:26:43 +01:00
|
|
|
};
|
2018-07-24 16:59:49 +01:00
|
|
|
|
2016-12-05 09:26:43 +01:00
|
|
|
class ClickableProgressBar : public QProgressBar
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
2018-07-24 16:59:49 +01:00
|
|
|
|
2016-12-05 09:26:43 +01:00
|
|
|
Q_SIGNALS:
|
|
|
|
/** Emitted when the progressbar is clicked. The relative mouse coordinates of the click are
|
|
|
|
* passed to the signal.
|
|
|
|
*/
|
|
|
|
void clicked(const QPoint& point);
|
|
|
|
protected:
|
2020-03-14 08:49:59 +02:00
|
|
|
void mouseReleaseEvent(QMouseEvent *event) override;
|
2016-12-05 09:26:43 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
typedef ClickableProgressBar ProgressBar;
|
2016-11-24 14:26:20 +01:00
|
|
|
|
2018-07-30 22:44:18 +01:00
|
|
|
class ItemDelegate : public QItemDelegate
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
ItemDelegate(QObject* parent) : QItemDelegate(parent) {}
|
|
|
|
|
|
|
|
Q_SIGNALS:
|
|
|
|
void keyEscapePressed();
|
|
|
|
|
|
|
|
private:
|
2020-03-14 08:49:59 +02:00
|
|
|
bool eventFilter(QObject *object, QEvent *event) override;
|
2018-07-30 22:44:18 +01:00
|
|
|
};
|
2018-12-26 22:19:14 +02:00
|
|
|
|
|
|
|
// Fix known bugs in QProgressDialog class.
|
|
|
|
void PolishProgressDialog(QProgressDialog* dialog);
|
2019-08-23 20:13:11 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the distance in pixels appropriate for drawing a subsequent character after text.
|
|
|
|
*
|
2020-08-09 16:25:22 +03:00
|
|
|
* In Qt 5.12 and before the QFontMetrics::width() is used and it is deprecated since Qt 5.13.
|
2019-08-23 20:13:11 +03:00
|
|
|
* In Qt 5.11 the QFontMetrics::horizontalAdvance() was introduced.
|
|
|
|
*/
|
|
|
|
int TextWidth(const QFontMetrics& fm, const QString& text);
|
2019-12-29 17:29:45 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Writes to debug.log short info about the used Qt and the host system.
|
|
|
|
*/
|
|
|
|
void LogQtInfo();
|
2020-01-11 14:35:34 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Call QMenu::popup() only on supported QT_QPA_PLATFORM.
|
|
|
|
*/
|
|
|
|
void PopupMenu(QMenu* menu, const QPoint& point, QAction* at_action = nullptr);
|
2020-08-09 16:25:22 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the start-moment of the day in local time.
|
|
|
|
*
|
|
|
|
* QDateTime::QDateTime(const QDate& date) is deprecated since Qt 5.15.
|
|
|
|
* QDate::startOfDay() was introduced in Qt 5.14.
|
|
|
|
*/
|
|
|
|
QDateTime StartOfDay(const QDate& date);
|
|
|
|
|
2020-08-09 17:55:34 +03:00
|
|
|
/**
|
|
|
|
* Returns true if pixmap has been set.
|
|
|
|
*
|
|
|
|
* QPixmap* QLabel::pixmap() is deprecated since Qt 5.15.
|
|
|
|
*/
|
|
|
|
bool HasPixmap(const QLabel* label);
|
|
|
|
QImage GetImage(const QLabel* label);
|
|
|
|
|
2020-08-09 19:53:25 +03:00
|
|
|
/**
|
|
|
|
* Splits the string into substrings wherever separator occurs, and returns
|
|
|
|
* the list of those strings. Empty strings do not appear in the result.
|
|
|
|
*
|
|
|
|
* QString::split() signature differs in different Qt versions:
|
|
|
|
* - QString::SplitBehavior is deprecated since Qt 5.15
|
|
|
|
* - Qt::SplitBehavior was introduced in Qt 5.14
|
|
|
|
* If {QString|Qt}::SkipEmptyParts behavior is required, use this
|
|
|
|
* function instead of QString::split().
|
|
|
|
*/
|
|
|
|
template <typename SeparatorType>
|
|
|
|
QStringList SplitSkipEmptyParts(const QString& string, const SeparatorType& separator)
|
|
|
|
{
|
|
|
|
#if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0))
|
|
|
|
return string.split(separator, Qt::SkipEmptyParts);
|
|
|
|
#else
|
|
|
|
return string.split(separator, QString::SkipEmptyParts);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-03-27 18:52:22 +02:00
|
|
|
/**
|
|
|
|
* Replaces a plain text link with an HTML tagged one.
|
|
|
|
*/
|
|
|
|
QString MakeHtmlLink(const QString& source, const QString& link);
|
|
|
|
|
2021-03-27 18:52:22 +02:00
|
|
|
void PrintSlotException(
|
|
|
|
const std::exception* exception,
|
|
|
|
const QObject* sender,
|
|
|
|
const QObject* receiver);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A drop-in replacement of QObject::connect function
|
|
|
|
* (see: https://doc.qt.io/qt-5/qobject.html#connect-3), that
|
|
|
|
* guaranties that all exceptions are handled within the slot.
|
|
|
|
*
|
|
|
|
* NOTE: This function is incompatible with Qt private signals.
|
|
|
|
*/
|
|
|
|
template <typename Sender, typename Signal, typename Receiver, typename Slot>
|
|
|
|
auto ExceptionSafeConnect(
|
|
|
|
Sender sender, Signal signal, Receiver receiver, Slot method,
|
|
|
|
Qt::ConnectionType type = Qt::AutoConnection)
|
|
|
|
{
|
|
|
|
return QObject::connect(
|
|
|
|
sender, signal, receiver,
|
|
|
|
[sender, receiver, method](auto&&... args) {
|
|
|
|
bool ok{true};
|
|
|
|
try {
|
|
|
|
(receiver->*method)(std::forward<decltype(args)>(args)...);
|
|
|
|
} catch (const NonFatalCheckError& e) {
|
|
|
|
PrintSlotException(&e, sender, receiver);
|
|
|
|
ok = QMetaObject::invokeMethod(
|
|
|
|
qApp, "handleNonFatalException",
|
|
|
|
blockingGUIThreadConnection(),
|
|
|
|
Q_ARG(QString, QString::fromStdString(e.what())));
|
|
|
|
} catch (const std::exception& e) {
|
|
|
|
PrintSlotException(&e, sender, receiver);
|
|
|
|
ok = QMetaObject::invokeMethod(
|
|
|
|
qApp, "handleRunawayException",
|
|
|
|
blockingGUIThreadConnection(),
|
|
|
|
Q_ARG(QString, QString::fromStdString(e.what())));
|
|
|
|
} catch (...) {
|
|
|
|
PrintSlotException(nullptr, sender, receiver);
|
|
|
|
ok = QMetaObject::invokeMethod(
|
|
|
|
qApp, "handleRunawayException",
|
|
|
|
blockingGUIThreadConnection(),
|
|
|
|
Q_ARG(QString, "Unknown failure occurred."));
|
|
|
|
}
|
|
|
|
assert(ok);
|
|
|
|
},
|
|
|
|
type);
|
|
|
|
}
|
|
|
|
|
2021-06-07 18:00:36 +03:00
|
|
|
/**
|
|
|
|
* Shows a QDialog instance asynchronously, and deletes it on close.
|
|
|
|
*/
|
2022-02-08 18:16:11 +02:00
|
|
|
void ShowModalDialogAsynchronously(QDialog* dialog);
|
2021-06-07 18:00:36 +03:00
|
|
|
|
2021-12-03 01:02:10 +02:00
|
|
|
inline bool IsEscapeOrBack(int key)
|
|
|
|
{
|
|
|
|
if (key == Qt::Key_Escape) return true;
|
|
|
|
#ifdef Q_OS_ANDROID
|
|
|
|
if (key == Qt::Key_Back) return true;
|
|
|
|
#endif // Q_OS_ANDROID
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-02-18 01:34:53 +11:00
|
|
|
} // namespace GUIUtil
|
2011-05-27 18:38:30 +02:00
|
|
|
|
2014-11-03 16:16:40 +01:00
|
|
|
#endif // BITCOIN_QT_GUIUTIL_H
|