コード例 #1
0
ファイル: pfd.py プロジェクト: wangyeee/MiniGCS
    def paintEvent(self, event):
        unused(event)
        compassAIIntrusion = 0
        compassHalfSpan = 180
        painter = QPainter()
        painter.begin(self)
        painter.setRenderHint(QPainter.Antialiasing, True)
        painter.setRenderHint(QPainter.HighQualityAntialiasing, True)

        tapeGaugeWidth = self.tapesGaugeWidthFor(self.width(), self.width())
        aiheight = self.height()
        aiwidth = self.width() - tapeGaugeWidth * 2
        if (aiheight > aiwidth):
            aiheight = aiwidth
        AIMainArea = QRectF(tapeGaugeWidth, 0, aiwidth, aiheight)
        AIPaintArea = QRectF(0, 0, self.width(), self.height())

        velocityMeterArea = QRectF(0, 0, tapeGaugeWidth, aiheight)
        altimeterArea = QRectF(AIMainArea.right(), 0, tapeGaugeWidth, aiheight)

        # calc starts
        compassRelativeWidth = 0.75
        compassBottomMargin = 0.78
        compassSize = compassRelativeWidth * AIMainArea.width(
        )  # Diameter is this times the width.
        compassCenterY = AIMainArea.bottom() + compassSize / 4

        if self.height(
        ) - compassCenterY > AIMainArea.width() / 2 * compassBottomMargin:
            compassCenterY = self.height(
            ) - AIMainArea.width() / 2 * compassBottomMargin
        compassCenterY = (compassCenterY * 2 + AIMainArea.bottom() +
                          compassSize / 4) / 3

        compassArea = QRectF(
            AIMainArea.x() +
            (1 - compassRelativeWidth) / 2 * AIMainArea.width(),
            compassCenterY - compassSize / 2, compassSize, compassSize)

        if self.height() - compassCenterY < compassSize / 2:
            compassHalfSpan = math.acos(
                (compassCenterY - self.height()) * 2 /
                compassSize) * 180 / math.pi + self.COMPASS_DISK_RESOLUTION
            if compassHalfSpan > 180:
                compassHalfSpan = 180

        compassAIIntrusion = compassSize / 2 + AIMainArea.bottom(
        ) - compassCenterY
        if compassAIIntrusion < 0:
            compassAIIntrusion = 0
        #calc ends

        hadClip = painter.hasClipping()

        painter.setClipping(True)
        painter.setClipRect(AIPaintArea)

        self.drawAIGlobalFeatures(painter, AIMainArea, AIPaintArea)
        self.drawAIAttitudeScales(painter, AIMainArea, compassAIIntrusion)
        self.drawAIAirframeFixedFeatures(painter, AIMainArea)
        self.drawAICompassDisk(painter, compassArea, compassHalfSpan)

        painter.setClipping(hadClip)
        if self.isGPSAltitudePrimary:
            self.drawAltimeter(painter, altimeterArea, self.GPSAltitude,
                               self.primaryAltitude, self.verticalVelocity)
        else:
            self.drawAltimeter(painter, altimeterArea, self.primaryAltitude,
                               self.GPSAltitude, self.verticalVelocity)
        if self.isGPSSpeedPrimary:
            self.drawVelocityMeter(painter, velocityMeterArea,
                                   self.groundspeed, self.primarySpeed)
        else:
            self.drawVelocityMeter(painter, velocityMeterArea,
                                   self.primarySpeed, self.groundspeed)
        painter.end()