mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
double-click selection
This commit is contained in:
parent
a6e3fc671e
commit
34c7c7250b
|
@ -49,6 +49,12 @@ void ChatLineContent::selectionStarted(QPointF)
|
||||||
|
|
||||||
void ChatLineContent::selectionCleared()
|
void ChatLineContent::selectionCleared()
|
||||||
{
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void ChatLineContent::selectionDoubleClick(QPointF)
|
||||||
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ChatLineContent::isOverSelection(QPointF) const
|
bool ChatLineContent::isOverSelection(QPointF) const
|
||||||
|
|
|
@ -38,6 +38,7 @@ public:
|
||||||
virtual void selectionMouseMove(QPointF scenePos);
|
virtual void selectionMouseMove(QPointF scenePos);
|
||||||
virtual void selectionStarted(QPointF scenePos);
|
virtual void selectionStarted(QPointF scenePos);
|
||||||
virtual void selectionCleared();
|
virtual void selectionCleared();
|
||||||
|
virtual void selectionDoubleClick(QPointF scenePos);
|
||||||
virtual bool isOverSelection(QPointF scenePos) const;
|
virtual bool isOverSelection(QPointF scenePos) const;
|
||||||
virtual QString getSelectedText() const;
|
virtual QString getSelectedText() const;
|
||||||
|
|
||||||
|
|
|
@ -479,6 +479,22 @@ void ChatLog::scrollToBottom()
|
||||||
verticalScrollBar()->setValue(verticalScrollBar()->maximum());
|
verticalScrollBar()->setValue(verticalScrollBar()->maximum());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ChatLog::mouseDoubleClickEvent(QMouseEvent *ev)
|
||||||
|
{
|
||||||
|
QPointF scenePos = mapToScene(ev->pos());
|
||||||
|
ChatLineContent* content = getContentFromPos(scenePos);
|
||||||
|
|
||||||
|
if(content)
|
||||||
|
{
|
||||||
|
content->selectionDoubleClick(scenePos);
|
||||||
|
selClickedCol = content->getColumn();
|
||||||
|
selClickedRow = content->getRow();
|
||||||
|
selFirstRow = content->getRow();
|
||||||
|
selLastRow = content->getRow();
|
||||||
|
selectionMode = Precise;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
QString ChatLog::getSelectedText() const
|
QString ChatLog::getSelectedText() const
|
||||||
{
|
{
|
||||||
if(selectionMode == Precise)
|
if(selectionMode == Precise)
|
||||||
|
|
|
@ -69,6 +69,7 @@ protected:
|
||||||
void checkVisibility();
|
void checkVisibility();
|
||||||
void scrollToBottom();
|
void scrollToBottom();
|
||||||
|
|
||||||
|
virtual void mouseDoubleClickEvent(QMouseEvent* ev);
|
||||||
virtual void mousePressEvent(QMouseEvent* ev);
|
virtual void mousePressEvent(QMouseEvent* ev);
|
||||||
virtual void mouseReleaseEvent(QMouseEvent* ev);
|
virtual void mouseReleaseEvent(QMouseEvent* ev);
|
||||||
virtual void mouseMoveEvent(QMouseEvent* ev);
|
virtual void mouseMoveEvent(QMouseEvent* ev);
|
||||||
|
|
|
@ -133,6 +133,26 @@ void Text::selectionCleared()
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Text::selectionDoubleClick(QPointF scenePos)
|
||||||
|
{
|
||||||
|
if(!doc)
|
||||||
|
return;
|
||||||
|
|
||||||
|
int cur = cursorFromPos(scenePos);
|
||||||
|
|
||||||
|
if(cur >= 0)
|
||||||
|
{
|
||||||
|
QTextCursor cursor(doc);
|
||||||
|
cursor.setPosition(cur);
|
||||||
|
cursor.select(QTextCursor::WordUnderCursor);
|
||||||
|
|
||||||
|
selectionAnchor = cursor.selectionStart();
|
||||||
|
selectionEnd = cursor.selectionEnd();
|
||||||
|
}
|
||||||
|
|
||||||
|
update();
|
||||||
|
}
|
||||||
|
|
||||||
bool Text::isOverSelection(QPointF scenePos) const
|
bool Text::isOverSelection(QPointF scenePos) const
|
||||||
{
|
{
|
||||||
int cur = cursorFromPos(scenePos);
|
int cur = cursorFromPos(scenePos);
|
||||||
|
|
|
@ -27,6 +27,8 @@ class CustomTextDocument;
|
||||||
class Text : public ChatLineContent
|
class Text : public ChatLineContent
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
// txt: may contain html code
|
||||||
|
// rawText: does not contain html code
|
||||||
Text(const QString& txt = "", QFont font = QFont(), bool enableElide = false, const QString& rawText = QString());
|
Text(const QString& txt = "", QFont font = QFont(), bool enableElide = false, const QString& rawText = QString());
|
||||||
virtual ~Text();
|
virtual ~Text();
|
||||||
|
|
||||||
|
@ -37,6 +39,7 @@ public:
|
||||||
virtual void selectionMouseMove(QPointF scenePos) override;
|
virtual void selectionMouseMove(QPointF scenePos) override;
|
||||||
virtual void selectionStarted(QPointF scenePos) override;
|
virtual void selectionStarted(QPointF scenePos) override;
|
||||||
virtual void selectionCleared() override;
|
virtual void selectionCleared() override;
|
||||||
|
virtual void selectionDoubleClick(QPointF scenePos) override;
|
||||||
virtual bool isOverSelection(QPointF scenePos) const override;
|
virtual bool isOverSelection(QPointF scenePos) const override;
|
||||||
virtual QString getSelectedText() const override;
|
virtual QString getSelectedText() const override;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user