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

Generated on 31 Aug 2016 for casa by  doxygen 1.6.1