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
29class Q_DECL_EXPORT ScaleBarItem : public DecoItem, public QGraphicsItem
30{
31public:
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);
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
114protected:
116 void init();
118 virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent* event);
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
Decoration item class.
Definition: decoitem.h:36
Scale bar item class.
Definition: scalebaritem.h:30
void init()
Performs initialization.
void setVertical(bool vertical)
Sets orientation.
Definition: scalebaritem.h:99
ScaleBarItem(const ScaleBarItem &a)
Copy constructor.
virtual int type() const
Returns specific QGraphicsItem type number.
Definition: scalebaritem.h:103
void setLength(double length)
Sets length.
Definition: scalebaritem.h:82
void setSize()
Sets size according to transformation matrix.
void setProperties(const QTransform &m)
Sets properties according to transformation matrix.
QPixmap pixmap() const
Returns decoration pixmap for item list.
ScaleBarItem(double x0=0, double y0=0, unsigned color=0, QGraphicsItem *parent=0, double length=1, const QString &text="", bool visible=true, bool vertical=false, double relSize=1)
Constructor.
void setProperties()
Sets properties according to transformation matrix.
QRectF textRect() const
Returns text rectangle in pixel units.
virtual ~ScaleBarItem()
Destructor.
virtual QRectF boundingRect() const
Calculates bounding rectangle.
void update()
Applies changes and forces redrawing.
double length() const
Returns length in cm.
Definition: scalebaritem.h:72
void setText(const QString &text)
Sets text.
Definition: scalebaritem.h:94
ScaleBarItem(const KConfigGroup *plo, unsigned color=0, QGraphicsItem *parent=0)
Constructor.
virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
Updates position.
QString text() const
Returns text.
Definition: scalebaritem.h:101
virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget=0)
Paints item.
bool vertical() const
Returns true for vertical, false for horizontal orientation.
Definition: scalebaritem.h:107
void writePlo(KConfigGroup *plo) const
Writes into plot file.