Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
target_pos : QPoint
The global target position of the parent anchor.
offset : QPoint
The offset to apply to the parent anchor.
Returns
-------
result : tuple
A 4-tuple of (QRect, ArrowEdge, int, int) which represent the
adjusted rect, the new arrow edge, and x and y deltas to apply
to the arrow position.
"""
ax = ay = 0
rect = QRect(rect)
desktop = QApplication.desktop()
if arrow_edge == ArrowEdge.Left:
bottom_edge = bottom_screen_edge(desktop, rect)
if rect.bottom() > bottom_edge:
ay += rect.bottom() - bottom_edge
rect.moveBottom(bottom_edge)
top_edge = top_screen_edge(desktop, rect)
if rect.top() < top_edge:
ay -= top_edge - rect.top()
rect.moveTop(top_edge)
left_edge = left_screen_edge(desktop, rect)
if rect.left() < left_edge:
rect.moveLeft(left_edge)
right_edge = right_screen_edge(desktop, rect)
if rect.right() > right_edge:
painter : QPainter
The painter to use for drawing.
"""
# hack to get the current stylesheet foreground color
hint = QStyle.SH_GroupBox_TextLabelColor
fg = self.style().styleHint(hint, opt, self)
# mask signed to unsigned which 'fromRgba' requires
painter.setPen(QColor.fromRgba(0xffffffff & fg))
size = self.size()
im_size = bmp.size()
x = size.width() / 2 - im_size.width() / 2
y = size.height() / 2 - im_size.height() / 2
source = QRect(QPoint(0, 0), im_size)
dest = QRect(QPoint(x, y), im_size)
painter.drawPixmap(dest, bmp, source)
Returns
-------
result : QRect
The geometry rect for the title bar, expressed in frame
coordinates. An invalid rect is returned if title bar
should not be active.
"""
cmargins = self.layout().contentsMargins()
if self.isMaximized():
return QRect(0, 0, self.width(), cmargins.top())
rmargins = self.ResizeMargins
width = self.width() - (cmargins.left() + cmargins.right())
height = cmargins.top() - rmargins.top()
return QRect(cmargins.left(), rmargins.top(), width, height)
end_pos = QPoint(0, 0)
size = QSize(pane.width(), hint.height())
elif position == QDockBar.East:
start_pos = QPoint(pane.width(), 0)
end_pos = QPoint(pane.width() - hint.width(), 0)
size = QSize(hint.width(), pane.height())
elif position == QDockBar.South:
start_pos = QPoint(0, pane.height())
end_pos = QPoint(0, pane.height() - hint.height())
size = QSize(pane.width(), hint.height())
else:
start_pos = QPoint(-hint.width(), 0)
end_pos = QPoint(0, 0)
size = QSize(hint.width(), pane.height())
start_geo = QRect(start_pos, size)
end_geo = QRect(end_pos, size)
return start_geo, end_geo
def init_floating_frame(self, frame, layout):
""" Initialize a floating frame.
This initializer sets up the geometry, maximized state, and
linked state for the floating frame.
Parameters
----------
frame : QDockFrame
The floating dock frame of interest.
layout : ItemLayout or AreaLayout
The layout describing the floating state of the frame.
"""
rect = QRect(*layout.geometry)
if rect.isValid():
rect = ensure_on_screen(rect)
frame.setGeometry(rect)
frame.show()
if layout.linked:
frame.setLinked(True)
if layout.maximized:
frame.showMaximized()
def _band_geometry(self, widget, guide):
""" Compute the geometry for an overlay rubber band.
Parameters
----------
widget : QWidget
The widget to which the band geometry should be fit.
guide : Guide
The rose guide under the mouse. This determines how the
geometry of the band will be fit to the widget.
"""
Guide = QGuideRose.Guide
if guide == Guide.NoGuide:
return QRect()
# border hits
border_size = self.border_size
rect = widget.contentsRect()
if guide == Guide.BorderNorth:
rect.setHeight(border_size)
elif guide == Guide.BorderEast:
rect.setLeft(rect.right() + 1 - border_size)
elif guide == Guide.BorderSouth:
rect.setTop(rect.bottom() + 1 - border_size)
elif guide == Guide.BorderWest:
rect.setWidth(border_size)
# For the next 4 conditions `widget` will be a QDockArea
elif guide == Guide.BorderExNorth:
bar_rect = widget.dockBarGeometry(QDockBar.North)
if bar_rect.isValid():
empty : bool, optional
Whether the widget represents an empty widget. If this is
True, a single center guide will be shown instead of the
guide rose.
"""
Mode = QGuideRose.Mode
rose = self._rose
target_mode = Mode.AreaCenter if empty else Mode.CompassEx
self._target_rose_mode = target_mode
if rose.mode() != target_mode:
rose.setMode(Mode.NoMode)
self._rose_timer.start(self.rose_delay)
self._band_timer.start(self.band_delay)
origin = widget.mapToGlobal(QPoint(0, 0))
geo = QRect(origin, widget.size())
dirty = rose.geometry() != geo
if dirty:
rose.hide()
rose.setMode(Mode.NoMode)
rose.setGeometry(geo)
guide = rose.guideAt(pos, target_mode)
if dirty or guide != self._last_guide:
self._last_guide = guide
self._target_band_geo = self._band_geometry(widget, guide)
self._band_timer.start(self.band_delay)
rose.setCenterPoint(QPoint(geo.width() / 2, geo.height() / 2))
rose.mouseOver(pos)
rose.show()
start_pos = QPoint(0, -hint.height())
end_pos = QPoint(0, 0)
size = QSize(pane.width(), hint.height())
elif position == QDockBar.East:
start_pos = QPoint(pane.width(), 0)
end_pos = QPoint(pane.width() - hint.width(), 0)
size = QSize(hint.width(), pane.height())
elif position == QDockBar.South:
start_pos = QPoint(0, pane.height())
end_pos = QPoint(0, pane.height() - hint.height())
size = QSize(pane.width(), hint.height())
else:
start_pos = QPoint(-hint.width(), 0)
end_pos = QPoint(0, 0)
size = QSize(hint.width(), pane.height())
start_geo = QRect(start_pos, size)
end_geo = QRect(end_pos, size)
return start_geo, end_geo
start_pos = QPoint(0, -hint.height())
end_pos = QPoint(0, 0)
size = QSize(pane.width(), hint.height())
elif position == QDockBar.East:
start_pos = QPoint(pane.width(), 0)
end_pos = QPoint(pane.width() - hint.width(), 0)
size = QSize(hint.width(), pane.height())
elif position == QDockBar.South:
start_pos = QPoint(0, pane.height())
end_pos = QPoint(0, pane.height() - hint.height())
size = QSize(pane.width(), hint.height())
else:
start_pos = QPoint(-hint.width(), 0)
end_pos = QPoint(0, 0)
size = QSize(hint.width(), pane.height())
start_geo = QRect(start_pos, size)
end_geo = QRect(end_pos, size)
return start_geo, end_geo