mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
ChatLog: Autoscroll while selecting
This commit is contained in:
parent
64024c77a6
commit
a74b9ce11c
|
@ -23,6 +23,7 @@
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
#include <QClipboard>
|
#include <QClipboard>
|
||||||
#include <QAction>
|
#include <QAction>
|
||||||
|
#include <QTimer>
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
T clamp(T x, T min, T max)
|
T clamp(T x, T min, T max)
|
||||||
|
@ -62,6 +63,12 @@ ChatLog::ChatLog(QWidget* parent)
|
||||||
{
|
{
|
||||||
copySelectedText();
|
copySelectedText();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
selectionTimer = new QTimer(this);
|
||||||
|
selectionTimer->setInterval(1000/60);
|
||||||
|
selectionTimer->setSingleShot(false);
|
||||||
|
selectionTimer->start();
|
||||||
|
connect(selectionTimer, &QTimer::timeout, this, &ChatLog::onSelectionTimerTimeout);
|
||||||
}
|
}
|
||||||
|
|
||||||
ChatLog::~ChatLog()
|
ChatLog::~ChatLog()
|
||||||
|
@ -243,6 +250,8 @@ void ChatLog::mouseReleaseEvent(QMouseEvent* ev)
|
||||||
|
|
||||||
emit customContextMenuRequested(ev->pos());
|
emit customContextMenuRequested(ev->pos());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
selectionScrollDir = NoDirection;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ChatLog::mouseMoveEvent(QMouseEvent* ev)
|
void ChatLog::mouseMoveEvent(QMouseEvent* ev)
|
||||||
|
@ -253,6 +262,15 @@ void ChatLog::mouseMoveEvent(QMouseEvent* ev)
|
||||||
|
|
||||||
if(ev->buttons() & Qt::LeftButton)
|
if(ev->buttons() & Qt::LeftButton)
|
||||||
{
|
{
|
||||||
|
//autoscroll
|
||||||
|
if(ev->pos().y() < 0)
|
||||||
|
selectionScrollDir = Up;
|
||||||
|
else if(ev->pos().y() > height())
|
||||||
|
selectionScrollDir = Down;
|
||||||
|
else
|
||||||
|
selectionScrollDir = NoDirection;
|
||||||
|
|
||||||
|
//select
|
||||||
if(selectionMode == None && (clickPos - ev->pos()).manhattanLength() > QApplication::startDragDistance())
|
if(selectionMode == None && (clickPos - ev->pos()).manhattanLength() > QApplication::startDragDistance())
|
||||||
{
|
{
|
||||||
QPointF sceneClickPos = mapToScene(clickPos.toPoint());
|
QPointF sceneClickPos = mapToScene(clickPos.toPoint());
|
||||||
|
@ -579,3 +597,20 @@ void ChatLog::updateMultiSelectionRect()
|
||||||
selGraphItem->hide();
|
selGraphItem->hide();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ChatLog::onSelectionTimerTimeout()
|
||||||
|
{
|
||||||
|
const int scrollSpeed = 10;
|
||||||
|
|
||||||
|
switch(selectionScrollDir)
|
||||||
|
{
|
||||||
|
case Up:
|
||||||
|
verticalScrollBar()->setValue(verticalScrollBar()->value() - scrollSpeed);
|
||||||
|
break;
|
||||||
|
case Down:
|
||||||
|
verticalScrollBar()->setValue(verticalScrollBar()->value() + scrollSpeed);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -26,6 +26,7 @@
|
||||||
|
|
||||||
class QGraphicsScene;
|
class QGraphicsScene;
|
||||||
class QGraphicsRectItem;
|
class QGraphicsRectItem;
|
||||||
|
class QTimer;
|
||||||
class ChatLineContent;
|
class ChatLineContent;
|
||||||
class ToxFile;
|
class ToxFile;
|
||||||
|
|
||||||
|
@ -81,6 +82,9 @@ protected:
|
||||||
|
|
||||||
void updateMultiSelectionRect();
|
void updateMultiSelectionRect();
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void onSelectionTimerTimeout();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
enum SelectionMode {
|
enum SelectionMode {
|
||||||
None,
|
None,
|
||||||
|
@ -88,6 +92,12 @@ private:
|
||||||
Multi,
|
Multi,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum AutoScrollDirection {
|
||||||
|
NoDirection,
|
||||||
|
Up,
|
||||||
|
Down,
|
||||||
|
};
|
||||||
|
|
||||||
QGraphicsScene* scene = nullptr;
|
QGraphicsScene* scene = nullptr;
|
||||||
QList<ChatLine::Ptr> lines;
|
QList<ChatLine::Ptr> lines;
|
||||||
QList<ChatLine::Ptr> visibleLines;
|
QList<ChatLine::Ptr> visibleLines;
|
||||||
|
@ -105,6 +115,8 @@ private:
|
||||||
QPointF clickPos;
|
QPointF clickPos;
|
||||||
QPointF lastPos;
|
QPointF lastPos;
|
||||||
QGraphicsRectItem* selGraphItem = nullptr;
|
QGraphicsRectItem* selGraphItem = nullptr;
|
||||||
|
QTimer* selectionTimer = nullptr;
|
||||||
|
AutoScrollDirection selectionScrollDir = NoDirection;
|
||||||
|
|
||||||
// actions
|
// actions
|
||||||
QAction* copyAction = nullptr;
|
QAction* copyAction = nullptr;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user