Snapshot/SnapshotRegionGrabber.py

branch
Py2 comp.
changeset 3060
5883ce99ee12
parent 3058
0a02c433f52d
parent 3039
8dd0165d805d
child 3145
a9de05d4a22f
equal deleted inserted replaced
3058:0a02c433f52d 3060:5883ce99ee12
195 r.height() > 100: 195 r.height() > 100:
196 # center, unsuitable for small selections 196 # center, unsuitable for small selections
197 boundingRect.moveCenter(r.center()) 197 boundingRect.moveCenter(r.center())
198 textRect.moveCenter(r.center()) 198 textRect.moveCenter(r.center())
199 elif r.y() - 3 > textRect.height() and \ 199 elif r.y() - 3 > textRect.height() and \
200 r.x() + textRect.width() < self.rect().width(): 200 r.x() + textRect.width() < self.rect().width():
201 # on top, left aligned 201 # on top, left aligned
202 boundingRect.moveBottomLeft(QPoint(r.x(), r.y() - 3)) 202 boundingRect.moveBottomLeft(QPoint(r.x(), r.y() - 3))
203 textRect.moveBottomLeft(QPoint(r.x() + 2, r.y() - 3)) 203 textRect.moveBottomLeft(QPoint(r.x() + 2, r.y() - 3))
204 elif r.x() - 3 > textRect.width(): 204 elif r.x() - 3 > textRect.width():
205 # left, top aligned 205 # left, top aligned
206 boundingRect.moveTopRight(QPoint(r.x() - 3, r.y())) 206 boundingRect.moveTopRight(QPoint(r.x() - 3, r.y()))
207 textRect.moveTopRight(QPoint(r.x() - 5, r.y())) 207 textRect.moveTopRight(QPoint(r.x() - 5, r.y()))
208 elif r.bottom() + 3 + textRect.height() < self.rect().bottom() and \ 208 elif r.bottom() + 3 + textRect.height() < self.rect().bottom() and \
209 r.right() > textRect.width(): 209 r.right() > textRect.width():
210 # at bottom, right aligned 210 # at bottom, right aligned
211 boundingRect.moveTopRight(QPoint(r.right(), r.bottom() + 3)) 211 boundingRect.moveTopRight(QPoint(r.right(), r.bottom() + 3))
212 textRect.moveTopRight(QPoint(r.right() - 2, r.bottom() + 3)) 212 textRect.moveTopRight(QPoint(r.right() - 2, r.bottom() + 3))
213 elif r.right() + textRect.width() + 3 < self.rect().width(): 213 elif r.right() + textRect.width() + 3 < self.rect().width():
214 # right, bottom aligned 214 # right, bottom aligned
218 # If the above didn't catch it, you are running on a very 218 # If the above didn't catch it, you are running on a very
219 # tiny screen... 219 # tiny screen...
220 drawRect(painter, boundingRect, textColor, textBackgroundColor) 220 drawRect(painter, boundingRect, textColor, textBackgroundColor)
221 painter.drawText(textRect, Qt.AlignHCenter, txt) 221 painter.drawText(textRect, Qt.AlignHCenter, txt)
222 222
223 if (r.height() > self.__handleSize * 2 and \ 223 if (r.height() > self.__handleSize * 2 and
224 r.width() > self.__handleSize * 2) or \ 224 r.width() > self.__handleSize * 2) or \
225 not self.__mouseDown: 225 not self.__mouseDown:
226 self.__updateHandles() 226 self.__updateHandles()
227 painter.setPen(Qt.NoPen) 227 painter.setPen(Qt.NoPen)
228 painter.setBrush(handleColor) 228 painter.setBrush(handleColor)
297 # moving the whole selection 297 # moving the whole selection
298 r = self.rect().normalized() 298 r = self.rect().normalized()
299 s = self.__selectionBeforeDrag.normalized() 299 s = self.__selectionBeforeDrag.normalized()
300 p = s.topLeft() + evt.pos() - self.__dragStartPoint 300 p = s.topLeft() + evt.pos() - self.__dragStartPoint
301 r.setBottomRight( 301 r.setBottomRight(
302 r.bottomRight() - QPoint(s.width(), s.height()) + 302 r.bottomRight() - QPoint(s.width(), s.height()) +
303 QPoint(1, 1)) 303 QPoint(1, 1))
304 if not r.isNull() and r.isValid(): 304 if not r.isNull() and r.isValid():
305 self.__selection.moveTo(self.__limitPointToRect(p, r)) 305 self.__selection.moveTo(self.__limitPointToRect(p, r))
306 else: 306 else:
307 # dragging a handle 307 # dragging a handle
460 Private method to normalize the given selection. 460 Private method to normalize the given selection.
461 461
462 @param sel selection to be normalized (QRect) 462 @param sel selection to be normalized (QRect)
463 @return normalized selection (QRect) 463 @return normalized selection (QRect)
464 """ 464 """
465 r = QRect(sel) 465 rect = QRect(sel)
466 if r.width() <= 0: 466 if rect.width() <= 0:
467 l = r.left() 467 left = rect.left()
468 w = r.width() 468 width = rect.width()
469 r.setLeft(l + w - 1) 469 rect.setLeft(left + width - 1)
470 r.setRight(l) 470 rect.setRight(left)
471 if r.height() <= 0: 471 if rect.height() <= 0:
472 t = r.top() 472 top = rect.top()
473 h = r.height() 473 height = rect.height()
474 r.setTop(t + h - 1) 474 rect.setTop(top + height - 1)
475 r.setBottom(t) 475 rect.setBottom(top)
476 return r 476 return rect
477 477
478 def __grabRect(self): 478 def __grabRect(self):
479 """ 479 """
480 Private method to grab the selected rectangle (i.e. do the snapshot). 480 Private method to grab the selected rectangle (i.e. do the snapshot).
481 """ 481 """
493 493
494 pt = QPainter() 494 pt = QPainter()
495 pt.begin(pixmap2) 495 pt.begin(pixmap2)
496 if pt.paintEngine().hasFeature(QPaintEngine.PorterDuff): 496 if pt.paintEngine().hasFeature(QPaintEngine.PorterDuff):
497 pt.setRenderHints( 497 pt.setRenderHints(
498 QPainter.Antialiasing | \ 498 QPainter.Antialiasing |
499 QPainter.HighQualityAntialiasing | \ 499 QPainter.HighQualityAntialiasing |
500 QPainter.SmoothPixmapTransform, 500 QPainter.SmoothPixmapTransform,
501 True) 501 True)
502 pt.setBrush(Qt.black) 502 pt.setBrush(Qt.black)
503 pt.setPen(QPen(QBrush(Qt.black), 0.5)) 503 pt.setPen(QPen(QBrush(Qt.black), 0.5))
504 pt.drawEllipse(translatedEll.boundingRect()) 504 pt.drawEllipse(translatedEll.boundingRect())

eric ide

mercurial