'Return line number from mouse event'

def get_linenumber_from_mouse_event(self, event):

    block = self.firstVisibleBlock()
    line_number = block.blockNumber()
    top = self.blockBoundingGeometry(block).translated(self.contentOffset()).top()
    bottom = (top + self.blockBoundingRect(block).height())
    while (block.isValid() and (top < event.pos().y())):
        block = block.next()
        if block.isVisible():
            top = bottom
            bottom = (top + self.blockBoundingRect(block).height())
            line_number += 1
    return line_number
