1 /*************************************************************************** 2 * * 3 * copyright : (C) 2007 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 VIEW_H 14 #define VIEW_H 15 16 #include <QGraphicsView> 17 18 #include "kst_export.h" 19 20 #include "curveplacement.h" 21 22 class QMenu; 23 class QUndoStack; 24 class QXmlStreamWriter; 25 26 namespace Kst { 27 28 class ViewItem; 29 class LayoutBoxItem; 30 class PlotItem; 31 32 class View : public QGraphicsView 33 { 34 Q_OBJECT 35 public: 36 enum ViewMode { Data, Layout }; 37 enum MouseMode { Default, Move, Create, Resize, Scale, Rotate }; 38 enum ZoomOnlyMode { ZoomOnlyDisabled, ZoomOnlyX, ZoomOnlyY }; 39 enum CreationEvent { 40 MousePress = 0x0, 41 MouseRelease =0x1, 42 MouseMove = 0x2, 43 EscapeEvent = 0x3 44 }; 45 Q_DECLARE_FLAGS(CreationEvents, CreationEvent) 46 47 View(); 48 explicit View(QWidget* parent); 49 virtual ~View(); 50 staticDefaultsGroupName()51 static QString staticDefaultsGroupName() { return QString("view");} 52 53 void init(); 54 55 virtual void save(QXmlStreamWriter &xml); 56 57 QUndoStack *undoStack() const; 58 59 ViewItem *selectedViewItem() const; 60 61 ViewMode viewMode() const; 62 void setViewMode(ViewMode mode); 63 64 MouseMode mouseMode() const; 65 void setMouseMode(MouseMode mode); 66 67 QPolygonF creationPolygon(CreationEvents events) const; 68 69 //LayoutBoxItem* layoutBoxItem() const { return _layoutBoxItem; } setLayoutBoxItem(LayoutBoxItem * layoutBoxItem)70 void setLayoutBoxItem(LayoutBoxItem *layoutBoxItem) { _layoutBoxItem = layoutBoxItem; } 71 showGrid()72 bool showGrid() const { return _showGrid; } 73 void setShowGrid(bool showGrid); 74 75 qreal scaledFontSize(qreal pointSize, const QPaintDevice &p) const; 76 gridSpacing()77 QSizeF gridSpacing() const { return _gridSpacing; } 78 void setGridSpacing(const QSizeF &gridSpacing); 79 snapToGridHorizontal()80 bool snapToGridHorizontal() const 81 { return _snapToGridHorizontal; } setSnapToGridHorizontal(bool snapToGridHorizontal)82 void setSnapToGridHorizontal(bool snapToGridHorizontal) 83 { _snapToGridHorizontal = snapToGridHorizontal; } 84 snapToGridVertical()85 bool snapToGridVertical() const 86 { return _snapToGridVertical; } setSnapToGridVertical(bool snapToGridVertical)87 void setSnapToGridVertical(bool snapToGridVertical) 88 { _snapToGridVertical = snapToGridVertical; } 89 snapToGrid()90 bool snapToGrid() const 91 { return _snapToGridHorizontal && _snapToGridVertical; } setSnapToGrid(bool snapToGrid)92 void setSnapToGrid(bool snapToGrid) 93 { _snapToGridHorizontal = snapToGrid; _snapToGridVertical = snapToGrid; } 94 95 QPointF snapPoint(const QPointF &point); 96 setPrinting(bool printing)97 void setPrinting(bool printing) { _printing = printing; } isPrinting()98 bool isPrinting() { return _printing; } 99 100 //TODO cleanup/remove setDataMode(bool dataMode)101 void setDataMode(bool dataMode) { _dataMode = dataMode; } isDataMode()102 bool isDataMode() { return _dataMode; } 103 104 virtual void viewContextMenuEvent(); 105 plotBordersDirty()106 bool plotBordersDirty() const {return _plotBordersDirty;} setPlotBordersDirty(bool dirty)107 void setPlotBordersDirty(bool dirty) {_plotBordersDirty = dirty;} 108 109 void configurePlotFontDefaults(PlotItem *plot); 110 111 double resetPlotFontSizes(PlotItem* plot); 112 113 double resetPlotFontSizes(QList<PlotItem*> new_plots = QList<PlotItem*>()); 114 setFontRescale(qreal rescale)115 void setFontRescale(qreal rescale) {_fontRescale = rescale;} fontRescale()116 qreal fontRescale() const {return _fontRescale;} 117 setChildMaximized(bool isMax)118 void setChildMaximized(bool isMax) { _childMaximized = isMax;} childMaximized()119 bool childMaximized() const {return _childMaximized;} 120 121 void applyDialogDefaultsFill(); referenceFontsToView()122 void referenceFontsToView() { _referenceFontSizeToView = true;} referenceFontsToPainter()123 void referenceFontsToPainter() { _referenceFontSizeToView = false;} 124 125 QList<ViewItem*> layoutableViewItems(); 126 nRows()127 virtual int nRows() {return 1.0;} nCols()128 virtual int nCols() {return 1.0;} 129 130 131 Q_SIGNALS: 132 void viewModeChanged(View::ViewMode oldMode); 133 void mouseModeChanged(View::MouseMode oldMode); 134 void creationPolygonChanged(View::CreationEvent event); 135 136 public Q_SLOTS: 137 void createLayout(bool preserve = true, int columns = 0); 138 void createUnprotectedLayout(bool preserve = true, int columns = 0) {createLayout(false);} 139 void appendToLayout(CurvePlacement::Layout layout, ViewItem* item, int columns = 0); 140 void createCustomLayout(); 141 void viewChanged(); 142 void forceChildResize(QRectF oldRect, QRectF newRect); 143 void processResize(QSize size); 144 void setZoomOnly(ZoomOnlyMode); 145 146 147 148 protected: 149 bool event(QEvent *event); 150 bool eventFilter(QObject *obj, QEvent *event); 151 void resizeEvent(QResizeEvent *event=NULL); 152 void drawBackground(QPainter *painter, const QRectF &rect); 153 void addTitle(QMenu *menu) const; 154 155 QAction *_editAction; 156 QAction *_autoLayoutAction; 157 QAction *_protectedLayoutAction; 158 QAction *_customLayoutAction; 159 160 private Q_SLOTS: 161 void updateSettings(); 162 void loadSettings(); 163 virtual void edit(); 164 165 private: 166 void updateChildGeometry(const QRectF &oldSceneRect); 167 168 private: 169 QUndoStack *_undoStack; 170 ViewMode _viewMode; 171 MouseMode _mouseMode; 172 LayoutBoxItem *_layoutBoxItem; 173 QPolygonF _creationPolygonPress; 174 QPolygonF _creationPolygonMove; 175 QPolygonF _creationPolygonRelease; 176 QSizeF _gridSpacing; 177 bool _showGrid; 178 bool _snapToGridHorizontal; 179 bool _snapToGridVertical; 180 bool _plotBordersDirty; 181 bool _printing; 182 bool _dataMode; 183 qreal _fontRescale; 184 bool _childMaximized; 185 bool _referenceFontSizeToView; 186 }; 187 188 } 189 190 #endif 191 192 // vim: ts=2 sw=2 et 193