|
|
|
@ -32,6 +32,8 @@ class WorldRegionsWidget(QScrollArea):
|
|
|
|
|
region_label_collection = RegionLabelCollection |
|
|
|
|
|
|
|
|
|
action_open_world_file = QAction |
|
|
|
|
action_save_world_file = QAction |
|
|
|
|
|
|
|
|
|
world_regions_image = QImage |
|
|
|
|
world_regions_image_raw_data = np.array |
|
|
|
|
|
|
|
|
@ -40,6 +42,7 @@ class WorldRegionsWidget(QScrollArea):
|
|
|
|
|
cursor_add_region = QCursor |
|
|
|
|
cursor_remove_region = QCursor |
|
|
|
|
cursor_hover_region = QCursor |
|
|
|
|
cursor_plot_region = QCursor |
|
|
|
|
|
|
|
|
|
def __init__(self, zoom_factor=1.0, min_zoom_factor=0.5, max_zoom_factor=24.0, region_size=48): |
|
|
|
|
super().__init__() |
|
|
|
@ -78,6 +81,14 @@ class WorldRegionsWidget(QScrollArea):
|
|
|
|
|
self.action_open_world_file = open_world_file |
|
|
|
|
self.addAction(self.action_open_world_file) |
|
|
|
|
|
|
|
|
|
save_world_file = QAction() |
|
|
|
|
save_world_file.setShortcut( |
|
|
|
|
QKeySequence(Qt.ControlModifier | Qt.Key_S) |
|
|
|
|
) |
|
|
|
|
save_world_file.triggered.connect(self.save_world_file_dialogue) |
|
|
|
|
self.action_save_world_file = save_world_file |
|
|
|
|
self.addAction(self.action_save_world_file) |
|
|
|
|
|
|
|
|
|
def init_cursors(self): |
|
|
|
|
self.root_dir = os.path.dirname(os.path.abspath(__file__)) |
|
|
|
|
|
|
|
|
@ -93,6 +104,9 @@ class WorldRegionsWidget(QScrollArea):
|
|
|
|
|
self.cursor_remove_region = QCursor(QPixmap( |
|
|
|
|
os.path.join(self.root_dir, 'cursors/remove_region.png') |
|
|
|
|
).scaled(cursor_size, Qt.KeepAspectRatio), -1, -1) |
|
|
|
|
self.cursor_plot_region = QCursor(QPixmap( |
|
|
|
|
os.path.join(self.root_dir, 'cursors/plot_region.png') |
|
|
|
|
).scaled(cursor_size, Qt.KeepAspectRatio), -1, -1) |
|
|
|
|
|
|
|
|
|
self.setCursor(self.cursor_hover_region) |
|
|
|
|
|
|
|
|
@ -160,6 +174,16 @@ class WorldRegionsWidget(QScrollArea):
|
|
|
|
|
self.setCursor(self.cursor_remove_region) |
|
|
|
|
else: |
|
|
|
|
self.setCursor(self.cursor_add_region) |
|
|
|
|
elif modifiers == Qt.ShiftModifier or (event is not None and event.key() == 16777248): |
|
|
|
|
try: |
|
|
|
|
currently_hovered_region_is_loaded = self.currently_hovered_region.is_region |
|
|
|
|
except AttributeError: |
|
|
|
|
currently_hovered_region_is_loaded = None |
|
|
|
|
|
|
|
|
|
if currently_hovered_region_is_loaded: |
|
|
|
|
self.setCursor(self.cursor_plot_region) |
|
|
|
|
else: |
|
|
|
|
self.setCursor(self.cursor_hover_region) |
|
|
|
|
else: |
|
|
|
|
self.setCursor(self.cursor_hover_region) |
|
|
|
|
|
|
|
|
@ -167,6 +191,9 @@ class WorldRegionsWidget(QScrollArea):
|
|
|
|
|
def mousePressEvent(self, event): |
|
|
|
|
if event.button() == Qt.LeftButton: |
|
|
|
|
self.trigger_cursor_change() |
|
|
|
|
modifiers = QApplication.keyboardModifiers() |
|
|
|
|
if modifiers == Qt.ShiftModifier and self.currently_hovered_region.is_region: |
|
|
|
|
pass |
|
|
|
|
|
|
|
|
|
if event.button() == Qt.RightButton: |
|
|
|
|
self.drag_in_progress = True |
|
|
|
@ -212,7 +239,7 @@ class WorldRegionsWidget(QScrollArea):
|
|
|
|
|
# super().wheelEvent(event) |
|
|
|
|
|
|
|
|
|
def keyPressEvent(self, event): |
|
|
|
|
if event.key() in (16777249, 16777250): |
|
|
|
|
if event.key() in (16777249, 16777250, 16777248): |
|
|
|
|
self.trigger_cursor_change(event) |
|
|
|
|
|
|
|
|
|
super().keyPressEvent(event) |
|
|
|
@ -239,9 +266,18 @@ class WorldRegionsWidget(QScrollArea):
|
|
|
|
|
|
|
|
|
|
self.world_regions_image_raw_data = raw_data_array |
|
|
|
|
|
|
|
|
|
map_image = QImage(raw_data_array, length, length, QImage.Format_Grayscale16) |
|
|
|
|
self.world_regions_image = map_image |
|
|
|
|
|
|
|
|
|
self.region_label_collection.update_label_collection_with_loaded_image( |
|
|
|
|
map_image, offset=offset |
|
|
|
|
self.region_label_collection.update_label_collection_with_raw_map_data( |
|
|
|
|
raw_data_array, length, offset=offset |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
def save_world_file_dialogue(self): |
|
|
|
|
options = QFileDialog.Options() |
|
|
|
|
file_name, _ = QFileDialog.getSaveFileName( |
|
|
|
|
self, caption='QFileDialog.getSaveFileName()', filter='RAW files (*.raw)', options=options |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
if file_name: |
|
|
|
|
with open(file_name, 'w+b') as raw_file: |
|
|
|
|
raw_file.write( |
|
|
|
|
bytearray(self.world_regions_image_raw_data) |
|
|
|
|
) |
|
|
|
|