add list of thumbnails
This commit is contained in:
@@ -8,6 +8,7 @@ from PySide6.QtGui import QPalette, QColor
|
||||
|
||||
from ui.widgets.placeholder_widget import PlaceholderWidget
|
||||
from ui.widgets.color_list_widget import ColorListWidget
|
||||
from ui.widgets.thumbnail_list_widget import ThumbnailListWidget
|
||||
|
||||
class MainWindow(QMainWindow):
|
||||
def __init__(self):
|
||||
@@ -26,13 +27,11 @@ class MainWindow(QMainWindow):
|
||||
self.preview_widget.addWidget(PlaceholderWidget("Camera View", "#750466"))
|
||||
self.preview_widget.addWidget(PlaceholderWidget("Image View", "#007981"))
|
||||
|
||||
self.thumbnail_widget = PlaceholderWidget("Thumbnails", "#AAAAAA")
|
||||
self.thumbnail_widget = ThumbnailListWidget()
|
||||
self.thumbnail_widget.setFixedWidth(200)
|
||||
|
||||
# self.control_widget = PlaceholderWidget("Controls", "#CCCCCC")
|
||||
self.control_widget = QWidget()
|
||||
self.control_widget.setFixedWidth(300)
|
||||
# self.control_widget.setContentsMargins(0, 0, 0, 0)
|
||||
|
||||
main_layout.addWidget(self.preview_widget)
|
||||
main_layout.addWidget(self.thumbnail_widget)
|
||||
@@ -45,20 +44,13 @@ class MainWindow(QMainWindow):
|
||||
control_layout.addWidget(histogram_view)
|
||||
|
||||
self.color_list_widget = ColorListWidget(self.control_widget)
|
||||
|
||||
# color_list_widget.set_colors_from_db([
|
||||
# {"name": "Red", "color": "#FF0000"},
|
||||
# {"name": "Green", "color": "#00FF00"},
|
||||
# {"name": "Blue", "color": "#0000FF"},
|
||||
# {"name": "Yellow", "color": "#FFFF00"},
|
||||
# {"name": "Cyan", "color": "#00FFFF"},
|
||||
# {"name": "Magenta", "color": "#FF00FF"},
|
||||
# ])
|
||||
|
||||
control_layout.addWidget(self.color_list_widget)
|
||||
|
||||
self.thumbnail_widget.add_thumbnail("media/red/bolton_01092025.jpg", "model 1")
|
||||
self.thumbnail_widget.add_thumbnail("media/red/bolton_01092025.jpg", "model 2")
|
||||
self.thumbnail_widget.add_thumbnail("media/red/bolton_01092025.jpg", "model 3")
|
||||
self.thumbnail_widget.add_thumbnail("empty", "model 4")
|
||||
|
||||
# control_layout.addStretch()
|
||||
record_button = QPushButton("Nagraj Wideo")
|
||||
record_button.setMinimumHeight(40)
|
||||
record_button.setStyleSheet("font-size: 12pt;")
|
||||
|
||||
83
ui/widgets/thumbnail_list_widget.py
Normal file
83
ui/widgets/thumbnail_list_widget.py
Normal file
@@ -0,0 +1,83 @@
|
||||
from PySide6.QtWidgets import (
|
||||
QApplication, QWidget, QVBoxLayout, QListWidget, QListWidgetItem,
|
||||
QLabel, QHBoxLayout
|
||||
)
|
||||
from PySide6.QtGui import QPixmap, QIcon
|
||||
from PySide6.QtCore import Qt, QSize
|
||||
import sys
|
||||
|
||||
def make_thumbnail(image_path: str, size: QSize) -> QPixmap:
|
||||
pixmap = QPixmap(image_path)
|
||||
|
||||
if pixmap.isNull():
|
||||
pixmap = QPixmap("media/empty_guitar_h.jpg") # pusta miniatura, gdy nie uda się wczytać
|
||||
|
||||
# dopasuj tak, aby całkowicie wypełnić prostokąt (cover)
|
||||
scaled = pixmap.scaled(
|
||||
size,
|
||||
Qt.AspectRatioMode.KeepAspectRatioByExpanding,
|
||||
Qt.TransformationMode.SmoothTransformation
|
||||
)
|
||||
|
||||
# wytnij nadmiar, żeby miało dokładnie żądany rozmiar
|
||||
x = (scaled.width() - size.width()) // 2
|
||||
y = (scaled.height() - size.height()) // 2
|
||||
cropped = scaled.copy(x, y, size.width(), size.height())
|
||||
|
||||
return cropped
|
||||
|
||||
|
||||
class ThumbnailItemWidget(QWidget):
|
||||
def __init__(self, image_path: str, text: str = "", parent=None):
|
||||
super().__init__(parent)
|
||||
|
||||
layout = QHBoxLayout(self)
|
||||
layout.setContentsMargins(6, 6, 6, 6)
|
||||
layout.setAlignment(Qt.AlignmentFlag.AlignCenter)
|
||||
|
||||
# miniatura
|
||||
pixmap = make_thumbnail(image_path, QSize(180, 160))
|
||||
self.icon_label = QLabel()
|
||||
self.icon_label.setPixmap(pixmap)
|
||||
|
||||
# podpis
|
||||
self.text_label = QLabel(text)
|
||||
self.text_label.setStyleSheet("font-size: 12pt;")
|
||||
self.text_label.setAlignment(Qt.AlignmentFlag.AlignCenter)
|
||||
|
||||
# ustawiamy pionowy layout dla ikony i tekstu
|
||||
vbox = QVBoxLayout()
|
||||
vbox.setContentsMargins(0, 0, 0, 0)
|
||||
vbox.setAlignment(Qt.AlignmentFlag.AlignCenter)
|
||||
vbox.addWidget(self.icon_label)
|
||||
vbox.addWidget(self.text_label)
|
||||
|
||||
layout.addLayout(vbox)
|
||||
|
||||
|
||||
class ThumbnailListWidget(QWidget):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
layout = QVBoxLayout(self)
|
||||
layout.setContentsMargins(0, 0, 0, 0)
|
||||
|
||||
self.list_widget = QListWidget()
|
||||
# self.list_widget.setIconSize(QSize(100, 100))
|
||||
self.list_widget.setSpacing(2)
|
||||
|
||||
layout.addWidget(self.list_widget)
|
||||
|
||||
self.list_widget.itemPressed.connect(self.on_item_pressed)
|
||||
|
||||
def add_thumbnail(self, image_path: str, text: str):
|
||||
item = QListWidgetItem()
|
||||
item.setSizeHint(QSize(192, 192)) # rozmiar „wiersza”
|
||||
|
||||
widget = ThumbnailItemWidget(image_path, text)
|
||||
self.list_widget.addItem(item)
|
||||
self.list_widget.setItemWidget(item, widget)
|
||||
|
||||
def on_item_pressed(self, item: QListWidgetItem):
|
||||
row = self.list_widget.row(item)
|
||||
print(f"Kliknięto miniaturę w wierszu: {row}")
|
||||
|
||||
Reference in New Issue
Block a user