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

Merge pull request #4305

ezavod (1):
      feat(chatform): mark message with triple click
This commit is contained in:
sudden6 2017-04-07 18:40:07 +02:00
commit 0f54e44262
No known key found for this signature in database
GPG Key ID: 279509B499E032B9
6 changed files with 87 additions and 0 deletions

View File

@ -56,6 +56,10 @@ void ChatLineContent::selectionDoubleClick(QPointF)
{ {
} }
void ChatLineContent::selectionTripleClick(QPointF)
{
}
void ChatLineContent::selectionFocusChanged(bool) void ChatLineContent::selectionFocusChanged(bool)
{ {
} }

View File

@ -45,6 +45,7 @@ public:
virtual void selectionStarted(QPointF scenePos); virtual void selectionStarted(QPointF scenePos);
virtual void selectionCleared(); virtual void selectionCleared();
virtual void selectionDoubleClick(QPointF scenePos); virtual void selectionDoubleClick(QPointF scenePos);
virtual void selectionTripleClick(QPointF scenePos);
virtual void selectionFocusChanged(bool focusIn); virtual void selectionFocusChanged(bool focusIn);
virtual bool isOverSelection(QPointF scenePos) const; virtual bool isOverSelection(QPointF scenePos) const;
virtual QString getSelectedText() const; virtual QString getSelectedText() const;

View File

@ -105,6 +105,12 @@ ChatLog::ChatLog(QWidget* parent)
workerTimer->setInterval(5); workerTimer->setInterval(5);
connect(workerTimer, &QTimer::timeout, this, &ChatLog::onWorkerTimeout); connect(workerTimer, &QTimer::timeout, this, &ChatLog::onWorkerTimeout);
// This timer is used to detect multiple clicks
multiClickTimer = new QTimer(this);
multiClickTimer->setSingleShot(true);
multiClickTimer->setInterval(QApplication::doubleClickInterval());
connect(multiClickTimer, &QTimer::timeout, this, &ChatLog::onMultiClickTimeout);
// selection // selection
connect(this, &ChatLog::selectionChanged, this, [this]() { connect(this, &ChatLog::selectionChanged, this, [this]() {
copyAction->setEnabled(hasTextToBeCopied()); copyAction->setEnabled(hasTextToBeCopied());
@ -190,6 +196,13 @@ void ChatLog::mousePressEvent(QMouseEvent* ev)
clickPos = ev->pos(); clickPos = ev->pos();
clearSelection(); clearSelection();
} }
// Counts only single clicks and first click of doule click
clickCount++;
lastClickPos = ev->pos();
// Triggers on odd click counts
handleMultiClickEvent();
} }
void ChatLog::mouseReleaseEvent(QMouseEvent* ev) void ChatLog::mouseReleaseEvent(QMouseEvent* ev)
@ -197,6 +210,8 @@ void ChatLog::mouseReleaseEvent(QMouseEvent* ev)
QGraphicsView::mouseReleaseEvent(ev); QGraphicsView::mouseReleaseEvent(ev);
selectionScrollDir = NoDirection; selectionScrollDir = NoDirection;
multiClickTimer->start();
} }
void ChatLog::mouseMoveEvent(QMouseEvent* ev) void ChatLog::mouseMoveEvent(QMouseEvent* ev)
@ -461,6 +476,13 @@ void ChatLog::mouseDoubleClickEvent(QMouseEvent* ev)
emit selectionChanged(); emit selectionChanged();
} }
// Counts the second click of double click
clickCount++;
lastClickPos = ev->pos();
// Triggers on even click counts
handleMultiClickEvent();
} }
QString ChatLog::getSelectedText() const QString ChatLog::getSelectedText() const
@ -796,6 +818,36 @@ void ChatLog::onWorkerTimeout()
} }
} }
void ChatLog::onMultiClickTimeout()
{
clickCount = 0;
}
void ChatLog::handleMultiClickEvent()
{
// Ignore single or double clicks
if (clickCount < 2)
return;
switch (clickCount) {
case 3:
QPointF scenePos = mapToScene(lastClickPos);
ChatLineContent* content = getContentFromPos(scenePos);
if (content) {
content->selectionTripleClick(scenePos);
selClickedCol = content->getColumn();
selClickedRow = content->getRow();
selFirstRow = content->getRow();
selLastRow = content->getRow();
selectionMode = Precise;
emit selectionChanged();
}
break;
}
}
void ChatLog::showEvent(QShowEvent*) void ChatLog::showEvent(QShowEvent*)
{ {
// Empty. // Empty.

View File

@ -74,6 +74,7 @@ public slots:
private slots: private slots:
void onSelectionTimerTimeout(); void onSelectionTimerTimeout();
void onWorkerTimeout(); void onWorkerTimeout();
void onMultiClickTimeout();
protected: protected:
QRectF calculateSceneRect() const; QRectF calculateSceneRect() const;
@ -111,6 +112,7 @@ protected:
private: private:
void retranslateUi(); void retranslateUi();
bool isActiveFileTransfer(ChatLine::Ptr l); bool isActiveFileTransfer(ChatLine::Ptr l);
void handleMultiClickEvent();
private: private:
enum SelectionMode enum SelectionMode
@ -147,7 +149,10 @@ private:
QGraphicsRectItem* selGraphItem = nullptr; QGraphicsRectItem* selGraphItem = nullptr;
QTimer* selectionTimer = nullptr; QTimer* selectionTimer = nullptr;
QTimer* workerTimer = nullptr; QTimer* workerTimer = nullptr;
QTimer* multiClickTimer = nullptr;
AutoScrollDirection selectionScrollDir = NoDirection; AutoScrollDirection selectionScrollDir = NoDirection;
int clickCount = 0;
QPoint lastClickPos;
// worker vars // worker vars
int workerLastIndex = 0; int workerLastIndex = 0;

View File

@ -121,6 +121,30 @@ void Text::selectionDoubleClick(QPointF scenePos)
update(); update();
} }
void Text::selectionTripleClick(QPointF scenePos)
{
if (!doc)
return;
int cur = cursorFromPos(scenePos);
if (cur >= 0) {
QTextCursor cursor(doc);
cursor.setPosition(cur);
cursor.select(QTextCursor::BlockUnderCursor);
selectionAnchor = cursor.selectionStart();
selectionEnd = cursor.selectionEnd();
if (cursor.block().isValid() && cursor.block().blockNumber() != 0)
selectionAnchor++;
selectedText = extractSanitizedText(getSelectionStart(), getSelectionEnd());
}
update();
}
void Text::selectionFocusChanged(bool focusIn) void Text::selectionFocusChanged(bool focusIn)
{ {
selectionHasFocus = focusIn; selectionHasFocus = focusIn;

View File

@ -43,6 +43,7 @@ public:
virtual void selectionStarted(QPointF scenePos) final; virtual void selectionStarted(QPointF scenePos) final;
virtual void selectionCleared() final; virtual void selectionCleared() final;
virtual void selectionDoubleClick(QPointF scenePos) final; virtual void selectionDoubleClick(QPointF scenePos) final;
virtual void selectionTripleClick(QPointF scenePos) final;
virtual void selectionFocusChanged(bool focusIn) final; virtual void selectionFocusChanged(bool focusIn) final;
virtual bool isOverSelection(QPointF scenePos) const final; virtual bool isOverSelection(QPointF scenePos) const final;
virtual QString getSelectedText() const final; virtual QString getSelectedText() const final;