@@ -122,6 +122,8 @@ class ColorMapManager(QW.QDialog):
122122 Args:
123123 parent: parent QWidget. Defaults to None.
124124 active_colormap: name of the active colormap.
125+ invert: initial state of the 'Invert colormap' checkbox.
126+ Defaults to False.
125127
126128 .. note::
127129
@@ -134,12 +136,13 @@ class ColorMapManager(QW.QDialog):
134136 that the colormap cannot be removed.
135137 """
136138
137- SIG_APPLY_COLORMAP = QC .Signal (str )
139+ SIG_APPLY_COLORMAP = QC .Signal (str , bool )
138140
139141 def __init__ (
140142 self ,
141143 parent : QW .QWidget | None = None ,
142144 active_colormap : str | None = None ,
145+ invert : bool = False ,
143146 ) -> None :
144147 super ().__init__ (parent )
145148 self .setWindowIcon (get_icon ("cmap_edit.png" ))
@@ -148,6 +151,7 @@ def __init__(
148151 self .active_cmap_name = default_colormap = active_colormap
149152
150153 self .__returned_colormap : EditableColormap | None = None
154+ self .__returned_invert : bool = invert
151155
152156 if default_colormap is None or not cmap_exists (default_colormap , ALL_COLORMAPS ):
153157 default_colormap = next (iter (ALL_COLORMAPS ))
@@ -171,6 +175,10 @@ def __init__(
171175 self ._remove_btn .setEnabled (is_custom_cmap )
172176 self ._remove_btn .clicked .connect (self .remove_colormap )
173177
178+ self ._invert_checkbox = QW .QCheckBox (_ ("Invert colormap" ))
179+ self ._invert_checkbox .setChecked (invert )
180+ self ._invert_checkbox .toggled .connect (self ._on_invert_toggled )
181+
174182 select_gbox = QW .QGroupBox (_ ("Select or create a colormap" ))
175183 select_label = QW .QLabel (_ ("Colormap presets:" ))
176184 select_gbox_layout = QW .QHBoxLayout ()
@@ -179,6 +187,8 @@ def __init__(
179187 select_gbox_layout .addSpacing (10 )
180188 select_gbox_layout .addWidget (add_btn )
181189 select_gbox_layout .addWidget (self ._remove_btn )
190+ select_gbox_layout .addSpacing (10 )
191+ select_gbox_layout .addWidget (self ._invert_checkbox )
182192 select_gbox .setLayout (select_gbox_layout )
183193
184194 # Edit the selected colormap
@@ -192,6 +202,13 @@ def __init__(
192202 current_cmap = None
193203 self .colormap_editor = ColorMapEditor (self , colormap = current_cmap )
194204
205+ # Apply initial invert state to the colormap preview
206+ if invert :
207+ cmap = self .colormap_editor .get_colormap ()
208+ if cmap is not None :
209+ cmap .invert = True
210+ self .colormap_editor .colormap_widget .COLORMAP_CHANGED .emit ()
211+
195212 self ._edit_gbox = QW .QGroupBox (_ ("Edit the selected colormap" ))
196213 edit_gbox_layout = QW .QVBoxLayout ()
197214 edit_gbox_layout .setContentsMargins (0 , 0 , 0 , 0 )
@@ -237,14 +254,33 @@ def button_clicked(self, button: QW.QAbstractButton) -> None:
237254 if not self .current_changes_saved and not self .save_colormap ():
238255 return
239256 self ._apply_btn .setEnabled (False )
240- self .SIG_APPLY_COLORMAP .emit (self .colormap_editor .get_colormap ().name )
257+ self .SIG_APPLY_COLORMAP .emit (
258+ self .colormap_editor .get_colormap ().name ,
259+ self ._invert_checkbox .isChecked (),
260+ )
241261 elif button is self ._save_btn :
242262 self .save_colormap ()
243263 elif self .bbox .buttonRole (button ) == QW .QDialogButtonBox .AcceptRole :
244264 self .accept ()
245265 else :
246266 self .reject ()
247267
268+ def _on_invert_toggled (self , checked : bool ) -> None :
269+ """Callback for the 'Invert colormap' checkbox toggle.
270+
271+ Inversion is a display parameter independent of the colormap definition,
272+ so toggling it only updates the preview without marking the colormap as
273+ having unsaved changes.
274+
275+ Args:
276+ checked: True if the checkbox is checked, False otherwise.
277+ """
278+ self .__returned_invert = checked
279+ cmap = self .colormap_editor .get_colormap ()
280+ if cmap is not None :
281+ cmap .invert = checked
282+ self .colormap_editor .colormap_widget .draw_colormap_image ()
283+
248284 def _changes_not_saved (self ) -> None :
249285 """Callback function to be called when the colormap is modified. Enables the
250286 save button and sets the current_changes_saved attribute to False."""
@@ -270,6 +306,7 @@ def set_colormap(self, index: int) -> None:
270306 index: index of the colormap in the QComboBox.
271307 """
272308 cmap_copy : EditableColormap = deepcopy (self ._cmap_choice .itemData (index ))
309+ cmap_copy .invert = self ._invert_checkbox .isChecked ()
273310 self .colormap_editor .set_colormap (cmap_copy )
274311
275312 is_custom_cmap = cmap_exists (cmap_copy .name , CUSTOM_COLORMAPS )
@@ -287,6 +324,14 @@ def get_colormap(self) -> EditableColormap | None:
287324 """
288325 return self .__returned_colormap
289326
327+ def get_invert (self ) -> bool :
328+ """Return the current state of the 'Invert colormap' checkbox.
329+
330+ Returns:
331+ True if the colormap should be inverted, False otherwise.
332+ """
333+ return self .__returned_invert
334+
290335 def __get_new_colormap_name (self , title : str , name : str ) -> str | None :
291336 """Return a new colormap name that does not already exists in the list of
292337 colormaps.
0 commit comments