Skip to content
This repository has been archived by the owner on Feb 12, 2023. It is now read-only.

Commit

Permalink
fix(ui): tighten idealSize() for chatlog Timestamps
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
tpikonen committed Jan 13, 2019
1 parent 23da95a commit c9f3830
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/chatlog/content/text.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,30 +70,31 @@ class Text : public ChatLineContent
void regenerate();
void freeResources();

QSizeF idealSize();
virtual QSizeF idealSize();
int cursorFromPos(QPointF scenePos, bool fuzzy = true) const;
int getSelectionEnd() const;
int getSelectionStart() const;
bool hasSelection() const;
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;
bool selectionHasFocus = true;
int selectionEnd = -1;
int selectionAnchor = -1;
qreal ascent = 0.0;
qreal width = 0.0;
QFont defFont;
QString defStyleSheet;
QColor color;
Expand Down
8 changes: 8 additions & 0 deletions src/chatlog/content/timestamp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
6 changes: 6 additions & 0 deletions src/chatlog/content/timestamp.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@

#include "text.h"
#include <QDateTime>
#include <QTextDocument>

class QTextDocument;

class Timestamp : public Text
{
Expand All @@ -30,6 +33,9 @@ class Timestamp : public Text
Timestamp(const QDateTime& time, const QString& format, const QFont& font);
QDateTime getTime();

protected:
QSizeF idealSize();

private:
QDateTime time;
};
Expand Down

0 comments on commit c9f3830

Please sign in to comment.