casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
QtNewRegionShape.qo.h
Go to the documentation of this file.
00001 //# QtNewRegionShape.qo.h: Widgets for creating a new region shape(s).
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 QTNEWREGIONSHAPE_QO_H
00028 #define QTNEWREGIONSHAPE_QO_H
00029 
00030 #include <QDialog>
00031 #include <QStackedLayout>
00032 #include <QListWidget>
00033 #include <QRadioButton>
00034 #include <QLabel>
00035 
00036 #include <display/RegionShapes/QtNewRegionShape.ui.h>
00037 #include <display/RegionShapes/RegionShapes.h>
00038 
00039 #include <casa/namespace.h>
00040 
00041 namespace casa {
00042 
00043 class QtRegionShapeManager;
00044 class QtEditRegionShape;
00045 
00046 // Dialog for creating a new region shape.  For now basically a wrapper with
00047 // a shape chooser around a QtEditRegionShape widget.  For more complex shapes
00048 // (polygon, composite) this will have to be changed.
00049 class QtNewRegionShape : public QWidget, Ui::NewRegionShape {
00050     Q_OBJECT
00051     
00052 public:
00053     // Static Members //
00054     
00055     // Returns creation widgets.
00056     static vector<pair<String, RegionShape*> >
00057     creationShapes(bool includeComposite = true) {
00058         vector<pair<String, RegionShape*> > v(includeComposite ? 9 : 8);        
00059         for(unsigned int i = 0; i < v.size(); i++)
00060             v[i] = pair<String,RegionShape*>(creationName(i),creationShape(i));        
00061         return v;
00062     }
00063     
00064     
00065     // Non-Static Members //
00066     
00067     // Constructor that takes parent.
00068     QtNewRegionShape(QtRegionShapeManager* manager,
00069                      bool includeComposite = true, bool deleteOnClose = true);
00070     
00071     // Destructor.
00072     ~QtNewRegionShape();
00073     
00074     // Shows/hides the close button.
00075     void showCloseButton(bool show = true);
00076     
00077 signals:
00078     // Emitted whenever the user creates a shape.  After this signal is
00079     // emitted the newly created shape is replaced in the widget with a
00080     // blank one.
00081     void shapeCreated(RegionShape* createdShape);
00082     
00083 private:
00084     QtRegionShapeManager* m_manager; // Parent
00085     vector<RegionShape*> m_shapes;   // Shapes
00086     QStackedLayout* m_widgets;       // Edit widgets
00087     
00088     static RegionShape* creationShape(int i) {
00089         if(i < 0)       return NULL;
00090         else if(i == 0) return new RSEllipse(0,0,0,0);
00091         else if(i == 1) return new RSCircle(0,0,0);
00092         else if(i == 2) return new RSRectangle(0,0,0,0);
00093         else if(i == 3)return new RSPolygon(Vector<double>(),Vector<double>());
00094         else if(i == 4) return new RSLine(0,0,0,0,7);
00095         else if(i == 5) return new RSVector(0,0,0,0,7);
00096         else if(i == 6) return new RSMarker(0,0,Display::X,10);
00097         else if(i == 7) return new RSText(0,0,"");
00098         else if(i == 8) return new RSComposite();
00099         else            return NULL;
00100     }
00101     static RegionShape* creationShape(unsigned int i) {
00102         return creationShape((int)i);
00103     }
00104     
00105     static String creationName(int i) {
00106         if(i < 0)       return "";
00107         else if(i == 0) return "ellipse";
00108         else if(i == 1) return "circle";
00109         else if(i == 2) return "rectangle";
00110         else if(i == 3) return "polygon";
00111         else if(i == 4) return "line";
00112         else if(i == 5) return "vector";
00113         else if(i == 6) return "marker";
00114         else if(i == 7) return "text";
00115         else if(i == 8) return "composite";
00116         else            return "";
00117     }
00118     static String creationName(unsigned int i) {
00119         return creationName((int)i);
00120     }
00121     
00122 private slots:
00123     // When the "create" button is clicked.
00124     void create();
00125 };
00126 
00127 
00128 // Specialized widget for creating a new polygon.
00129 class QtNewRSPolygon : public QWidget {
00130     Q_OBJECT
00131     
00132 public:
00133     // Constructor which takes the polygon to modify.
00134     QtNewRSPolygon(RSPolygon* poly, QtRegionShapeManager* manager);
00135     
00136     // Destructor.
00137     ~QtNewRSPolygon();
00138     
00139     // See QtEditRegionShape::enteredCoordinatesAreValid.
00140     bool enteredCoordinatesAreValid(String& reason) const;
00141     
00142 public slots:
00143     // Applies the entered values to the RSPolygon.
00144     void apply();
00145     
00146 private:
00147     RSPolygon* m_polygon; // Polygon.
00148     QtEditRegionShape* m_editor; // Region shape editor.
00149     QListWidget* m_coordList; // List widget for displaying entered coordinates
00150     QFrame* m_coordFrame;     // Frame that holds list widget and buttons.
00151     vector<pair<QString, QString> > m_enteredCoords; // Entered coordinates
00152     QLineEdit* m_coordXEdit, *m_coordYEdit; // Coordinate edits.
00153     
00154 private slots:
00155     // Add the values entered in the line edits to the coord list.
00156     void addCoordinates();
00157     
00158     // Moves the selected coordinate up in the list.
00159     void listMoveUp();
00160     
00161     // Moves the selected coordinate down in the list.
00162     void listMoveDown();
00163     
00164     // Deletes the selected coordinate in the list.
00165     void listDelete();
00166 };
00167 
00168 
00169 // Specialized widget for creating a new composite.
00170 class QtNewRSComposite : public QWidget {
00171     Q_OBJECT
00172     
00173 public:
00174     // Constructor which takes the composite to modify.
00175     QtNewRSComposite(RSComposite* comp, QtRegionShapeManager* manager);  
00176     
00177     // Destructor.
00178     ~QtNewRSComposite();
00179     
00180     // Returns whether the entered values are valid or not.  Returns true if
00181     // at least one child is entered, and all children have valid coordinates.
00182     bool enteredValuesAreValid(String& reason) const;
00183     
00184 public slots:
00185     // Applies the entered values to the RSComposite.
00186     void apply();
00187     
00188 private:
00189     // Top-lebel members.
00190     // <group>
00191     QtRegionShapeManager* m_manager;
00192     RSComposite* m_composite;
00193     vector<RegionShape*> m_children;
00194     QStackedLayout* m_layout;
00195     // </group>
00196     
00197     // First screen
00198     // <group>
00199     QRadioButton* m_dependentChildren;
00200     QRadioButton* m_newShapes;
00201     QLabel* m_dependentLabel1, *m_dependentLabel2;
00202     // </group>
00203     
00204     // Second screen: new shapes
00205     // <group>
00206     QListWidget* m_newShapeList;
00207     QComboBox* m_editChooser;
00208     QStackedLayout* m_editWidgets;
00209     // </group>
00210     
00211     // Second screen: existing shapes
00212     // <group>
00213     QListWidget* m_existingList, *m_moveList;
00214     vector<RegionShape*> m_existingShapes, m_moveShapes;
00215     // </group>
00216     
00217     
00218     // GUI initialization methods.
00219     // <group>
00220     QWidget* initFirstScreen();
00221     QWidget* initSecondScreen1();
00222     QWidget* initSecondScreen2();
00223     // </group>
00224     
00225     // Updated m_existingList and m_moveList based on m_existingShapes and
00226     // m_movesshapes.
00227     void updateLists();
00228     
00229     // Returns the adjusted index (m_existingList => m_existingShapes).
00230     unsigned int adjustedIndex(int row);
00231     
00232 private slots:
00233     // Switches to second page.
00234     void next();
00235     
00236     // New shapes
00237     
00238     // Adds a new shape to the composite.
00239     void nAddShape(RegionShape* shape);
00240     
00241     // Moves the selected shape up in the list.
00242     void nListUp();
00243     
00244     // Moves the selected shape down in the list.
00245     void nListDown();
00246     
00247     // Deletes the selected shape in the list.
00248     void nListDelete();
00249     
00250     // Existing shapes
00251     
00252     // Adds the selected existing shape to the composite.
00253     void eAddShape();
00254     
00255     // Remove the selected shape from the composite.
00256     void eRemoveShape();
00257     
00258     // Moves the selected shape up in the list.
00259     void eListUp();
00260     
00261     // Moves the selected shape down in the list.
00262     void eListDown();
00263 };
00264 
00265 }
00266 
00267 #endif /* QTNEWREGIONSHAPE_QO_H */