 |
Bitcoin Core
22.99.0
P2P Digital Currency
|
Go to the documentation of this file.
5 #ifndef BITCOIN_QT_GUIUTIL_H
6 #define BITCOIN_QT_GUIUTIL_H
14 #include <QApplication>
16 #include <QHeaderView>
17 #include <QItemDelegate>
19 #include <QMessageBox>
20 #include <QMetaObject>
22 #include <QProgressBar>
40 class QAbstractButton;
41 class QAbstractItemView;
50 class QProgressDialog;
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."));
433 if (key == Qt::Key_Escape)
return true;
435 if (key == Qt::Key_Back)
return true;
436 #endif // Q_OS_ANDROID
442 #endif // BITCOIN_QT_GUIUTIL_H
QString PathToQString(const fs::path &path)
Convert OS specific boost path to QString through UTF-8.
Qt event filter that intercepts ToolTipChange events, and replaces the tooltip with a rich text repre...
void PopupMenu(QMenu *menu, const QPoint &point, QAction *at_action)
Call QMenu::popup() only on supported QT_QPA_PLATFORM.
fs::path QStringToPath(const QString &path)
Convert QString to OS specific boost path through UTF-8.
ToolTipToRichTextFilter(int size_threshold, QObject *parent=nullptr)
bool SetStartOnSystemStartup(bool fAutoStart)
ItemDelegate(QObject *parent)
bool eventFilter(QObject *object, QEvent *event) override
void clicked(const QPoint &point)
Emitted when the progressbar is clicked.
Utility functions used by the Bitcoin Qt UI.
bool hasEntryData(const QAbstractItemView *view, int column, int role)
Returns true if the specified field of the currently selected view entry is not empty.
bool parseBitcoinURI(const QUrl &uri, SendCoinsRecipient *out)
QString formatBitcoinURI(const SendCoinsRecipient &info)
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....
void bringToFront(QWidget *w)
constexpr auto dialog_flags
bool isObscured(QWidget *w)
void setClipboard(const QString &str)
ClickableLabel(const PlatformStyle *platform_style, QWidget *parent=nullptr)
void ObjectInvoke(QObject *object, Fn &&function, Qt::ConnectionType connection=Qt::QueuedConnection)
Queue a function to run in an object's event loop.
QImage GetImage(const QLabel *label)
Qt event filter that intercepts QEvent::FocusOut events for QLabel objects, and resets their ‘textInt...
QString ConnectionTypeToQString(ConnectionType conn_type, bool prepend_direction)
Convert enum ConnectionType to QString.
void ShowModalDialogAsynchronously(QDialog *dialog)
Shows a QDialog instance asynchronously, and deletes it on close.
QString formatTimeOffset(int64_t nTimeOffset)
Format a CNodeCombinedStats.nTimeOffset into a user-readable string.
QString formatDurationStr(std::chrono::seconds dur)
Convert seconds into a QString with days, hours, mins, secs.
QString getOpenFileName(QWidget *parent, const QString &caption, const QString &dir, const QString &filter, QString *selectedSuffixOut)
Get open filename, convenience wrapper for QFileDialog::getOpenFileName.
QString formatNiceTimeOffset(qint64 secs)
QDateTime StartOfDay(const QDate &date)
Returns the start-moment of the day in local time.
Path class wrapper to block calls to the fs::path(std::string) implicit constructor and the fs::path:...
void clicked(const QPoint &point)
Emitted when the label is clicked.
void PrintSlotException(const std::exception *exception, const QObject *sender, const QObject *receiver)
void mouseReleaseEvent(QMouseEvent *event) override
bool eventFilter(QObject *watched, QEvent *event) override
void changeEvent(QEvent *e) override
void PolishProgressDialog(QProgressDialog *dialog)
int64_t CAmount
Amount in satoshis (Can be negative)
Line edit that can be marked as "invalid" to show input validation feedback.
void AddButtonShortcut(QAbstractButton *button, const QKeySequence &shortcut)
Connects an additional shortcut to a QAbstractButton.
QString formatBytes(uint64_t bytes)
QString formatServicesStr(quint64 mask)
Format CNodeStats.nServices bitmask into a user-readable string.
QFont fixedPitchFont(bool use_embedded_font)
QString MakeHtmlLink(const QString &source, const QString &link)
Replaces a plain text link with an HTML tagged one.
QString getDefaultDataDirectory()
Determine default data directory for operating system.
Top-level interface for a bitcoin node (bitcoind process).
bool HasPixmap(const QLabel *label)
Returns true if pixmap has been set.
bool eventFilter(QObject *obj, QEvent *evt) override
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 ...
LabelOutOfFocusEventFilter(QObject *parent)
bool GetStartOnSystemStartup()
QString HtmlEscape(const QString &str, bool fMultiLine)
void copyEntryData(const QAbstractItemView *view, int column, int role)
Copy a field of the currently selected entry of a view to the clipboard.
ThemedLabel(const PlatformStyle *platform_style, QWidget *parent=nullptr)
bool IsEscapeOrBack(int key)
QStringList SplitSkipEmptyParts(const QString &string, const SeparatorType &separator)
Splits the string into substrings wherever separator occurs, and returns the list of those strings.
Qt::ConnectionType blockingGUIThreadConnection()
Get connection type to call object slot in GUI thread with invokeMethod.
QString NetworkToQString(Network net)
Convert enum Network to QString.
void LogQtInfo()
Writes to debug.log short info about the used Qt and the host system.
void mouseReleaseEvent(QMouseEvent *event) override
qreal calculateIdealFontSize(int width, const QString &text, QFont font, qreal minPointSize, qreal font_size)
bool isDust(interfaces::Node &node, const QString &address, const CAmount &amount)
int TextWidth(const QFontMetrics &fm, const QString &text)
Returns the distance in pixels appropriate for drawing a subsequent character after text.
QString dateTimeStr(const QDateTime &date)
void handleCloseWindowShortcut(QWidget *w)
QList< QModelIndex > getEntryData(const QAbstractItemView *view, int column)
Return a field of the currently selected entry as a QString.
void setThemedPixmap(const QString &image_filename, int width, int height)
void LoadFont(const QString &file_name)
Loads the font from the file specified by file_name, aborts if it fails.
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.
void setupAddressWidget(QValidatedLineEdit *widget, QWidget *parent)
const PlatformStyle * m_platform_style
ConnectionType
Different types of connections to a peer.
ClickableProgressBar ProgressBar
void updateThemedPixmap()