本文整理汇总了Python中PyQt5.QtCore.QPoint.setX方法的典型用法代码示例。如果您正苦于以下问题:Python QPoint.setX方法的具体用法?Python QPoint.setX怎么用?Python QPoint.setX使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.QtCore.QPoint
的用法示例。
在下文中一共展示了QPoint.setX方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: dropEvent
# 需要导入模块: from PyQt5.QtCore import QPoint [as 别名]
# 或者: from PyQt5.QtCore.QPoint import setX [as 别名]
def dropEvent(self, event):
if event.mimeData().hasText():
mime = event.mimeData()
pieces = mime.text().split()
position = event.pos()
hotSpot = QPoint()
hotSpotPos = mime.data('application/x-hotspot').split(' ')
if len(hotSpotPos) == 2:
hotSpot.setX(hotSpotPos[0].toInt()[0])
hotSpot.setY(hotSpotPos[1].toInt()[0])
for piece in pieces:
newLabel = DragLabel(piece, self)
newLabel.move(position - hotSpot)
newLabel.show()
position += QPoint(newLabel.width(), 0)
if event.source() in self.children():
event.setDropAction(Qt.MoveAction)
event.accept()
else:
event.acceptProposedAction()
else:
event.ignore()
示例2: draw_item
# 需要导入模块: from PyQt5.QtCore import QPoint [as 别名]
# 或者: from PyQt5.QtCore.QPoint import setX [as 别名]
def draw_item(self, face, painter):
is_draw = True
if self.is_clipping:
is_draw = self.sphere.is_face_visible(face)
if is_draw:
polygon = QPolygon()
for index, point_index in enumerate(face):
p1_x = int(self.sphere.geom.points[face[index-1]][0])
p1_y = int(self.sphere.geom.points[face[index-1]][1])
p1_z = int(self.sphere.geom.points[face[index-1]][2])
p2_x = int(self.sphere.geom.points[point_index][0])
p2_y = int(self.sphere.geom.points[point_index][1])
p2_z = int(self.sphere.geom.points[point_index][2])
if self.sphere.projection_name == "front":
# Фронтальная проекция (вид спереди) -> z = 0
real_p1 = QPoint(p1_x, p1_y)
real_p2 = QPoint(p2_x, p2_y)
elif self.sphere.projection_name == "horizontal":
# Горизонтальная проекция (вид сверху) -> y = 0
real_p1 = QPoint(p1_x, p1_z)
real_p2 = QPoint(p2_x, p2_z)
elif self.sphere.projection_name == "profile":
# Профильная проекция (вид сбоку) -> x = 0
real_p1 = QPoint(p1_y, p1_z)
real_p2 = QPoint(p2_y, p2_z)
else:
real_p1 = QPoint(p1_x, p1_y)
real_p2 = QPoint(p2_x, p2_y)
# Точки для проволочного рисования
real_p1.setX(self.width()/2 + real_p1.x())
real_p1.setY(self.height()/2 - real_p1.y())
real_p2.setX(self.width()/2 + real_p2.x())
real_p2.setY(self.height()/2 - real_p2.y())
# Полигоны для рисования с цветом
polygon.append(real_p1)
polygon.append(real_p2)
if not self.is_light:
painter.drawLine(real_p1, real_p2)
if self.is_light:
painter.setBrush(self.sphere.get_face_light(face, self.faces_color))
painter.drawPolygon(polygon)
示例3: tryMove
# 需要导入模块: from PyQt5.QtCore import QPoint [as 别名]
# 或者: from PyQt5.QtCore.QPoint import setX [as 别名]
def tryMove(self, oldPos, newPos, directions):
p = QPoint(oldPos)
if directions & 1: #X轴方向
gridX = self.parent().width() / 40
delta = newPos.x() - oldPos.x()
if abs(delta) / gridX > 0.5:
newX = oldPos.x() + delta / abs(delta) * gridX * round(abs(delta) / gridX)
newX = gridX * round(newX / gridX)
p.setX(newX)
if directions & 2:
gridY = self.parent().height() / 30
delta = newPos.y() - oldPos.y()
if abs(delta) / gridY > 0.5:
newY = oldPos.y() + delta / abs(delta) * gridY * round(abs(delta) / gridY)
newY = gridY * round(newY / gridY)
p.setY(newY)
return p
示例4: update_me
# 需要导入模块: from PyQt5.QtCore import QPoint [as 别名]
# 或者: from PyQt5.QtCore.QPoint import setX [as 别名]
def update_me(self):
"""
Triangle types: :. | .: | ˸˙ | ˙˸
Store vertexes as { most left, most rith, third };
those at the top go first
"""
self.vertexes = list()
most_left = QPoint(self.x, self.y)
most_right = QPoint(self.x + self.width, self.y)
third = QPoint(self.x, self.y + self.height)
form = self.mesh.data['form']
if form == 1:
most_left.setY(self.y + self.height)
third.setX(self.x + self.width)
elif form == 0:
most_right.setY(self.y + self.height)
elif form == 3:
third.setX(self.x + self.width)
self.vertexes.append(most_left)
self.vertexes.append(most_right)
self.vertexes.append(third)
示例5: __limitPointToRect
# 需要导入模块: from PyQt5.QtCore import QPoint [as 别名]
# 或者: from PyQt5.QtCore.QPoint import setX [as 别名]
def __limitPointToRect(self, point, rect):
"""
Private method to limit the given point to the given rectangle.
@param point point to be limited (QPoint)
@param rect rectangle the point shall be limited to (QRect)
@return limited point (QPoint)
"""
q = QPoint()
if point.x() < rect.x():
q.setX(rect.x())
elif point.x() < rect.right():
q.setX(point.x())
else:
q.setX(rect.right())
if point.y() < rect.y():
q.setY(rect.y())
elif point.y() < rect.bottom():
q.setY(point.y())
else:
q.setY(rect.bottom())
return q
示例6: paintEvent
# 需要导入模块: from PyQt5.QtCore import QPoint [as 别名]
# 或者: from PyQt5.QtCore.QPoint import setX [as 别名]
def paintEvent(self, event):
painter = QPainter(self)
painter.setPen(self.pen)
painter.setBrush(self.brush)
if self.antialiased:
painter.setRenderHint(QPainter.Antialiasing)
angle_step = 360 / self.n_states
painter.save() #Save_1. Save the state of the system (push matrix)
painter.translate(self.dist_center.x(), self.dist_center.y()) # go to the center of the render area
painter.rotate(-180) #to start painting from the left side of the circle (clockwise)
#center of the circumference where through we are going to paint our states
x = self.dist_radius * math.cos(0)
y = self.dist_radius * math.sin(0)
for h in range(self.n_states):
rot = angle_step * h # each state is equidistant from the others. We paint them in circles
painter.save() #Save_2
painter.rotate(rot) #now our system is pointing to the next state to be drawn
painter.translate(x,y) #now our origin is in the center of the next state to be drawn
#if the state is active, fill it green
if self.machine.getState(h).isActive():
painter.setBrush(self.greenGradientBrush)
painter.drawEllipse(QPoint(0,0), self.state_radius, self.state_radius) #draw the new state
#global position of transformed coordinates (before any transformation, origin at top-left corner)
gx = painter.worldTransform().map(QPoint(0,0)).x()
gy = painter.worldTransform().map(QPoint(0,0)).y()
self.machine.getState(h).setPos(gx, gy) #store the center of the state without any transformation applied
# text transformation. Our origin is still in the center of the current state
painter.save() #Save_3
painter.rotate(180) #making the text go vertical
painter.rotate(-rot) #undoing the rotation made for painting the state. No the text is horizontal
font = painter.font();
font.setPixelSize(self.state_radius*.4);
painter.setFont(font);
rect = QRect(-self.state_radius, -self.state_radius, self.state_radius*2, self.state_radius*2)
painter.drawText(rect, Qt.AlignCenter, self.machine.getState(h).getName());
painter.restore() #Restore_3
#end text transformation
painter.restore() #Restore_2
painter.restore() #Restore_1. Restore the state of the system (pop matrix)
#drawing transitions. Line between states
painter.save() # Save_4
pptv = QTransform() #Define a new transformation. Needed to rotate the system along other axis than Z
pptv.translate(0, self.height()) #We are now at the bottom-left corner of the screen
pptv.rotate(-180, Qt.XAxis) #Rotate along the X-axis so now we are in a typical cartesian system.
painter.setTransform(pptv) #Apply the transformation
states = self.machine.getStates()
for state in states:
transitions = state.getTransitions()
for transition in transitions:
#get the center of the origin and destination states in our current system state
orig = QPoint(state.getPos()[0], state.getPos()[1])
end = QPoint(self.machine.getState(transition.getStateEnd()).getPos()[0], self.machine.getState(transition.getStateEnd()).getPos()[1])
# get those coordinates without transformation
orig2 = QPoint(painter.worldTransform().map(orig))
end2 = QPoint(painter.worldTransform().map(end))
#get the angle between states centers and the horizon
angle = math.atan2(end2.y() - orig2.y(), end2.x() - orig2.x())
#get the coordinates of the starting point of the transition (it starts in the bound of the state, not in the center)
newX = self.state_radius * math.cos(angle) + orig2.x()
newY = self.state_radius * math.sin(angle) + orig2.y()
#now the transition starts at the border, not in the center
orig2.setX(newX)
orig2.setY(newY)
#same for the destination state
angle2 = math.atan2(orig2.y() - end2.y(), orig2.x() - end2.x())
newX2 = self.state_radius * math.cos(angle2) + end2.x()
newY2 = self.state_radius * math.sin(angle2) + end2.y()
end2.setX(newX2)
end2.setY(newY2)
#draw the line between the origin and destination states
painter.drawLine(orig2, end2)
#get the start and the end of the transition untransformed
init = QPoint(painter.worldTransform().map(orig2))
end = QPoint(painter.worldTransform().map(end2))
#store that info
transition.setOrig(init.x(), init.y())
transition.setDest(end.x(), end.y())
transition.setAngle(angle)
painter.restore() #Restore_4
#.........这里部分代码省略.........
示例7: kineticMove
# 需要导入模块: from PyQt5.QtCore import QPoint [as 别名]
# 或者: from PyQt5.QtCore.QPoint import setX [as 别名]
def kineticMove(self, oldx, oldy, newx, newy ):
"""Start a kinetic move from (oldx, oldy) to (newx, newy)"""
if newx == oldx and newy == oldy:
return
speed = QPoint(0,0)
# solve speed*(speed+1)/2 = delta to ensure 1+2+3+...+speed is as close as possible under delta..
speed.setX((sqrt(1+8*abs(newx-oldx))-1)/2)
speed.setY((sqrt(1+8*abs(newy-oldy))-1)/2)
# compute the amount of displacement still needed because we're dealing with integer values.
diff = QPoint(0,0)
diff.setX((speed.x() * (speed.x() + 1) // 2) - abs(newx - oldx))
diff.setY((speed.y() * (speed.y() + 1) // 2) - abs(newy - oldy))
# Since this function is called for exact moves (not free scrolling)
# limit the kinetic time to 2 seconds, which means 100 ticks, 5050 pixels.
if speed.y() > 100:
speed.setY(100)
diff.setY(-abs(newy-oldy) + 5050)
# Although it is less likely to go beyond that limit for horizontal scrolling,
# do it for x as well.
if speed.x() > 100:
speed.setX(100)
diff.setX(-abs(newx-oldx) + 5050)
# move left or right, up or down
if newx > oldx :
speed.setX(-speed.x())
diff.setX(-diff.x())
if newy > oldy :
speed.setY(-speed.y())
diff.setY(-diff.y())
# move immediately by the step that cannot be handled by kinetic scrolling.
# By construction that step is smaller that the initial speed value.
self.fastScrollBy(diff)
self.kineticStart(speed)
示例8: draw_rect_mesh
# 需要导入模块: from PyQt5.QtCore import QPoint [as 别名]
# 或者: from PyQt5.QtCore.QPoint import setX [as 别名]
def draw_rect_mesh(self, canvas, grid_x, grid_y, grid_width, grid_height):
"""
Draw rectangular region of mesh. First divide to squares,
then draw diagonal and transform them to triangles
'grid_*' arguments is numbers of nodes of the mesh
"""
x0 = self.pixel_x(grid_x)
y0 = self.pixel_y(grid_y)
xn = self.pixel_x(grid_x + grid_width)
yn = self.pixel_y(grid_y + grid_height)
# Horizontal & diagonal lines
A = QPoint(x0, y0)
B = QPoint(xn, y0)
canvas.drawLine(A, B) # first line
for j in range(1, grid_height+1):
y = self.pixel_y(grid_y+j)
A.setY(y)
B.setY(y)
canvas.drawLine(A, B)
# Vertical lines
A.setX(x0)
B.setX(x0)
A.setY(y0)
B.setY(yn)
canvas.drawLine(A, B)
for i in range(1, grid_width+1):
x = self.pixel_x(grid_x+i)
A.setX(x)
B.setX(x)
canvas.drawLine(A, B)
# Diagonal lines
A.setX(x0)
A.setY(y0)
B.setX(self.pixel_x(grid_x + 1)) # Diagonal
B.setY(self.pixel_y(grid_y + 1))
for j in range(1, grid_height+1):
for i in range(1, grid_width+1):
canvas.drawLine(A, B)
A.setX(self.pixel_x(grid_x + i))
B.setX(self.pixel_x(grid_x + i + 1))
A.setX(x0)
A.setY(self.pixel_y(grid_y + j))
B.setX(self.pixel_x(grid_x + 1))
B.setY(self.pixel_y(grid_y + j + 1))
示例9: ScreenShot
# 需要导入模块: from PyQt5.QtCore import QPoint [as 别名]
# 或者: from PyQt5.QtCore.QPoint import setX [as 别名]
#.........这里部分代码省略.........
stepSize *= self.stepBigMultipler if (modifier & Qt.ShiftModifier) else 1
stepSize *= self.stepMultiplier if (modifier & Qt.ControlModifier) else 1
#Resize end point height and width (mouseReleaseEvent)
if key == Qt.Key_Left:
self.resize_end_point(-stepSize, 0)
if key == Qt.Key_Right:
self.resize_end_point(stepSize, 0)
if key == Qt.Key_Up:
self.resize_end_point(0, -stepSize)
if key == Qt.Key_Down:
self.resize_end_point(0, stepSize)
##Resize begin point height and width (mousePressEvent)
if key == Qt.Key_A:
self.resize_start_point(-stepSize, 0)
if key == Qt.Key_D:
self.resize_start_point(stepSize, 0)
if key == Qt.Key_W:
self.resize_start_point(0, -stepSize)
if key == Qt.Key_S:
self.resize_start_point(0, stepSize)
#Screenshot Functions/Miscellaneous
if key == Qt.Key_Space:
self.take_screenshot()
if key == Qt.Key_Z:
self.save_screenshot()
if key == Qt.Key_C:
self.change_transparent()
self.clear_screenshot()
if key == Qt.Key_Q:
self.close()
def resize_start_point(self, inc_x, inc_y): #Top left
new_x = self.begin.x() + inc_x
new_y = self.begin.y() + inc_y
if new_x < 0:
new_x = 0
if new_y < 0:
new_y = 0
self.begin.setX(new_x)
self.begin.setY(new_y)
self.screenshot_width = self.end.x() - self.begin.x()
self.screenshot_height = self.end.y() - self.begin.y()
self.update()
def resize_end_point(self, inc_x, inc_y): #Bottom right
new_x = self.end.x() + inc_x
new_y = self.end.y() + inc_y
if new_x > self.maxWidth:
new_x = self.maxWidth
if new_y > self.maxHeight:
new_y = self.maxHeight
self.end.setX(new_x)
self.end.setY(new_y)
self.screenshot_width = self.end.x() - self.begin.x()
self.screenshot_height = self.end.y() - self.begin.y()
self.update()
def clear_screenshot(self):
self.imagePreviewer.hide()
self.pixmap = None
def take_screenshot(self):
screen = app.primaryScreen()
self.hide()
#If not screenshot window is set, the program defaults to taking a screenshot of the entire window
if any(i == None for i in [self.begin.x(), self.begin.y(), self.screenshot_height, self.screenshot_width]):
self.pixmap = screen.grabWindow(MainWindow.id, 0, 0, self.maxWidth, self.maxHeight)
else:
self.pixmap = screen.grabWindow(MainWindow.id, self.begin.x(), self.begin.y()+2*self.y_compensate, self.screenshot_width, self.screenshot_height)
self.imagePreviewer.setPixmap(self.pixmap)
self.imagePreviewer.adjustSize()
self.imagePreviewer.resize(self.imagePreviewer.sizeHint())
self.imagePreviewer.show()
self.activateWindow()
self.done = True
def save_screenshot(self):
if self.done:
filename = QFileDialog.getSaveFileName(self, "Save As", QDir.currentPath(), "PNG Files (*.png)")
if filename:
self.pixmap.save(filename[0], "png")
self.imagePreviewer.hide()
else:
take_screenshot()
save_screenshot()
self.done = False
def change_transparent(self):
self.taking_screenshot = not self.taking_screenshot
if self.taking_screenshot:
self.opacity = 0
self.initUI()
self.update()
else:
self.opacity = 0.3
self.initUI()
self.update()
示例10: Decision
# 需要导入模块: from PyQt5.QtCore import QPoint [as 别名]
# 或者: from PyQt5.QtCore.QPoint import setX [as 别名]
class Decision(VerticalSymbol):
''' SDL DECISION Symbol '''
_unique_followers = ['Comment']
_insertable_followers = ['DecisionAnswer', 'Task', 'ProcedureCall',
'Output', 'Decision', 'Label']
_terminal_followers = ['Join', 'State', 'ProcedureStop']
common_name = 'decision'
# Define reserved keywords for the syntax highlighter
blackbold = SDL_BLACKBOLD + ['\\b{}\\b'.format(word)
for word in ('AND', 'OR')]
redbold = SDL_REDBOLD
def __init__(self, parent=None, ast=None):
ast = ast or ogAST.Decision()
self.ast = ast
# Define the point where all branches of the decision can join again
self.connectionPoint = QPoint(ast.width / 2, ast.height + 30)
super(Decision, self).__init__(parent, text=ast.inputString,
x=ast.pos_x or 0, y=ast.pos_y or 0, hyperlink=ast.hyperlink)
self.set_shape(ast.width, ast.height)
self.setBrush(QColor(255, 255, 202))
self.minDistanceToSymbolAbove = 0
self.parser = ogParser
self.text_alignment = Qt.AlignHCenter
if ast.comment:
Comment(parent=self, ast=ast.comment)
@property
def terminal_symbol(self):
'''
Compute dynamically if the item is terminal by checking
if all its branches end with a terminator
'''
for branch in self.branches():
if not branch.last_branch_item.terminal_symbol:
return False
return True
@property
def completion_list(self):
''' Set auto-completion list '''
return chain(variables_autocompletion(self), ('length', 'present'))
def branches(self):
''' Return the list of decision answers (as a generator) '''
return (branch for branch in self.childSymbols()
if isinstance(branch, DecisionAnswer))
def set_shape(self, width, height):
''' Define polygon points to draw the symbol '''
path = QPainterPath()
path.moveTo(width / 2, 0)
path.lineTo(width, height / 2)
path.lineTo(width / 2, height)
path.lineTo(0, height / 2)
path.lineTo(width / 2, 0)
self.setPath(path)
super(Decision, self).set_shape(width, height)
def resize_item(self, rect):
''' On resize event, make sure connection points are updated '''
delta_y = self.boundingRect().height() - rect.height()
super(Decision, self).resize_item(rect)
self.connectionPoint.setX(self.boundingRect().center().x())
self.connectionPoint.setY(self.connectionPoint.y() - delta_y)
self.update_connections()
def update_connections(self):
''' Redefined - update arrows shape below connection point '''
super(Decision, self).update_connections()
for branch in self.branches():
for cnx in branch.last_branch_item.connections():
cnx.reshape()
def updateConnectionPointPosition(self):
''' Compute the joining point of decision branches '''
new_y = 0
new_x = self.boundingRect().width() / 2.0
answers = False
for branch in self.branches():
answers = True
last_cnx = None
last = branch.last_branch_item
try:
# To compute the branch length, we must keep only the symbols,
# so we must remove the last connection (if any)
last_cnx, = (c for c in last.childItems() if
isinstance(c, Connection) and not
isinstance(c.child, (Comment, HorizontalSymbol)))
# Don't set parent item to None to avoid Qt segfault
last_cnx.setParentItem(self)
except ValueError:
pass
branch_len = branch.y() + (
branch.boundingRect() |
branch.childrenBoundingRect()).height()
try:
last_cnx.setParentItem(last)
except AttributeError:
pass
#.........这里部分代码省略.........
示例11: screenToTileCoords
# 需要导入模块: from PyQt5.QtCore import QPoint [as 别名]
# 或者: from PyQt5.QtCore.QPoint import setX [as 别名]
def screenToTileCoords(self, x, y):
p = RenderParams(self.map())
if (p.staggerX):
if p.staggerEven:
x -= p.tileWidth
else:
x -= p.sideOffsetX
else:
if p.staggerEven:
y -= p.tileHeight
else:
y -= p.sideOffsetY
# Start with the coordinates of a grid-aligned tile
lenx = p.tileWidth + p.sideLengthX
leny = p.tileHeight + p.sideLengthY
referencePoint = QPoint(math.floor(x / lenx), math.floor(y / leny))
# Relative x and y position on the base square of the grid-aligned tile
rel = QVector2D(x - referencePoint.x() * lenx, y - referencePoint.y() * leny)
# Adjust the reference point to the correct tile coordinates
if p.staggerX:
staggerAxisIndex = referencePoint.x()
else:
staggerAxisIndex = referencePoint.y()
staggerAxisIndex *= 2
if (p.staggerEven):
staggerAxisIndex += 1
if p.staggerX:
referencePoint.setX(staggerAxisIndex)
else:
referencePoint.setY(staggerAxisIndex)
# Determine the nearest hexagon tile by the distance to the center
centers = [0, 0, 0, 0]
if (p.staggerX):
left = int(p.sideLengthX / 2)
centerX = left + p.columnWidth
centerY = int(p.tileHeight / 2)
centers[0] = QVector2D(left, centerY)
centers[1] = QVector2D(centerX, centerY - p.rowHeight)
centers[2] = QVector2D(centerX, centerY + p.rowHeight)
centers[3] = QVector2D(centerX + p.columnWidth, centerY)
else:
top = int(p.sideLengthY / 2)
centerX = int(p.tileWidth / 2)
centerY = top + p.rowHeight
centers[0] = QVector2D(centerX, top)
centers[1] = QVector2D(centerX - p.columnWidth, centerY)
centers[2] = QVector2D(centerX + p.columnWidth, centerY)
centers[3] = QVector2D(centerX, centerY + p.rowHeight)
nearest = 0
minDist = 1.7976931348623157e+308
for i in range(4):
center = centers[i]
dc = (center - rel).lengthSquared()
if (dc < minDist):
minDist = dc
nearest = i
offsetsStaggerX = [
QPoint( 0, 0),
QPoint(+1, -1),
QPoint(+1, 0),
QPoint(+2, 0),
]
offsetsStaggerY = [
QPoint( 0, 0),
QPoint(-1, +1),
QPoint( 0, +1),
QPoint( 0, +2),
]
if p.staggerX:
offsets = offsetsStaggerX
else:
offsets = offsetsStaggerY
return QPointF(referencePoint + offsets[nearest])
示例12: drawTileLayer
# 需要导入模块: from PyQt5.QtCore import QPoint [as 别名]
# 或者: from PyQt5.QtCore.QPoint import setX [as 别名]
def drawTileLayer(self, painter, layer, exposed = QRectF()):
p = RenderParams(self.map())
rect = exposed.toAlignedRect()
if (rect.isNull()):
rect = self.boundingRect(layer.bounds())
drawMargins = layer.drawMargins()
drawMargins.setBottom(drawMargins.bottom() + p.tileHeight)
drawMargins.setRight(drawMargins.right() - p.tileWidth)
rect.adjust(-drawMargins.right(),
-drawMargins.bottom(),
drawMargins.left(),
drawMargins.top())
# Determine the tile and pixel coordinates to start at
startTile = self.screenToTileCoords_(rect.topLeft()).toPoint()
# Compensate for the layer position
startTile -= layer.position()
startPos = self.tileToScreenCoords_(startTile + layer.position())
## Determine in which half of the tile the top-left corner of the area we
# need to draw is. If we're in the upper half, we need to start one row
# up due to those tiles being visible as well. How we go up one row
# depends on whether we're in the left or right half of the tile.
##
inUpperHalf = rect.y() - startPos.y() < p.sideOffsetY
inLeftHalf = rect.x() - startPos.x() < p.sideOffsetX
if (inUpperHalf):
startTile.setY(startTile.y() - 1)
if (inLeftHalf):
startTile.setX(startTile.x() - 1)
renderer = CellRenderer(painter)
if (p.staggerX):
startTile.setX(max(-1, startTile.x()))
startTile.setY(max(-1, startTile.y()))
startPos = self.tileToScreenCoords_(startTile + layer.position()).toPoint()
startPos.setY(startPos.y() + p.tileHeight)
staggeredRow = p.doStaggerX(startTile.x() + layer.x())
while(startPos.y() < rect.bottom() and startTile.y() < layer.height()):
rowTile = QPoint(startTile)
rowPos = QPoint(startPos)
while(rowPos.x() < rect.right() and rowTile.x() < layer.width()):
if (layer.contains(rowTile)):
cell = layer.cellAt(rowTile)
if (not cell.isEmpty()):
renderer.render(cell, rowPos, QSizeF(0, 0), CellRenderer.BottomLeft)
rowPos.setX(rowPos.x() + p.tileWidth + p.sideLengthX)
rowTile.setX(rowTile.x() + 2)
if (staggeredRow):
startTile.setX(startTile.x() - 1)
startTile.setY(startTile.y() + 1)
startPos.setX(startPos.x() - p.columnWidth)
staggeredRow = False
else:
startTile.setX(startTile.x() + 1)
startPos.setX(startPos.x() + p.columnWidth)
staggeredRow = True
startPos.setY(startPos.y() + p.rowHeight)
else:
startTile.setX(max(0, startTile.x()))
startTile.setY(max(0, startTile.y()))
startPos = self.tileToScreenCoords_(startTile + layer.position()).toPoint()
startPos.setY(startPos.y() + p.tileHeight)
# Odd row shifting is applied in the rendering loop, so un-apply it here
if (p.doStaggerY(startTile.y() + layer.y())):
startPos.setX(startPos.x() - p.columnWidth)
while(startPos.y() < rect.bottom() and startTile.y() < layer.height()):
rowTile = QPoint(startTile)
rowPos = QPoint(startPos)
if (p.doStaggerY(startTile.y() + layer.y())):
rowPos.setX(rowPos.x() + p.columnWidth)
while(rowPos.x() < rect.right() and rowTile.x() < layer.width()):
cell = layer.cellAt(rowTile)
if (not cell.isEmpty()):
renderer.render(cell, rowPos, QSizeF(0, 0), CellRenderer.BottomLeft)
rowPos.setX(rowPos.x() + p.tileWidth + p.sideLengthX)
rowTile.setX(rowTile.x() + 1)
startPos.setY(startPos.y() + p.rowHeight)
startTile.setY(startTile.y() + 1)
示例13: drawGrid
# 需要导入模块: from PyQt5.QtCore import QPoint [as 别名]
# 或者: from PyQt5.QtCore.QPoint import setX [as 别名]
def drawGrid(self, painter, exposed, gridColor):
rect = exposed.toAlignedRect()
if (rect.isNull()):
return
p = RenderParams(self.map())
# Determine the tile and pixel coordinates to start at
startTile = self.screenToTileCoords_(rect.topLeft()).toPoint()
startPos = self.tileToScreenCoords_(startTile).toPoint()
## Determine in which half of the tile the top-left corner of the area we
# need to draw is. If we're in the upper half, we need to start one row
# up due to those tiles being visible as well. How we go up one row
# depends on whether we're in the left or right half of the tile.
##
inUpperHalf = rect.y() - startPos.y() < p.sideOffsetY
inLeftHalf = rect.x() - startPos.x() < p.sideOffsetX
if (inUpperHalf):
startTile.setY(startTile.y() - 1)
if (inLeftHalf):
startTile.setX(startTile.x() - 1)
startTile.setX(max(0, startTile.x()))
startTile.setY(max(0, startTile.y()))
startPos = self.tileToScreenCoords_(startTile).toPoint()
oct = [
QPoint(0, p.tileHeight - p.sideOffsetY),
QPoint(0, p.sideOffsetY),
QPoint(p.sideOffsetX, 0),
QPoint(p.tileWidth - p.sideOffsetX, 0),
QPoint(p.tileWidth, p.sideOffsetY),
QPoint(p.tileWidth, p.tileHeight - p.sideOffsetY),
QPoint(p.tileWidth - p.sideOffsetX, p.tileHeight),
QPoint(p.sideOffsetX, p.tileHeight)]
lines = QVector()
#lines.reserve(8)
gridColor.setAlpha(128)
gridPen = QPen(gridColor)
gridPen.setCosmetic(True)
_x = QVector()
_x.append(2)
_x.append(2)
gridPen.setDashPattern(_x)
painter.setPen(gridPen)
if (p.staggerX):
# Odd row shifting is applied in the rendering loop, so un-apply it here
if (p.doStaggerX(startTile.x())):
startPos.setY(startPos.y() - p.rowHeight)
while(startPos.x() <= rect.right() and startTile.x() < self.map().width()):
rowTile = QPoint(startTile)
rowPos = QPoint(startPos)
if (p.doStaggerX(startTile.x())):
rowPos.setY(rowPos.y() + p.rowHeight)
while(rowPos.y() <= rect.bottom() and rowTile.y() < self.map().height()):
lines.append(QLineF(rowPos + oct[1], rowPos + oct[2]))
lines.append(QLineF(rowPos + oct[2], rowPos + oct[3]))
lines.append(QLineF(rowPos + oct[3], rowPos + oct[4]))
isStaggered = p.doStaggerX(startTile.x())
lastRow = rowTile.y() == self.map().height() - 1
lastColumn = rowTile.x() == self.map().width() - 1
bottomLeft = rowTile.x() == 0 or (lastRow and isStaggered)
bottomRight = lastColumn or (lastRow and isStaggered)
if (bottomRight):
lines.append(QLineF(rowPos + oct[5], rowPos + oct[6]))
if (lastRow):
lines.append(QLineF(rowPos + oct[6], rowPos + oct[7]))
if (bottomLeft):
lines.append(QLineF(rowPos + oct[7], rowPos + oct[0]))
painter.drawLines(lines)
lines.resize(0)
rowPos.setY(rowPos.y() + p.tileHeight + p.sideLengthY)
rowTile.setY(rowTile.y() + 1)
startPos.setX(startPos.x() + p.columnWidth)
startTile.setX(startTile.x() + 1)
else:
# Odd row shifting is applied in the rendering loop, so un-apply it here
if (p.doStaggerY(startTile.y())):
startPos.setX(startPos.x() - p.columnWidth)
while(startPos.y() <= rect.bottom() and startTile.y() < self.map().height()):
rowTile = QPoint(startTile)
rowPos = QPoint(startPos)
if (p.doStaggerY(startTile.y())):
rowPos.setX(rowPos.x() + p.columnWidth)
while(rowPos.x() <= rect.right() and rowTile.x() < self.map().width()):
lines.append(QLineF(rowPos + oct[0], rowPos + oct[1]))
lines.append(QLineF(rowPos + oct[1], rowPos + oct[2]))
lines.append(QLineF(rowPos + oct[3], rowPos + oct[4]))
isStaggered = p.doStaggerY(startTile.y())
lastRow = rowTile.y() == self.map().height() - 1
lastColumn = rowTile.x() == self.map().width() - 1
bottomLeft = lastRow or (rowTile.x() == 0 and not isStaggered)
bottomRight = lastRow or (lastColumn and isStaggered)
if (lastColumn):
lines.append(QLineF(rowPos + oct[4], rowPos + oct[5]))
if (bottomRight):
lines.append(QLineF(rowPos + oct[5], rowPos + oct[6]))
if (bottomLeft):
lines.append(QLineF(rowPos + oct[7], rowPos + oct[0]))
painter.drawLines(lines)
lines.resize(0)
rowPos.setX(rowPos.x() + p.tileWidth + p.sideLengthX)
#.........这里部分代码省略.........
示例14: drawTileLayer
# 需要导入模块: from PyQt5.QtCore import QPoint [as 别名]
# 或者: from PyQt5.QtCore.QPoint import setX [as 别名]
def drawTileLayer(self, painter, layer, exposed = QRectF()):
tileWidth = self.map().tileWidth()
tileHeight = self.map().tileHeight()
if (tileWidth <= 0 or tileHeight <= 1):
return
rect = exposed.toAlignedRect()
if (rect.isNull()):
rect = self.boundingRect(layer.bounds())
drawMargins = layer.drawMargins()
drawMargins.setTop(drawMargins.top() - tileHeight)
drawMargins.setRight(drawMargins.right() - tileWidth)
rect.adjust(-drawMargins.right(),
-drawMargins.bottom(),
drawMargins.left(),
drawMargins.top())
# Determine the tile and pixel coordinates to start at
tilePos = self.screenToTileCoords(rect.x(), rect.y())
rowItr = QPoint( math.floor(tilePos.x()),
math.floor(tilePos.y()))
startPos = self.tileToScreenCoords_(rowItr)
startPos.setX(startPos.x() - tileWidth / 2)
startPos.setY(startPos.y() + tileHeight)
# Compensate for the layer position
rowItr -= QPoint(layer.x(), layer.y())
## Determine in which half of the tile the top-left corner of the area we
# need to draw is. If we're in the upper half, we need to start one row
# up due to those tiles being visible as well. How we go up one row
# depends on whether we're in the left or right half of the tile.
##
inUpperHalf = startPos.y() - rect.y() > tileHeight / 2
inLeftHalf = rect.x() - startPos.x() < tileWidth / 2
if (inUpperHalf):
if (inLeftHalf):
rowItr.setX(rowItr.x() - 1)
startPos.setX(startPos.x() - tileWidth / 2)
else:
rowItr.setY(rowItr.y() - 1)
startPos.setX(startPos.x() + tileWidth / 2)
startPos.setY(startPos.y() - tileHeight / 2)
# Determine whether the current row is shifted half a tile to the right
shifted = inUpperHalf ^ inLeftHalf
renderer = CellRenderer(painter)
y = startPos.y() * 2
while(y - tileHeight*2 < rect.bottom()*2):
columnItr = QPoint(rowItr)
x = startPos.x()
while(x < rect.right()):
if (layer.contains(columnItr)):
cell = layer.cellAt(columnItr)
if (not cell.isEmpty()):
renderer.render(cell, QPointF(x, y/2), QSizeF(0, 0),
CellRenderer.BottomLeft)
# Advance to the next column
columnItr.setX(columnItr.x() + 1)
columnItr.setY(columnItr.y() - 1)
x += tileWidth
# Advance to the next row
if (not shifted):
rowItr.setX(rowItr.x() + 1)
startPos.setX(startPos.x() + tileWidth / 2)
shifted = True
else:
rowItr.setY(rowItr.y() + 1)
startPos.setX(startPos.x() - tileWidth / 2)
shifted = False
y += tileHeight
示例15: paintEvent
# 需要导入模块: from PyQt5.QtCore import QPoint [as 别名]
# 或者: from PyQt5.QtCore.QPoint import setX [as 别名]
def paintEvent(self, event):
rect = QRect(10, 20, 80, 60)
path = QPainterPath()
path.moveTo(20, 80)
path.lineTo(20, 30)
path.cubicTo(80, 0, 50, 50, 80, 80)
startAngle = 30 * 16
arcLength = 120 * 16
painter = QPainter(self)
painter.setPen(self.pen)
painter.setBrush(self.brush)
if self.antialiased:
painter.setRenderHint(QPainter.Antialiasing)
angle_step = 360 / self.n_states
painter.save()
painter.translate(self.dist_center.x(), self.dist_center.y())
#painter.drawRect(- self.dist_radius, - self.dist_radius, self.dist_radius *2,self.dist_radius*2)
#painter.drawEllipse(QPoint(0, 0), self.dist_radius , self.dist_radius)
painter.rotate(-180) #to start painting from the left side of the circle
x = self.dist_radius * math.cos(0)
y = self.dist_radius * math.sin(0)
for h in range(self.n_states):
rot = angle_step * h
painter.save()
painter.rotate(rot)
painter.translate(x,y)
if self.machine.getState(h).isActive():
painter.setBrush(self.greenGradientBrush)
painter.drawEllipse(QPoint(0,0), self.state_radius, self.state_radius)
#global position of transformed coordinates
gx = painter.worldTransform().map(QPoint(0,0)).x()
gy = painter.worldTransform().map(QPoint(0,0)).y()
self.machine.getState(h).setPos(gx, gy)
# text transformation
painter.save()
painter.rotate(180)
painter.rotate(-rot)
font = painter.font();
font.setPixelSize(self.state_radius*.4);
painter.setFont(font);
rect = QRect(-self.state_radius, -self.state_radius, self.state_radius*2, self.state_radius*2)
painter.drawText(rect, Qt.AlignCenter, self.machine.getState(h).getName());
painter.restore()
#end text transformation
painter.restore()
painter.restore()
#drawing transitions.
painter.save()
pptv = QTransform()
pptv.translate(0, self.height())
pptv.rotate(-180, Qt.XAxis)
painter.setTransform(pptv)
s = self.machine.getStates()
for j in s:
t = j.getTransitions()
for i in t:
#get the points in the canvas
init = QPoint(j.getPos()[0], j.getPos()[1])
end = QPoint(self.machine.getState(i.getStateEnd()).getPos()[0], self.machine.getState(i.getStateEnd()).getPos()[1])
# get the transformed ponts
init2 = QPoint(painter.worldTransform().map(init))
end2 = QPoint(painter.worldTransform().map(end))
#get the angle between states centers
angle = math.atan2(end2.y() - init2.y(), end2.x() - init2.x())
#get the coordinates of the starting point of the transition (it starts in the bound, not in the center)
newX = self.state_radius * math.cos(angle) + init2.x()
newY = self.state_radius * math.sin(angle) + init2.y()
init2.setX(newX)
init2.setY(newY)
#same for the end of the transition
angle2 = math.atan2(init2.y() - end2.y(), init2.x() - end2.x())
newX2 = self.state_radius * math.cos(angle2) + end2.x()
newY2 = self.state_radius * math.sin(angle2) + end2.y()
end2.setX(newX2)
end2.setY(newY2)
#painter.drawLine(init, end)
painter.drawLine(init2, end2)
init = QPoint(painter.worldTransform().map(init2))
end = QPoint(painter.worldTransform().map(end2))
i.setOrig(init.x(), init.y())
#.........这里部分代码省略.........