def drawImage(self, qp):
        # Return if no image available
        if self.image.isNull():
            return

        # Save the painters current setting to a stack
        qp.save()
        # Draw the image
        qp.drawImage(QtCore.QRect(self.xoff, self.yoff, self.w, self.h), self.image)
        # Restore the saved setting from the stack
        qp.restore()
    def drawLabelAtMouse(self, qp):
        # Nothing to do without a highlighted object
        if not self.highlightObj:
            return
        # Nothing to without a mouse position
        if not self.mousePosOrig:
            return

        # Save QPainter settings to stack
        qp.save()

        # That is the mouse positiong
        mouse = self.mousePosOrig

        # Will show zoom
        showZoom = self.zoom and not self.image.isNull() and self.w and self.h

        # The text that is written next to the mouse
        mouseText = self.highlightObj.label

        # Where to write the text
        # Depends on the zoom (additional offset to mouse to make space for zoom?)
        # The location in the image (if we are at the top we want to write below of the mouse)
        off = 36
        if showZoom:
            off += self.zoomSize / 2
        if mouse.y() - off > self.toolbar.height():
            top = mouse.y() - off
            btm = mouse.y()
            vAlign = QtCore.Qt.AlignTop
        else:
            # The height of the cursor
            if not showZoom:
                off += 20
            top = mouse.y()
            btm = mouse.y() + off
            vAlign = QtCore.Qt.AlignBottom

        # Here we can draw
        rect = QtCore.QRect()
        rect.setTopLeft(QtCore.QPoint(mouse.x() - 200, top))
        rect.setBottomRight(QtCore.QPoint(mouse.x() + 200, btm))

        # The color
        qp.setPen(QtGui.QColor('white'))
        # The font to use
        font = QtGui.QFont("Helvetica", 20, QtGui.QFont.Bold)
        qp.setFont(font)
        # Non-transparent
        qp.setOpacity(1)
        # Draw the text, horizontally centered
        qp.drawText(rect, QtCore.Qt.AlignHCenter | vAlign, mouseText)
        # Restore settings
        qp.restore()
    def drawDisp(self, qp):
        if not self.dispOverlay:
            return

        # Save QPainter settings to stack
        qp.save()
        # Define transparency
        qp.setOpacity(self.transp)
        # Draw the overlay image
        qp.drawImage(QtCore.QRect(self.xoff, self.yoff, self.w, self.h), self.dispOverlay)
        # Restore settings
        qp.restore()

        return self.dispOverlay
Ejemplo n.º 4
0
    def setupUi(self, RocketSimWindow, screen):
        RocketSimWindow.setObjectName("RocketSimWindow")
        RocketSimWindow.resize(518, 636)
        self.centralwidget = QWidget(RocketSimWindow)
        self.centralwidget.setObjectName("centralwidget")
        self.gridLayout = QGridLayout(self.centralwidget)
        self.gridLayout.setObjectName("gridLayout")
        self.lineEdit = QLineEdit(self.centralwidget)
        self.lineEdit.setObjectName("lineEdit")
        self.lineEdit.setText(str(Globals.G))
        self.lineEdit.textChanged.connect(self.update_gravity)
        self.gridLayout.addWidget(self.lineEdit, 5, 1, 1, 1)
        self.pushButton = QPushButton(self.centralwidget)
        self.pushButton.setObjectName("pushButton")
        self.pushButton.clicked.connect(self.restart)
        self.gridLayout.addWidget(self.pushButton, 1, 2, 1, 1)
        self.graphicsView = ImageWidget(screen)
        self.graphicsView.setEnabled(True)
        self.graphicsView.setMouseTracking(False)
        self.graphicsView.setObjectName("graphicsView")
        self.gridLayout.addWidget(self.graphicsView, 0, 0, 1, 3)
        self.label_3 = QLabel(self.centralwidget)
        self.label_3.setObjectName("label_3")
        self.gridLayout.addWidget(self.label_3, 5, 0, 1, 1)
        self.horizontalSlider = QSlider(self.centralwidget)
        self.horizontalSlider.setOrientation(QtCore.Qt.Horizontal)
        self.horizontalSlider.setObjectName("horizontalSlider")
        self.horizontalSlider.setMinimum(0)
        self.horizontalSlider.setMaximum(180)
        self.horizontalSlider.valueChanged.connect(self.angle_change)
        self.gridLayout.addWidget(self.horizontalSlider, 3, 0, 1, 1)
        self.label = QLabel(self.centralwidget)
        self.label.setObjectName("label")
        self.gridLayout.addWidget(self.label, 1, 0, 1, 1)
        self.horizontalSlider_2 = QSlider(self.centralwidget)
        self.horizontalSlider_2.setOrientation(QtCore.Qt.Horizontal)
        self.horizontalSlider_2.setObjectName("horizontalSlider_2")
        self.horizontalSlider_2.setMinimum(0)
        self.horizontalSlider_2.setMaximum(10)
        self.horizontalSlider_2.valueChanged.connect(self.velocity_change)
        self.gridLayout.addWidget(self.horizontalSlider_2, 3, 1, 1, 1)
        self.label_2 = QLabel(self.centralwidget)
        self.label_2.setObjectName("label_2")
        self.gridLayout.addWidget(self.label_2, 1, 1, 1, 1)
        self.pushButton_2 = QPushButton(self.centralwidget)
        self.pushButton_2.setObjectName("pushButton_2")
        self.pushButton_2.clicked.connect(self.wait)
        self.gridLayout.addWidget(self.pushButton_2, 3, 2, 1, 1)
        RocketSimWindow.setCentralWidget(self.centralwidget)
        self.menubar = QMenuBar(RocketSimWindow)
        self.menubar.setGeometry(QtCore.QRect(0, 0, 518, 21))
        self.menubar.setObjectName("menubar")
        self.menuSymulacja = QMenu(self.menubar)
        self.menuSymulacja.setObjectName("menuSymulacja")
        self.menuEdytor_poziom_w = QMenu(self.menubar)
        self.menuEdytor_poziom_w.setObjectName("menuEdytor_poziom_w")
        RocketSimWindow.setMenuBar(self.menubar)
        self.actionSymulacja = QAction(RocketSimWindow)
        self.actionSymulacja.setObjectName("actionSymulacja")
        self.actionSymulacja.triggered.connect(ChangePlanetsWindow)
        self.actionEdytor_Poziom_w = QAction(RocketSimWindow)
        self.actionEdytor_Poziom_w.setEnabled(False)
        self.actionEdytor_Poziom_w.setObjectName("actionEdytor_Poziom_w")
        # self.actionWczytaj = QtWidgets.QAction(RocketSimWindow)
        # self.actionWczytaj.setObjectName("actionWczytaj")
        # self.actionZapisz = QtWidgets.QAction(RocketSimWindow)
        # self.actionZapisz.setObjectName("actionZapisz")
        self.actionWyj_cie = QAction(RocketSimWindow)
        self.actionWyj_cie.setObjectName("actionWyj_cie")
        self.actionWyj_cie.triggered.connect(self.quit)
        # self.menuSymulacja.addAction(self.actionZapisz)
        # self.menuSymulacja.addAction(self.actionWczytaj)
        self.menuSymulacja.addSeparator()
        self.menuSymulacja.addAction(self.actionWyj_cie)
        self.menuEdytor_poziom_w.addAction(self.actionSymulacja)
        self.menuEdytor_poziom_w.addAction(self.actionEdytor_Poziom_w)
        self.menubar.addAction(self.menuSymulacja.menuAction())
        self.menubar.addAction(self.menuEdytor_poziom_w.menuAction())
        oprogAct = QAction("O programie", self.centralwidget)
        oprogAct.triggered.connect(AboutWindow)
        self.menubar.addAction(oprogAct)

        self.retranslateUi(RocketSimWindow)
        QtCore.QMetaObject.connectSlotsByName(RocketSimWindow)