1 /*************************************************************************** 2 * * 3 * copyright : (C) 2008 The University of Toronto * 4 * netterfield@astro.utoronto.ca * 5 * * 6 * This program is free software; you can redistribute it and/or modify * 7 * it under the terms of the GNU General Public License as published by * 8 * the Free Software Foundation; either version 2 of the License, or * 9 * (at your option) any later version. * 10 * * 11 ***************************************************************************/ 12 13 #ifndef SHAREDAXISBOXITEM_H 14 #define SHAREDAXISBOXITEM_H 15 16 #include "viewitem.h" 17 #include "plotitem.h" 18 #include "plotaxis.h" 19 #include "graphicsfactory.h" 20 21 namespace Kst { 22 23 class SharedAxisBoxItem : public ViewItem 24 { 25 Q_OBJECT 26 public: 27 friend class SharedAxisBoxItemFactory; 28 29 explicit SharedAxisBoxItem(View *parent); 30 virtual ~SharedAxisBoxItem(); 31 32 virtual void save(QXmlStreamWriter &xml); 33 virtual void paint(QPainter *painter); 34 35 virtual void addToMenuForContextEvent(QMenu &menu); 36 void triggerContextEvent(QGraphicsSceneContextMenuEvent *event); 37 38 bool tryMousePressEvent(ViewItem* viewItem, QGraphicsSceneMouseEvent *event); setDirty()39 void setDirty() { _dirty = true; } 40 isXAxisShared()41 bool isXAxisShared() const { return _shareX; } 42 void setXAxisShared(const bool shared); 43 isYAxisShared()44 bool isYAxisShared() const { return _shareY; } 45 void setYAxisShared(const bool shared); 46 xAxisZoomMode()47 PlotAxis::ZoomMode xAxisZoomMode() const { return _xAxisZoomMode; } 48 void setXAxisZoomMode(PlotAxis::ZoomMode mode); 49 yAxisZoomMode()50 PlotAxis::ZoomMode yAxisZoomMode() const { return _yAxisZoomMode; } 51 void setYAxisZoomMode(PlotAxis::ZoomMode mode); 52 53 void updateZoomForDataUpdate(qint64 serial); 54 keyPlot()55 PlotItem* keyPlot() { return _keyPlot; }; defaultsGroupName()56 const QString defaultsGroupName() const {return QString("plot");} 57 58 virtual int nRows(); 59 virtual int nCols(); 60 61 Q_SIGNALS: 62 void breakShareSignal(); 63 64 public Q_SLOTS: 65 void breakShare(); 66 bool acceptItems(); 67 void lockItems(); 68 69 void shareXAxis(); 70 void shareYAxis(); 71 72 void zoomFixedExpression(const QRectF &projection, PlotItem* originPlotItem); 73 void zoomXRange(const QRectF &projection, PlotItem* originPlotItem); 74 void zoomYRange(const QRectF &projection, PlotItem* originPlotItem); 75 void zoomMaximum(PlotItem* originPlotItem); 76 void zoomMaxSpikeInsensitive(PlotItem* originPlotItem); 77 void zoomMeanCentered(PlotItem* originPlotItem); 78 79 void zoomXMeanCentered(PlotItem* originPlotItem); 80 void zoomXMaximum(PlotItem* originPlotItem); 81 void zoomXNoSpike(PlotItem* originPlotItem); 82 void zoomXAutoBorder(PlotItem* originPlotItem); 83 void zoomXRight(PlotItem* originPlotItem, bool far = false); 84 void zoomXLeft(PlotItem* originPlotItem, bool far = false); 85 void zoomXOut(PlotItem* originPlotItem); 86 void zoomXIn(PlotItem* originPlotItem); 87 void zoomNormalizeXtoY(PlotItem* originPlotItem); 88 void zoomLogX(PlotItem* originPlotItem, bool autoEnable = true, bool enable = true); 89 90 void zoomYMeanCentered(qreal dY, PlotItem* originPlotItem); 91 void zoomYLocalMaximum(PlotItem* originPlotItem); 92 void zoomYMaximum(PlotItem* originPlotItem); 93 void zoomYNoSpike(PlotItem* originPlotItem); 94 void zoomYAutoBorder(PlotItem* originPlotItem); 95 void zoomYUp(PlotItem* originPlotItem); 96 void zoomYDown(PlotItem* originPlotItem); 97 void zoomYOut(PlotItem* originPlotItem); 98 void zoomYIn(PlotItem* originPlotItem); 99 void zoomNormalizeYtoX(PlotItem* originPlotItem); 100 void zoomLogY(PlotItem* originPlotItem, bool autoEnable = true, bool enable = true); 101 QList<PlotItem*> getSharedPlots(); 102 103 protected Q_SLOTS: 104 virtual void creationPolygonChanged(View::CreationEvent event); 105 106 private: 107 void updateShare(); 108 void updatePlotTiedZoomSupport(); 109 void highlightPlots(QList<PlotItem*> plots); 110 111 QRectF computeRect(PlotAxis::ZoomMode xMode, PlotAxis::ZoomMode yMode); 112 void applyZoom(const QRectF &projection, PlotItem* originPlotItem, bool applyX = true, bool applyY = true); 113 114 QList<PlotItem*> getTiedPlots(PlotItem* originPlotItem); 115 116 QAction *_breakAction; 117 118 QPointer<ViewGridLayout> _layout; 119 QList<PlotItem*> _highlightedPlots; 120 QList<PlotItem*> _sharedPlots; 121 PlotItem* _keyPlot; 122 123 bool _loaded; 124 bool _firstPaint; 125 bool _dirty; 126 bool _shareX, _shareY; 127 qint64 _serialOfLastChange; 128 129 PlotAxis::ZoomMode _xAxisZoomMode, _yAxisZoomMode; 130 bool _sharedIsDirty; 131 }; 132 133 class CreateSharedAxisBoxCommand : public CreateCommand 134 { 135 Q_OBJECT 136 public: CreateSharedAxisBoxCommand()137 CreateSharedAxisBoxCommand() : CreateCommand(QObject::tr("Create Shared Axis Box")) {} CreateSharedAxisBoxCommand(View * view)138 CreateSharedAxisBoxCommand(View *view) : CreateCommand(view, QObject::tr("Create Shared Axis Box")) {} ~CreateSharedAxisBoxCommand()139 virtual ~CreateSharedAxisBoxCommand() {} 140 virtual void undo(); 141 virtual void redo(); 142 virtual void createItem(); 143 144 public Q_SLOTS: 145 virtual void creationComplete(); 146 }; 147 148 class SharedAxisBoxItemFactory : public GraphicsFactory { 149 public: 150 SharedAxisBoxItemFactory(); 151 ~SharedAxisBoxItemFactory(); 152 ViewItem* generateGraphics(QXmlStreamReader& stream, ObjectStore *store, View *view, ViewItem *parent = 0); 153 }; 154 155 } 156 157 #endif 158 159 // vim: ts=2 sw=2 et 160