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);
136 QString
getSaveFileName(QWidget *parent,
const QString &caption,
const QString &dir,
137 const QString &filter,
138 QString *selectedSuffixOut);
149 QString
getOpenFileName(QWidget *parent,
const QString &caption,
const QString &dir,
150 const QString &filter,
151 QString *selectedSuffixOut);
187 bool eventFilter(QObject *obj, QEvent *evt)
override;
205 bool eventFilter(QObject* watched, QEvent* event)
override;
239 qreal
calculateIdealFontSize(
int width,
const QString& text, QFont font, qreal minPointSize = 4, qreal startPointSize = 14);
247 void setThemedPixmap(
const QString& image_filename,
int width,
int height);
271 void clicked(
const QPoint& point);
284 void clicked(
const QPoint& point);
301 bool eventFilter(QObject *
object, QEvent *event)
override;
313 int TextWidth(
const QFontMetrics& fm,
const QString& text);
323 void PopupMenu(QMenu* menu,
const QPoint& point, QAction* at_action =
nullptr);
339 QImage
GetImage(
const QLabel* label);
351 template <
typename SeparatorType>
354 #if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0))
355 return string.split(separator, Qt::SkipEmptyParts);
357 return string.split(separator, QString::SkipEmptyParts);
367 template <
typename Fn>
371 QObject::connect(&
source, &QObject::destroyed,
object, std::forward<Fn>(
function), connection);
380 const std::exception* exception,
381 const QObject* sender,
382 const QObject* receiver);
391 template <
typename Sender,
typename Signal,
typename Receiver,
typename Slot>
393 Sender sender, Signal signal, Receiver receiver, Slot method,
396 return QObject::connect(
397 sender, signal, receiver,
398 [sender, receiver, method](
auto&&... args) {
401 (receiver->*method)(std::forward<
decltype(args)>(args)...);
404 ok = QMetaObject::invokeMethod(
405 qApp,
"handleNonFatalException",
407 Q_ARG(QString, QString::fromStdString(e.what())));
408 }
catch (
const std::exception& e) {
410 ok = QMetaObject::invokeMethod(
411 qApp,
"handleRunawayException",
413 Q_ARG(QString, QString::fromStdString(e.what())));
416 ok = QMetaObject::invokeMethod(
417 qApp,
"handleRunawayException",
419 Q_ARG(QString,
"Unknown failure occurred."));
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 prepare application code for transition from boost::filesystem library to std::...
Top-level interface for a bitcoin node (bitcoind process).
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)
QImage GetImage(const QLabel *label)
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.
QFont fixedPitchFont(bool use_embedded_font)
QString formatBytes(uint64_t bytes)
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)
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.
QString boostPathToQString(const fs::path &path)
Convert OS specific boost path to QString through UTF-8.
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 dateTimeStr(const QDateTime &date)
QString formatDurationStr(int secs)
Convert seconds into a QString with days, hours, mins, secs.
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 formatTimeOffset(int64_t nTimeOffset)
Format a CNodeCombinedStats.nTimeOffset into a user-readable string.
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
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.
void ShowModalDialogAndDeleteOnClose(QDialog *dialog)
Shows a QDialog instance asynchronously, and deletes it on close.
int TextWidth(const QFontMetrics &fm, const QString &text)
Returns the distance in pixels appropriate for drawing a subsequent character after text.
void ObjectInvoke(QObject *object, Fn &&function, Qt::ConnectionType connection=Qt::QueuedConnection)
Queue a function to run in an object's event loop.
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)
ConnectionType
Different types of connections to a peer.