mirror of
https://github.com/Nheko-Reborn/nheko.git
synced 2024-11-26 21:18:48 +03:00
Fix support for Qt versions < 5.11
This commit is contained in:
parent
2484e0c118
commit
4c0d4f35fe
8 changed files with 56 additions and 12 deletions
|
@ -19,6 +19,7 @@
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QMouseEvent>
|
#include <QMouseEvent>
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
|
#include <QtGlobal>
|
||||||
|
|
||||||
#include "Cache.h"
|
#include "Cache.h"
|
||||||
#include "Config.h"
|
#include "Config.h"
|
||||||
|
@ -182,9 +183,12 @@ RoomInfoListItem::paintEvent(QPaintEvent *event)
|
||||||
|
|
||||||
QFont tsFont;
|
QFont tsFont;
|
||||||
tsFont.setPointSizeF(tsFont.pointSizeF() * 0.9);
|
tsFont.setPointSizeF(tsFont.pointSizeF() * 0.9);
|
||||||
|
#if QT_VERSION < QT_VERSION_CHECK(5, 11, 0)
|
||||||
|
const int msgStampWidth = QFontMetrics(tsFont).width(lastMsgInfo_.timestamp) + 4;
|
||||||
|
#else
|
||||||
const int msgStampWidth =
|
const int msgStampWidth =
|
||||||
QFontMetrics(tsFont).horizontalAdvance(lastMsgInfo_.timestamp) + 4;
|
QFontMetrics(tsFont).horizontalAdvance(lastMsgInfo_.timestamp) + 4;
|
||||||
|
#endif
|
||||||
// We use the full width of the widget if there is no unread msg bubble.
|
// We use the full width of the widget if there is no unread msg bubble.
|
||||||
const int bottomLineWidthLimit = (unreadMsgCount_ > 0) ? msgStampWidth : 0;
|
const int bottomLineWidthLimit = (unreadMsgCount_ > 0) ? msgStampWidth : 0;
|
||||||
|
|
||||||
|
@ -212,8 +216,11 @@ RoomInfoListItem::paintEvent(QPaintEvent *event)
|
||||||
p.setFont(QFont{});
|
p.setFont(QFont{});
|
||||||
p.drawText(QPoint(2 * wm.padding + wm.iconSize, bottom_y), userName);
|
p.drawText(QPoint(2 * wm.padding + wm.iconSize, bottom_y), userName);
|
||||||
|
|
||||||
|
#if QT_VERSION < QT_VERSION_CHECK(5, 11, 0)
|
||||||
|
int nameWidth = QFontMetrics(QFont{}).width(userName);
|
||||||
|
#else
|
||||||
int nameWidth = QFontMetrics(QFont{}).horizontalAdvance(userName);
|
int nameWidth = QFontMetrics(QFont{}).horizontalAdvance(userName);
|
||||||
|
#endif
|
||||||
p.setFont(QFont{});
|
p.setFont(QFont{});
|
||||||
|
|
||||||
// The limit is the space between the end of the username and the start of
|
// The limit is the space between the end of the username and the start of
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
#include <QPoint>
|
#include <QPoint>
|
||||||
#include <QShowEvent>
|
#include <QShowEvent>
|
||||||
|
#include <QtGlobal>
|
||||||
|
|
||||||
#include "Config.h"
|
#include "Config.h"
|
||||||
#include "TypingDisplay.h"
|
#include "TypingDisplay.h"
|
||||||
|
@ -69,9 +70,12 @@ TypingDisplay::paintEvent(QPaintEvent *)
|
||||||
text_ = fm.elidedText(text_, Qt::ElideRight, (double)(width() * 0.75));
|
text_ = fm.elidedText(text_, Qt::ElideRight, (double)(width() * 0.75));
|
||||||
|
|
||||||
QPainterPath path;
|
QPainterPath path;
|
||||||
|
#if QT_VERSION < QT_VERSION_CHECK(5, 11, 0)
|
||||||
|
path.addRoundedRect(QRectF(0, 0, fm.width(text_) + 2 * LEFT_PADDING, height()), 3, 3);
|
||||||
|
#else
|
||||||
path.addRoundedRect(
|
path.addRoundedRect(
|
||||||
QRectF(0, 0, fm.horizontalAdvance(text_) + 2 * LEFT_PADDING, height()), 3, 3);
|
QRectF(0, 0, fm.horizontalAdvance(text_) + 2 * LEFT_PADDING, height()), 3, 3);
|
||||||
|
#endif
|
||||||
p.fillPath(path, backgroundColor());
|
p.fillPath(path, backgroundColor());
|
||||||
p.drawText(region, Qt::AlignVCenter, text_);
|
p.drawText(region, Qt::AlignVCenter, text_);
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,6 +21,7 @@
|
||||||
#include <QFontDatabase>
|
#include <QFontDatabase>
|
||||||
#include <QMenu>
|
#include <QMenu>
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
|
#include <QtGlobal>
|
||||||
|
|
||||||
#include "ChatPage.h"
|
#include "ChatPage.h"
|
||||||
#include "Config.h"
|
#include "Config.h"
|
||||||
|
@ -731,11 +732,13 @@ TimelineItem::generateUserName(const QString &user_id, const QString &displaynam
|
||||||
userName_->setToolTipDuration(1500);
|
userName_->setToolTipDuration(1500);
|
||||||
userName_->setAttribute(Qt::WA_Hover);
|
userName_->setAttribute(Qt::WA_Hover);
|
||||||
userName_->setAlignment(Qt::AlignLeft | Qt::AlignTop);
|
userName_->setAlignment(Qt::AlignLeft | Qt::AlignTop);
|
||||||
|
#if QT_VERSION < QT_VERSION_CHECK(5, 11, 0)
|
||||||
// width deprecated in 5.13:
|
// width deprecated in 5.13:
|
||||||
// userName_->setFixedWidth(QFontMetrics(userName_->font()).width(userName_->text()));
|
userName_->setFixedWidth(QFontMetrics(userName_->font()).width(userName_->text()));
|
||||||
|
#else
|
||||||
userName_->setFixedWidth(
|
userName_->setFixedWidth(
|
||||||
QFontMetrics(userName_->font()).horizontalAdvance(userName_->text()));
|
QFontMetrics(userName_->font()).horizontalAdvance(userName_->text()));
|
||||||
|
#endif
|
||||||
// Set the user color asynchronously if it hasn't been generated yet,
|
// Set the user color asynchronously if it hasn't been generated yet,
|
||||||
// otherwise this will just set it.
|
// otherwise this will just set it.
|
||||||
refreshAuthorColor();
|
refreshAuthorColor();
|
||||||
|
|
|
@ -21,6 +21,7 @@
|
||||||
#include <QFileDialog>
|
#include <QFileDialog>
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
#include <QPixmap>
|
#include <QPixmap>
|
||||||
|
#include <QtGlobal>
|
||||||
|
|
||||||
#include "Logging.h"
|
#include "Logging.h"
|
||||||
#include "MatrixClient.h"
|
#include "MatrixClient.h"
|
||||||
|
@ -162,10 +163,14 @@ AudioItem::resizeEvent(QResizeEvent *event)
|
||||||
font.setWeight(QFont::Medium);
|
font.setWeight(QFont::Medium);
|
||||||
|
|
||||||
QFontMetrics fm(font);
|
QFontMetrics fm(font);
|
||||||
|
#if QT_VERSION < QT_VERSION_CHECK(5, 11, 0)
|
||||||
|
const int computedWidth = std::min(
|
||||||
|
fm.width(text_) + 2 * IconRadius + VerticalPadding * 2 + TextPadding, (double)MaxWidth);
|
||||||
|
#else
|
||||||
const int computedWidth =
|
const int computedWidth =
|
||||||
std::min(fm.horizontalAdvance(text_) + 2 * IconRadius + VerticalPadding * 2 + TextPadding,
|
std::min(fm.horizontalAdvance(text_) + 2 * IconRadius + VerticalPadding * 2 + TextPadding,
|
||||||
(double)MaxWidth);
|
(double)MaxWidth);
|
||||||
|
#endif
|
||||||
resize(computedWidth, Height);
|
resize(computedWidth, Height);
|
||||||
|
|
||||||
event->accept();
|
event->accept();
|
||||||
|
|
|
@ -21,6 +21,7 @@
|
||||||
#include <QFileDialog>
|
#include <QFileDialog>
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
#include <QPixmap>
|
#include <QPixmap>
|
||||||
|
#include <QtGlobal>
|
||||||
|
|
||||||
#include "Logging.h"
|
#include "Logging.h"
|
||||||
#include "MatrixClient.h"
|
#include "MatrixClient.h"
|
||||||
|
@ -153,10 +154,14 @@ FileItem::resizeEvent(QResizeEvent *event)
|
||||||
font.setWeight(QFont::Medium);
|
font.setWeight(QFont::Medium);
|
||||||
|
|
||||||
QFontMetrics fm(font);
|
QFontMetrics fm(font);
|
||||||
|
#if QT_VERSION < QT_VERSION_CHECK(5, 11, 0)
|
||||||
|
const int computedWidth = std::min(
|
||||||
|
fm.width(text_) + 2 * IconRadius + VerticalPadding * 2 + TextPadding, (double)MaxWidth);
|
||||||
|
#else
|
||||||
const int computedWidth =
|
const int computedWidth =
|
||||||
std::min(fm.horizontalAdvance(text_) + 2 * IconRadius + VerticalPadding * 2 + TextPadding,
|
std::min(fm.horizontalAdvance(text_) + 2 * IconRadius + VerticalPadding * 2 + TextPadding,
|
||||||
(double)MaxWidth);
|
(double)MaxWidth);
|
||||||
|
#endif
|
||||||
resize(computedWidth, Height);
|
resize(computedWidth, Height);
|
||||||
|
|
||||||
event->accept();
|
event->accept();
|
||||||
|
|
|
@ -22,6 +22,7 @@
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
#include <QPixmap>
|
#include <QPixmap>
|
||||||
#include <QUuid>
|
#include <QUuid>
|
||||||
|
#include <QtGlobal>
|
||||||
|
|
||||||
#include "Config.h"
|
#include "Config.h"
|
||||||
#include "ImageItem.h"
|
#include "ImageItem.h"
|
||||||
|
@ -191,9 +192,11 @@ ImageItem::paintEvent(QPaintEvent *event)
|
||||||
|
|
||||||
if (image_.isNull()) {
|
if (image_.isNull()) {
|
||||||
QString elidedText = metrics.elidedText(text_, Qt::ElideRight, max_width_ - 10);
|
QString elidedText = metrics.elidedText(text_, Qt::ElideRight, max_width_ - 10);
|
||||||
|
#if QT_VERSION < QT_VERSION_CHECK(5, 11, 0)
|
||||||
|
setFixedSize(metrics.width(elidedText), fontHeight);
|
||||||
|
#else
|
||||||
setFixedSize(metrics.horizontalAdvance(elidedText), fontHeight);
|
setFixedSize(metrics.horizontalAdvance(elidedText), fontHeight);
|
||||||
|
#endif
|
||||||
painter.setFont(font);
|
painter.setFont(font);
|
||||||
painter.setPen(QPen(QColor(66, 133, 244)));
|
painter.setPen(QPen(QColor(66, 133, 244)));
|
||||||
painter.drawText(QPoint(0, fontHeight / 2), elidedText);
|
painter.drawText(QPoint(0, fontHeight / 2), elidedText);
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
#include <QDateTime>
|
#include <QDateTime>
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
#include <QPen>
|
#include <QPen>
|
||||||
|
#include <QtGlobal>
|
||||||
|
|
||||||
constexpr int VPadding = 6;
|
constexpr int VPadding = 6;
|
||||||
constexpr int HPadding = 12;
|
constexpr int HPadding = 12;
|
||||||
|
@ -22,7 +23,13 @@ InfoMessage::InfoMessage(QString msg, QWidget *parent)
|
||||||
initFont();
|
initFont();
|
||||||
|
|
||||||
QFontMetrics fm{font()};
|
QFontMetrics fm{font()};
|
||||||
width_ = fm.horizontalAdvance(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;
|
height_ = fm.ascent() + 2 * VPadding;
|
||||||
|
|
||||||
setFixedHeight(height_ + 2 * HMargin);
|
setFixedHeight(height_ + 2 * HMargin);
|
||||||
|
@ -64,7 +71,12 @@ DateSeparator::DateSeparator(QDateTime datetime, QWidget *parent)
|
||||||
msg_ = datetime.toString(fmt);
|
msg_ = datetime.toString(fmt);
|
||||||
|
|
||||||
QFontMetrics fm{font()};
|
QFontMetrics fm{font()};
|
||||||
width_ = fm.horizontalAdvance(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;
|
height_ = fm.ascent() + 2 * VPadding;
|
||||||
|
|
||||||
setFixedHeight(height_ + 2 * HMargin);
|
setFixedHeight(height_ + 2 * HMargin);
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
#include <QFontMetrics>
|
#include <QFontMetrics>
|
||||||
#include <QPaintDevice>
|
#include <QPaintDevice>
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
|
#include <QtGlobal>
|
||||||
|
|
||||||
class Painter : public QPainter
|
class Painter : public QPainter
|
||||||
{
|
{
|
||||||
|
@ -21,8 +22,12 @@ public:
|
||||||
{
|
{
|
||||||
QFontMetrics m(fontMetrics());
|
QFontMetrics m(fontMetrics());
|
||||||
if (textWidth < 0) {
|
if (textWidth < 0) {
|
||||||
// deprecated in 5.13: textWidth = m.width(text);
|
#if QT_VERSION < QT_VERSION_CHECK(5, 11, 0)
|
||||||
|
// deprecated in 5.13:
|
||||||
|
textWidth = m.width(text);
|
||||||
|
#else
|
||||||
textWidth = m.horizontalAdvance(text);
|
textWidth = m.horizontalAdvance(text);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
drawText((outerw - x - textWidth), y + m.ascent(), text);
|
drawText((outerw - x - textWidth), y + m.ascent(), text);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue