Changeset View
Changeset View
Standalone View
Standalone View
src/qt/guiutil.cpp
Show First 20 Lines • Show All 62 Lines • ▼ Show 20 Lines | |||||
#include <CoreServices/CoreServices.h> | #include <CoreServices/CoreServices.h> | ||||
void ForceActivation(); | void ForceActivation(); | ||||
#endif | #endif | ||||
namespace GUIUtil { | namespace GUIUtil { | ||||
auto PortableQtWidthFunction = [](const QFontMetrics &metrics, | |||||
const QString &text) { | |||||
#if (QT_VERSION >= QT_VERSION_CHECK(5, 11, 0)) | |||||
return metrics.horizontalAdvance(text); | |||||
#else | |||||
return metrics.width(text); | |||||
#endif | |||||
}; | |||||
QString dateTimeStr(const QDateTime &date) { | QString dateTimeStr(const QDateTime &date) { | ||||
return date.date().toString(Qt::SystemLocaleShortDate) + QString(" ") + | return date.date().toString(Qt::SystemLocaleShortDate) + QString(" ") + | ||||
date.toString("hh:mm"); | date.toString("hh:mm"); | ||||
} | } | ||||
QString dateTimeStr(qint64 nTime) { | QString dateTimeStr(qint64 nTime) { | ||||
return dateTimeStr(QDateTime::fromTime_t((qint32)nTime)); | return dateTimeStr(QDateTime::fromTime_t((qint32)nTime)); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 870 Lines • ▼ Show 20 Lines | |||||
#endif | #endif | ||||
} | } | ||||
qreal calculateIdealFontSize(int width, const QString &text, QFont font, | qreal calculateIdealFontSize(int width, const QString &text, QFont font, | ||||
qreal minPointSize, qreal font_size) { | qreal minPointSize, qreal font_size) { | ||||
while (font_size >= minPointSize) { | while (font_size >= minPointSize) { | ||||
font.setPointSizeF(font_size); | font.setPointSizeF(font_size); | ||||
QFontMetrics fm(font); | QFontMetrics fm(font); | ||||
if (fm.horizontalAdvance(text) < width) { | if (PortableQtWidthFunction(fm, text) < width) { | ||||
break; | break; | ||||
} | } | ||||
font_size -= 0.5; | font_size -= 0.5; | ||||
} | } | ||||
return font_size; | return font_size; | ||||
} | } | ||||
void ClickableLabel::mouseReleaseEvent(QMouseEvent *event) { | void ClickableLabel::mouseReleaseEvent(QMouseEvent *event) { | ||||
Show All 9 Lines | if (event->type() == QEvent::KeyPress) { | ||||
if (static_cast<QKeyEvent *>(event)->key() == Qt::Key_Escape) { | if (static_cast<QKeyEvent *>(event)->key() == Qt::Key_Escape) { | ||||
Q_EMIT keyEscapePressed(); | Q_EMIT keyEscapePressed(); | ||||
} | } | ||||
} | } | ||||
return QItemDelegate::eventFilter(object, event); | return QItemDelegate::eventFilter(object, event); | ||||
} | } | ||||
int TextWidth(const QFontMetrics &fm, const QString &text) { | int TextWidth(const QFontMetrics &fm, const QString &text) { | ||||
#if (QT_VERSION >= QT_VERSION_CHECK(5, 11, 0)) | return PortableQtWidthFunction(fm, text); | ||||
return fm.horizontalAdvance(text); | |||||
#else | |||||
return fm.width(text); | |||||
#endif | |||||
} | } | ||||
void PolishProgressDialog(QProgressDialog *dialog) { | void PolishProgressDialog(QProgressDialog *dialog) { | ||||
#ifdef Q_OS_MAC | #ifdef Q_OS_MAC | ||||
// Workaround for macOS-only Qt bug; see: QTBUG-65750, QTBUG-70357. | // Workaround for macOS-only Qt bug; see: QTBUG-65750, QTBUG-70357. | ||||
const int margin = dialog->fontMetrics().width("X"); | const int margin = dialog->fontMetrics().width("X"); | ||||
dialog->resize(dialog->width() + 2 * margin, dialog->height()); | dialog->resize(dialog->width() + 2 * margin, dialog->height()); | ||||
dialog->show(); | dialog->show(); | ||||
#else | #else | ||||
Q_UNUSED(dialog); | Q_UNUSED(dialog); | ||||
#endif | #endif | ||||
} | } | ||||
} // namespace GUIUtil | } // namespace GUIUtil |