00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
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
00097
00098
00099
00100
00101
00102
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
00114
00115
00116
00117
00118
00119
00120
00121
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
00130 void drawImage(const Matrix<uInt> &data, Matrix<uInt> *mask);
00131 void drawImage(const Matrix<uInt> &data);
00132
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