当前位置: 首页>>代码示例>>Python>>正文


Python QVector.first方法代码示例

本文整理汇总了Python中pyqtcore.QVector.first方法的典型用法代码示例。如果您正苦于以下问题:Python QVector.first方法的具体用法?Python QVector.first怎么用?Python QVector.first使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pyqtcore.QVector的用法示例。


在下文中一共展示了QVector.first方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: Zoomable

# 需要导入模块: from pyqtcore import QVector [as 别名]
# 或者: from pyqtcore.QVector import first [as 别名]
class Zoomable(QObject):
    scaleChanged = pyqtSignal(float)

    def __init__(self, parent = None):
        super().__init__(parent)
        self.mScale = 1
        self.mZoomFactors = QVector()
        self.mGestureStartScale = 0
        self.mComboBox = None
        self.mComboRegExp = QRegExp("^\\s*(\\d+)\\s*%?\\s*$")
        self.mComboValidator = None

        for i in range(zoomFactorCount):
            self.mZoomFactors.append(zoomFactors[i])

    def setScale(self, scale):
        if (scale == self.mScale):
            return
        self.mScale = scale
        self.syncComboBox()
        self.scaleChanged.emit(self.mScale)

    def scale(self):
        return self.mScale

    def canZoomIn(self):
        return self.mScale < self.mZoomFactors.last()

    def canZoomOut(self):
        return self.mScale > self.mZoomFactors.first()

    ##
    # Changes the current scale based on the given mouse wheel \a delta.
    #
    # For convenience, the delta is assumed to be in the same units as
    # QWheelEvent.delta, which is the distance that the wheel is rotated,
    # in eighths of a degree.
    ##
    def handleWheelDelta(self, delta):
        if (delta <= -120):
            self.zoomOut()
        elif (delta >= 120):
            self.zoomIn()
        else:
            # We're dealing with a finer-resolution mouse. Allow it to have finer
            # control over the zoom level.
            factor = 1 + 0.3 * qAbs(delta / 8 / 15)
            if (delta < 0):
                factor = 1 / factor
            scale = qBound(self.mZoomFactors.first(),
                                 self.mScale * factor,
                                 self.mZoomFactors.back())
            # Round to at most four digits after the decimal point
            self.setScale(math.floor(scale * 10000 + 0.5) / 10000)

    ##
    # Changes the current scale based on the given pinch gesture.
    ##
    def handlePinchGesture(self, pinch):
        if (not (pinch.changeFlags() & QPinchGesture.ScaleFactorChanged)):
            return
        x = pinch.state()
        if x==Qt.NoGesture:
            pass
        elif x==Qt.GestureStarted:
            self.mGestureStartScale = self.mScale
            # fall through
        elif x==Qt.GestureUpdated:
            factor = pinch.scaleFactor()
            scale = qBound(self.mZoomFactors.first(),
                                 self.mGestureStartScale * factor,
                                 self.mZoomFactors.back())
            self.setScale(math.floor(scale * 10000 + 0.5) / 10000)
        elif x==Qt.GestureFinished:
            pass
        elif x==Qt.GestureCanceled:
            pass

    ##
    # Returns whether images should be smoothly transformed when drawn at the
    # current scale. This is the case when the scale is not 1 and smaller than
    # 2.
    ##
    def smoothTransform(self):
        return self.mScale != 1.0 and self.mScale < 2.0

    def setZoomFactors(self, factors):
        self.mZoomFactors = factors

    def connectToComboBox(self, comboBox):
        if (self.mComboBox):
            self.mComboBox.disconnect()
            if (self.mComboBox.lineEdit()):
                self.mComboBox.lineEdit().disconnect()
            self.mComboBox.setValidator(None)

        self.mComboBox = comboBox
        if type(comboBox) is QComboBox:
            self.mComboBox.clear()
            for scale in self.mZoomFactors:
#.........这里部分代码省略.........
开发者ID:theall,项目名称:Python-Tiled,代码行数:103,代码来源:zoomable.py

示例2: ObjectSelectionTool

# 需要导入模块: from pyqtcore import QVector [as 别名]
# 或者: from pyqtcore.QVector import first [as 别名]

#.........这里部分代码省略.........
                    self.mapScene().setSelectedObjectItems(QSet())
        elif x==Action.Selecting:
            self.updateSelection(event.scenePos(), event.modifiers())
            self.mapScene().removeItem(self.mSelectionRectangle)
            self.mAction = Action.NoAction
        elif x==Action.Moving:
            self.finishMoving(event.scenePos())
        elif x==Action.Rotating:
            self.finishRotating(event.scenePos())
        elif x==Action.Resizing:
            self.finishResizing(event.scenePos())

        self.mMousePressed = False
        self.mClickedObjectItem = None
        self.mClickedRotateHandle = None
        self.mClickedResizeHandle = None
        self.refreshCursor()
        
    def modifiersChanged(self, modifiers):
        self.mModifiers = modifiers
        self.refreshCursor()

    def languageChanged(self):
        self.setName(self.tr("Select Objects"))
        self.setShortcut(QKeySequence(self.tr("S")))

    def updateHandles(self):
        if (self.mAction == Action.Moving or self.mAction == Action.Rotating or self.mAction == Action.Resizing):
            return
        objects = self.mapDocument().selectedObjects()
        showHandles = objects.size() > 0
        if (showHandles):
            renderer = self.mapDocument().renderer()
            boundingRect = objectBounds(objects.first(), renderer, objectTransform(objects.first(), renderer))
            for i in range(1, objects.size()):
                object = objects.at(i)
                boundingRect |= objectBounds(object, renderer, objectTransform(object, renderer))

            topLeft = boundingRect.topLeft()
            topRight = boundingRect.topRight()
            bottomLeft = boundingRect.bottomLeft()
            bottomRight = boundingRect.bottomRight()
            center = boundingRect.center()
            handleRotation = 0
            # If there is only one object selected, align to its orientation.
            if (objects.size() == 1):
                object = objects.first()
                handleRotation = object.rotation()
                if (resizeInPixelSpace(object)):
                    bounds = pixelBounds(object)
                    transform = QTransform(objectTransform(object, renderer))
                    topLeft = transform.map(renderer.pixelToScreenCoords_(bounds.topLeft()))
                    topRight = transform.map(renderer.pixelToScreenCoords_(bounds.topRight()))
                    bottomLeft = transform.map(renderer.pixelToScreenCoords_(bounds.bottomLeft()))
                    bottomRight = transform.map(renderer.pixelToScreenCoords_(bounds.bottomRight()))
                    center = transform.map(renderer.pixelToScreenCoords_(bounds.center()))
                    # Ugly hack to make handles appear nicer in this case
                    if (self.mapDocument().map().orientation() == Map.Orientation.Isometric):
                        handleRotation += 45
                else:
                    bounds = objectBounds(object, renderer, QTransform())
                    transform = QTransform(objectTransform(object, renderer))
                    topLeft = transform.map(bounds.topLeft())
                    topRight = transform.map(bounds.topRight())
                    bottomLeft = transform.map(bounds.bottomLeft())
                    bottomRight = transform.map(bounds.bottomRight())
开发者ID:theall,项目名称:Python-Tiled,代码行数:70,代码来源:objectselectiontool.py


注:本文中的pyqtcore.QVector.first方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。