5#ifndef BITCOIN_QT_GUIUTIL_H
6#define BITCOIN_QT_GUIUTIL_H
14#include <QApplication>
17#include <QItemDelegate>
22#include <QProgressBar>
41class QAbstractItemView;
60 constexpr auto dialog_flags = Qt::WindowTitleHint | Qt::WindowSystemMenuHint | Qt::WindowCloseButtonHint;
89 QString
HtmlEscape(
const QString& str,
bool fMultiLine=
false);
90 QString
HtmlEscape(
const std::string& str,
bool fMultiLine=
false);
98 void copyEntryData(
const QAbstractItemView *view,
int column,
int role=Qt::EditRole);
105 QList<QModelIndex>
getEntryData(
const QAbstractItemView *view,
int column);
112 bool hasEntryData(
const QAbstractItemView *view,
int column,
int role);
119 void LoadFont(
const QString& file_name);
144 QString
getSaveFileName(QWidget *parent,
const QString &caption,
const QString &dir,
145 const QString &filter,
146 QString *selectedSuffixOut);
157 QString
getOpenFileName(QWidget *parent,
const QString &caption,
const QString &dir,
158 const QString &filter,
159 QString *selectedSuffixOut);
195 bool eventFilter(QObject *obj, QEvent *evt)
override;
213 bool eventFilter(QObject* watched, QEvent* event)
override;
250 qreal
calculateIdealFontSize(
int width,
const QString& text, QFont font, qreal minPointSize = 4, qreal startPointSize = 14);
258 void setThemedPixmap(
const QString& image_filename,
int width,
int height);
312 bool eventFilter(QObject *
object, QEvent *event)
override;
324 int TextWidth(
const QFontMetrics& fm,
const QString& text);
334 void PopupMenu(QMenu* menu,
const QPoint& point, QAction* at_action =
nullptr);
350 QImage
GetImage(
const QLabel* label);
362 template <
typename SeparatorType>
365 #if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0))
366 return string.split(separator, Qt::SkipEmptyParts);
368 return string.split(separator, QString::SkipEmptyParts);
379 const std::exception* exception,
380 const QObject* sender,
381 const QObject* receiver);
390 template <
typename Sender,
typename Signal,
typename Receiver,
typename Slot>
392 Sender sender, Signal signal, Receiver receiver, Slot method,
395 return QObject::connect(
396 sender, signal, receiver,
397 [sender, receiver, method](
auto&&...
args) {
400 (receiver->*method)(std::forward<
decltype(
args)>(
args)...);
403 ok = QMetaObject::invokeMethod(
404 qApp,
"handleNonFatalException",
406 Q_ARG(QString, QString::fromStdString(e.what())));
407 }
catch (
const std::exception& e) {
409 ok = QMetaObject::invokeMethod(
410 qApp,
"handleRunawayException",
412 Q_ARG(QString, QString::fromStdString(e.what())));
415 ok = QMetaObject::invokeMethod(
416 qApp,
"handleRunawayException",
418 Q_ARG(QString,
"Unknown failure occurred."));
432 if (key == Qt::Key_Escape)
return true;
434 if (key == Qt::Key_Back)
return true;
int64_t CAmount
Amount in satoshis (Can be negative)
void mouseReleaseEvent(QMouseEvent *event) override
ClickableLabel(const PlatformStyle *platform_style, QWidget *parent=nullptr)
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.
ItemDelegate(QObject *parent)
bool eventFilter(QObject *object, QEvent *event) override
Qt event filter that intercepts QEvent::FocusOut events for QLabel objects, and resets their ‘textInt...
bool eventFilter(QObject *watched, QEvent *event) override
LabelOutOfFocusEventFilter(QObject *parent)
const PlatformStyle * m_platform_style
void changeEvent(QEvent *e) override
ThemedLabel(const PlatformStyle *platform_style, QWidget *parent=nullptr)
void setThemedPixmap(const QString &image_filename, int width, int height)
void updateThemedPixmap()
Qt event filter that intercepts ToolTipChange events, and replaces the tooltip with a rich text repre...
bool eventFilter(QObject *obj, QEvent *evt) override
ToolTipToRichTextFilter(int size_threshold, QObject *parent=nullptr)
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:...
Top-level interface for a bitcoin node (bitcoind process).
ConnectionType
Different types of connections to a peer.
Utility functions used by the Bitcoin Qt UI.
QString NetworkToQString(Network net)
Convert enum Network to QString.
bool isObscured(QWidget *w)
QImage GetImage(const QLabel *label)
Qt::ConnectionType blockingGUIThreadConnection()
Get connection type to call object slot in GUI thread with invokeMethod.
QString WalletDisplayName(const QString &name)
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.
QFont fixedPitchFont(bool use_embedded_font)
QString formatBytes(uint64_t bytes)
void ShowModalDialogAsynchronously(QDialog *dialog)
Shows a QDialog instance asynchronously, and deletes it on close.
QString formatDurationStr(std::chrono::seconds dur)
Convert seconds into a QString with days, hours, mins, secs.
void AddButtonShortcut(QAbstractButton *button, const QKeySequence &shortcut)
Connects an additional shortcut to a QAbstractButton.
QString MakeHtmlLink(const QString &source, const QString &link)
Replaces a plain text link with an HTML tagged one.
void handleCloseWindowShortcut(QWidget *w)
QString ExtractFirstSuffixFromFilter(const QString &filter)
Extract first suffix from filter pattern "Description (*.foo)" or "Description (*....
void PolishProgressDialog(QProgressDialog *dialog)
bool isDust(interfaces::Node &node, const QString &address, const CAmount &amount)
QString getOpenFileName(QWidget *parent, const QString &caption, const QString &dir, const QString &filter, QString *selectedSuffixOut)
Get open filename, convenience wrapper for QFileDialog::getOpenFileName.
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 ...
QDateTime StartOfDay(const QDate &date)
Returns the start-moment of the day in local time.
bool SetStartOnSystemStartup(bool fAutoStart)
ClickableProgressBar ProgressBar
void bringToFront(QWidget *w)
bool HasPixmap(const QLabel *label)
Returns true if pixmap has been set.
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 PathToQString(const fs::path &path)
Convert OS specific boost path to QString through UTF-8.
QString dateTimeStr(const QDateTime &date)
void LoadFont(const QString &file_name)
Loads the font from the file specified by file_name, aborts if it fails.
void PrintSlotException(const std::exception *exception, const QObject *sender, const QObject *receiver)
QString formatBitcoinURI(const SendCoinsRecipient &info)
QString ConnectionTypeToQString(ConnectionType conn_type, bool prepend_direction)
Convert enum ConnectionType to QString.
QString formatServicesStr(quint64 mask)
Format CNodeStats.nServices bitmask into a user-readable string.
QString formatNiceTimeOffset(qint64 secs)
constexpr auto dialog_flags
QString FormatPeerAge(std::chrono::seconds time_connected)
Convert peer connection time to a QString denominated in the most relevant unit.
QString formatTimeOffset(int64_t time_offset)
Format a CNodeStateStats.time_offset into a user-readable string.
bool parseBitcoinURI(const QUrl &uri, SendCoinsRecipient *out)
auto ExceptionSafeConnect(Sender sender, Signal signal, Receiver receiver, Slot method, Qt::ConnectionType type=Qt::AutoConnection)
A drop-in replacement of QObject::connect function (see: https://doc.qt.io/qt-5/qobject....
bool GetStartOnSystemStartup()
QStringList SplitSkipEmptyParts(const QString &string, const SeparatorType &separator)
Splits the string into substrings wherever separator occurs, and returns the list of those strings.
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 IsEscapeOrBack(int key)
bool hasEntryData(const QAbstractItemView *view, int column, int role)
Returns true if the specified field of the currently selected view entry is not empty.
fs::path QStringToPath(const QString &path)
Convert QString to OS specific boost path through UTF-8.
qreal calculateIdealFontSize(int width, const QString &text, QFont font, qreal minPointSize, qreal font_size)