· · ·
layout.h
1 /***************************************************************************
2 ** **
3 ** QCustomPlot, an easy to use, modern plotting widget for Qt **
4 ** Copyright (C) 2011, 2012, 2013, 2014 Emanuel Eichhammer **
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 3 of the License, or **
9 ** (at your option) any later version. **
10 ** **
11 ** This program is distributed in the hope that it will be useful, **
12 ** but WITHOUT ANY WARRANTY; without even the implied warranty of **
13 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the **
14 ** GNU General Public License for more details. **
15 ** **
16 ** You should have received a copy of the GNU General Public License **
17 ** along with this program. If not, see http://www.gnu.org/licenses/. **
18 ** **
19 ****************************************************************************
20 ** Author: Emanuel Eichhammer **
21 ** Website/Contact: http://www.qcustomplot.com/ **
22 ** Date: 07.04.14 **
23 ** Version: 1.2.1 **
24 ****************************************************************************/
25
26 #ifndef QCP_LAYOUT_H
27 #define QCP_LAYOUT_H
28
29 #include "global.h"
30 #include "layer.h"
31
32 class QCPLayout;
33 class QCPLayoutElement;
34 class QCustomPlot;
35
36 class QCP_LIB_DECL QCPMarginGroup : public QObject
37 {
38 Q_OBJECT
39 public:
40 QCPMarginGroup(QCustomPlot *parentPlot);
41 ~QCPMarginGroup();
42
43 // non-virtual methods:
44 QList<QCPLayoutElement*> elements(QCP::MarginSide side) const { return mChildren.value(side); }
45 bool isEmpty() const;
46 void clear();
47
48 protected:
49 // non-property members:
50 QCustomPlot *mParentPlot;
51 QHash<QCP::MarginSide, QList<QCPLayoutElement*> > mChildren;
52
53 // non-virtual methods:
54 int commonMargin(QCP::MarginSide side) const;
55 void addChild(QCP::MarginSide side, QCPLayoutElement *element);
56 void removeChild(QCP::MarginSide side, QCPLayoutElement *element);
57
58 private:
59 Q_DISABLE_COPY(QCPMarginGroup)
60
61 friend class QCPLayoutElement;
62 };
63
64
65 class QCP_LIB_DECL QCPLayoutElement : public QCPLayerable
66 {
67 Q_OBJECT
69 Q_PROPERTY(QCPLayout* layout READ layout)
70 Q_PROPERTY(QRect rect READ rect)
71 Q_PROPERTY(QRect outerRect READ outerRect WRITE setOuterRect)
72 Q_PROPERTY(QMargins margins READ margins WRITE setMargins)
73 Q_PROPERTY(QMargins minimumMargins READ minimumMargins WRITE setMinimumMargins)
74 Q_PROPERTY(QSize minimumSize READ minimumSize WRITE setMinimumSize)
75 Q_PROPERTY(QSize maximumSize READ maximumSize WRITE setMaximumSize)
77 public:
82 enum UpdatePhase { upPreparation
83 ,upMargins
84 ,upLayout
85 };
86 Q_ENUMS(UpdatePhase)
87
88 explicit QCPLayoutElement(QCustomPlot *parentPlot=0);
89 virtual ~QCPLayoutElement();
90
91 // getters:
92 QCPLayout *layout() const { return mParentLayout; }
93 QRect rect() const { return mRect; }
94 QRect outerRect() const { return mOuterRect; }
95 QMargins margins() const { return mMargins; }
96 QMargins minimumMargins() const { return mMinimumMargins; }
97 QCP::MarginSides autoMargins() const { return mAutoMargins; }
98 QSize minimumSize() const { return mMinimumSize; }
99 QSize maximumSize() const { return mMaximumSize; }
100 QCPMarginGroup *marginGroup(QCP::MarginSide side) const { return mMarginGroups.value(side, (QCPMarginGroup*)0); }
101 QHash<QCP::MarginSide, QCPMarginGroup*> marginGroups() const { return mMarginGroups; }
102
103 // setters:
104 void setOuterRect(const QRect &rect);
105 void setMargins(const QMargins &margins);
106 void setMinimumMargins(const QMargins &margins);
107 void setAutoMargins(QCP::MarginSides sides);
108 void setMinimumSize(const QSize &size);
109 void setMinimumSize(int width, int height);
110 void setMaximumSize(const QSize &size);
111 void setMaximumSize(int width, int height);
112 void setMarginGroup(QCP::MarginSides sides, QCPMarginGroup *group);
113
114 // introduced virtual methods:
115 virtual void update(UpdatePhase phase);
116 virtual QSize minimumSizeHint() const;
117 virtual QSize maximumSizeHint() const;
118 virtual QList<QCPLayoutElement*> elements(bool recursive) const;
119
120 // reimplemented virtual methods:
121 virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const;
122
123 protected:
124 // property members:
125 QCPLayout *mParentLayout;
126 QSize mMinimumSize, mMaximumSize;
127 QRect mRect, mOuterRect;
128 QMargins mMargins, mMinimumMargins;
129 QCP::MarginSides mAutoMargins;
130 QHash<QCP::MarginSide, QCPMarginGroup*> mMarginGroups;
131
132 // introduced virtual methods:
133 virtual int calculateAutoMargin(QCP::MarginSide side);
134 // events:
135 virtual void mousePressEvent(QMouseEvent *event) {Q_UNUSED(event)}
136 virtual void mouseMoveEvent(QMouseEvent *event) {Q_UNUSED(event)}
137 virtual void mouseReleaseEvent(QMouseEvent *event) {Q_UNUSED(event)}
138 virtual void mouseDoubleClickEvent(QMouseEvent *event) {Q_UNUSED(event)}
139 virtual void wheelEvent(QWheelEvent *event) {Q_UNUSED(event)}
140
141 // reimplemented virtual methods:
142 virtual void applyDefaultAntialiasingHint(QCPPainter *painter) const { Q_UNUSED(painter) }
143 virtual void draw(QCPPainter *painter) { Q_UNUSED(painter) }
144 virtual void parentPlotInitialized(QCustomPlot *parentPlot);
145
146 private:
147 Q_DISABLE_COPY(QCPLayoutElement)
148
149 friend class QCustomPlot;
150 friend class QCPLayout;
151 friend class QCPMarginGroup;
152 };
153
154
155 class QCP_LIB_DECL QCPLayout : public QCPLayoutElement
156 {
157 Q_OBJECT
158 public:
159 explicit QCPLayout();
160
161 // reimplemented virtual methods:
162 virtual void update(UpdatePhase phase);
163 virtual QList<QCPLayoutElement*> elements(bool recursive) const;
164
165 // introduced virtual methods:
166 virtual int elementCount() const = 0;
167 virtual QCPLayoutElement* elementAt(int index) const = 0;
168 virtual QCPLayoutElement* takeAt(int index) = 0;
169 virtual bool take(QCPLayoutElement* element) = 0;
170 virtual void simplify();
171
172 // non-virtual methods:
173 bool removeAt(int index);
174 bool remove(QCPLayoutElement* element);
175 void clear();
176
177 protected:
178 // introduced virtual methods:
179 virtual void updateLayout();
180
181 // non-virtual methods:
182 void sizeConstraintsChanged() const;
183 void adoptElement(QCPLayoutElement *el);
184 void releaseElement(QCPLayoutElement *el);
185 QVector<int> getSectionSizes(QVector<int> maxSizes, QVector<int> minSizes, QVector<double> stretchFactors, int totalSize) const;
186
187 private:
188 Q_DISABLE_COPY(QCPLayout)
189 friend class QCPLayoutElement;
190 };
191
192
193 class QCP_LIB_DECL QCPLayoutGrid : public QCPLayout
194 {
195 Q_OBJECT
197 Q_PROPERTY(int rowCount READ rowCount)
198 Q_PROPERTY(int columnCount READ columnCount)
199 Q_PROPERTY(QList<double> columnStretchFactors READ columnStretchFactors WRITE setColumnStretchFactors)
200 Q_PROPERTY(QList<double> rowStretchFactors READ rowStretchFactors WRITE setRowStretchFactors)
201 Q_PROPERTY(int columnSpacing READ columnSpacing WRITE setColumnSpacing)
202 Q_PROPERTY(int rowSpacing READ rowSpacing WRITE setRowSpacing)
204 public:
205 explicit QCPLayoutGrid();
206 virtual ~QCPLayoutGrid();
207
208 // getters:
209 int rowCount() const;
210 int columnCount() const;
211 QList<double> columnStretchFactors() const { return mColumnStretchFactors; }
212 QList<double> rowStretchFactors() const { return mRowStretchFactors; }
213 int columnSpacing() const { return mColumnSpacing; }
214 int rowSpacing() const { return mRowSpacing; }
215
216 // setters:
217 void setColumnStretchFactor(int column, double factor);
218 void setColumnStretchFactors(const QList<double> &factors);
219 void setRowStretchFactor(int row, double factor);
220 void setRowStretchFactors(const QList<double> &factors);
221 void setColumnSpacing(int pixels);
222 void setRowSpacing(int pixels);
223
224 // reimplemented virtual methods:
225 virtual void updateLayout();
226 virtual int elementCount() const;
227 virtual QCPLayoutElement* elementAt(int index) const;
228 virtual QCPLayoutElement* takeAt(int index);
229 virtual bool take(QCPLayoutElement* element);
230 virtual QList<QCPLayoutElement*> elements(bool recursive) const;
231 virtual void simplify();
232 virtual QSize minimumSizeHint() const;
233 virtual QSize maximumSizeHint() const;
234
235 // non-virtual methods:
236 QCPLayoutElement *element(int row, int column) const;
237 bool addElement(int row, int column, QCPLayoutElement *element);
238 bool hasElement(int row, int column);
239 void expandTo(int newRowCount, int newColumnCount);
240 void insertRow(int newIndex);
241 void insertColumn(int newIndex);
242
243 protected:
244 // property members:
245 QList<QList<QCPLayoutElement*> > mElements;
246 QList<double> mColumnStretchFactors;
247 QList<double> mRowStretchFactors;
248 int mColumnSpacing, mRowSpacing;
249
250 // non-virtual methods:
251 void getMinimumRowColSizes(QVector<int> *minColWidths, QVector<int> *minRowHeights) const;
252 void getMaximumRowColSizes(QVector<int> *maxColWidths, QVector<int> *maxRowHeights) const;
253
254 private:
255 Q_DISABLE_COPY(QCPLayoutGrid)
256 };
257
258
259 class QCP_LIB_DECL QCPLayoutInset : public QCPLayout
260 {
261 Q_OBJECT
262 public:
266 enum InsetPlacement { ipFree
267 ,ipBorderAligned
268 };
269
270 explicit QCPLayoutInset();
271 virtual ~QCPLayoutInset();
272
273 // getters:
274 InsetPlacement insetPlacement(int index) const;
275 Qt::Alignment insetAlignment(int index) const;
276 QRectF insetRect(int index) const;
277
278 // setters:
279 void setInsetPlacement(int index, InsetPlacement placement);
280 void setInsetAlignment(int index, Qt::Alignment alignment);
281 void setInsetRect(int index, const QRectF &rect);
282
283 // reimplemented virtual methods:
284 virtual void updateLayout();
285 virtual int elementCount() const;
286 virtual QCPLayoutElement* elementAt(int index) const;
287 virtual QCPLayoutElement* takeAt(int index);
288 virtual bool take(QCPLayoutElement* element);
289 virtual void simplify() {}
290 virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const;
291
292 // non-virtual methods:
293 void addElement(QCPLayoutElement *element, Qt::Alignment alignment);
294 void addElement(QCPLayoutElement *element, const QRectF &rect);
295
296 protected:
297 // property members:
298 QList<QCPLayoutElement*> mElements;
299 QList<InsetPlacement> mInsetPlacement;
300 QList<Qt::Alignment> mInsetAlignment;
301 QList<QRectF> mInsetRect;
302
303 private:
304 Q_DISABLE_COPY(QCPLayoutInset)
305 };
306
307 #endif // QCP_LAYOUT_H
Generated with Doxygen 1.8.1.2