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:
parent
75a0e8ac2e
commit
4852a7efa5
|
@ -221,6 +221,9 @@ void Text::hoverMoveEvent(QGraphicsSceneHoverEvent *event)
|
||||||
setCursor(QCursor(Qt::PointingHandCursor));
|
setCursor(QCursor(Qt::PointingHandCursor));
|
||||||
else
|
else
|
||||||
setCursor(QCursor());
|
setCursor(QCursor());
|
||||||
|
|
||||||
|
// tooltip
|
||||||
|
setToolTip(extractImgTooltip(cursorFromPos(event->scenePos(), false)));
|
||||||
}
|
}
|
||||||
|
|
||||||
QString Text::getText() const
|
QString Text::getText() const
|
||||||
|
@ -287,10 +290,10 @@ QSizeF Text::idealSize()
|
||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
|
|
||||||
int Text::cursorFromPos(QPointF scenePos) const
|
int Text::cursorFromPos(QPointF scenePos, bool fuzzy) const
|
||||||
{
|
{
|
||||||
if(doc)
|
if(doc)
|
||||||
return doc->documentLayout()->hitTest(mapFromScene(scenePos), Qt::FuzzyHit);
|
return doc->documentLayout()->hitTest(mapFromScene(scenePos), fuzzy ? Qt::FuzzyHit : Qt::ExactHit);
|
||||||
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -348,3 +351,17 @@ QString Text::extractSanitizedText(int from, int to) const
|
||||||
|
|
||||||
return txt;
|
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();
|
||||||
|
}
|
||||||
|
|
|
@ -61,11 +61,12 @@ protected:
|
||||||
void freeResources();
|
void freeResources();
|
||||||
|
|
||||||
QSizeF idealSize();
|
QSizeF idealSize();
|
||||||
int cursorFromPos(QPointF scenePos) const;
|
int cursorFromPos(QPointF scenePos, bool fuzzy = true) const;
|
||||||
int getSelectionEnd() const;
|
int getSelectionEnd() const;
|
||||||
int getSelectionStart() const;
|
int getSelectionStart() const;
|
||||||
bool hasSelection() const;
|
bool hasSelection() const;
|
||||||
QString extractSanitizedText(int from, int to) const;
|
QString extractSanitizedText(int from, int to) const;
|
||||||
|
QString extractImgTooltip(int pos) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QTextDocument* doc = nullptr;
|
QTextDocument* doc = nullptr;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user