From 4f2824b115a9c713e6439d91360a7c7362522b91 Mon Sep 17 00:00:00 2001 From: Tobias Markmann Date: Thu, 10 Sep 2015 14:41:02 +0200 Subject: Keep scroll position in highlight rule editor when moving rules When moving a rule up or down in the highlight rule editor on Linux, the scroll area scrolled all the way down after each move. This problem is not reproducible on OS X. With this commit the dialog remembers the scroll area position before moving a rule and sets the scroll position back to the remembered value after the move of the highlight rule. Test-Information: Verified that the scroll position is not changed when moving highlight rules up or down on Debian 8.2 and OS X 10.9.5. Change-Id: Ide7c99e1311671c77cbf72da5cad4f64bfaab11f diff --git a/Swift/QtUI/QtHighlightEditor.cpp b/Swift/QtUI/QtHighlightEditor.cpp index 7aea26b..50d1f78 100644 --- a/Swift/QtUI/QtHighlightEditor.cpp +++ b/Swift/QtUI/QtHighlightEditor.cpp @@ -17,6 +17,7 @@ #include #include +#include #include #include @@ -203,20 +204,24 @@ void QtHighlightEditor::onDeleteButtonClicked() } } +void QtHighlightEditor::moveRowFromTo(int fromRow, int toRow) { + int verticalScrollAreaPosition = ui_.scrollArea->verticalScrollBar()->value(); + highlightManager_->swapRules(fromRow, toRow); + populateList(); + selectRow(toRow); + ui_.scrollArea->verticalScrollBar()->setValue(verticalScrollAreaPosition); +} + void QtHighlightEditor::onUpButtonClicked() { const size_t moveFrom = ui_.listWidget->currentRow(); const size_t moveTo = moveFrom - 1; - highlightManager_->swapRules(moveFrom, moveTo); - populateList(); - selectRow(moveTo); + moveRowFromTo(moveFrom, moveTo); } void QtHighlightEditor::onDownButtonClicked() { const size_t moveFrom = ui_.listWidget->currentRow(); const size_t moveTo = moveFrom + 1; - highlightManager_->swapRules(moveFrom, moveTo); - populateList(); - selectRow(moveTo); + moveRowFromTo(moveFrom, moveTo); } void QtHighlightEditor::onCurrentRowChanged(int currentRow) diff --git a/Swift/QtUI/QtHighlightEditor.h b/Swift/QtUI/QtHighlightEditor.h index bcceb72..eb6a52b 100644 --- a/Swift/QtUI/QtHighlightEditor.h +++ b/Swift/QtUI/QtHighlightEditor.h @@ -12,9 +12,10 @@ #pragma once +#include + #include #include -#include namespace Swift { @@ -61,6 +62,7 @@ namespace Swift { HighlightRule ruleFromDialog(); void ruleToDialog(const HighlightRule& rule); void updateResetToDefaultRulesVisibility(); + void moveRowFromTo(int fromRow, int toRow); Ui::QtHighlightEditor ui_; QtSettingsProvider* settings_; -- cgit v0.10.2-6-g49f6