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

Text: Tooltips (issue #1238)

This commit is contained in:
krepa098 2015-02-25 12:02:52 +01:00
parent 75a0e8ac2e
commit 4852a7efa5
2 changed files with 21 additions and 3 deletions

View File

@ -221,6 +221,9 @@ void Text::hoverMoveEvent(QGraphicsSceneHoverEvent *event)
setCursor(QCursor(Qt::PointingHandCursor));
else
setCursor(QCursor());
// tooltip
setToolTip(extractImgTooltip(cursorFromPos(event->scenePos(), false)));
}
QString Text::getText() const
@ -287,10 +290,10 @@ QSizeF Text::idealSize()
return size;
}
int Text::cursorFromPos(QPointF scenePos) const
int Text::cursorFromPos(QPointF scenePos, bool fuzzy) const
{
if(doc)
return doc->documentLayout()->hitTest(mapFromScene(scenePos), Qt::FuzzyHit);
return doc->documentLayout()->hitTest(mapFromScene(scenePos), fuzzy ? Qt::FuzzyHit : Qt::ExactHit);
return -1;
}
@ -348,3 +351,17 @@ QString Text::extractSanitizedText(int from, int to) const
return txt;
}
QString Text::extractImgTooltip(int pos) const
{
for(QTextBlock::Iterator itr = doc->firstBlock().begin(); itr!=doc->firstBlock().end(); ++itr)
{
if(itr.fragment().contains(pos) && itr.fragment().charFormat().isImageFormat())
{
QTextImageFormat imgFmt = itr.fragment().charFormat().toImageFormat();
return imgFmt.toolTip();
}
}
return QString();
}

View File

@ -61,11 +61,12 @@ protected:
void freeResources();
QSizeF idealSize();
int cursorFromPos(QPointF scenePos) const;
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;
private:
QTextDocument* doc = nullptr;