QtDrawCanvas.qo.h

Go to the documentation of this file.
00001 //# Copyright (C) 2005
00002 //# Associated Universities, Inc. Washington DC, USA.
00003 //#
00004 //# This library is free software; you can redistribute it and/or modify it
00005 //# under the terms of the GNU Library General Public License as published by
00006 //# the Free Software Foundation; either version 2 of the License, or (at your
00007 //# option) any later version.
00008 //#
00009 //# This library is distributed in the hope that it will be useful, but WITHOUT
00010 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00011 //# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
00012 //# License for more details.
00013 //#
00014 //# You should have received a copy of the GNU Library General Public License
00015 //# along with this library; if not, write to the Free Software Foundation,
00016 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
00017 //#
00018 //# Correspondence concerning AIPS++ should be addressed as follows:
00019 //#        Internet email: aips2-request@nrao.edu.
00020 //#        Postal address: AIPS++ Project Office
00021 //#                        National Radio Astronomy Observatory
00022 //#                        520 Edgemont Road
00023 //#                        Charlottesville, VA 22903-2475 USA
00024 //#
00025 
00026 
00027 #ifndef TQDRAWCANVAS_H
00028 #define TQDRAWCANVAS_H
00029 
00030 #include <casa/aips.h>
00031 #include <casa/BasicSL/String.h>
00032 #include <casa/Containers/Record.h>
00033 #include <casa/Arrays/Array.h>
00034 #include <casa/Arrays/ArrayMath.h>
00035 #include <casa/Arrays/Vector.h>
00036 #include <casa/Arrays/Matrix.h>
00037 #include <casa/Inputs/Input.h>
00038 #include <casa/Arrays/IPosition.h>
00039 
00040 #include <display/QtPlotter/QtDrawSettings.h>
00041 
00042 #include <graphics/X11/X_enter.h>
00043 #include <QDir>
00044 #include <QColor>
00045 #include <QHash>
00046 #include <QWidget>
00047 #include <QMouseEvent>
00048 #include <QToolButton>
00049 #include <QDialog>
00050 #include <QPixmap>
00051 #include <QVBoxLayout>
00052 #include <QLabel>
00053 #include <map>
00054 #include <vector>
00055 #include <graphics/X11/X_exit.h>
00056 
00057 namespace casa {
00058 
00059         typedef std::vector<double> CurveData;
00060 
00061         class GraphLabel {
00062         public:
00063                 QString text;
00064                 QString fontName;
00065                 int fontSize;
00066                 QColor color;
00067                 GraphLabel() : text(""), fontName("Helvetica [Cronyx]"),
00068                         fontSize(12), color(Qt::blue) {}
00069         };
00070 
00071         class QtDrawCanvas : public QWidget {
00072                 Q_OBJECT
00073         public:
00074                 enum {LINE = 0, POINT, FPOINT, CIRCLE, FCIRCLE,
00075                       RECT, FRECT, DIM, FDIM,
00076                       PLUS, FPLUS, CROSS, FCROSS,
00077                       TRIGU, FTRIGU, TRIGD, FTRIGD,
00078                       TRIGL, FTRIGL, TRIGR, FTRIGR,
00079                       SAND, FSAND, WING, FWING,
00080                       BEAM, FBEAM, BED, FBED,
00081                       HIST, FHIST
00082                      };
00083                 QtDrawCanvas(QWidget *parent = 0);
00084 
00085                 void setPlotSettings(const QtDrawSettings &settings);
00086                 void setCurveData(int id, const CurveData data,
00087                                   int tp = 0, int cl = 0);
00088                 void clearCurve(int id);
00089                 void setDataRange();
00090                 void setImageMode(bool);
00091                 void setPixmap(const QImage&);
00092                 QPixmap* graph();
00093                 void drawBackBuffer(QPainter *);
00094                 void plotPolyLines(QString);
00095 
00096                 //ln = 0, new chart
00097                 //ln < 0, remove trace
00098                 //ln > 0, append trace if ln exists, otherwise add trace
00099                 //tp = 0, continous line
00100                 //tp > 0, discrete symbols
00101                 //tp < 0, line and symbols
00102                 //cl, color value range from 0 up
00103                 void plotPolyLine(const Vector<Int>&,
00104                                   const Vector<Int>&,
00105                                   int ln = 0, int tp = 0, int cl = 0);
00106                 void plotPolyLine(const Vector<Float> &x,
00107                                   const Vector<Float> &y,
00108                                   int ln = 0, int tp = 0, int cl = 0);
00109                 void plotPolyLine(const Vector<Double>&,
00110                                   const Vector<Double>&,
00111                                   int ln = 0, int tp = 0, int cl = 0);
00112 
00113                 //Each row is a trace
00114                 //ln = 0, new chart
00115                 //ln < 0, remove traces
00116                 //ln > 0, append traces from (ln)th, add if not exists
00117                 //tp < 0, same shape for all traces
00118                 //tp = 0, continuous lines
00119                 //tp > 0, different discrete shape for each trace
00120                 //cl > 0, different color for each trace
00121                 //cl <= 0, same color for all traces
00122                 void plotPolyLine(const Matrix<Int> &verts,
00123                                   int ln = 0, int tp = 0, int cl = 0);
00124                 void plotPolyLine(const Matrix<Float> &verts,
00125                                   int ln = 0, int tp = 0, int cl = 0);
00126                 void plotPolyLine(const Matrix<Double> &verts,
00127                                   int ln = 0, int tp = 0, int cl = 0);
00128 
00129                 // template<class T>
00130                 void drawImage(const Matrix<uInt> &data, Matrix<uInt> *mask);
00131                 void drawImage(const Matrix<uInt> &data);
00132                 //void setMarkMode(bool);
00133 
00134                 QColor getLinearColor(double);
00135                 QSize minimumSizeHint() const;
00136                 QSize sizeHint() const;
00137                 ~QtDrawCanvas();
00138                 void increaseCurZoom();
00139                 int getCurZoom();
00140                 int getZoomStackSize();
00141                 int getCurLine();
00142                 int getTotalLines();
00143 
00144                 void setTitle(const QString &text,
00145                               int fontSize = 12, int color = 0,
00146                               const QString &font = "Helvetica [Cronyx]");
00147                 void setXLabel(const QString &text,
00148                                int fontSize = 10, int color = 1,
00149                                const QString &font = "Helvetica [Cronyx]");
00150                 void setYLabel(const QString &text,
00151                                int fontSize = 10, int color = 2,
00152                                const QString &font = "Helvetica [Cronyx]");
00153                 void setWelcome(const QString &text, int fontSize = 14,
00154                                 int color = 1,
00155                                 const QString &font = "Helvetica [Cronyx]");
00156 
00157         public slots:
00158                 void zoomIn();
00159                 void zoomOut();
00160                 void markPrev();
00161                 void markNext();
00162 
00163         signals:
00164                 void zoomChanged();
00165                 void gotFocus();
00166 
00167         protected:
00168                 void paintEvent(QPaintEvent *event);
00169                 void resizeEvent(QResizeEvent *event);
00170                 void mousePressEvent(QMouseEvent *event);
00171                 void mouseMoveEvent(QMouseEvent *event);
00172                 void mouseReleaseEvent(QMouseEvent *event);
00173                 void keyPressEvent(QKeyEvent *event);
00174                 void wheelEvent(QWheelEvent *event);
00175                 void focusInEvent(QFocusEvent *event);
00176 
00177         private:
00178                 void updateRubberBandRegion();
00179                 void refreshPixmap();
00180                 void drawGrid(QPainter *painter);
00181                 void drawTicks(QPainter *painter);
00182                 void drawLabels(QPainter *painter);
00183                 void drawWelcome(QPainter *painter);
00184                 void drawCurves(QPainter *painter);
00185                 void drawRects(QPainter *painter);
00186 
00187                 enum { Margin = 60 };
00188 
00189                 GraphLabel title;
00190                 GraphLabel xLabel;
00191                 GraphLabel yLabel;
00192                 GraphLabel welcome;
00193 
00194                 std::map<int, CurveData> curveMap;
00195                 std::map<int, int> typeMap;
00196                 std::map<int, int> colorMap;
00197                 int curLine;
00198 
00199                 std::vector<QtDrawSettings> zoomStack;
00200                 int curZoom;
00201 
00202                 std::map<int, CurveData> markerStack;
00203                 int curMarker;
00204 
00205                 QRect rubberBandRect;
00206                 bool rubberBandIsShown;
00207 
00208                 bool imageMode;
00209                 bool markMode;
00210 
00211                 QPixmap pixmap;
00212                 QPixmap backBuffer;
00213                 Matrix<uInt> *pMask;
00214 
00215         };
00216 
00217 }
00218 #endif
00219 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on 31 Aug 2016 for casa by  doxygen 1.6.1