mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
don't depend on valid cursur
This commit is contained in:
parent
a1cfbeffcb
commit
c91b7cb03c
|
@ -78,7 +78,10 @@ void Text::selectionMouseMove(QPointF scenePos)
|
|||
ensureIntegrity();
|
||||
int cur = cursorFromPos(scenePos);
|
||||
if(cur >= 0)
|
||||
{
|
||||
cursor.setPosition(cur, QTextCursor::KeepAnchor);
|
||||
selectedText = cursor.selectedText();
|
||||
}
|
||||
|
||||
update();
|
||||
}
|
||||
|
@ -89,12 +92,17 @@ void Text::selectionStarted(QPointF scenePos)
|
|||
int cur = cursorFromPos(scenePos);
|
||||
if(cur >= 0)
|
||||
cursor.setPosition(cur);
|
||||
|
||||
selectedText.clear();
|
||||
selectedText.squeeze();
|
||||
}
|
||||
|
||||
void Text::selectionCleared()
|
||||
{
|
||||
ensureIntegrity();
|
||||
cursor.setPosition(0);
|
||||
selectedText.clear();
|
||||
selectedText.squeeze();
|
||||
freeResources();
|
||||
|
||||
update();
|
||||
|
@ -104,6 +112,7 @@ void Text::selectAll()
|
|||
{
|
||||
ensureIntegrity();
|
||||
cursor.select(QTextCursor::Document);
|
||||
selectedText = text;
|
||||
update();
|
||||
}
|
||||
|
||||
|
@ -118,7 +127,7 @@ bool Text::isOverSelection(QPointF scenePos) const
|
|||
|
||||
QString Text::getSelectedText() const
|
||||
{
|
||||
return cursor.selectedText();
|
||||
return selectedText;
|
||||
}
|
||||
|
||||
QRectF Text::boundingSceneRect() const
|
||||
|
@ -181,6 +190,11 @@ void Text::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
|
|||
QDesktopServices::openUrl(anchor);
|
||||
}
|
||||
|
||||
QString Text::getText() const
|
||||
{
|
||||
return text;
|
||||
}
|
||||
|
||||
void Text::ensureIntegrity()
|
||||
{
|
||||
if(!doc)
|
||||
|
|
|
@ -32,24 +32,26 @@ public:
|
|||
|
||||
void setText(const QString& txt);
|
||||
|
||||
virtual void setWidth(qreal width);
|
||||
virtual void setWidth(qreal width) override;
|
||||
|
||||
virtual void selectionMouseMove(QPointF scenePos);
|
||||
virtual void selectionStarted(QPointF scenePos);
|
||||
virtual void selectionCleared();
|
||||
virtual void selectAll();
|
||||
virtual bool isOverSelection(QPointF scenePos) const;
|
||||
virtual QString getSelectedText() const;
|
||||
virtual void selectionMouseMove(QPointF scenePos) override;
|
||||
virtual void selectionStarted(QPointF scenePos) override;
|
||||
virtual void selectionCleared() override;
|
||||
virtual void selectAll() override;
|
||||
virtual bool isOverSelection(QPointF scenePos) const override;
|
||||
virtual QString getSelectedText() const override;
|
||||
|
||||
virtual QRectF boundingSceneRect() const;
|
||||
virtual QRectF boundingRect() const;
|
||||
virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
|
||||
virtual QRectF boundingSceneRect() const override;
|
||||
virtual QRectF boundingRect() const override;
|
||||
virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override;
|
||||
|
||||
virtual void visibilityChanged(bool isVisible);
|
||||
virtual void visibilityChanged(bool isVisible) override;
|
||||
|
||||
virtual qreal firstLineVOffset() const;
|
||||
virtual void mousePressEvent(QGraphicsSceneMouseEvent *event);
|
||||
virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
|
||||
virtual qreal firstLineVOffset() const override;
|
||||
virtual void mousePressEvent(QGraphicsSceneMouseEvent *event) override;
|
||||
virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) override;
|
||||
|
||||
virtual QString getText() const override;
|
||||
|
||||
protected:
|
||||
// dynamic resource management
|
||||
|
@ -63,6 +65,7 @@ private:
|
|||
CustomTextDocument* doc = nullptr;
|
||||
QString text;
|
||||
QString elidedText;
|
||||
QString selectedText;
|
||||
QSizeF size;
|
||||
bool isVisible = false;
|
||||
bool elide = false;
|
||||
|
|
Loading…
Reference in New Issue
Block a user