casa
$Rev:20696$
|
00001 //# QtSingleRegionShape.qo.h: Classes for viewing/editing a single RegionShape. 00002 //# Copyright (C) 2008 00003 //# Associated Universities, Inc. Washington DC, USA. 00004 //# 00005 //# This library is free software; you can redistribute it and/or modify it 00006 //# under the terms of the GNU Library General Public License as published by 00007 //# the Free Software Foundation; either version 2 of the License, or (at your 00008 //# option) any later version. 00009 //# 00010 //# This library is distributed in the hope that it will be useful, but WITHOUT 00011 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 00012 //# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public 00013 //# License for more details. 00014 //# 00015 //# You should have received a copy of the GNU Library General Public License 00016 //# along with this library; if not, write to the Free Software Foundation, 00017 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA. 00018 //# 00019 //# Correspondence concerning AIPS++ should be addressed as follows: 00020 //# Internet email: aips2-request@nrao.edu. 00021 //# Postal address: AIPS++ Project Office 00022 //# National Radio Astronomy Observatory 00023 //# 520 Edgemont Road 00024 //# Charlottesville, VA 22903-2475 USA 00025 //# 00026 //# $Id$ 00027 #ifndef QTSINGLEREGIONSHAPE_QO_H 00028 #define QTSINGLEREGIONSHAPE_QO_H 00029 00030 #include <QWidget> 00031 00032 #include <display/RegionShapes/QtSingleRegionShape.ui.h> 00033 #include <display/RegionShapes/QtEditRegionShape.ui.h> 00034 00035 #include <display/RegionShapes/RegionShape.h> 00036 #include <display/RegionShapes/RSUtils.qo.h> 00037 00038 #include <casa/namespace.h> 00039 00040 namespace casa { 00041 00042 class QtRegionShapeManager; 00043 class QtDisplayPanel; 00044 00045 // Widget for displaying a single region in the list of a QtRegionShapeManager. 00046 // QtSingleRegionShape is the main interaction between the GUI classes and the 00047 // underlying RegionShape. Provides widgets for: 00048 // <ul><li>showing/hiding the region shape</li> 00049 // <li>deleting the region shape</li> 00050 // <li>editing the region shape</li></ul> 00051 // Is also responsible for registering/unregistering the region shape on the 00052 // parent QtDisplayPanel as necessary. 00053 class QtSingleRegionShape : public QWidget, Ui::SingleRegionShape { 00054 Q_OBJECT 00055 00056 friend class QtEditRegionShape; 00057 00058 public: 00059 // Constructor which takes the RegionShape, the manager parent, and the 00060 // optional composite parent. If a composite parent is given, some 00061 // behaviors are different. The constructor will register the RegionShape 00062 // IF compositeParent is NULL. 00063 QtSingleRegionShape(RegionShape* shape, QtRegionShapeManager* parent, 00064 bool reportDrawErrors = false, 00065 RegionShape* compositeParent = NULL); 00066 00067 // Destructor. 00068 ~QtSingleRegionShape(); 00069 00070 // Returns the RegionShape. 00071 RegionShape* shape(); 00072 00073 // Returns this shape's composite parent, or NULL if it has none. 00074 RegionShape* compositeParent(); 00075 00076 // Returns the parent manager. 00077 QtRegionShapeManager* manager(); 00078 00079 // Returns the display panel. 00080 QtDisplayPanel* panel(); 00081 00082 // Sets whether the QtSingleRegionShape should delete its RegionShape 00083 // during destruction or not. 00084 void setShouldDelete(bool shouldDelete = true); 00085 00086 // Refreshes the GUI display. 00087 void refresh(); 00088 00089 // Returns whether this shape is currently showing (registered) on the 00090 // panel or not. 00091 bool isShown() const; 00092 00093 // Show/hide the region shape by registering/unregistering. 00094 void showHide(bool show, bool reportErrors = true); 00095 00096 public slots: 00097 // Show a QtEditRegionShape for editing. 00098 void edit(); 00099 00100 private: 00101 RegionShape* m_shape; // Shape (deletes on deconstruction). 00102 RegionShape* m_compositeParent; // Composite parent, or NULL. 00103 QtRegionShapeManager* m_parent; // Manager. 00104 QtDisplayPanel* m_panel; // Panel. 00105 bool m_shouldDelete; // Should delete shape on destruction. 00106 00107 // Sets up the GUI widgets to display information from the underlying 00108 // region shape. 00109 void setupGUI(); 00110 00111 // Registers the shape on the underlying display panel, if applicable. 00112 void registerShape(); 00113 00114 // Unregisters the shape on the underlying display panel, if applicable. 00115 void unregisterShape(); 00116 00117 private slots: 00118 // Slot for checkbox. 00119 void showHide_(bool show) { showHide(show, true); } 00120 00121 // Deletes this shape by unregistering the region shape and then calling 00122 // the manager's delete method. 00123 void deleteShape(); 00124 }; 00125 00126 00127 // Widget that can be used to input a String, String choice, double, bool, 00128 // String array, or String choice array. 00129 class QtRSOption : public QHBoxLayout { 00130 Q_OBJECT 00131 00132 public: 00133 // Constructor. 00134 QtRSOption(RegionShape::OptionType type, const String& name, 00135 const RSOption& value, const vector<String>& choices); 00136 00137 // Destructor. 00138 ~QtRSOption(); 00139 00140 // Returns entered value. 00141 RSOption value() const; 00142 00143 private: 00144 // Type. 00145 RegionShape::OptionType m_type; 00146 00147 // Value widgets. 00148 // <group> 00149 QLineEdit* m_string; 00150 QComboBox* m_choice; 00151 QDoubleSpinBox* m_double; 00152 QCheckBox* m_bool; 00153 vector<QLineEdit*> m_stringArray; 00154 vector<QComboBox*> m_choiceArray; 00155 vector<String> m_choices; 00156 QToolButton* m_lessButton, *m_moreButton; 00157 // </group> 00158 00159 private slots: 00160 // Add another array widget. 00161 void moreArray(); 00162 00163 // Remove an array widget. 00164 void lessArray(); 00165 }; 00166 00167 00168 // Dialog for editing a single region shape. Can either be used in editing 00169 // or creation mode. Currently there are three sections: 00170 // <ol><li>Coordinate editing. Using the RegionShape's coordinate parameter 00171 // methods, the shape's current coordinates are displayed and can be 00172 // changed (both value and system/unit).</li> 00173 // <li>General options. Line width/color, label text/font, linethrough, 00174 // etc.</li> 00175 // <li>Specific options. Customization specific to each shape 00176 // type.</li></ol> 00177 class QtEditRegionShape : public QWidget, Ui::EditRegionShape { 00178 Q_OBJECT 00179 00180 public: 00181 // Static Members // 00182 00183 // System/Unit constants. 00184 // <group> 00185 static const String SEXAGESIMAL; 00186 static const String UNKNOWN; 00187 // </group> 00188 00189 // Returns available systems for the system chooser. 00190 static vector<String> systems() { 00191 static vector<String> v(6); 00192 v[0] = MDirection::showType(MDirection::B1950); 00193 v[1] = MDirection::showType(MDirection::J2000); 00194 v[2] = MDirection::showType(MDirection::GALACTIC); 00195 v[3] = MDirection::showType(MDirection::SUPERGAL); 00196 v[4] = MDirection::showType(MDirection::ECLIPTIC); 00197 v[5] = RSUtils::PIXEL; 00198 return v; 00199 } 00200 00201 static QComboBox* systemsChooser() { 00202 vector<String> v = systems(); 00203 QComboBox* b = new QComboBox(); 00204 for(unsigned int i = 0; i < v.size(); i++) b->addItem(v[i].c_str()); 00205 return b; 00206 } 00207 00208 00209 // Non-Static Members // 00210 00211 // Editing mode constructor. 00212 QtEditRegionShape(QtSingleRegionShape* shape); 00213 00214 // Creation mode constructor. showPosition, showSize, and applyButtonText 00215 // are only used if coordWidget is not NULL. 00216 QtEditRegionShape(RegionShape* shape, QtRegionShapeManager* manager, 00217 QWidget* coordWidget = NULL, bool showPosition = true, 00218 bool showSize = true, String applyButtonText = ""); 00219 00220 // Destructor. 00221 ~QtEditRegionShape(); 00222 00223 00224 // Methods used for accessing what coordinate system/unit the user has 00225 // chosen. 00226 // <group> 00227 String chosenCoordinateSystem() const; 00228 String chosenPositionUnit() const; 00229 String chosenSizeUnit() const; 00230 // </group> 00231 00232 // Returns true if the entered coordinates are valid, false otherwise. 00233 // Has no effect if a custom coordinate widget is provided. 00234 // Entered coordinates are valid if: 00235 // 1) Non-empty 00236 // 2) For non-sexagesimal, contains a number 00237 // 3) For sexagesimal, contains three numbers separated by :'s. 00238 // If invalid, a reason is given. 00239 bool enteredCoordinatesAreValid(String& reason) const; 00240 00241 public slots: 00242 // Apply changes to the underlying region shape. 00243 void apply(); 00244 00245 signals: 00246 // Only emitted when widget is in creation mode, the apply button is shown, 00247 // and the apply button is clicked. 00248 void applyClicked(); 00249 00250 private: 00251 // Indicates whether the widget is being used in creation or editing mode. 00252 bool m_creation; 00253 00254 // Shape being edited. 00255 QtSingleRegionShape* m_shape; 00256 00257 // Shape being created. 00258 RegionShape* m_cShape; 00259 00260 // Shape manager. 00261 QtRegionShapeManager* m_manager; 00262 00263 // Coordinate editing fields. 00264 vector<QLineEdit*> m_coordEdits; 00265 00266 // Coord types. 00267 vector<RegionShape::CoordinateParameterType> m_coordTypes; 00268 00269 // Last chosen system, position unit, and size unit. 00270 String m_lastSystem, m_lastPosUnit, m_lastSizeUnit; 00271 00272 // Line color widget. 00273 QtColorWidget* m_lineColor; 00274 00275 // Linethrough color widget. 00276 QtColorWidget* m_ltColor; 00277 00278 // Label color widget. 00279 QtColorWidget* m_labelColor; 00280 00281 // Option widgets. 00282 vector<QtRSOption*> m_optWidgets; 00283 00284 // Option types. 00285 vector<RegionShape::OptionType> m_optTypes; 00286 00287 00288 // Initial GUI setup, depending on creation/edit mode. 00289 void init(QWidget* coordWidget = NULL, bool showPosition = true, 00290 bool showSize = true, String applyButtonText = ""); 00291 00292 // Sets up the GUI to reflect values/properties of the underlying region 00293 // shape. 00294 void setupGui(); 00295 00296 // Takes the value entered in the coordinate at the given index of 00297 // m_coordEdits and converts it into a number that can be sent to the 00298 // shape's coordinate parameter methods. 00299 double convertToRS(int index, bool& ok) const; 00300 00301 // Displays the given coordinates with the proper unit. Assumes that the 00302 // world system matches the GUI and the unit matches RegionShape::UNIT. 00303 void displayCoordinates(const vector<double>& coords); 00304 00305 00306 // Private Static Methods // 00307 00308 // Returns available units for the position unit chooser. 00309 static vector<String> positionUnits() { 00310 static vector<String> v(5); 00311 v[0] = RSValue::DEG; v[1] = RSValue::RAD; 00312 v[2] = SEXAGESIMAL; v[3] = RSValue::HMS; 00313 v[4] = RSValue::DMS; 00314 return v; 00315 } 00316 00317 // Returns available units for the size unit chooser. 00318 static vector<String> sizeUnits() { 00319 static vector<String> v(4); 00320 v[0] = RSValue::DEG; v[1] = RSValue::RAD; 00321 v[2] = RSValue::ARCSEC; v[3] = RSValue::ARCMIN; 00322 return v; 00323 } 00324 00325 private slots: 00326 // Update the displayed values to reflect the coordinate system, position 00327 // unit, and size unit chosen by the user. 00328 void coordSystemChanged(); 00329 00330 // Resets the values, system, and units to that of the underlying shape. 00331 void coordReset(); 00332 00333 // Enable/disable the linethrough options. 00334 void linethrough(); 00335 00336 // Call apply() if in edit mode, otherwise emit applyClicked() signal. 00337 void applySlot() { 00338 if(m_creation) emit applyClicked(); 00339 else apply(); 00340 } 00341 }; 00342 00343 } 00344 00345 #endif /* QTSINGLEREGIONSHAPE_QO_H */