Commit 0bf6e608 authored by Luci Stanescu's avatar Luci Stanescu

Fixed currentIndex in contact list and contact search list

parent 05316632
...@@ -1010,6 +1010,12 @@ class ContactListView(QListView): ...@@ -1010,6 +1010,12 @@ class ContactListView(QListView):
self.actions.share_my_desktop = QAction("Share My Desktop", self, triggered=self._AH_ShareMyDesktop) self.actions.share_my_desktop = QAction("Share My Desktop", self, triggered=self._AH_ShareMyDesktop)
self.needs_restore = False self.needs_restore = False
def setModel(self, model):
selection_model = self.selectionModel() or Null
selection_model.selectionChanged.disconnect(self._SH_SelectionModelSelectionChanged)
super(ContactListView, self).setModel(model)
self.selectionModel().selectionChanged.connect(self._SH_SelectionModelSelectionChanged)
def paintEvent(self, event): def paintEvent(self, event):
super(ContactListView, self).paintEvent(event) super(ContactListView, self).paintEvent(event)
if self.drop_indicator_index.isValid(): if self.drop_indicator_index.isValid():
...@@ -1331,6 +1337,13 @@ class ContactListView(QListView): ...@@ -1331,6 +1337,13 @@ class ContactListView(QListView):
else: else:
event.ignore(rect) event.ignore(rect)
def _SH_SelectionModelSelectionChanged(self, selected, deselected):
selection_model = self.selectionModel()
selection = selection_model.selection()
if selection_model.currentIndex() not in selection:
index = selection.indexes()[0] if not selection.isEmpty() else self.model().index(-1)
selection_model.setCurrentIndex(index, selection_model.Select)
class ContactSearchListView(QListView): class ContactSearchListView(QListView):
def __init__(self, parent=None): def __init__(self, parent=None):
...@@ -1350,13 +1363,18 @@ class ContactSearchListView(QListView): ...@@ -1350,13 +1363,18 @@ class ContactSearchListView(QListView):
self.actions.request_remote_desktop = QAction("Request Remote Desktop", self, triggered=self._AH_RequestRemoteDesktop) self.actions.request_remote_desktop = QAction("Request Remote Desktop", self, triggered=self._AH_RequestRemoteDesktop)
self.actions.share_my_desktop = QAction("Share My Desktop", self, triggered=self._AH_ShareMyDesktop) self.actions.share_my_desktop = QAction("Share My Desktop", self, triggered=self._AH_ShareMyDesktop)
def setModel(self, model):
selection_model = self.selectionModel() or Null
selection_model.selectionChanged.disconnect(self._SH_SelectionModelSelectionChanged)
super(ContactSearchListView, self).setModel(model)
self.selectionModel().selectionChanged.connect(self._SH_SelectionModelSelectionChanged)
def focusInEvent(self, event): def focusInEvent(self, event):
super(ContactSearchListView, self).focusInEvent(event) super(ContactSearchListView, self).focusInEvent(event)
model = self.model() model = self.model()
selection_model = self.selectionModel() selection_model = self.selectionModel()
if not selection_model.selectedIndexes() and model.rowCount() > 0: if not selection_model.selectedIndexes() and model.rowCount() > 0:
selection_model.select(model.index(0, 0), selection_model.Select) selection_model.select(model.index(0, 0), selection_model.Select)
selection_model.setCurrentIndex(model.index(0, 0), selection_model.Select)
def paintEvent(self, event): def paintEvent(self, event):
super(ContactSearchListView, self).paintEvent(event) super(ContactSearchListView, self).paintEvent(event)
...@@ -1535,6 +1553,13 @@ class ContactSearchListView(QListView): ...@@ -1535,6 +1553,13 @@ class ContactSearchListView(QListView):
rect.setTop(self.visualRect(model.index(model.rowCount()-1, 0)).bottom()) rect.setTop(self.visualRect(model.index(model.rowCount()-1, 0)).bottom())
event.ignore(rect) event.ignore(rect)
def _SH_SelectionModelSelectionChanged(self, selected, deselected):
selection_model = self.selectionModel()
selection = selection_model.selection()
if selection_model.currentIndex() not in selection:
index = selection.indexes()[0] if not selection.isEmpty() else self.model().index(-1)
selection_model.setCurrentIndex(index, selection_model.Select)
# The contact editor dialog # The contact editor dialog
# #
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment