libkpl  5.0
A Library for Graphical Presentation of Data Sets and Functions
scalebaritem.h
1 /***************************************************************************
2  scalebaritem.h - description
3  -------------------
4  begin : Don Jun 12 2003
5  copyright : (C) 2017 by Werner Stille
6  email : kpl@werner-stille.de
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  ***************************************************************************/
17 
18 #ifndef SCALEBARITEM_H
19 #define SCALEBARITEM_H
20 
21 #include <QGraphicsItem>
22 #include <QTextDocument>
23 #include "decoitem.h"
24 
29 class Q_DECL_EXPORT ScaleBarItem : public DecoItem, public QGraphicsItem
30 {
31 public:
33  enum {Type = UserType + ScaleBar
37  };
50  ScaleBarItem(double x0 = 0, double y0 = 0, unsigned color = 0,
51  QGraphicsItem* parent = 0, double length = 1,
52  const QString& text = "", bool visible = true,
53  bool vertical = false, double relSize = 1);
58  ScaleBarItem(const ScaleBarItem& a);
65  ScaleBarItem(const KConfigGroup* plo, unsigned color = 0,
66  QGraphicsItem* parent = 0);
68  virtual ~ScaleBarItem();
70  virtual QRectF boundingRect() const;
72  inline double length() const { return m_length; };
74  virtual void paint(QPainter* painter, const QStyleOptionGraphicsItem* option,
75  QWidget* widget = 0);
77  QPixmap pixmap() const;
82  inline void setLength(double length) { m_length = length; };
87  void setProperties(const QTransform& m);
89  void setSize();
94  inline void setText(const QString& text) { m_text = text; };
99  inline void setVertical(bool vertical) { m_vertical = vertical; };
101  inline QString text() const { return m_text; };
103  virtual int type() const { return Type; };
105  void update();
107  inline bool vertical() const { return m_vertical; };
112  void writePlo(KConfigGroup* plo) const;
113 
114 protected:
116  void init();
118  virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent* event);
120  void setProperties();
122  QRectF textRect() const;
123  bool m_vertical;
124  double m_length, l2, wRel;
125  QString m_text;
126  QTextDocument m_doc;
127  QPen m_pen;
128 };
129 
130 #endif
virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
virtual int type() const
Returns specific QGraphicsItem type number.
Definition: scalebaritem.h:103
virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)=0
void writePlo(KConfigGroup *plo, bool visible) const
Writes into plot file.
void update(const QRectF &rect)
Scale bar item class.
Definition: scalebaritem.h:29
void setVertical(bool vertical)
Sets orientation.
Definition: scalebaritem.h:99
bool vertical() const
Returns true for vertical, false for horizontal orientation.
Definition: scalebaritem.h:107
void setLength(double length)
Sets length.
Definition: scalebaritem.h:82
static QPixmap pixmap(Symbol symbol)
Returns black decoration pixmap of plot symbol for use in dialog GUI.
virtual QRectF boundingRect() const =0
Decoration item class.
Definition: decoitem.h:35
QString text() const
Returns text.
Definition: scalebaritem.h:101
void setText(const QString &text)
Sets text.
Definition: scalebaritem.h:94
double length() const
Returns length in cm.
Definition: scalebaritem.h:72