Пример #1
0
 def applyMask(self, bool):
     self.__show_mask_preview = bool
     if bool:
         self.setMask(
             QBitmap(self.__pmap.createHeuristicMask().scaled(self.size())))
     else:
         self.setMask(QBitmap())
Пример #2
0
 def round(self):
     bmp = QBitmap(self.size())
     p = QPainter()
     p.begin(bmp)
     p.fillRect(bmp.rect(), Qt.white)
     p.setBrush(QColor(0,0,0))
     p.drawRoundedRect(bmp.rect(), 5, 5)
     p.setPen(QColor(255,255,255,255))
     p.drawPoints(QPointF(self.width()-2,self.height()-1), QPointF(self.width()-1,self.height()-2))
     p.setPen(QColor(0,0,0))
     p.drawPoints(QPointF(0,2),QPointF(3,0),QPointF(2,0),QPointF(1,1))
     p.end()
     self.setMask(bmp)
Пример #3
0
 def round(self):
     bmp = QBitmap(self.size())
     p = QPainter()
     p.begin(bmp)
     p.fillRect(bmp.rect(), Qt.white)
     p.setBrush(QColor(0,0,0))
     p.drawRoundedRect(bmp.rect(), 5, 5)
     p.setPen(QColor(255,255,255,255))
     p.drawPoints(QPointF(self.width()-2,self.height()-1), QPointF(self.width()-1,self.height()-2))
     p.setPen(QColor(0,0,0))
     p.drawPoints(QPointF(0,2),QPointF(3,0),QPointF(2,0),QPointF(1,1))
     p.end()
     self.setMask(bmp)
Пример #4
0
    def __init__(self, parent, canvasLayer):
        QTreeWidgetItem.__init__(self)
        self.legend = parent
        self.canvasLayer = canvasLayer
        self.canvasLayer.layer().setLayerName(
            self.legend.normalizeLayerName(
                unicode(self.canvasLayer.layer().name())))
        self.setText(0, self.canvasLayer.layer().name())
        self.isVect = (self.canvasLayer.layer().type() == 0
                       )  # 0: Vector, 1: Raster
        self.layerId = self.canvasLayer.layer().id()

        if self.isVect:
            geom = self.canvasLayer.layer().dataProvider().geometryType()

        self.setCheckState(0, Qt.Checked)

        if self.isVect:
            pm = QPixmap(20, 20)
            icon = QIcon()
            if geom == 1 or geom == 4 or geom == 8 or geom == 11:  # Point
                icon.addPixmap(QPixmap(imgs_dir + "mIconPointLayer.png"),
                               QIcon.Normal, QIcon.On)
            elif geom == 2 or geom == 5 or geom == 9 or geom == 12:  # Polyline
                icon.addPixmap(QPixmap(imgs_dir + "mIconLineLayer.png"),
                               QIcon.Normal, QIcon.On)
            elif geom == 3 or geom == 6 or geom == 10 or geom == 13:  # Polygon
                icon.addPixmap(QPixmap(imgs_dir + "mIconPolygonLayer.png"),
                               QIcon.Normal, QIcon.On)
            else:  # Not a valid WKT Geometry
                geom = self.canvasLayer.layer().geometryType()  # QGis Geometry
                if geom == 0:  # Point
                    icon.addPixmap(QPixmap(imgs_dir + "mIconPointLayer.png"),
                                   QIcon.Normal, QIcon.On)
                elif geom == 1:  # Line
                    icon.addPixmap(QPixmap(imgs_dir + "mIconLineLayer.png"),
                                   QIcon.Normal, QIcon.On)
                elif geom == 2:  # Polygon
                    icon.addPixmap(QPixmap(imgs_dir + "mIconPolygonLayer.png"),
                                   QIcon.Normal, QIcon.On)
                else:
                    raise RuntimeError, 'Unknown geometry: ' + str(geom)

        else:
            qimg = self.canvasLayer.layer().previewAsImage(QSize(20, 20))
            icon = QIcon(QBitmap().fromImage(qimg))

        self.setIcon(0, icon)

        #self.setToolTip( 0, self.canvasLayer.layer().publicSource() )
        layerFont = QFont()
        layerFont.setBold(True)
        self.setFont(0, layerFont)

        # Display layer properties
        self.properties = self.legend.pyQGisApp.getLayerProperties(
            self.canvasLayer.layer())
        self.child = QTreeWidgetItem(self)
        self.child.setFlags(Qt.NoItemFlags)  # Avoid the item to be selected
        self.displayLayerProperties()
Пример #5
0
 def mask_round_corner(self):
     self.mask = QBitmap(self.size())
     self.mask.clear()
     self.p = QPainter(self.mask)
     self.p.fillRect(self.rect(), Qt.white)
     self.p.setBrush(Qt.black)
     self.p.drawRoundedRect(0, 0, self.width() - 1,
                            self.height() - 1, 20, 20)
     self.setMask(self.mask)
Пример #6
0
 def __onResize(self, event):
     self.__fixed_label.move(0, self.geometry().height() - 35)
     self.__fixed_label.resize(self.geometry().width(),
                               self.__fixed_label.geometry().height())
     self.setIndicatorPos(QPoint(self.width() - self.__indicator.width(),
                                 0))
     self.__pmap.scaled(self.size())
     if self.__show_mask_preview:
         self.setMask(
             QBitmap(self.__pmap.createHeuristicMask().scaled(self.size())))
Пример #7
0
 def adjustMask(self):
     """
     Updates the alpha mask for this popup widget.
     """
     if self.currentMode() == XPopupWidget.Mode.Dialog:
         self.clearMask()
         return
     
     path = self.borderPath()
     bitmap = QBitmap(self.width(), self.height())
     bitmap.fill(QColor('white'))
     
     painter = QPainter()
     painter.begin(bitmap)
     painter.setRenderHint(QPainter.Antialiasing)
     pen = QPen(QColor('black'))
     pen.setWidthF(0.75)
     painter.setPen(pen)
     painter.setBrush(QColor('black'))
     painter.drawPath(path)
     painter.end()
     
     self.setMask(bitmap)
Пример #8
0
    def adjustMask(self):
        """
        Updates the alpha mask for this popup widget.
        """
        if self.currentMode() == XPopupWidget.Mode.Dialog:
            self.clearMask()
            return

        path = self.borderPath()
        bitmap = QBitmap(self.width(), self.height())
        bitmap.fill(QColor('white'))

        painter = QPainter()
        painter.begin(bitmap)
        painter.setRenderHint(QPainter.Antialiasing)
        pen = QPen(QColor('black'))
        pen.setWidthF(0.75)
        painter.setPen(pen)
        painter.setBrush(QColor('black'))
        painter.drawPath(path)
        painter.end()

        self.setMask(bitmap)
Пример #9
0
def autoCropRect(image):
    """Returns a QRect specifying the contents of the QImage.
    
    Edges of the image are trimmed if they have the same color.
    
    """
    # pick the color at most of the corners
    colors = collections.defaultdict(int)
    w, h = image.width(), image.height()
    for x, y in (0, 0), (w - 1, 0), (w - 1, h - 1), (0, h - 1):
        colors[image.pixel(x, y)] += 1
    most = max(colors, key=colors.get)
    # let Qt do the masking work
    mask = image.createMaskFromColor(most)
    return QRegion(QBitmap.fromImage(mask)).boundingRect()
Пример #10
0
def autoCropRect(image):
    """Returns a QRect specifying the contents of the QImage.
    
    Edges of the image are trimmed if they have the same color.
    
    """
    # pick the color at most of the corners
    colors = collections.defaultdict(int)
    w, h = image.width(), image.height()
    for x, y in (0, 0), (w - 1, 0), (w - 1, h - 1), (0, h - 1):
        colors[image.pixel(x, y)] += 1
    most = max(colors, key=colors.get)
    # let Qt do the masking work
    mask = image.createMaskFromColor(most)
    return QRegion(QBitmap.fromImage(mask)).boundingRect()
Пример #11
0
    def __updateMask(self):
        opt = QStyleOption()
        opt.init(self)
        rect = opt.rect

        size = rect.size()
        mask = QBitmap(size)

        p = QPainter(mask)
        p.setRenderHint(QPainter.Antialiasing)
        p.setBrush(Qt.black)
        p.setPen(Qt.NoPen)
        p.drawRoundedRect(rect, self.__radius, self.__radius)
        p.end()

        self.setMask(mask)
Пример #12
0
 def __onResize(self, event):
     self.__pmap.scaled(self.size())
     if self.__show_mask_preview:
         self.setMask(QBitmap(self.__pmap.createHeuristicMask().scaled(self.size())))
Пример #13
0
class CommandDialog(QtGui.QDialog):
    def __init__(self):
        super(CommandDialog, self).__init__()

        self.setFocusPolicy(Qt.TabFocus)

        self.mask = None
        self.p = None

        self.setWindowFlags(QtCore.Qt.FramelessWindowHint)

        self.textEdit = QtGui.QComboBox(self)
        # self.textEdit.addItem("")
        self.textEdit.setMinimumWidth(500)
        self.textEdit.setStyleSheet(
            """
            QComboBox {
                 border:2px groove gray;
                 border-radius:10px;
                 padding:2px 4px;
             }
             QComboBox::drop-down {
                border:0px;
                left:100px;
             }
             """)
        self.textEdit.setAutoCompletion(True)
        self.connect(self.textEdit, SIGNAL('editTextChanged(QString)'),
                     self.text_change)

        layout = QtGui.QVBoxLayout()
        layout.addWidget(self.textEdit)
        self.setLayout(layout)

    def text_change(self, value):
        if State.currentHotKey == 'command' and value == 'C':
            self.textEdit.setEditText(value.rstrip('C'))

    def mask_round_corner(self):
        self.mask = QBitmap(self.size())
        self.mask.clear()
        self.p = QPainter(self.mask)
        self.p.fillRect(self.rect(), Qt.white)
        self.p.setBrush(Qt.black)
        self.p.drawRoundedRect(0, 0, self.width() - 1,
                               self.height() - 1, 20, 20)
        self.setMask(self.mask)

    def resizeEvent(self, event):
        self.mask_round_corner()

    def keyPressEvent(self, event):
        logging.debug('Q key id %s ', event.key())

        if event.key() == 16777216:
            self.hide()

        if event.key() == 16777220 or event.key() == 16777221:
            commnd = self.textEdit.currentText()
            logging.info('command %s', command)

            self.textEdit.setEditText('')

            if command == 'proxy':
                from commands import proxy

                proxy.execute()