This commit is contained in:
Yuvi9587
2025-07-14 08:19:58 -07:00
parent f41f354737
commit b191776f65
3 changed files with 1435 additions and 1731 deletions

File diff suppressed because it is too large Load Diff

93
src/ui/flow_layout.py Normal file
View File

@@ -0,0 +1,93 @@
# src/ui/flow_layout.py
from PyQt5.QtWidgets import QLayout, QSizePolicy, QStyle
from PyQt5.QtCore import QPoint, QRect, QSize, Qt
class FlowLayout(QLayout):
"""A custom layout that arranges widgets in a flow, wrapping as necessary."""
def __init__(self, parent=None, margin=0, spacing=-1):
super(FlowLayout, self).__init__(parent)
if parent is not None:
self.setContentsMargins(margin, margin, margin, margin)
self.setSpacing(spacing)
self.itemList = []
def __del__(self):
item = self.takeAt(0)
while item:
item = self.takeAt(0)
def addItem(self, item):
self.itemList.append(item)
def count(self):
return len(self.itemList)
def itemAt(self, index):
if 0 <= index < len(self.itemList):
return self.itemList[index]
return None
def takeAt(self, index):
if 0 <= index < len(self.itemList):
return self.itemList.pop(index)
return None
def expandingDirections(self):
return Qt.Orientations(Qt.Orientation(0))
def hasHeightForWidth(self):
return True
def heightForWidth(self, width):
return self._do_layout(QRect(0, 0, width, 0), True)
def setGeometry(self, rect):
super(FlowLayout, self).setGeometry(rect)
self._do_layout(rect, False)
def sizeHint(self):
return self.minimumSize()
def minimumSize(self):
size = QSize()
for item in self.itemList:
size = size.expandedTo(item.minimumSize())
margin, _, _, _ = self.getContentsMargins()
size += QSize(2 * margin, 2 * margin)
return size
def _do_layout(self, rect, test_only):
x = rect.x()
y = rect.y()
line_height = 0
space_x = self.spacing()
space_y = self.spacing()
if self.layout() is not None:
space_x = self.spacing()
space_y = self.spacing()
else:
space_x = self.spacing()
space_y = self.spacing()
for item in self.itemList:
wid = item.widget()
next_x = x + item.sizeHint().width() + space_x
if next_x - space_x > rect.right() and line_height > 0:
x = rect.x()
y = y + line_height + space_y
next_x = x + item.sizeHint().width() + space_x
line_height = 0
if not test_only:
item.setGeometry(QRect(QPoint(x, y), item.sizeHint()))
x = next_x
line_height = max(line_height, item.sizeHint().height())
return y + line_height - rect.y()

File diff suppressed because it is too large Load Diff