From e0c049eb429e54aff555a49a8aa2be3f39ab2f5f Mon Sep 17 00:00:00 2001 From: Sobottasgithub Date: Sun, 4 Feb 2024 23:10:41 +0100 Subject: [PATCH] [MLV] Add switching to first/last widget in viewport --- src/LogViewer/ui/main_window.py | 30 ++++++++++++++++++++++++++++++ src/LogViewer/ui/main_window.ui | 18 ++++++++++++++++++ 2 files changed, 48 insertions(+) diff --git a/src/LogViewer/ui/main_window.py b/src/LogViewer/ui/main_window.py index 7351c7c..c7e94d6 100644 --- a/src/LogViewer/ui/main_window.py +++ b/src/LogViewer/ui/main_window.py @@ -61,6 +61,8 @@ def __init__(self): self.uiAction_goToRow.triggered.connect(self.openGoToRowWidget) self.uiAction_firstRow.triggered.connect(self.goToFirstRow) self.uiAction_lastRow.triggered.connect(self.goToLastRow) + self.uiAction_firstRowInViewport.triggered.connect(self.goToFirstRowInViewport) + self.uiAction_lastRowInViewport.triggered.connect(self.goToLastRowInViewport) self.uiWidget_listView.doubleClicked.connect(self.inspectLine) self.uiWidget_listView.clicked.connect(self.listViewClicked) @@ -124,6 +126,8 @@ def toggleUiItems(self): self.uiSpinBox_goToRow.setEnabled(self.file != None) self.uiCombobox_searchInput.setEnabled(self.file != None) self.uiCombobox_filterInput.setEnabled(self.file != None) + self.uiAction_lastRowInViewport.setEnabled(self.file != None) + self.uiAction_firstRowInViewport.setEnabled(self.file != None) def export(self): if self.rawlog: @@ -628,6 +632,32 @@ def goToLastRow(self, *args): self.uiWidget_listView.setCurrentRow(index) self.statusbar.showDynamicText(str("Done ✓ | Switched to last row: %d" % index)) break + + @catch_exceptions(logger=logger) + def goToFirstRowInViewport(self, *args): + lastIndex = self.uiWidget_listView.selectedIndexes()[0].row() + # Counts backwards from the current entry + for index in range(self.uiWidget_listView.selectedIndexes()[0].row(), -1, -1): + # The entry height is added to the Y position of the entry to see if that line is still in the viewport + if self.uiWidget_listView.visualItemRect(self.rawlog[index]["uiItem"]).height() + self.uiWidget_listView.visualItemRect(self.rawlog[index]["uiItem"]).y() < 0: + self.uiWidget_listView.setCurrentRow(lastIndex) + self.statusbar.showDynamicText(str("Done ✓ | Switched to the first line in the viewport: %d" % lastIndex)) + break + else: + lastIndex = index + + @catch_exceptions(logger=logger) + def goToLastRowInViewport(self, *args): + lastIndex = self.uiWidget_listView.selectedIndexes()[0].row() + # Counts upwards from the current entry + for index in range(self.uiWidget_listView.selectedIndexes()[0].row(), 32): + # If the item position is larger than the listview-height, it must be the last one in our viewport + if self.uiWidget_listView.visualItemRect(self.rawlog[index]["uiItem"]).y() > self.uiWidget_listView.height(): + self.uiWidget_listView.setCurrentRow(lastIndex) + self.statusbar.showDynamicText(str("Done ✓ | Switched to the last line in the viewport: %d" % lastIndex)) + break + else: + lastIndex = index def cancelFilter(self): for index in range(len(self.rawlog)): diff --git a/src/LogViewer/ui/main_window.ui b/src/LogViewer/ui/main_window.ui index b84b14a..5cda4c3 100755 --- a/src/LogViewer/ui/main_window.ui +++ b/src/LogViewer/ui/main_window.ui @@ -277,6 +277,8 @@ + + @@ -437,6 +439,22 @@ Ctrl+End + + + First row in viewport + + + Home + + + + + Last row in viewport + + + End + +