def mouseMoveEvent(self, event): """ Don't allow user to move locked columns """ if (self.cursor().shape() == QtCore.Qt.ArrowCursor and # not a resize event.buttons() == QtCore.Qt.LeftButton and # not a context menu self.__dragLogicalIdx is not None # is a drag-move ): scrollOffset = self.offset() pos = event.pos().x() # current mouse x position logicalIdx, cursorOffset = self.__dragLogicalIdx # the logical column index of the column currently being dragged draggedSize = self.sectionSize( logicalIdx) # the size of the column that's being dragged rightLogicalIndex = self.logicalIndexAt( (pos + (draggedSize / 2) + cursorOffset) - scrollOffset ) # the column under the right hand edge of the dragged column leftLogicalIndex = self.logicalIndexAt( (pos - (draggedSize / 2) + cursorOffset) - scrollOffset ) # the column under the left hand edge of the dragged column centralLogicalIndex = self.logicalIndexAt( pos) # the column under the cursor currentVisualIndex = self.visualIndexAt(pos) startVisualIndex = self.visualIndex(logicalIdx) columnOnLeftIsLocked = not self.__columnIsUnlocked( leftLogicalIndex ) # the column under the left hand edge is locked columnOnRightIsLocked = not self.__columnIsUnlocked( rightLogicalIndex ) # the column under the right hand edge is locked columnUnderMouseIsLocked = not self.__columnIsUnlocked( centralLogicalIndex) def snapToLeft(): # get furthest left column furthestLeft = sorted(filter(self.__columnIsUnlocked, range(self.count())), key=self.sectionPosition)[0] offset = (self.sectionPosition(furthestLeft) - scrollOffset) + (draggedSize / 2) return offset def snapToRight(): # get furthest right column furthestRight = sorted(filter(self.__columnIsUnlocked, range(self.count())), key=self.sectionPosition)[-1] offset = self.sectionPosition(furthestRight) - ( draggedSize / 2) - scrollOffset return offset offset = None # if its gone to the far left and the first column on the far left is locked... if currentVisualIndex == 0 and (columnOnLeftIsLocked or columnUnderMouseIsLocked): offset = snapToLeft() # if its dragged as far right as it can go and the last column is locked... elif currentVisualIndex == self.count() - 1 and ( columnOnRightIsLocked or columnUnderMouseIsLocked): offset = snapToRight() # if we've dragged it into left-hand edge of a locked column elif startVisualIndex > self.visualIndex(leftLogicalIndex) and ( columnOnLeftIsLocked or columnUnderMouseIsLocked): offset = snapToLeft() # if we've dragged it into right-hand edge of a locked column elif startVisualIndex < self.visualIndex(rightLogicalIndex) and ( columnOnRightIsLocked or columnUnderMouseIsLocked): offset = snapToRight() # if we need to override the position because we've hit a locked column... if offset is not None: QtGui.QHeaderView.mouseMoveEvent( self, QtGui.QMouseEvent( event.type(), QtCore.QPoint(offset - cursorOffset, 0), event.button(), event.buttons(), event.modifiers(), )) return QtGui.QHeaderView.mouseMoveEvent(self, event)
DEFAULT_LEVEL_CONSOLE = crosslogging.DEBUG DEFAULT_LEVEL_FILE = crosslogging.DEBUG DEFAULT_LEVEL_QT = crosslogging.INFO # Integer limits # do not use sys.maxint # the values defined here are compatible with QSpinBox widgets MINIMUM_INTEGER = -2147483648 MAXIMUM_INTEGER = 2147483647 # Float limits MINIMUM_FLOAT = -1.7976931348623157e+308 MAXIMUM_FLOAT = 1.7976931348623157e+308 # Default window geometry DEFAULT_WINDOW_POS = QtCore.QPoint(50, 50) DEFAULT_WINDOW_SIZE = QtCore.QSize(800, 600) # log level icons LEVEL_ICON_MAP = { crosslogging.CRITICAL: icons.ICON_ERROR_SML, crosslogging.ERROR: icons.ICON_ERROR_SML, crosslogging.WARNING: icons.ICON_WARNING_SML, crosslogging.INFO: icons.ICON_INFO_SML, crosslogging.VERBOSE: icons.ICON_VERBOSE_SML, crosslogging.DEBUG: icons.ICON_DEBUG_SML, } # cell edit types EDITBITMASK_INSERT = 0x1 << 0 EDITBITMASK_DELETE = 0x1 << 1