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

fixed eliding (ie. invisible nicknames)

This commit is contained in:
krepa098 2015-01-03 21:19:28 +01:00
parent 64f7f7c45e
commit b3507152eb
2 changed files with 14 additions and 8 deletions

View File

@ -26,7 +26,6 @@
#include <QAbstractTextDocumentLayout> #include <QAbstractTextDocumentLayout>
#include <QApplication> #include <QApplication>
#include <QGraphicsSceneMouseEvent> #include <QGraphicsSceneMouseEvent>
#include <QFontMetrics>
#include <QRegExp> #include <QRegExp>
#include <QDesktopServices> #include <QDesktopServices>
@ -51,6 +50,7 @@ Text::~Text()
void Text::setText(const QString& txt) void Text::setText(const QString& txt)
{ {
text = txt; text = txt;
dirty = true;
ensureIntegrity(); ensureIntegrity();
freeResources(); freeResources();
@ -65,10 +65,13 @@ void Text::setWidth(qreal w)
if(elide) if(elide)
{ {
QFontMetrics metrics = QFontMetrics(QFont()); QFontMetrics metrics = QFontMetrics(defFont);
elidedText = metrics.elidedText(text, Qt::ElideRight, width); elidedText = metrics.elidedText(text, Qt::ElideRight, width);
dirty = true;
} }
size = idealSize();
ensureIntegrity(); ensureIntegrity();
freeResources(); freeResources();
} }
@ -168,6 +171,8 @@ void Text::visibilityChanged(bool visible)
ensureIntegrity(); ensureIntegrity();
else else
freeResources(); freeResources();
update();
} }
qreal Text::getAscent() const qreal Text::getAscent() const
@ -197,7 +202,7 @@ QString Text::getText() const
void Text::ensureIntegrity() void Text::ensureIntegrity()
{ {
if(!doc) if(!doc || dirty)
{ {
doc = new CustomTextDocument(); doc = new CustomTextDocument();
doc->setDefaultFont(defFont); doc->setDefaultFont(defFont);
@ -215,6 +220,7 @@ void Text::ensureIntegrity()
} }
cursor = QTextCursor(doc); cursor = QTextCursor(doc);
dirty = false;
} }
doc->setTextWidth(width); doc->setTextWidth(width);
@ -224,10 +230,9 @@ void Text::ensureIntegrity()
vOffset = doc->firstBlock().layout()->lineAt(0).ascent(); vOffset = doc->firstBlock().layout()->lineAt(0).ascent();
if(size != idealSize()) if(size != idealSize())
{
prepareGeometryChange(); prepareGeometryChange();
size = idealSize();
} size = idealSize();
} }
void Text::freeResources() void Text::freeResources()
@ -243,9 +248,9 @@ void Text::freeResources()
QSizeF Text::idealSize() QSizeF Text::idealSize()
{ {
if(doc) if(doc)
return QSizeF(doc->idealWidth(), doc->size().height()); return QSizeF(qMin(doc->idealWidth(), width), doc->size().height());
return QSizeF(); return size;
} }
int Text::cursorFromPos(QPointF scenePos) const int Text::cursorFromPos(QPointF scenePos) const

View File

@ -69,6 +69,7 @@ private:
QSizeF size; QSizeF size;
bool isVisible = false; bool isVisible = false;
bool elide = false; bool elide = false;
bool dirty = false;
QTextCursor cursor; QTextCursor cursor;
qreal vOffset = 0.0; qreal vOffset = 0.0;
qreal width = 0.0; qreal width = 0.0;