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 QPCANVASHELPERS_QO_H_
00028 #define QPCANVASHELPERS_QO_H_
00029
00030 #ifdef AIPS_HAS_QWT
00031
00032 #include <casaqt/QwtPlotter/QPOptions.h>
00033 #include <casaqt/QwtPlotter/QPPlotItem.qo.h>
00034 #include <graphics/GenericPlotter/PlotCanvas.h>
00035
00036 #include <qwt_legend.h>
00037 #if QWT_VERSION >= 0x060000
00038 #include <qwt_plot_legenditem.h>
00039 #endif
00040 #include <qwt_plot.h>
00041 #include <qwt_plot_grid.h>
00042 #include <qwt_scale_draw.h>
00043
00044 #include <QObject>
00045 #include <QMouseEvent>
00046 #include <QSpacerItem>
00047
00048 namespace casa {
00049
00050
00051 class QPCanvas;
00052
00053
00054
00055
00056
00057
00058 class QPMouseFilter : public QObject {
00059 Q_OBJECT
00060
00061 public:
00062
00063 QPMouseFilter(QwtPlotCanvas* canvas);
00064 QPMouseFilter(QWidget* widget);
00065
00066
00067 ~QPMouseFilter();
00068
00069
00070 void turnTracking(bool on);
00071
00072 signals:
00073
00074
00075 void mouseMoveEvent(QMouseEvent* e);
00076
00077 protected:
00078
00079
00080 bool eventFilter(QObject* obj, QEvent* ev);
00081
00082 private:
00083
00084 QwtPlotCanvas* m_canvas;
00085 };
00086
00087
00088
00089
00090
00091
00092
00093
00094 class QPScaleDraw : public QwtScaleDraw {
00095 public:
00096
00097 QPScaleDraw(QwtPlot* parent, QwtPlot::Axis axis);
00098
00099
00100 ~QPScaleDraw();
00101
00102
00103
00104 PlotAxisScale scale() const;
00105 void setScale(PlotAxisScale scale);
00106
00107
00108
00109
00110 const String& dateFormat() const;
00111 void setDateFormat(const String& newFormat);
00112
00113
00114
00115
00116
00117 const String& relativeDateFormat() const;
00118 void setRelativeDateFormat(const String& newFormat);
00119
00120
00121
00122
00123 bool referenceValueSet() const;
00124 double referenceValue() const;
00125 void setReferenceValue(bool on, double value = 0);
00126
00127
00128
00129 QwtText label(double value) const;
00130
00131 virtual void draw(QPainter* painter, const QPalette& palette) const;
00132
00133 #if QWT_VERSION < 0x060000
00134 virtual int extent( const QPen& pen, const QFont& font ) const;
00135 #endif
00136
00137 private:
00138
00139 QwtPlot* m_parent;
00140
00141
00142 QwtPlot::Axis m_axis;
00143
00144
00145 PlotAxisScale m_scale;
00146
00147
00148
00149 String m_dateFormat;
00150 String m_relativeDateFormat;
00151
00152
00153
00154
00155 bool m_referenceSet;
00156 double m_referenceValue;
00157
00158 };
00159
00160
00161
00162
00163
00164
00165 class QPLegend : public QwtLegend {
00166 public:
00167
00168 QPLegend(QWidget* parent = NULL);
00169
00170
00171 ~QPLegend();
00172
00173
00174
00175 QSize sizeHint() const;
00176
00177
00178
00179 const QPLine& line() const;
00180 const QPen& pen() const;
00181 void setLine(const PlotLine& line);
00182 void setLine(const QPen& pen) { setLine(QPLine(pen)); }
00183
00184
00185
00186
00187 const QPAreaFill& areaFill() const;
00188 const QBrush& brush() const;
00189
00190
00191 void setAreaFill(const PlotAreaFill& fill, bool update=true);
00192 void setAreaFill(const QBrush& brush) { setAreaFill(QPAreaFill(brush)); }
00193
00194
00195
00196
00197
00198 void drawOutlineAndBackground(QPainter* painter, const QRect& rect,
00199 bool useQwtPainter = false);
00200
00201 protected:
00202
00203
00204 void paintEvent(QPaintEvent* event);
00205
00206 private:
00207
00208 QPLine m_line;
00209
00210
00211 QPAreaFill m_areaFill;
00212 };
00213
00214
00215
00216 class QPLegendHolder : public QWidget {
00217 Q_OBJECT
00218
00219 public:
00220
00221 static const int DEFAULT_INTERNAL_PADDING;
00222
00223
00224 static QwtPlot::LegendPosition legendPosition(
00225 PlotCanvas::LegendPosition pos);
00226
00227
00228
00229 QPLegendHolder(QPCanvas* canvas, PlotCanvas::LegendPosition position,
00230 int padding = DEFAULT_INTERNAL_PADDING);
00231
00232
00233 ~QPLegendHolder();
00234
00235 QPLegend* legend() { return m_legend; }
00236
00237
00238 bool legendShown() const;
00239 void showLegend(bool show = true);
00240
00241
00242
00243
00244 bool isInternal() const;
00245 PlotCanvas::LegendPosition position() const;
00246 void setPosition(PlotCanvas::LegendPosition position);
00247
00248
00249
00250
00251 const QPLine& line() const { return m_legend->line(); }
00252 const QPen& pen() const { return m_legend->pen(); }
00253 void setLine(const PlotLine& line) { m_legend->setLine(line); }
00254 void setLine(const QPen& pen) { m_legend->setLine(pen); }
00255
00256
00257
00258
00259 const QPAreaFill& areaFill() const { return m_legend->areaFill(); }
00260 const QBrush& brush() const { return m_legend->brush(); }
00261
00262
00263 void setAreaFill(const PlotAreaFill& fill, bool update = true ) {
00264 if (m_legend) m_legend->setAreaFill(fill, update); }
00265 void setAreaFill(const QBrush& brush) {
00266 if (m_legend) m_legend->setAreaFill(brush); }
00267
00268
00269
00270 QRect internalLegendRect(const QRect& canvasRect) const;
00271
00272
00273 void drawOutlineAndBackground(QPainter* painter, const QRect& rect,
00274 bool useQwtPainter = false) {
00275 m_legend->drawOutlineAndBackground(painter, rect, useQwtPainter); }
00276
00277 private:
00278
00279 QPCanvas* m_canvas;
00280
00281
00282 QPLegend* m_legend;
00283
00284 #if QWT_VERSION >= 0x060000
00285 QwtPlotLegendItem* m_legendItem;
00286 void setupLegendItem();
00287 void setAlignment(PlotCanvas::LegendPosition pos);
00288 #endif
00289
00290
00291 PlotCanvas::LegendPosition m_position;
00292
00293
00294 QSpacerItem* m_spaceTop, *m_spaceLeft, *m_spaceRight, *m_spaceBottom;
00295
00296
00297 int m_padding;
00298
00299
00300
00301 void updateSpacers();
00302 };
00303
00304
00305
00306
00307
00308
00309
00310 class QPBaseItem : public QPLayerItem {
00311 friend class QPLayeredCanvas;
00312
00313 public:
00314
00315
00316 static const double BASE_Z_CARTAXIS;
00317 static const double BASE_Z_GRID;
00318
00319
00320
00321
00322 QPBaseItem();
00323
00324
00325 virtual ~QPBaseItem();
00326
00327
00328
00329 virtual void itemChanged() { QwtPlotItem::itemChanged(); }
00330
00331
00332 virtual unsigned int itemDrawCount() const { return 1; }
00333
00334 protected:
00335
00336 QPCanvas* m_canvas;
00337
00338
00339
00340 void qpAttach(QPCanvas* canvas);
00341
00342
00343 void qpDetach();
00344 };
00345
00346
00347
00348
00349 class QPGrid : public QPBaseItem, public QwtPlotGrid {
00350 public:
00351
00352 QPGrid();
00353
00354
00355 ~QPGrid();
00356
00357
00358
00359 void itemChanged() { QPBaseItem::itemChanged(); }
00360
00361
00362 bool shouldDraw() const;
00363
00364
00365 String itemTitle() const { return "grid"; }
00366
00367
00368 QwtDoubleRect boundingRect() const { return QwtPlotGrid::boundingRect(); }
00369
00370
00371 void updateScaleDiv(const QwtScaleDiv& xDiv, const QwtScaleDiv& yDiv) {
00372 QwtPlotGrid::updateScaleDiv(xDiv, yDiv); }
00373
00374 protected:
00375
00376 #if QWT_VERSION >= 0x060000
00377 void draw_(QPainter* p, const QwtScaleMap& xMap,
00378 const QwtScaleMap& yMap, const QRectF& drawRect,
00379 unsigned int drawIndex, unsigned int drawCount) const {
00380 #else
00381 void draw_(QPainter* p, const QwtScaleMap& xMap,
00382 const QwtScaleMap& yMap, const QRect& drawRect,
00383 unsigned int drawIndex, unsigned int drawCount) const {
00384 #endif
00385 (void)drawIndex; (void)drawCount;
00386 QwtPlotGrid::draw(p, xMap, yMap, drawRect); }
00387 };
00388
00389
00390
00391
00392 class QPCartesianAxis : public QPBaseItem {
00393 public:
00394
00395
00396 QPCartesianAxis(QwtPlot::Axis master, QwtPlot::Axis slave);
00397
00398
00399 ~QPCartesianAxis();
00400
00401
00402
00403 bool shouldDraw() const { return true; }
00404
00405
00406 String itemTitle() const { return "cartesian axis"; }
00407
00408 protected:
00409
00410 #if QWT_VERSION >= 0x060000
00411 void draw_(QPainter* p, const QwtScaleMap& xMap,
00412 const QwtScaleMap& yMap, const QRectF& drawRect,
00413 unsigned int drawIndex, unsigned int drawCount) const;
00414 #else
00415 void draw_(QPainter* p, const QwtScaleMap& xMap,
00416 const QwtScaleMap& yMap, const QRect& drawRect,
00417 unsigned int drawIndex, unsigned int drawCount) const;
00418 #endif
00419
00420 private:
00421
00422 QwtPlot::Axis m_axis;
00423
00424
00425 QwtScaleDraw m_scaleDraw;
00426 };
00427
00428 }
00429
00430 #endif
00431
00432 #endif