perf: reduce repaints amount caused by selection (#4889)
Co-authored-by: nerix <nero.9@hotmail.de> Co-authored-by: Rasmus Karlsson <rasmus.karlsson@pajlada.com>
This commit is contained in:
@@ -39,6 +39,7 @@
|
|||||||
- Dev: Add a compile-time flag `USE_SYSTEM_MINIAUDIO` which can be turned on to use the system miniaudio. (#4867)
|
- Dev: Add a compile-time flag `USE_SYSTEM_MINIAUDIO` which can be turned on to use the system miniaudio. (#4867)
|
||||||
- Dev: Update vcpkg to use Qt6. (#4872)
|
- Dev: Update vcpkg to use Qt6. (#4872)
|
||||||
- Dev: Replace `boost::optional` with `std::optional`. (#4877)
|
- Dev: Replace `boost::optional` with `std::optional`. (#4877)
|
||||||
|
- Dev: Improve performance by reducing repaints caused by selections. (#4889)
|
||||||
|
|
||||||
## 2.4.6
|
## 2.4.6
|
||||||
|
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ struct SelectionItem {
|
|||||||
|
|
||||||
bool operator!=(const SelectionItem &b) const
|
bool operator!=(const SelectionItem &b) const
|
||||||
{
|
{
|
||||||
return this->operator==(b);
|
return !this->operator==(b);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -62,6 +62,16 @@ struct Selection {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool operator==(const Selection &b) const
|
||||||
|
{
|
||||||
|
return this->start == b.start && this->end == b.end;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool operator!=(const Selection &b) const
|
||||||
|
{
|
||||||
|
return !this->operator==(b);
|
||||||
|
}
|
||||||
|
|
||||||
bool isEmpty() const
|
bool isEmpty() const
|
||||||
{
|
{
|
||||||
return this->start == this->end;
|
return this->start == this->end;
|
||||||
|
|||||||
@@ -1091,18 +1091,13 @@ void ChannelView::resizeEvent(QResizeEvent *)
|
|||||||
void ChannelView::setSelection(const SelectionItem &start,
|
void ChannelView::setSelection(const SelectionItem &start,
|
||||||
const SelectionItem &end)
|
const SelectionItem &end)
|
||||||
{
|
{
|
||||||
// selections
|
auto newSelection = Selection(start, end);
|
||||||
if (!this->selecting_ && start != end)
|
if (this->selection_ != newSelection)
|
||||||
{
|
{
|
||||||
// this->messagesAddedSinceSelectionPause_ = 0;
|
this->selection_ = newSelection;
|
||||||
|
this->selectionChanged.invoke();
|
||||||
this->selecting_ = true;
|
this->update();
|
||||||
// this->pausedBySelection_ = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this->selection_ = Selection(start, end);
|
|
||||||
|
|
||||||
this->selectionChanged.invoke();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
MessageElementFlags ChannelView::getFlags() const
|
MessageElementFlags ChannelView::getFlags() const
|
||||||
@@ -1520,13 +1515,10 @@ void ChannelView::mouseMoveEvent(QMouseEvent *event)
|
|||||||
// is selecting
|
// is selecting
|
||||||
if (this->isLeftMouseDown_)
|
if (this->isLeftMouseDown_)
|
||||||
{
|
{
|
||||||
// this->pause(PauseReason::Selecting, 300);
|
|
||||||
auto index = layout->getSelectionIndex(relativePos);
|
auto index = layout->getSelectionIndex(relativePos);
|
||||||
|
|
||||||
this->setSelection(this->selection_.start,
|
this->setSelection(this->selection_.start,
|
||||||
SelectionItem(messageIndex, index));
|
SelectionItem(messageIndex, index));
|
||||||
|
|
||||||
this->queueUpdate();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// message under cursor is collapsed
|
// message under cursor is collapsed
|
||||||
@@ -1980,6 +1972,15 @@ void ChannelView::mouseReleaseEvent(QMouseEvent *event)
|
|||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Triple-clicking a message selects the whole message
|
||||||
|
if (foundElement && this->clickTimer_->isActive() &&
|
||||||
|
(fabsf(distanceBetweenPoints(this->lastDClickPosition_,
|
||||||
|
event->screenPos())) < 10.f))
|
||||||
|
{
|
||||||
|
this->selectWholeMessage(layout.get(), messageIndex);
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -2061,15 +2062,6 @@ void ChannelView::mouseReleaseEvent(QMouseEvent *event)
|
|||||||
|
|
||||||
const MessageLayoutElement *hoverLayoutElement =
|
const MessageLayoutElement *hoverLayoutElement =
|
||||||
layout->getElementAt(relativePos);
|
layout->getElementAt(relativePos);
|
||||||
// Triple-clicking a message selects the whole message
|
|
||||||
if (this->clickTimer_->isActive() && this->selecting_)
|
|
||||||
{
|
|
||||||
if (fabsf(distanceBetweenPoints(this->lastDClickPosition_,
|
|
||||||
event->screenPos())) < 10.f)
|
|
||||||
{
|
|
||||||
this->selectWholeMessage(layout.get(), messageIndex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// handle the click
|
// handle the click
|
||||||
this->handleMouseClick(event, hoverLayoutElement, layout);
|
this->handleMouseClick(event, hoverLayoutElement, layout);
|
||||||
@@ -2084,16 +2076,6 @@ void ChannelView::handleMouseClick(QMouseEvent *event,
|
|||||||
switch (event->button())
|
switch (event->button())
|
||||||
{
|
{
|
||||||
case Qt::LeftButton: {
|
case Qt::LeftButton: {
|
||||||
if (this->selecting_)
|
|
||||||
{
|
|
||||||
// this->pausedBySelection = false;
|
|
||||||
this->selecting_ = false;
|
|
||||||
// this->pauseTimeout.stop();
|
|
||||||
// this->pausedTemporarily = false;
|
|
||||||
|
|
||||||
this->queueLayout();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (hoveredElement == nullptr)
|
if (hoveredElement == nullptr)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -330,7 +330,6 @@ private:
|
|||||||
} cursors_;
|
} cursors_;
|
||||||
|
|
||||||
Selection selection_;
|
Selection selection_;
|
||||||
bool selecting_ = false;
|
|
||||||
|
|
||||||
const Context context_;
|
const Context context_;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user