Merge pull request #130 from Nheko-Reborn/0.7.0-dev
0.7.0 dev merge to master
1 files changed, 21 insertions, 8 deletions
diff --git a/src/ui/InfoMessage.cpp b/src/ui/InfoMessage.cpp
index e9de20cc..27bc0a5f 100644
--- a/src/ui/InfoMessage.cpp
+++ b/src/ui/InfoMessage.cpp
@@ -2,8 +2,10 @@
#include "Config.h"
#include <QDateTime>
+#include <QLocale>
#include <QPainter>
#include <QPen>
+#include <QtGlobal>
constexpr int VPadding = 6;
constexpr int HPadding = 12;
@@ -22,7 +24,13 @@ InfoMessage::InfoMessage(QString msg, QWidget *parent)
initFont();
QFontMetrics fm{font()};
- width_ = fm.width(msg_) + HPadding * 2;
+#if QT_VERSION < QT_VERSION_CHECK(5, 11, 0)
+ // width deprecated in 5.13
+ width_ = fm.width(msg_) + HPadding * 2;
+#else
+ width_ = fm.horizontalAdvance(msg_) + HPadding * 2;
+#endif
+
height_ = fm.ascent() + 2 * VPadding;
setFixedHeight(height_ + 2 * HMargin);
@@ -54,17 +62,22 @@ DateSeparator::DateSeparator(QDateTime datetime, QWidget *parent)
{
auto now = QDateTime::currentDateTime();
- QString fmt;
+ QString fmt = QLocale::system().dateFormat(QLocale::LongFormat);
- if (now.date().year() != datetime.date().year())
- fmt = QString("ddd d MMMM yy");
- else
- fmt = QString("ddd d MMMM");
+ if (now.date().year() == datetime.date().year()) {
+ QRegularExpression rx("[^a-zA-Z]*y+[^a-zA-Z]*");
+ fmt = fmt.remove(rx);
+ }
- msg_ = datetime.toString(fmt);
+ msg_ = datetime.date().toString(fmt);
QFontMetrics fm{font()};
- width_ = fm.width(msg_) + HPadding * 2;
+#if QT_VERSION < QT_VERSION_CHECK(5, 11, 0)
+ // width deprecated in 5.13
+ width_ = fm.width(msg_) + HPadding * 2;
+#else
+ width_ = fm.horizontalAdvance(msg_) + HPadding * 2;
+#endif
height_ = fm.ascent() + 2 * VPadding;
setFixedHeight(height_ + 2 * HMargin);
|