Carregar ficheiros para "src/gui"
This commit is contained in:
186
src/gui/map_tools.py
Normal file
186
src/gui/map_tools.py
Normal file
@ -0,0 +1,186 @@
|
||||
from PySide6.QtWidgets import (QWidget, QVBoxLayout, QHBoxLayout, QGridLayout,
|
||||
QPushButton, QLabel, QSpinBox, QDoubleSpinBox,
|
||||
QGroupBox, QMessageBox)
|
||||
from PySide6.QtCore import Signal
|
||||
|
||||
class MapToolsWidget(QWidget):
|
||||
# Signals
|
||||
interpolationRequested = Signal(int, int, int, int) # x1, y1, x2, y2
|
||||
smoothingRequested = Signal(int, int, int, int, float) # x1, y1, x2, y2, factor
|
||||
valueChangeRequested = Signal(int, int, float) # x, y, value
|
||||
percentageChangeRequested = Signal(int, int, int, int, float) # x1, y1, x2, y2, percentage
|
||||
resetRequested = Signal(int, int, int, int) # x1, y1, x2, y2
|
||||
|
||||
def __init__(self, parent=None):
|
||||
super().__init__(parent)
|
||||
self.setup_ui()
|
||||
|
||||
def setup_ui(self):
|
||||
layout = QVBoxLayout(self)
|
||||
|
||||
# Selection group
|
||||
selection_group = QGroupBox("Seleção")
|
||||
selection_layout = QGridLayout()
|
||||
|
||||
# Start position
|
||||
selection_layout.addWidget(QLabel("Início:"), 0, 0)
|
||||
|
||||
self.start_x = QSpinBox()
|
||||
self.start_x.setMinimum(0)
|
||||
selection_layout.addWidget(QLabel("X:"), 0, 1)
|
||||
selection_layout.addWidget(self.start_x, 0, 2)
|
||||
|
||||
self.start_y = QSpinBox()
|
||||
self.start_y.setMinimum(0)
|
||||
selection_layout.addWidget(QLabel("Y:"), 0, 3)
|
||||
selection_layout.addWidget(self.start_y, 0, 4)
|
||||
|
||||
# End position
|
||||
selection_layout.addWidget(QLabel("Fim:"), 1, 0)
|
||||
|
||||
self.end_x = QSpinBox()
|
||||
self.end_x.setMinimum(0)
|
||||
selection_layout.addWidget(QLabel("X:"), 1, 1)
|
||||
selection_layout.addWidget(self.end_x, 1, 2)
|
||||
|
||||
self.end_y = QSpinBox()
|
||||
self.end_y.setMinimum(0)
|
||||
selection_layout.addWidget(QLabel("Y:"), 1, 3)
|
||||
selection_layout.addWidget(self.end_y, 1, 4)
|
||||
|
||||
selection_group.setLayout(selection_layout)
|
||||
layout.addWidget(selection_group)
|
||||
|
||||
# Tools group
|
||||
tools_group = QGroupBox("Ferramentas")
|
||||
tools_layout = QVBoxLayout()
|
||||
|
||||
# Interpolation
|
||||
interpolate_btn = QPushButton("Interpolar")
|
||||
interpolate_btn.clicked.connect(self.interpolate)
|
||||
tools_layout.addWidget(interpolate_btn)
|
||||
|
||||
# Smoothing
|
||||
smooth_layout = QHBoxLayout()
|
||||
smooth_layout.addWidget(QLabel("Fator:"))
|
||||
|
||||
self.smooth_factor = QDoubleSpinBox()
|
||||
self.smooth_factor.setMinimum(0.1)
|
||||
self.smooth_factor.setMaximum(10.0)
|
||||
self.smooth_factor.setValue(1.0)
|
||||
self.smooth_factor.setSingleStep(0.1)
|
||||
smooth_layout.addWidget(self.smooth_factor)
|
||||
|
||||
smooth_btn = QPushButton("Suavizar")
|
||||
smooth_btn.clicked.connect(self.smooth)
|
||||
smooth_layout.addWidget(smooth_btn)
|
||||
|
||||
tools_layout.addLayout(smooth_layout)
|
||||
|
||||
# Value change
|
||||
value_layout = QHBoxLayout()
|
||||
value_layout.addWidget(QLabel("Valor:"))
|
||||
|
||||
self.value_input = QDoubleSpinBox()
|
||||
self.value_input.setMinimum(-999999.0)
|
||||
self.value_input.setMaximum(999999.0)
|
||||
self.value_input.setDecimals(3)
|
||||
value_layout.addWidget(self.value_input)
|
||||
|
||||
value_btn = QPushButton("Definir")
|
||||
value_btn.clicked.connect(self.set_value)
|
||||
value_layout.addWidget(value_btn)
|
||||
|
||||
tools_layout.addLayout(value_layout)
|
||||
|
||||
# Percentage change
|
||||
percentage_layout = QHBoxLayout()
|
||||
percentage_layout.addWidget(QLabel("%:"))
|
||||
|
||||
self.percentage_input = QDoubleSpinBox()
|
||||
self.percentage_input.setMinimum(-100.0)
|
||||
self.percentage_input.setMaximum(100.0)
|
||||
self.percentage_input.setDecimals(1)
|
||||
percentage_layout.addWidget(self.percentage_input)
|
||||
|
||||
percentage_btn = QPushButton("Alterar")
|
||||
percentage_btn.clicked.connect(self.change_percentage)
|
||||
percentage_layout.addWidget(percentage_btn)
|
||||
|
||||
tools_layout.addLayout(percentage_layout)
|
||||
|
||||
# Reset
|
||||
reset_btn = QPushButton("Restaurar Original")
|
||||
reset_btn.clicked.connect(self.reset)
|
||||
tools_layout.addWidget(reset_btn)
|
||||
|
||||
tools_group.setLayout(tools_layout)
|
||||
layout.addWidget(tools_group)
|
||||
|
||||
def set_map_size(self, rows: int, cols: int):
|
||||
"""Update spinbox ranges based on map size"""
|
||||
self.start_x.setMaximum(cols - 1)
|
||||
self.end_x.setMaximum(cols - 1)
|
||||
self.start_y.setMaximum(rows - 1)
|
||||
self.end_y.setMaximum(rows - 1)
|
||||
|
||||
# Set end values to maximum
|
||||
self.end_x.setValue(cols - 1)
|
||||
self.end_y.setValue(rows - 1)
|
||||
|
||||
def get_selection(self):
|
||||
"""Get the current selection coordinates"""
|
||||
return (
|
||||
min(self.start_x.value(), self.end_x.value()),
|
||||
min(self.start_y.value(), self.end_y.value()),
|
||||
max(self.start_x.value(), self.end_x.value()),
|
||||
max(self.start_y.value(), self.end_y.value())
|
||||
)
|
||||
|
||||
def interpolate(self):
|
||||
"""Request interpolation of selected region"""
|
||||
x1, y1, x2, y2 = self.get_selection()
|
||||
self.interpolationRequested.emit(x1, y1, x2, y2)
|
||||
|
||||
def smooth(self):
|
||||
"""Request smoothing of selected region"""
|
||||
x1, y1, x2, y2 = self.get_selection()
|
||||
self.smoothingRequested.emit(x1, y1, x2, y2, self.smooth_factor.value())
|
||||
|
||||
def set_value(self):
|
||||
"""Request value change"""
|
||||
x1, y1, x2, y2 = self.get_selection()
|
||||
if x1 == x2 and y1 == y2:
|
||||
self.valueChangeRequested.emit(x1, y1, self.value_input.value())
|
||||
else:
|
||||
reply = QMessageBox.question(
|
||||
self,
|
||||
"Confirmar Alteração",
|
||||
"Deseja aplicar este valor a toda a região selecionada?",
|
||||
QMessageBox.Yes | QMessageBox.No,
|
||||
QMessageBox.No
|
||||
)
|
||||
|
||||
if reply == QMessageBox.Yes:
|
||||
for x in range(x1, x2 + 1):
|
||||
for y in range(y1, y2 + 1):
|
||||
self.valueChangeRequested.emit(x, y, self.value_input.value())
|
||||
|
||||
def change_percentage(self):
|
||||
"""Request percentage change in region"""
|
||||
x1, y1, x2, y2 = self.get_selection()
|
||||
self.percentageChangeRequested.emit(x1, y1, x2, y2, self.percentage_input.value())
|
||||
|
||||
def reset(self):
|
||||
"""Request reset of selected region"""
|
||||
x1, y1, x2, y2 = self.get_selection()
|
||||
reply = QMessageBox.question(
|
||||
self,
|
||||
"Confirmar Restauração",
|
||||
"Deseja restaurar os valores originais da região selecionada?",
|
||||
QMessageBox.Yes | QMessageBox.No,
|
||||
QMessageBox.No
|
||||
)
|
||||
|
||||
if reply == QMessageBox.Yes:
|
||||
self.resetRequested.emit(x1, y1, x2, y2)
|
||||
Reference in New Issue
Block a user