1509 ## work-arounds for buggy behavior |
1509 ## work-arounds for buggy behavior |
1510 ########################################################################### |
1510 ########################################################################### |
1511 |
1511 |
1512 def updateUserListSize(self): |
1512 def updateUserListSize(self): |
1513 """ |
1513 """ |
1514 Public method to resize the autocompletion list to fit with contents. |
1514 Public method to resize the completion list to fit with contents. |
1515 """ |
1515 """ |
1516 childs = self.findChildren(QListWidget) |
1516 children = self.findChildren(QListWidget) |
1517 if not childs: |
1517 if children: |
1518 return |
1518 userListWidget = children[-1] |
1519 |
1519 geom = userListWidget.geometry() |
1520 ch = childs[-1] |
1520 |
1521 geom = ch.geometry() |
1521 baseHeight = geom.height() |
1522 |
1522 |
1523 baseHeight = geom.height() |
1523 # Workaround for getting all items instead of |
1524 |
1524 # userListWidget.items() call with unknown mime types. |
1525 # Workaround for getting all items instead of ch.items() call with |
1525 all_items = userListWidget.findItems('', Qt.MatchStartsWith) |
1526 # unknown mime types. |
1526 if not all_items: |
1527 all_items = ch.findItems('', Qt.MatchStartsWith) |
1527 return |
1528 if not all_items: |
1528 |
1529 return |
1529 width = 0 |
1530 |
1530 maxItemHeight = 0 |
1531 width = 0 |
1531 for item in all_items: |
1532 maxItemHeight = 0 |
1532 visualRect = userListWidget.visualItemRect(item) |
1533 for item in all_items: |
1533 itemWidth = visualRect.width() |
1534 visualRect = ch.visualItemRect(item) |
1534 if itemWidth > width: |
1535 itemWidth = visualRect.width() |
1535 width = itemWidth |
1536 if itemWidth > width: |
1536 itemHeight = visualRect.height() |
1537 width = itemWidth |
1537 if itemHeight > maxItemHeight: |
1538 itemHeight = visualRect.height() |
1538 maxItemHeight = itemHeight |
1539 if itemHeight > maxItemHeight: |
1539 |
1540 maxItemHeight = itemHeight |
1540 height = min(self.maxLines, len(all_items)) * maxItemHeight |
1541 |
1541 # Just a fiddling factor: 2 for better readability, |
1542 height = min(self.maxLines, len(all_items)) * maxItemHeight |
1542 # e.g. underscores at the end of the list. |
1543 # Just a fiddling factor: 2 for better readability, |
1543 height += 2 |
1544 # e.g. underscores at the end of the list. |
1544 |
1545 height += 2 |
1545 # Borders |
1546 |
1546 borders = geom.size() - userListWidget.contentsRect().size() |
1547 # Borders |
1547 width += borders.width() |
1548 borders = geom.size() - ch.contentsRect().size() |
1548 height += borders.height() |
1549 width += borders.width() |
1549 |
1550 height += borders.height() |
1550 font = userListWidget.font() |
1551 |
1551 fm = QFontMetrics(font) |
1552 font = ch.font() |
1552 averageCharWidth = fm.averageCharWidth() |
1553 fm = QFontMetrics(font) |
1553 maxWidth = averageCharWidth * self.maxChars |
1554 averageCharWidth = fm.averageCharWidth() |
1554 if width > maxWidth: |
1555 maxWidth = averageCharWidth * self.maxChars |
1555 width = maxWidth |
1556 if width > maxWidth: |
1556 height += userListWidget.horizontalScrollBar().sizeHint()\ |
1557 width = maxWidth |
1557 .height() |
1558 height += ch.horizontalScrollBar().sizeHint().height() |
1558 # List box doesn't honor limited size to show scroll bars, e.g. |
1559 # List box doesn't honor limited size to show scroll bars, e.g. |
1559 # Python 2 on Win 10. So just force it. |
1560 # Python 2 on Win 10. So just force it. |
1560 userListWidget.setHorizontalScrollBarPolicy( |
1561 ch.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOn) |
1561 Qt.ScrollBarAlwaysOn) |
1562 |
1562 |
1563 if len(all_items) > self.maxLines: |
1563 if len(all_items) > self.maxLines: |
1564 width += ch.verticalScrollBar().sizeHint().width() |
1564 width += userListWidget.verticalScrollBar().sizeHint().width() |
1565 |
1565 |
1566 # Special case, where the space below current line where to less |
1566 # Special case, where the space below current line where to less |
1567 yPos = geom.y() |
1567 yPos = geom.y() |
1568 charPos = self.SendScintilla(QsciScintilla.SCI_GETCURRENTPOS) |
1568 charPos = self.SendScintilla(QsciScintilla.SCI_GETCURRENTPOS) |
1569 currentYPos = self.SendScintilla( |
1569 currentYPos = self.SendScintilla( |
1570 QsciScintilla.SCI_POINTYFROMPOSITION, 0, charPos) |
1570 QsciScintilla.SCI_POINTYFROMPOSITION, 0, charPos) |
1571 |
1571 |
1572 # X position doesn't matter: set to 0 |
1572 # X position doesn't matter: set to 0 |
1573 globalPos = self.mapToGlobal(QPoint(0, currentYPos)) |
1573 globalPos = self.mapToGlobal(QPoint(0, currentYPos)) |
1574 if yPos < globalPos.y(): |
1574 if yPos < globalPos.y(): |
1575 deltaHeight = baseHeight - height |
1575 deltaHeight = baseHeight - height |
1576 geom.setY(yPos + deltaHeight - 4) |
1576 geom.setY(yPos + deltaHeight - 4) |
1577 |
1577 |
1578 geom.setWidth(width) |
1578 geom.setWidth(width) |
1579 geom.setHeight(height) |
1579 geom.setHeight(height) |
1580 ch.setGeometry(geom) |
1580 userListWidget.setGeometry(geom) |
1581 |
1581 |
1582 def __completionListSelected(self, listId, txt): |
1582 def __completionListSelected(self, listId, txt): |
1583 """ |
1583 """ |
1584 Private slot to handle the selection from the completion list. |
1584 Private slot to handle the selection from the completion list. |
1585 |
1585 |