# HG changeset patch # User Jordi GutiƩrrez Hermoso # Date 1568136082 14400 # Node ID 9922cde5ad6c8e61ec04b8cea782d744899c9362 # Parent cc5ffdcf7108688086703173699c66df5265b99d MainWindow: refactor to move ROM grid into a dockable window Lots of big changes here. I'm still experimenting with the layout. Also, I've decided to use the Adwaita symbolic icons, in light and dark versions. I'll be using the color.is_dark to decide which version of the icons to use. diff --git a/colors.py b/colors.py --- a/colors.py +++ b/colors.py @@ -84,6 +84,10 @@ return luminance < 0.5 +def widget_icon_path(widget): + return "darkside" if is_dark(widget.palette().color(QG.QPalette.Background)) else "lightside" + + def palette_to_qt(palette): return [ QG.QColor(0, 0, 0, 0).rgba() if color_idx is None diff --git a/img/darkside/widget-close.svg b/img/darkside/widget-close.svg new file mode 100644 --- /dev/null +++ b/img/darkside/widget-close.svg @@ -0,0 +1,72 @@ + + + + + + + + + + + image/svg+xml + + + + + + + + + diff --git a/img/darkside/widget-undock.svg b/img/darkside/widget-undock.svg new file mode 100644 --- /dev/null +++ b/img/darkside/widget-undock.svg @@ -0,0 +1,92 @@ + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + diff --git a/img/darkside/zoom-in.svg b/img/darkside/zoom-in.svg new file mode 100644 --- /dev/null +++ b/img/darkside/zoom-in.svg @@ -0,0 +1,3 @@ + + + diff --git a/img/darkside/zoom-original.svg b/img/darkside/zoom-original.svg new file mode 100644 --- /dev/null +++ b/img/darkside/zoom-original.svg @@ -0,0 +1,3 @@ + + + diff --git a/img/darkside/zoom-out.svg b/img/darkside/zoom-out.svg new file mode 100644 --- /dev/null +++ b/img/darkside/zoom-out.svg @@ -0,0 +1,3 @@ + + + diff --git a/img/lightside/widget-close.svg b/img/lightside/widget-close.svg new file mode 100644 --- /dev/null +++ b/img/lightside/widget-close.svg @@ -0,0 +1,72 @@ + + + + + + + + + + + image/svg+xml + + + + + + + + + diff --git a/img/lightside/widget-undock.svg b/img/lightside/widget-undock.svg new file mode 100644 --- /dev/null +++ b/img/lightside/widget-undock.svg @@ -0,0 +1,104 @@ + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + diff --git a/img/lightside/zoom-in.svg b/img/lightside/zoom-in.svg new file mode 100644 --- /dev/null +++ b/img/lightside/zoom-in.svg @@ -0,0 +1,3 @@ + + + diff --git a/img/lightside/zoom-original.svg b/img/lightside/zoom-original.svg new file mode 100644 --- /dev/null +++ b/img/lightside/zoom-original.svg @@ -0,0 +1,3 @@ + + + diff --git a/img/lightside/zoom-out.svg b/img/lightside/zoom-out.svg new file mode 100644 --- /dev/null +++ b/img/lightside/zoom-out.svg @@ -0,0 +1,3 @@ + + + diff --git a/tilerswift b/tilerswift --- a/tilerswift +++ b/tilerswift @@ -281,7 +281,7 @@ background-repeat: repeat-xy; """ - def __init__(self, rom_canvas): + def __init__(self, rom_canvas=None): super().__init__( numcols=50, numrows=30, @@ -369,6 +369,7 @@ return self.setText(f"{colour_idx:0{2}X}") + bgcolour = NES_PALETTE[colour_idx] qt_colour = QG.QColor(bgcolour) @@ -399,6 +400,21 @@ def __init__(self): super().__init__() + bar = self.menuBar() + file = bar.addMenu("&File") + open_action = file.addAction("&Open") + quit_action = file.addAction("&Quit") + open_action.triggered.connect(self.open_rom) + quit_action.triggered.connect(app.quit) + + self.tile_picker = TilePicker() + + scroll = QW.QScrollArea() + scroll.setWidget(self.tile_picker) + + self.setCentralWidget(scroll) + + def open_rom(self): filename = QW.QFileDialog.getOpenFileName( self, "Open ROM", "", "NES Files (*.nes)" @@ -407,23 +423,8 @@ self.grid_widget = ROMCanvas(rom) - self.tile_picker = TilePicker(self.grid_widget) - - scroll1 = QW.QScrollArea() - scroll1.setWidget(self.grid_widget) - - scroll2 = QW.QScrollArea() - scroll2.setWidget(self.tile_picker) - - horz = QW.QHBoxLayout() - horz.addWidget(scroll1) - horz.addWidget(scroll2) - - scrolls = QW.QWidget() - scrolls.setLayout(horz) - - vert = QW.QVBoxLayout() - vert.addWidget(scrolls) + scroll = QW.QScrollArea() + scroll.setWidget(self.grid_widget) self.colour_picker = ColourPicker() @@ -433,22 +434,40 @@ button.pressed.connect(lambda idx=button_idx: self.pick_palette_colour(idx)) self.palette.addWidget(button) - zoomInButton = QW.QPushButton("+") - zoomInButton.setFixedSize(QC.QSize(24, 24)) - zoomInButton.pressed.connect(self.grid_widget.zoomIn) - self.palette.addWidget(zoomInButton) + for zoom in ["in", "out", "original"]: + zoomButton = QW.QPushButton("") + iconpath = widget_icon_path(zoomButton) + zoomButton.setIcon(QG.QIcon(f"img/{iconpath}/zoom-{zoom}.svg")) + zoomButton.setFixedSize(QC.QSize(48, 48)) + zoomButton.setIconSize(QC.QSize(32, 32)) + zoomButton.setToolTip(f"Zoom {zoom}") + zoomButton.pressed.connect(getattr(self.grid_widget, f"zoom{zoom.capitalize()}")) + self.palette.addWidget(zoomButton) - zoomOutButton = QW.QPushButton("-") - zoomOutButton.setFixedSize(QC.QSize(24, 24)) - zoomOutButton.pressed.connect(self.grid_widget.zoomOut) - self.palette.addWidget(zoomOutButton) + left = QW.QVBoxLayout() + left.addWidget(scroll) + romWidget = QW.QWidget() + romWidget.setLayout(left) + paletteWidget = QW.QWidget() + paletteWidget.setLayout(self.palette) + left.addWidget(paletteWidget) + + left_dock = QW.QDockWidget("ROM tiles", self) + left_dock.setWidget(romWidget) - vert.addLayout(self.palette) + iconpath = widget_icon_path(left_dock) + left_dock.setStyleSheet( + f""" + QDockWidget + {{ + titlebar-close-icon: url(img/{iconpath}/widget-close.svg); + titlebar-normal-icon: url(img/{iconpath}/widget-undock.svg); + }} + """ + ) - main_widget = QW.QWidget() - main_widget.setLayout(vert) - - self.setCentralWidget(main_widget) + self.addDockWidget(QC.Qt.LeftDockWidgetArea, left_dock) + self.tile_picker.rom_canvas = self.grid_widget def pick_palette_colour(self, palette_idx): if self.colour_picker.exec_():