コード例 #1
0
    def paintSection(self, painter, rect, logicalIndex):
        '''
        The method paint the robot or capability images in the backgroud of the cell.
        :see: U{QtGui.QHeaderView.paintSection()<https://srinikom.github.io/pyside-docs/PySide/QtGui/QHeaderView.html#PySide.QtGui.PySide.QtGui.QHeaderView.paintSection>}
        '''
        painter.save()
        QHeaderView.paintSection(self, painter, rect, logicalIndex)
        painter.restore()

        if logicalIndex in range(len(
                self._data)) and self._data[logicalIndex]['images']:
            if len(self._data[logicalIndex]['images']) == 1:
                pix = self._data[logicalIndex]['images'][0]
                pix = pix.scaled(rect.width(),
                                 rect.height() - 20, Qt.KeepAspectRatio,
                                 Qt.SmoothTransformation)
                self.style().drawItemPixmap(painter, rect, 5, pix)
            elif len(self._data[logicalIndex]['images']) > 1:
                new_rect = QRect(rect.left(), rect.top(), rect.width(),
                                 (rect.height() - 20) / 2.)
                pix = self._data[logicalIndex]['images'][0]
                pix = pix.scaled(new_rect.width(), new_rect.height(),
                                 Qt.KeepAspectRatio, Qt.SmoothTransformation)
                self.style().drawItemPixmap(painter, new_rect, 5, pix)
                new_rect = QRect(rect.left(),
                                 rect.top() + new_rect.height(), rect.width(),
                                 new_rect.height())
                pix = self._data[logicalIndex]['images'][1]
                pix = pix.scaled(new_rect.width(), new_rect.height(),
                                 Qt.KeepAspectRatio, Qt.SmoothTransformation)
                self.style().drawItemPixmap(painter, new_rect, 5, pix)
コード例 #2
0
    def paintSection(self, painter, rect, logicalIndex):
        '''
        The method paint the robot or capability images in the backgroud of the cell.
        @see: U{QtGui.QHeaderView.paintSection()<https://srinikom.github.io/pyside-docs/PySide/QtGui/QHeaderView.html#PySide.QtGui.PySide.QtGui.QHeaderView.paintSection>}
        '''
        painter.save()
        QHeaderView.paintSection(self, painter, rect, logicalIndex)
        painter.restore()

        if logicalIndex in range(len(self._data)) and self._data[logicalIndex]['images']:
            if len(self._data[logicalIndex]['images']) == 1:
                pix = self._data[logicalIndex]['images'][0]
                pix = pix.scaled(rect.width(), rect.height() - 20, Qt.KeepAspectRatio, Qt.SmoothTransformation)
                self.style().drawItemPixmap(painter, rect, 5, pix)
            elif len(self._data[logicalIndex]['images']) > 1:
                new_rect = QRect(rect.left(), rect.top(), rect.width(), (rect.height() - 20) / 2.)
                pix = self._data[logicalIndex]['images'][0]
                pix = pix.scaled(new_rect.width(), new_rect.height(), Qt.KeepAspectRatio, Qt.SmoothTransformation)
                self.style().drawItemPixmap(painter, new_rect, 5, pix)
                new_rect = QRect(rect.left(), rect.top() + new_rect.height(), rect.width(), new_rect.height())
                pix = self._data[logicalIndex]['images'][1]
                pix = pix.scaled(new_rect.width(), new_rect.height(), Qt.KeepAspectRatio, Qt.SmoothTransformation)
                self.style().drawItemPixmap(painter, new_rect, 5, pix)
コード例 #3
0
ファイル: MyWidget.py プロジェクト: ctu-mrs/color_picker
    def mouseReleaseEvent(self, QMouseEvent):
        cursor = QCursor()
        x = QMouseEvent.x()
        y = QMouseEvent.y()
        if self._rubber is None:
            return
        if (x < 1280 and y < 720) and (x > 15
                                       and y > 15) and self.crop_stat == IMG:

            if not self.frozen_before:
                self.freeze()

            a = self.mapToGlobal(self.rub_origin)
            b = QMouseEvent.globalPos()
            a = self.wdg_img.mapFromGlobal(a)
            b = self.wdg_img.mapFromGlobal(b)

            self._rubber.hide()
            self._rubber = None

            pix = QPixmap(self.wdg_img.pixmap())
            sx = float(self.wdg_img.rect().width())
            sy = float(self.wdg_img.rect().height())

            # h 1080 w 1920
            sx = self.orig_w / sx
            sy = self.orig_h / sy

            a.setX(int(a.x() * sx))
            a.setY(int(a.y() * sy))

            b.setX(int(b.x() * sx))
            b.setY(int(b.y() * sy))
            rect_ = QRect(a, b)

            h_ = rect_.height()
            w_ = rect_.width()

            y1, x1, y2, x2 = rect_.getCoords()
            rospy.loginfo('Img cropped x1 {} y1 {} x2 {} y2{}'.format(
                x1, y1, x2, y2))
            self.log_info('Img cropped x1 {} y1 {} x2 {} y2{}'.format(
                x1, y1, x2, y2))
            self.capture_cropped(x1, y1, x2, y2)
        elif (x > 1300 and y > 520) and (x < 1907 and
                                         y < 1010) and self.crop_stat == HIST:

            # h 1080 w 1920

            if self.hist_status == HSV:
                cur_hist = self.inner_hist
            elif self.hist_status == LUV:
                cur_hist = self.inner_luv_hist

        # if not self.frozen_before:
        #     self.freeze()
            a = self.mapToGlobal(self.rub_origin)
            b = QMouseEvent.globalPos()
            a = cur_hist.mapFromGlobal(a)
            b = cur_hist.mapFromGlobal(b)

            self._rubber.hide()
            self._rubber = None

            pix = QPixmap(cur_hist.pixmap())
            sx = float(cur_hist.rect().width())
            sy = float(cur_hist.rect().height())

            # h 1080 w 1920
            if self.hist_status == HSV:
                sx = self.hist_hsv_orig_w / sx
                sy = self.hist_hsv_orig_h / sy
            elif self.hist_status == LUV:
                sx = self.hist_lab_orig_w / sx
                sy = self.hist_lab_orig_h / sy

            a.setX(int(a.x() * sx))
            a.setY(int(a.y() * sy))

            b.setX(int(b.x() * sx))
            b.setY(int(b.y() * sy))
            rect_ = QRect(a, b)

            h_ = rect_.height()
            w_ = rect_.width()

            # y1,x1,y2,x2 = rect_.getCoords()
            x1, y1, x2, y2 = rect_.getCoords()
            rospy.loginfo('Hist cropped x1 {} y1 {} x2 {} y2 {}'.format(
                x1, y1, x2, y2))
            self.log_info('Hist cropped x1 {} y1 {} x2 {} y2 {}'.format(
                x1, y1, x2, y2))
            if self.select_status == HIST_SELECTION:
                self.select_hist(x1, y1, x2, y2, h_, w_, self.hist_status)
            elif self.select_status == HIST_DESELECTION:
                self.deselect_hist(x1, y1, x2, y2, self.hist_status)

        else:
            if self._rubber is not None:
                self._rubber.hide()
                self._rubber = None
                self.crop_stat = 0