libkpl  5.0
A Library for Graphical Presentation of Data Sets and Functions
frameitem.h
1 /***************************************************************************
2  frameitem.h - description
3  -------------------
4 
5  This file is a part of kpl - a program for graphical presentation of
6  data sets and functions.
7 
8  begin : Sun Aug 29 1999
9  copyright : (C) 2017 by Werner Stille
10  email : kpl@werner-stille.de
11  ***************************************************************************/
12 
13 /***************************************************************************
14  * *
15  * This program is free software; you can redistribute it and/or modify *
16  * it under the terms of the GNU General Public License as published by *
17  * the Free Software Foundation; either version 2 of the License, or *
18  * (at your option) any later version. *
19  * *
20  ***************************************************************************/
21 
22 #ifndef FRAMEITEM_H
23 #define FRAMEITEM_H
24 
25 #include <math.h>
26 #include <QGraphicsRectItem>
27 #include "textitem.h"
28 
33 class Q_DECL_EXPORT FrameItem : public KplItem, public QGraphicsRectItem
34 {
35 public:
37  enum GridMode {
38  FrameOnly,
39  Axes,
40  AxesWithLabels,
41  Grid,
42  GridWithLabels
43  };
45  enum {
46  Type = UserType + Frame
48  };
85  FrameItem(double x0 = 4, double y0 = 3, double width = 15,
86  double height = 10, unsigned colorFrame = 0,
87  unsigned colorGrid = 0, bool logX = false, bool logY = false,
88  GridMode gridMode = AxesWithLabels, double xMax = 15,
89  double yMax = 10, const QString& textX = "",
90  const QString& textY = "", const QString& header = "",
91  double relSize = 1, int numDigX = -1, int numDigY = -1,
92  int minTicX = 5, int minTicY = 2, int expX = 0, int expY = 0,
93  double xMin = 0, double yMin = 0, double xTic = 5, double yTic = 2,
94  bool collapsed = false, bool visible = true, double xOffset = 0,
95  double yOffset = 0, bool xBottom = true, bool xTop = false,
96  bool yLeft = true, bool yRight = false);
101  FrameItem(const FrameItem& a);
113  FrameItem(const KConfigGroup* plo, double x0 = 4, double y0 = 3,
114  double width = 15, double height = 10, unsigned colorFrame = 0,
115  unsigned colorGrid = 0, GridMode gridMode = AxesWithLabels);
117  virtual ~FrameItem();
132  static void autoScale(double& xMin, double& xMax, double& tick, int& minTic,
133  int& numDig, double xmi, double xma, double f,
134  double c, bool log);
144  void autoScale(double xmi, double xma, double fx, double ymi, double yma,
145  double fy);
150  void autoScale(bool autoNorm = true);
152  virtual QRectF boundingRect() const;
161  bool calcAutoScale(bool autoNorm, const QList<QGraphicsItem*>& items,
162  double& fx, double& fy);
164  inline QRectF clipRect() const { return cRect; };
166  inline unsigned colorFrame() const { return m_colorFrame; };
168  inline unsigned colorGrid() const { return m_colorGrid; };
170  inline int expX() const { return m_expX; };
172  inline int expY() const { return m_expY; };
174  inline GridMode gridMode() const { return m_gridMode; };
176  inline QString header() const { return m_header; };
178  inline double height() const { return m_height; };
180  inline bool collapsed() const { return m_collapsed; };
182  inline bool logX() const { return m_logX; };
184  inline bool logY() const { return m_logY; };
190  QPointF mapFromUser(const QPointF& p) const;
196  QPointF mapToUser(const QPointF& p) const;
202  QRectF mapToUser(const QRectF& rect) const;
204  inline int minTicX() const { return m_minTicX; };
206  inline int minTicY() const { return m_minTicY; };
208  inline double normX() const { return m_normX; };
210  inline double normY() const { return m_normY; };
212  inline int numDigX() const { return m_numDigX; };
214  inline int numDigY() const { return m_numDigY; };
216  virtual void paint(QPainter* painter, const QStyleOptionGraphicsItem* option,
217  QWidget* widget = 0);
219  QPointF rectPos() const;
224  inline void setColorFrame(unsigned color) { m_colorFrame = color; };
229  inline void setColorGrid(unsigned color) { m_colorGrid = color; };
234  inline void setExpX(int expX) { m_expX = expX; m_normX = pow(10, expX); };
239  inline void setExpY(int expY) { m_expY = expY; m_normY = pow(10, expY); };
244  inline void setGridMode(GridMode gridMode) { m_gridMode = gridMode; };
249  inline void setHeight(double height) { m_height = height; };
254  inline void setLogX(bool logX) { m_logX = logX; };
259  inline void setLogY(bool logY) { m_logY = logY; };
264  inline void setMinTicX(int minTicX) { m_minTicX = minTicX; };
269  inline void setMinTicY(int minTicY) { m_minTicY = minTicY; };
274  inline void setNumDigX(int numDigX) { m_numDigX = numDigX; };
279  inline void setNumDigY(int numDigY) { m_numDigY = numDigY; };
284  void setProperties(const QTransform& m);
289  inline void setHeader(const QString& text) { m_header = text; };
294  inline void setTextX(const QString& text) { m_textX = text; };
299  inline void setTextY(const QString& text) { m_textY = text; };
304  inline void setWidth(double width) { m_width = width; };
309  inline void setX0(double x0) { m_x0 = x0; };
314  inline void setXBottom(bool xBottom) { m_xBottom = xBottom; };
319  inline void setXMax(double xMax) { m_xMax = xMax; };
324  inline void setXMin(double xMin) { m_xMin = xMin; };
329  inline void setXOffset(double xOffset) { m_xOffset = xOffset; };
334  inline void setXTic(double xTic) { m_xTic = xTic; };
339  inline void setXTop(bool xTop) { m_xTop = xTop; };
344  inline void setY0(double y0) { m_y0 = y0; };
349  inline void setYLeft(bool yLeft) { m_yLeft = yLeft; };
354  inline void setYMax(double yMax) { m_yMax = yMax; };
359  inline void setYMin(double yMin) { m_yMin = yMin; };
364  inline void setYOffset(double yOffset) { m_yOffset = yOffset; };
369  inline void setYRight(bool yRight) { m_yRight = yRight; };
374  inline void setYTic(double yTic) { m_yTic = yTic; };
376  QPointF steps() const;
378  inline QString textX() const { return m_textX; };
380  inline QString textY() const { return m_textY; };
382  virtual int type() const { return Type; };
384  inline void toggleCollapsed() { m_collapsed = !m_collapsed; };
386  void update();
391  void updatePos(QPointF p);
398  static inline bool valid(double v, bool log = false)
399  { return (v == v) && (fabs(v) <= 1e300) && ((!log) || (v > 0)); };
406  bool valid(double x, double y) const;
408  inline double width() const { return m_width; };
413  void writePlo(KConfigGroup* plo) const;
415  inline double x0() const { return m_x0; };
417  inline bool xBottom() const { return m_xBottom; };
419  inline double xMax() const { return m_xMax; };
421  inline double xMin() const { return m_xMin; };
423  inline double xOffset() const { return m_xOffset; };
425  inline double xTic() const { return m_xTic; };
427  inline bool xTop() const { return m_xTop; };
428  inline double y0() const { return m_y0; };
430  inline bool yLeft() const { return m_yLeft; };
432  inline bool yRight() const { return m_yRight; };
434  inline double yMax() const { return m_yMax; };
436  inline double yMin() const { return m_yMin; };
438  inline double yOffset() const { return m_yOffset; };
440  inline double yTic() const { return m_yTic; };
441 
442 protected:
452  void drawText(QPainter* painter, const QString& text, double x, double y,
453  TextItem::Alignment alignment, double dir = 0) const;
460  double incLog(double& x, double f) const;
462  virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent* event);
471  int number(double v, int numDig, QString& label) const;
476  void paintCond(QPainter* painter) const;
478  void setProperties();
485  double tick(double tic, bool log) const;
486  bool m_logX, m_logY, m_xBottom, m_xTop, m_yLeft, m_yRight, m_collapsed;
487  int m_numDigX, m_numDigY, m_minTicX, m_minTicY, m_expX, m_expY;
488  GridMode m_gridMode;
489  unsigned m_colorFrame, m_colorGrid;
490  double m_x0, m_y0, m_width, m_height, m_xMin, m_xMax, m_yMin, m_yMax, m_xTic,
491  m_yTic, m_xOffset, m_yOffset, m_normX, m_normY, xminl, xmaxl, yminl, ymaxl;
492  QString m_textX, m_textY, m_header;
493  mutable QRectF bRect;
494  QRectF cRect;
495  QTransform md, m_inv, m_matrix;
496 };
497 
498 #endif
KplItem::writePlo
void writePlo(KConfigGroup *plo, bool visible=true) const
Writes into plot file.
KplItem
Kpl item class.
Definition: kplitem.h:41
FrameItem::GridMode
GridMode
Grid mode.
Definition: frameitem.h:54
TextItem::Alignment
Alignment
Text alignment.
Definition: textitem.h:46
FrameItem
Frame item class.
Definition: frameitem.h:33