QSint Library  0.2.2
plotterbase.h
1 #ifndef PLOTTERBASE_H
2 #define PLOTTERBASE_H
3 
4 
5 #include <QPen>
6 #include <QBrush>
7 #include <QPainter>
8 #include <QMouseEvent>
9 #include <QWidget>
10 
11 #include <QtCore/QAbstractItemModel>
12 
13 
14 namespace QSint
15 {
16 
17 
18 class AxisBase;
19 
20 
36 class PlotterBase : public QWidget
37 {
38  Q_OBJECT
39 public:
40  explicit PlotterBase(QWidget *parent = 0);
41 
42 
44  void setBorderPen(const QPen &pen);
46  inline const QPen& borderPen() const { return m_pen; }
47 
49  void setBackground(const QBrush &brush);
51  inline const QBrush& background() const { return m_bg; }
52 
54  void setFont(const QFont &font);
56  inline const QFont& font() const { return m_font; }
57 
59  void setItemPen(const QPen &pen);
60  inline const QPen& itemPen() const { return m_itemPen; }
61 
63  void setHighlightTextColor(const QColor &color);
65  inline const QColor& highlightTextColor() const { return m_hlTextColor; }
66 
68  void setHighlightPen(const QPen &pen);
70  inline const QPen& highlightPen() const { return m_hlPen; }
71 
73  void setHighlightBrush(const QBrush &brush);
75  inline const QBrush& highlightBrush() const { return m_hlBrush; }
76 
79  void setHighlightAlpha(double alpha);
81  inline double highlightAlpha() const { return m_hlAlpha; }
82 
83 
85  inline void setAntiAliasing(bool set) { m_antiAliasing = set;}
86 
87 
89  inline AxisBase* axisX() const { return m_axisX; }
91  inline AxisBase* axisY() const { return m_axisY; }
92 
93 
95  void setModel(QAbstractItemModel *model);
97  inline QAbstractItemModel* model() const { return m_model; }
98 
99 
101  QRect dataRect() const;
102 
104  const QPoint& mousePos() const { return m_mousePos; }
106  QPoint globalMousePos() const { return mapToGlobal(m_mousePos); }
107 
109  const QModelIndex& highlightedIndex() const { return m_indexUnderMouse; }
110 
111 Q_SIGNALS:
114  void entered(const QModelIndex& index);
116  void pressed(const QModelIndex& index);
118  void clicked(const QModelIndex& index);
120  void doubleClicked(const QModelIndex& index);
121 
122 protected Q_SLOTS:
123  void scheduleUpdate();
124 
125 protected:
126  virtual void mousePressEvent(QMouseEvent *event);
127  virtual void mouseDoubleClickEvent(QMouseEvent *event);
128  virtual void mouseReleaseEvent(QMouseEvent *event);
129 
130  virtual void mouseMoveEvent(QMouseEvent *event);
131  virtual void leaveEvent(QMouseEvent *event);
132 
133  virtual void paintEvent(QPaintEvent *event);
134  virtual void resizeEvent(QResizeEvent *event);
135 
137  virtual void drawBackground(QPainter &p);
139  virtual void drawForeground(QPainter &p);
141  virtual void drawAxes(QPainter &p);
143  virtual void drawContent(QPainter &p) = 0;
144 
145  void setIndexUnderMouse(const QModelIndex& index);
146 
147  AxisBase *m_axisX;
148  AxisBase *m_axisY;
149 
150  QAbstractItemModel *m_model;
151 
152  QBrush m_bg;
153  QPen m_pen;
154 
155  QPen m_itemPen;
156  QFont m_font;
157 
158  QColor m_hlTextColor;
159  QPen m_hlPen;
160  QBrush m_hlBrush;
161  double m_hlAlpha;
162 
163  QPixmap m_buffer;
164  bool m_repaint;
165  bool m_antiAliasing;
166 
167  QPoint m_mousePos;
168  QModelIndex m_indexUnderMouse;
169  QModelIndex m_indexClick;
170 };
171 
172 
173 } // namespace
174 
175 #endif // PLOTTERBASE_H
void clicked(const QModelIndex &index)
Emitted when the mouse button has been clicked over the data item at index.
AxisBase * axisY() const
Retrieves Y axis object.
Definition: plotterbase.h:91
void pressed(const QModelIndex &index)
Emitted when the mouse button has been pressed over the data item at index.
const QBrush & highlightBrush() const
Retrieves highlighted data item brush.
Definition: plotterbase.h:75
QPoint globalMousePos() const
Retrieves current mouse cursor position in global coordinates.
Definition: plotterbase.h:106
void setHighlightPen(const QPen &pen)
Sets pen of the highlighted data item to pen.
Definition: plotterbase.cpp:62
const QFont & font() const
Retrieves data item font.
Definition: plotterbase.h:56
void setHighlightTextColor(const QColor &color)
Sets color of the highlighted data item text to color.
Definition: plotterbase.cpp:56
void setFont(const QFont &font)
Sets font of the data item to font.
Definition: plotterbase.cpp:50
void setBorderPen(const QPen &pen)
Sets pen of the plotter's border to pen.
Definition: plotterbase.cpp:32
const QColor & highlightTextColor() const
Retrieves highlighted data item text color.
Definition: plotterbase.h:65
const QModelIndex & highlightedIndex() const
Retrieves highlighted data model index, or invalid QModelIndex if nothing highlighted.
Definition: plotterbase.h:109
virtual void drawAxes(QPainter &p)
Draws axes of the plotter.
Definition: plotterbase.cpp:235
QAbstractItemModel * model() const
Retrieves active data model or NULL if not set.
Definition: plotterbase.h:97
double highlightAlpha() const
Retrieves highlighted data item opacity.
Definition: plotterbase.h:81
void setAntiAliasing(bool set)
Enables (set=true, the default) or disables (set=false) painter's antialiasing.
Definition: plotterbase.h:85
const QPoint & mousePos() const
Retrieves current mouse cursor position in local coordinates.
Definition: plotterbase.h:104
void entered(const QModelIndex &index)
void setBackground(const QBrush &brush)
Sets plotter's background to brush.
Definition: plotterbase.cpp:38
AxisBase * axisX() const
Retrieves X axis object.
Definition: plotterbase.h:89
const QBrush & background() const
Retrieves plotter background.
Definition: plotterbase.h:51
void setHighlightAlpha(double alpha)
Definition: plotterbase.cpp:74
Class representing single vertical or horizontal plotter axis.
Definition: axisbase.h:22
virtual void drawContent(QPainter &p)=0
Draws content of the plotter.
const QPen & highlightPen() const
Retrieves highlighted data item pen.
Definition: plotterbase.h:70
virtual void drawBackground(QPainter &p)
Draws default background of the plotter.
Definition: plotterbase.cpp:220
void setHighlightBrush(const QBrush &brush)
Sets brush of the highlighted data item to brush.
Definition: plotterbase.cpp:68
void setItemPen(const QPen &pen)
Sets pen of the data item to pen.
Definition: plotterbase.cpp:44
Base class for 2-dimensional plotter widgets.
Definition: plotterbase.h:36
const QPen & borderPen() const
Retrieves plotter's border pen.
Definition: plotterbase.h:46
void setModel(QAbstractItemModel *model)
Sets data model to model.
Definition: plotterbase.cpp:94
QRect dataRect() const
Retrieves data rectangle (excluding margins and axes).
Definition: plotterbase.cpp:80
virtual void drawForeground(QPainter &p)
Draws default foreground of the plotter.
Definition: plotterbase.cpp:226
void doubleClicked(const QModelIndex &index)
Emitted when the mouse button has been double clicked over the data item at index.

© Sintegrial Technologies 2011-2014
http://www.sintegrial.com