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 VIEWGRIDLAYOUT_H 14 #define VIEWGRIDLAYOUT_H 15 16 #include <QObject> 17 #include <QSizeF> 18 #include <QRectF> 19 #include <QPointF> 20 #include <QTransform> 21 #include <QHash> 22 23 namespace Kst { 24 25 class View; 26 class ViewItem; 27 class PlotItem; 28 29 class ViewGridLayout : public QObject 30 { 31 Q_OBJECT 32 public: 33 explicit ViewGridLayout(ViewItem *parent); 34 virtual ~ViewGridLayout(); 35 36 ViewItem *parentItem() const; 37 38 void addViewItem(ViewItem *viewItem, int row, int column); 39 void addViewItem(ViewItem *viewItem, int row, int column, int rowSpan, int columnSpan); 40 41 int rowCount() const; 42 int columnCount() const; setColumnCount(int count)43 void setColumnCount(int count) {_columnCount = (count>_columnCount)? count : _columnCount ;} 44 spacing()45 QSizeF spacing() const { return _spacing; } setSpacing(const QSizeF & spacing)46 void setSpacing(const QSizeF &spacing) { _spacing = spacing; } 47 margin()48 QSizeF margin() const { return _margin; } setMargin(const QSizeF & margin)49 void setMargin(const QSizeF &margin) { _margin = margin; } 50 51 qreal plotLabelMarginWidth(const PlotItem *plotItem) const; 52 qreal plotLabelMarginHeight(const PlotItem *plotItem) const; 53 54 qreal plotAxisMarginWidth(const PlotItem *plotItem) const; 55 qreal plotAxisMarginHeight(const PlotItem *plotItem) const; 56 57 bool isEnabled() const; 58 void setEnabled(bool enabled); 59 60 void calculateSharing(); 61 static void updateProjections(ViewItem *item, bool forceXShare = false, bool forceYShare = false); 62 63 static void standardizePlotMargins(ViewItem *item, QPainter *painter); 64 static void sharePlots(ViewItem *item, QPainter *painter, bool creation); 65 66 void reset(); 67 68 public Q_SLOTS: 69 void apply(); 70 void shareAxis(QPainter *painter, bool creation); 71 72 Q_SIGNALS: 73 void enabledChanged(bool enabled); 74 75 private Q_SLOTS: 76 void updatePlotMargins(); 77 78 private: 79 struct LayoutItem { 80 ViewItem *viewItem; 81 int row; 82 int column; 83 int rowSpan; 84 int columnSpan; 85 QTransform transform; 86 QPointF position; 87 QRectF rect; 88 }; 89 90 struct PlotMargins { 91 qreal labelMargin; 92 qreal axisMargin; 93 }; 94 95 private: 96 void updateSharedAxis(); 97 void unshareAxis(); 98 void shareAxisWithPlotToLeft(LayoutItem item); 99 void shareAxisWithPlotToRight(LayoutItem item); 100 void shareAxisWithPlotAbove(LayoutItem item); 101 void shareAxisWithPlotBelow(LayoutItem item); 102 103 private: 104 bool _enabled; 105 int _rowCount; 106 int _columnCount; 107 108 bool _shareX; 109 bool _shareY; 110 111 QSizeF _spacing; 112 QSizeF _margin; 113 114 QList<LayoutItem> _items; 115 QHash<int, PlotMargins> _plotMarginWidth; 116 QHash<int, PlotMargins> _plotMarginHeight; 117 QHash<const ViewItem*, LayoutItem> _itemInfos; 118 QHash< QPair<int, int>, LayoutItem> _itemLayouts; 119 }; 120 121 } 122 123 #endif 124 125 // vim: ts=2 sw=2 et 126