libkpl  5.0
A Library for Graphical Presentation of Data Sets and Functions
legenditem.h
1 /***************************************************************************
2  legenditem.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 : Tue Aug 31 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 LEGENDITEM_H
23 #define LEGENDITEM_H
24 
25 #include <QGraphicsItem>
26 #include <QTextDocument>
27 #include "decoitem.h"
28 
29 class KConfigGroup;
30 
36 class Q_DECL_EXPORT LegendItem : public DecoItem, public QGraphicsItem
37 {
38 public:
40  enum {Type = UserType + Legend
44  };
60  LegendItem(double x0 = 0, double y0 = 0, unsigned colorSymbol = 0,
61  unsigned colorText = 0, Symbol symbol = SolidLine,
62  double xOff = 1, double yOff = 0, QGraphicsItem* parent = 0,
63  const QString& text = QString(), bool visible = true,
64  double relSize = 1, double symbolSize = 1);
69  LegendItem(const LegendItem& a);
79  LegendItem(const KConfigGroup* plo, unsigned colorSymbol, unsigned colorText,
80  Symbol symbol, double frameWidth, QGraphicsItem* parent = 0);
82  virtual ~LegendItem();
84  virtual QRectF boundingRect() const;
86  virtual void paint(QPainter* painter, const QStyleOptionGraphicsItem* option,
87  QWidget* widget = 0);
89  QPixmap pixmap() const;
94  void setProperties(const QTransform& m);
96  void setSize();
101  inline void setSymbol(Symbol symbol) { m_symbol = symbol; };
106  inline void setSymbolSize(double symbolSize) { m_symbolSize = symbolSize; };
111  inline void setText(const QString& text) { m_text = text; };
116  inline void setTextColor(unsigned color) { m_textColor = color; };
121  inline void setTextX(double x) { m_textX = x; };
126  inline void setTextY(double y) { m_textY = y; };
128  inline Symbol symbol() const { return m_symbol; };
130  inline double symbolSize() const { return m_symbolSize; };
132  inline QString text() const { return m_text; };
134  inline unsigned textColor() const { return m_textColor; };
136  inline double textX() const { return m_textX; };
138  inline double textY() const { return m_textY; };
140  virtual int type() const { return Type; };
142  void update();
147  void writePlo(KConfigGroup* plo) const;
148 
149 protected:
151  void init();
153  virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent* event);
155  void setProperties();
157  QRectF textRect() const;
158  Symbol m_symbol;
159  unsigned m_textColor;
160  double m_textX, m_textY, m_symbolSize;
161  QString m_text;
162  QTextDocument m_doc;
163  QPen m_pen;
164  QRectF symbRect;
165 };
166 
167 #endif
virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
QString text() const
Returns text.
Definition: legenditem.h:132
qreal x() const
qreal y() const
double textX() const
Returns x offset for text in cm.
Definition: legenditem.h:136
virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)=0
Symbol
Symbol types.
Definition: kplitem.h:83
virtual int type() const
Returns specific QGraphicsItem type number.
Definition: legenditem.h:140
double symbolSize() const
Returns relative symbol size.
Definition: legenditem.h:130
void writePlo(KConfigGroup *plo, bool visible) const
Writes into plot file.
void update(const QRectF &rect)
Legend item class.
Definition: legenditem.h:36
double textY() const
Returns y offset for text in cm.
Definition: legenditem.h:138
void setTextX(double x)
Sets x offset for text.
Definition: legenditem.h:121
void setSymbol(Symbol symbol)
Sets symbol type.
Definition: legenditem.h:101
void setTextColor(unsigned color)
Sets text color.
Definition: legenditem.h:116
void setText(const QString &text)
Sets text.
Definition: legenditem.h:111
Symbol symbol() const
Returns symbol type.
Definition: legenditem.h:128
unsigned textColor() const
Returns text color.
Definition: legenditem.h:134
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
void setSymbolSize(double symbolSize)
Sets symbol size.
Definition: legenditem.h:106
void setTextY(double y)
Sets y offset for text.
Definition: legenditem.h:126
unsigned color() const
Returns color.
Definition: decoitem.h:56