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();
|
ensureIntegrity();
|
||||||
int cur = cursorFromPos(scenePos);
|
int cur = cursorFromPos(scenePos);
|
||||||
if(cur >= 0)
|
if(cur >= 0)
|
||||||
|
{
|
||||||
cursor.setPosition(cur, QTextCursor::KeepAnchor);
|
cursor.setPosition(cur, QTextCursor::KeepAnchor);
|
||||||
|
selectedText = cursor.selectedText();
|
||||||
|
}
|
||||||
|
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
@ -89,12 +92,17 @@ void Text::selectionStarted(QPointF scenePos)
|
||||||
int cur = cursorFromPos(scenePos);
|
int cur = cursorFromPos(scenePos);
|
||||||
if(cur >= 0)
|
if(cur >= 0)
|
||||||
cursor.setPosition(cur);
|
cursor.setPosition(cur);
|
||||||
|
|
||||||
|
selectedText.clear();
|
||||||
|
selectedText.squeeze();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Text::selectionCleared()
|
void Text::selectionCleared()
|
||||||
{
|
{
|
||||||
ensureIntegrity();
|
ensureIntegrity();
|
||||||
cursor.setPosition(0);
|
cursor.setPosition(0);
|
||||||
|
selectedText.clear();
|
||||||
|
selectedText.squeeze();
|
||||||
freeResources();
|
freeResources();
|
||||||
|
|
||||||
update();
|
update();
|
||||||
|
@ -104,6 +112,7 @@ void Text::selectAll()
|
||||||
{
|
{
|
||||||
ensureIntegrity();
|
ensureIntegrity();
|
||||||
cursor.select(QTextCursor::Document);
|
cursor.select(QTextCursor::Document);
|
||||||
|
selectedText = text;
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -118,7 +127,7 @@ bool Text::isOverSelection(QPointF scenePos) const
|
||||||
|
|
||||||
QString Text::getSelectedText() const
|
QString Text::getSelectedText() const
|
||||||
{
|
{
|
||||||
return cursor.selectedText();
|
return selectedText;
|
||||||
}
|
}
|
||||||
|
|
||||||
QRectF Text::boundingSceneRect() const
|
QRectF Text::boundingSceneRect() const
|
||||||
|
@ -181,6 +190,11 @@ void Text::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
|
||||||
QDesktopServices::openUrl(anchor);
|
QDesktopServices::openUrl(anchor);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString Text::getText() const
|
||||||
|
{
|
||||||
|
return text;
|
||||||
|
}
|
||||||
|
|
||||||
void Text::ensureIntegrity()
|
void Text::ensureIntegrity()
|
||||||
{
|
{
|
||||||
if(!doc)
|
if(!doc)
|
||||||
|
|
|
@ -32,24 +32,26 @@ public:
|
||||||
|
|
||||||
void setText(const QString& txt);
|
void setText(const QString& txt);
|
||||||
|
|
||||||
virtual void setWidth(qreal width);
|
virtual void setWidth(qreal width) override;
|
||||||
|
|
||||||
virtual void selectionMouseMove(QPointF scenePos);
|
virtual void selectionMouseMove(QPointF scenePos) override;
|
||||||
virtual void selectionStarted(QPointF scenePos);
|
virtual void selectionStarted(QPointF scenePos) override;
|
||||||
virtual void selectionCleared();
|
virtual void selectionCleared() override;
|
||||||
virtual void selectAll();
|
virtual void selectAll() override;
|
||||||
virtual bool isOverSelection(QPointF scenePos) const;
|
virtual bool isOverSelection(QPointF scenePos) const override;
|
||||||
virtual QString getSelectedText() const;
|
virtual QString getSelectedText() const override;
|
||||||
|
|
||||||
virtual QRectF boundingSceneRect() const;
|
virtual QRectF boundingSceneRect() const override;
|
||||||
virtual QRectF boundingRect() const;
|
virtual QRectF boundingRect() const override;
|
||||||
virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
|
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 qreal firstLineVOffset() const override;
|
||||||
virtual void mousePressEvent(QGraphicsSceneMouseEvent *event);
|
virtual void mousePressEvent(QGraphicsSceneMouseEvent *event) override;
|
||||||
virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
|
virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) override;
|
||||||
|
|
||||||
|
virtual QString getText() const override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
// dynamic resource management
|
// dynamic resource management
|
||||||
|
@ -63,6 +65,7 @@ private:
|
||||||
CustomTextDocument* doc = nullptr;
|
CustomTextDocument* doc = nullptr;
|
||||||
QString text;
|
QString text;
|
||||||
QString elidedText;
|
QString elidedText;
|
||||||
|
QString selectedText;
|
||||||
QSizeF size;
|
QSizeF size;
|
||||||
bool isVisible = false;
|
bool isVisible = false;
|
||||||
bool elide = false;
|
bool elide = false;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user