Browse Source

fix(chatlog): update precise selection when chatlog content changes

Fix #5769. Precise selections (within one chatline) need to be invalidated when
the line they are apart of is removed from the chatlog.
reviewable/pr5853/r1
Anthony Bilinski 6 years ago
parent
commit
b95bac238d
No known key found for this signature in database
GPG Key ID: 2AA8E0DA1B31FB3C
  1. 145
      src/chatlog/chatlog.cpp
  2. 8
      src/chatlog/chatlog.h

145
src/chatlog/chatlog.cpp

@ -457,7 +457,7 @@ void ChatLog::insertChatlinesOnTop(const QList<ChatLine::Ptr>& newLines) @@ -457,7 +457,7 @@ void ChatLog::insertChatlinesOnTop(const QList<ChatLine::Ptr>& newLines)
lines = combLines;
moveSelectionRectDownIfMulti(newLines.size());
moveSelectionRectDownIfSelected(newLines.size());
scene->setItemIndexMethod(oldIndexMeth);
@ -727,51 +727,6 @@ void ChatLog::reloadTheme() @@ -727,51 +727,6 @@ void ChatLog::reloadTheme()
}
}
/**
* @brief Adjusts the multi line selection rectangle based on chatlog changing lines
* @param offset Amount to shift selection rect up by. Must be non-negative.
*/
void ChatLog::moveSelectionRectUpIfMulti(int offset)
{
assert(offset >= 0);
if (selectionMode != SelectionMode::Multi) {
return;
}
if (selLastRow < offset) { // entire selection now out of bounds
clearSelection();
return;
} else {
selLastRow -= offset;
}
selClickedRow = std::max(0, selClickedRow - offset);
selFirstRow = std::max(0, selFirstRow - offset);
updateMultiSelectionRect();
emit selectionChanged();
}
/**
* @brief Adjusts the multi line selection rectangle based on chatlog changing lines
* @param offset Amount to shift selection rect down by. Must be non-negative.
*/
void ChatLog::moveSelectionRectDownIfMulti(int offset)
{
assert(offset >= 0);
if (selectionMode != SelectionMode::Multi) {
return;
}
const int lastLine = lines.size() - 1;
if (selFirstRow + offset > lastLine) { // entire selection now out of bounds
clearSelection();
return;
} else {
selFirstRow += offset;
}
selClickedRow = std::min(lastLine, selClickedRow + offset);
selLastRow = std::min(lastLine, selLastRow + offset);
updateMultiSelectionRect();
emit selectionChanged();
}
void ChatLog::removeFirsts(const int num)
{
if (lines.size() > num) {
@ -785,7 +740,7 @@ void ChatLog::removeFirsts(const int num) @@ -785,7 +740,7 @@ void ChatLog::removeFirsts(const int num)
lines[i]->setRow(i);
}
moveSelectionRectUpIfMulti(num);
moveSelectionRectUpIfSelected(num);
}
void ChatLog::removeLasts(const int num)
@ -1100,3 +1055,99 @@ bool ChatLog::isActiveFileTransfer(ChatLine::Ptr l) @@ -1100,3 +1055,99 @@ bool ChatLog::isActiveFileTransfer(ChatLine::Ptr l)
return false;
}
/**
* @brief Adjusts the selection based on chatlog changing lines
* @param offset Amount to shift selection rect up by. Must be non-negative.
*/
void ChatLog::moveSelectionRectUpIfSelected(int offset)
{
assert(offset >= 0);
switch (selectionMode)
{
case SelectionMode::None:
return;
case SelectionMode::Precise:
movePreciseSelectionUp(offset);
break;
case SelectionMode::Multi:
moveMultiSelectionUp(offset);
break;
}
}
/**
* @brief Adjusts the selections based on chatlog changing lines
* @param offset removed from the lines indexes. Must be non-negative.
*/
void ChatLog::moveSelectionRectDownIfSelected(int offset)
{
assert(offset >= 0);
switch (selectionMode)
{
case SelectionMode::None:
return;
case SelectionMode::Precise:
movePreciseSelectionDown(offset);
break;
case SelectionMode::Multi:
moveMultiSelectionDown(offset);
break;
}
}
void ChatLog::movePreciseSelectionDown(int offset)
{
assert(selFirstRow == selLastRow && selFirstRow == selClickedRow);
const int lastLine = lines.size() - 1;
if (selClickedRow + offset > lastLine) {
clearSelection();
} else {
const int newRow = selClickedRow + offset;
selClickedRow = newRow;
selLastRow = newRow;
selFirstRow = newRow;
emit selectionChanged();
}
}
void ChatLog::movePreciseSelectionUp(int offset)
{
assert(selFirstRow == selLastRow && selFirstRow == selClickedRow);
if (selClickedRow < offset) {
clearSelection();
} else {
const int newRow = selClickedRow - offset;
selClickedRow = newRow;
selLastRow = newRow;
selFirstRow = newRow;
emit selectionChanged();
}
}
void ChatLog::moveMultiSelectionUp(int offset)
{
if (selLastRow < offset) { // entire selection now out of bounds
clearSelection();
} else {
selLastRow -= offset;
selClickedRow = std::max(0, selClickedRow - offset);
selFirstRow = std::max(0, selFirstRow - offset);
updateMultiSelectionRect();
emit selectionChanged();
}
}
void ChatLog::moveMultiSelectionDown(int offset)
{
const int lastLine = lines.size() - 1;
if (selFirstRow + offset > lastLine) { // entire selection now out of bounds
clearSelection();
} else {
selFirstRow += offset;
selClickedRow = std::min(lastLine, selClickedRow + offset);
selLastRow = std::min(lastLine, selLastRow + offset);
updateMultiSelectionRect();
emit selectionChanged();
}
}

8
src/chatlog/chatlog.h

@ -58,8 +58,6 @@ public: @@ -58,8 +58,6 @@ public:
void selectAll();
void fontChanged(const QFont& font);
void reloadTheme();
void moveSelectionRectUpIfMulti(int offset);
void moveSelectionRectDownIfMulti(int offset);
void removeFirsts(const int num);
void removeLasts(const int num);
void setScroll(const bool scroll);
@ -130,6 +128,12 @@ private: @@ -130,6 +128,12 @@ private:
void retranslateUi();
bool isActiveFileTransfer(ChatLine::Ptr l);
void handleMultiClickEvent();
void moveSelectionRectUpIfSelected(int offset);
void moveSelectionRectDownIfSelected(int offset);
void movePreciseSelectionDown(int offset);
void movePreciseSelectionUp(int offset);
void moveMultiSelectionUp(int offset);
void moveMultiSelectionDown(int offset);
private:
enum class SelectionMode

Loading…
Cancel
Save