diff --git a/controllers/main_controller.py b/controllers/main_controller.py index d18a612..bc82411 100644 --- a/controllers/main_controller.py +++ b/controllers/main_controller.py @@ -3,6 +3,8 @@ from core.database import DatabaseManager from core.media import MediaRepository from ui.widgets.color_list_widget import ColorListWidget from ui.widgets.thumbnail_list_widget import ThumbnailListWidget +from ui.widgets.split_view_widget import SplitView +from PySide6.QtWidgets import QPushButton class MainController: @@ -15,7 +17,10 @@ class MainController: self.view = view self.color_list: ColorListWidget = view.color_list_widget self.thumbnail_list: ThumbnailListWidget = view.thumbnail_widget + self.split_view: SplitView = view.preview_widget + self.photo_button: QPushButton = view.photo_button + self.photo_button.clicked.connect(self.take_photo) self.color_list.colorSelected.connect(self.on_color_selected) self.color_list.editColor.connect(self.on_edit_color) @@ -49,5 +54,10 @@ class MainController: media = self.db.get_media(media_id) if media: print(f"Wybrano miniaturę o ID: {media_id}, ścieżka: {media['media_path']}") + self.split_view.set_reference_image(media['media_path']) else: print(f"Nie znaleziono mediów o ID: {media_id}") + + def take_photo(self): + print("Robienie zdjęcia...") + self.split_view.toglle_live_view() diff --git a/ui/main_window.py b/ui/main_window.py index 04bf1a9..e8a8464 100644 --- a/ui/main_window.py +++ b/ui/main_window.py @@ -9,6 +9,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 +from ui.widgets.split_view_widget import SplitView class MainWindow(QMainWindow): def __init__(self): @@ -23,10 +24,8 @@ class MainWindow(QMainWindow): main_layout = QHBoxLayout(central_widget) self.setCentralWidget(central_widget) - self.preview_widget = QSplitter(Qt.Orientation.Vertical) - self.preview_widget.addWidget(PlaceholderWidget("Camera View", "#750466")) - self.preview_widget.addWidget(PlaceholderWidget("Image View", "#007981")) - + self.preview_widget = SplitView() + self.thumbnail_widget = ThumbnailListWidget() self.thumbnail_widget.setFixedWidth(200) @@ -39,23 +38,24 @@ class MainWindow(QMainWindow): control_layout = QVBoxLayout(self.control_widget) control_layout.setContentsMargins(0, 0, 0, 0) + histogram_view = PlaceholderWidget("Histogram View", "#FF5733") histogram_view.setFixedHeight(200) - control_layout.addWidget(histogram_view) self.color_list_widget = ColorListWidget(self.control_widget) - control_layout.addWidget(self.color_list_widget) - record_button = QPushButton("Nagraj Wideo") - record_button.setMinimumHeight(40) - record_button.setStyleSheet("font-size: 12pt;") - control_layout.addWidget(record_button) + self.record_button = QPushButton("Nagraj Wideo") + self.record_button.setMinimumHeight(40) + self.record_button.setStyleSheet("font-size: 12pt;") - photo_button = QPushButton("Zrób zdjęcie") - photo_button.setMinimumHeight(40) - photo_button.setStyleSheet("font-size: 12pt;") - control_layout.addWidget(photo_button) + self.photo_button = QPushButton("Zrób zdjęcie") + self.photo_button.setMinimumHeight(40) + self.photo_button.setStyleSheet("font-size: 12pt;") + control_layout.addWidget(histogram_view) + control_layout.addWidget(self.color_list_widget) + control_layout.addWidget(self.record_button) + control_layout.addWidget(self.photo_button) diff --git a/ui/widgets/split_view_widget.py b/ui/widgets/split_view_widget.py new file mode 100644 index 0000000..d5f9a87 --- /dev/null +++ b/ui/widgets/split_view_widget.py @@ -0,0 +1,164 @@ +from PySide6.QtWidgets import QGraphicsView, QGraphicsScene, QGraphicsPixmapItem, QApplication, QMainWindow, QWidget, QVBoxLayout, QSplitter, QStackedWidget, QPushButton, QLabel +from PySide6.QtGui import QPixmap, QWheelEvent, QPainter, QBrush, QColor +from PySide6.QtCore import Qt +import sys +from ui.widgets.placeholder_widget import PlaceholderWidget + +class ZoomableImageView(QGraphicsView): + def __init__(self, parent=None): + super().__init__(parent) + + # Scena i element obrazu + self._scene = QGraphicsScene(self) + self.setScene(self._scene) + self._scene.setBackgroundBrush(QBrush(QColor(20, 20, 20))) # ciemne tło + + self._pixmap_item = QGraphicsPixmapItem() + self._scene.addItem(self._pixmap_item) + + # Ustawienia widoku + self.setDragMode(QGraphicsView.DragMode.ScrollHandDrag) # przesuwanie myszą + self.setRenderHint(QPainter.RenderHint.Antialiasing) + self.setRenderHint(QPainter.RenderHint.SmoothPixmapTransform) + + # Wyłączenie suwaków + self.setHorizontalScrollBarPolicy(Qt.ScrollBarPolicy.ScrollBarAlwaysOff) + self.setVerticalScrollBarPolicy(Qt.ScrollBarPolicy.ScrollBarAlwaysOff) + # Parametry zoomu + self._zoom_factor = 1.25 + self._current_scale = 1.0 + + def set_image(self, pixmap: QPixmap): + # pixmap = QPixmap(image_path) + self._pixmap_item.setPixmap(pixmap) + self._scene.setSceneRect(pixmap.rect()) + # self.reset_transform() + + def reset_transform(self): + """Resetuje skalowanie i ustawia 1:1""" + self._current_scale = 1.0 + self.setTransform(self.transform().fromScale(1, 1)) + + def wheelEvent(self, event: QWheelEvent): + """Zoom kółkiem myszy""" + if event.modifiers() & Qt.KeyboardModifier.ControlModifier: # zoom tylko z CTRL + if event.angleDelta().y() > 0: + zoom = self._zoom_factor + else: + zoom = 1 / self._zoom_factor + + self._current_scale *= zoom + self.scale(zoom, zoom) + else: + return + super().wheelEvent(event) # normalne przewijanie + +class CameraPlaceholder(QWidget): + def __init__(self, parent=None): + super().__init__(parent) + + self.setAutoFillBackground(True) + self.setStyleSheet("background-color: #141414;") + + layout = QVBoxLayout(self) + layout.setSpacing(20) + + self.camera_start_btn = QPushButton("Start Camera") + self.camera_start_btn.setFixedSize(200, 50) + style_sheet = """ + QPushButton { + /* --- Styl podstawowy --- */ + background-color: transparent; + border: 2px solid #CECECE; /* Grubość, styl i kolor obramowania */ + border-radius: 25px; /* Kluczowa właściwość do zaokrąglenia rogów! */ + color: #CECECE; + padding: 10px 20px; /* Wewnętrzny margines */ + font-size: 16px; + } + + QPushButton:hover { + /* --- Styl po najechaniu myszką --- */ + color: #F0F0F0; + border: 2px solid #F0F0F0; + } + + QPushButton:pressed { + /* --- Styl po naciśnięciu --- */ + background-color: #e0e0e0; /* Ciemniejsze tło w momencie kliknięcia */ + border: 2px solid #e0e0e0; /* Zmiana koloru ramki dla sygnalizacji akcji */ + } + """ + self.camera_start_btn.setStyleSheet(style_sheet) + + self.info_label = QLabel("Kliknij, aby uruchomić kamerę") + self.info_label.setStyleSheet("background-color: transparent; color: #CECECE; font-size: 18px;") + self.info_label.setAlignment(Qt.AlignmentFlag.AlignCenter) + + layout.addStretch() + layout.addWidget(self.camera_start_btn, alignment=Qt.AlignmentFlag.AlignCenter) + layout.addWidget(self.info_label) + layout.addStretch() + self.setLayout(layout) + + def set_info_text(self, text: str): + self.info_label.setText(text) + +class SplitView(QSplitter): + def __init__(self, parent=None): + super().__init__(parent) + print("Inicjalizacja SplitView2") + self.setOrientation(Qt.Orientation.Vertical) + + self.widget_start = CameraPlaceholder() + self.widget_live = ZoomableImageView() + # self.widget_live = PlaceholderWidget("Camera View", "#750466") + self.widget_ref = ZoomableImageView() + # self.widget_ref = PlaceholderWidget("Image View", "#007981") + + self.stack = QStackedWidget() + self.stack.addWidget(self.widget_start) + self.stack.addWidget(self.widget_live) + self.stack.setCurrentWidget(self.widget_start) + + self.addWidget(self.stack) + self.addWidget(self.widget_ref) + + self.setSizes([self.height(), 0]) + + pixmap = QPixmap("media/empty_guitar_h.jpg") + # pixmap.fill(Qt.GlobalColor.lightGray) + self.widget_live.set_image(pixmap) + + def toggle_orientation(self): + if self.orientation() == Qt.Orientation.Vertical: + self.setOrientation(Qt.Orientation.Horizontal) + self.setSizes([self.width()//2, self.width()//2]) + else: + self.setOrientation(Qt.Orientation.Vertical) + self.setSizes([self.height()//2, self.height()//2]) + + # def set_live_image(self, path_image: str): + # """Ustawienie obrazu na żywo""" + # pixmap = QPixmap(path_image) + # self.widget_live.set_image(pixmap) + + def set_live_image(self, pixmap: QPixmap): + """Ustawienie obrazu na żywo""" + self.widget_live.set_image(pixmap) + if self.stack.currentWidget() != self.widget_live: + self.stack.setCurrentWidget(self.widget_live) + + def set_reference_image(self, path_image: str): + """Ustawienie obrazu referencyjnego""" + pixmap = QPixmap(path_image) + self.widget_ref.set_image(pixmap) + + def toglle_live_view(self): + """Przełączanie widoku na żywo""" + if self.stack.currentWidget() == self.widget_start: + self.stack.setCurrentWidget(self.widget_live) + else: + self.stack.setCurrentWidget(self.widget_start) + + +