File indexing completed on 2024-12-22 04:17:48

0001 /***************************************************************************
0002  *                                                                         *
0003  *   copyright : (C) 2007 The University of Toronto                        *
0004  *                   netterfield@astro.utoronto.ca                         *
0005  *                                                                         *
0006  *   This program is free software; you can redistribute it and/or modify  *
0007  *   it under the terms of the GNU General Public License as published by  *
0008  *   the Free Software Foundation; either version 2 of the License, or     *
0009  *   (at your option) any later version.                                   *
0010  *                                                                         *
0011  ***************************************************************************/
0012 
0013 #ifndef VIEWGRIDLAYOUT_H
0014 #define VIEWGRIDLAYOUT_H
0015 
0016 #include <QObject>
0017 #include <QSizeF>
0018 #include <QRectF>
0019 #include <QPointF>
0020 #include <QTransform>
0021 #include <QHash>
0022 
0023 namespace Kst {
0024 
0025 class View;
0026 class ViewItem;
0027 class PlotItem;
0028 
0029 class ViewGridLayout : public QObject
0030 {
0031   Q_OBJECT
0032   public:
0033     explicit ViewGridLayout(ViewItem *parent);
0034     virtual ~ViewGridLayout();
0035 
0036     ViewItem *parentItem() const;
0037 
0038     void addViewItem(ViewItem *viewItem, int row, int column);
0039     void addViewItem(ViewItem *viewItem, int row, int column, int rowSpan, int columnSpan);
0040 
0041     int rowCount() const;
0042     int columnCount() const;
0043     void setColumnCount(int count) {_columnCount = (count>_columnCount)? count : _columnCount ;}
0044 
0045     QSizeF spacing() const { return _spacing; }
0046     void setSpacing(const QSizeF &spacing) { _spacing = spacing; }
0047 
0048     QSizeF margin() const { return _margin; }
0049     void setMargin(const QSizeF &margin) { _margin = margin; }
0050 
0051     qreal plotLabelMarginWidth(const PlotItem *plotItem) const;
0052     qreal plotLabelMarginHeight(const PlotItem *plotItem) const;
0053 
0054     qreal plotAxisMarginWidth(const PlotItem *plotItem) const;
0055     qreal plotAxisMarginHeight(const PlotItem *plotItem) const;
0056 
0057     bool isEnabled() const;
0058     void setEnabled(bool enabled);
0059 
0060     void calculateSharing();
0061     static void updateProjections(ViewItem *item, bool forceXShare = false, bool forceYShare = false);
0062 
0063     static void standardizePlotMargins(ViewItem *item, QPainter *painter);
0064     static void sharePlots(ViewItem *item, QPainter *painter, bool creation);
0065 
0066     void reset();
0067 
0068   public Q_SLOTS:
0069     void apply();
0070     void shareAxis(QPainter *painter, bool creation);
0071 
0072   Q_SIGNALS:
0073     void enabledChanged(bool enabled);
0074 
0075   private Q_SLOTS:
0076     void updatePlotMargins();
0077 
0078   private:
0079     struct LayoutItem {
0080       ViewItem *viewItem;
0081       int row;
0082       int column;
0083       int rowSpan;
0084       int columnSpan;
0085       QTransform transform;
0086       QPointF position;
0087       QRectF rect;
0088     };
0089 
0090     struct PlotMargins {
0091       qreal labelMargin;
0092       qreal axisMargin;
0093     };
0094 
0095   private:
0096     void updateSharedAxis();
0097     void unshareAxis();
0098     void shareAxisWithPlotToLeft(LayoutItem item);
0099     void shareAxisWithPlotToRight(LayoutItem item);
0100     void shareAxisWithPlotAbove(LayoutItem item);
0101     void shareAxisWithPlotBelow(LayoutItem item);
0102 
0103   private:
0104     bool _enabled;
0105     int _rowCount;
0106     int _columnCount;
0107 
0108     bool _shareX;
0109     bool _shareY;
0110 
0111     QSizeF _spacing;
0112     QSizeF _margin;
0113 
0114     QList<LayoutItem> _items;
0115     QHash<int, PlotMargins> _plotMarginWidth;
0116     QHash<int, PlotMargins> _plotMarginHeight;
0117     QHash<const ViewItem*, LayoutItem> _itemInfos;
0118     QHash< QPair<int, int>, LayoutItem> _itemLayouts;
0119 };
0120 
0121 }
0122 
0123 #endif
0124 
0125 // vim: ts=2 sw=2 et