1
0
mirror of https://github.com/qTox/qTox.git synced 2024-03-22 14:00:36 +08:00

fix(ui): tighten idealSize() for chatlog Timestamps

Make Text::idealSize() a virtual function and override it in the derived
class Timestamp. The idealSize() function for Timestamps now returns a
tighter size to enable better right-alignment of the timestamps in
chatlog.

Fixes #3957. Note that this change assumes that timestamps do not
contain RTL text.
This commit is contained in:
Teemu Ikonen 2019-01-10 10:45:14 +02:00
parent 23da95a983
commit c9f3830bc2
3 changed files with 19 additions and 4 deletions

View File

@ -70,7 +70,7 @@ protected:
void regenerate();
void freeResources();
QSizeF idealSize();
virtual QSizeF idealSize();
int cursorFromPos(QPointF scenePos, bool fuzzy = true) const;
int getSelectionEnd() const;
int getSelectionStart() const;
@ -78,14 +78,16 @@ protected:
QString extractSanitizedText(int from, int to) const;
QString extractImgTooltip(int pos) const;
QTextDocument* doc = nullptr;
QSizeF size;
qreal width = 0.0;
private:
void selectText(QTextCursor& cursor, const std::pair<int, int>& point);
QTextDocument* doc = nullptr;
QString text;
QString rawText;
QString selectedText;
QSizeF size;
bool keepInMemory = false;
bool elide = false;
bool dirty = false;
@ -93,7 +95,6 @@ private:
int selectionEnd = -1;
int selectionAnchor = -1;
qreal ascent = 0.0;
qreal width = 0.0;
QFont defFont;
QString defStyleSheet;
QColor color;

View File

@ -29,3 +29,11 @@ QDateTime Timestamp::getTime()
{
return time;
}
QSizeF Timestamp::idealSize()
{
if (doc) {
return QSizeF(qMin(doc->idealWidth(), width), doc->size().height());
}
return size;
}

View File

@ -22,6 +22,9 @@
#include "text.h"
#include <QDateTime>
#include <QTextDocument>
class QTextDocument;
class Timestamp : public Text
{
@ -30,6 +33,9 @@ public:
Timestamp(const QDateTime& time, const QString& format, const QFont& font);
QDateTime getTime();
protected:
QSizeF idealSize();
private:
QDateTime time;
};